Beispiel #1
0
 def enterPrimary4(self, ctx: JavaParserLabeled.Primary4Context):
     if self.fields:
         field_name = ctx.getText()
         if field_name in self.fields and field_name not in self.moved_fields:
             self.fields.remove(field_name)
             self.token_stream_rewriter.insertBeforeToken(token=ctx.start,
                                                          text="ref.")
Beispiel #2
0
 def exitPrimary4(self, ctx: JavaParserLabeled.Primary4Context):
     if self.is_package_imported \
             or self.package_identifier is None \
             or self.in_selected_package:
         if ctx.getText() == self.class_identifier:
             self.token_stream_rewriter.replaceIndex(
                 index=ctx.start.tokenIndex, text=self.class_new_name)
Beispiel #3
0
    def enterPrimary4(self, ctx: JavaParserLabeled.Primary4Context):

        # checks if we are in target method
        if self.is_in_target_method:

            # print('entering:',ctx.getText())
            # print(self.assigning_value_pre)
            # print(self.assigning_value_mid)
            # print(self.assigning_value_post)

            # writing value to a variable in mid
            if self.assigning_value_mid:

                # adding variable
                action = 'write'
                if (isinstance(ctx.parentCtx.parentCtx,
                               JavaParserLabeled.Expression1Context) and ctx.parentCtx.parentCtx.DOT()) or \
                        (isinstance(ctx.parentCtx.parentCtx,
                                    JavaParserLabeled.Expression2Context) and ctx.parentCtx.parentCtx.LBRACK()):
                    # print("exiting:", ctx.getText())
                    action = 'read'
                if self.mid_variables.keys().__contains__(str(
                        ctx.IDENTIFIER())):
                    self.mid_variables[str(ctx.IDENTIFIER())][action] = True
                else:
                    self.mid_variables[str(ctx.IDENTIFIER())] = {action: True}
                self.assigning_value_mid = False

            # writing value to a variable in pre
            elif self.assigning_value_pre:

                # adding variable
                action = 'write'
                if (isinstance(ctx.parentCtx.parentCtx,
                               JavaParserLabeled.Expression1Context) and ctx.parentCtx.parentCtx.DOT()) or \
                        (isinstance(ctx.parentCtx.parentCtx,
                                    JavaParserLabeled.Expression2Context) and ctx.parentCtx.parentCtx.LBRACK()):
                    # print("exiting:", ctx.getText())
                    action = 'read'
                if self.pre_variables.keys().__contains__(str(
                        ctx.IDENTIFIER())):
                    self.pre_variables[str(ctx.IDENTIFIER())][action] = True
                else:
                    self.pre_variables[str(ctx.IDENTIFIER())] = {action: True}
                self.assigning_value_pre = False

            # writing value to a variable in post
            elif self.assigning_value_post:

                # adding variable
                action = 'write'
                if (isinstance(ctx.parentCtx.parentCtx,
                               JavaParserLabeled.Expression1Context) and ctx.parentCtx.parentCtx.DOT()) or \
                        (isinstance(ctx.parentCtx.parentCtx,
                                    JavaParserLabeled.Expression2Context) and ctx.parentCtx.parentCtx.LBRACK()):
                    # print("exiting:", ctx.getText())
                    action = 'read'
                if self.post_variables.keys().__contains__(
                        str(ctx.IDENTIFIER())):
                    self.post_variables[str(ctx.IDENTIFIER())][action] = True
                else:
                    self.post_variables[str(ctx.IDENTIFIER())] = {action: True}
                self.assigning_value_post = False

            # reading a variable value not in extracting lines
            elif not set(range(ctx.start.line, ctx.stop.line + 1)).issubset(
                    set(self.lines)):

                # checks if this statement is after extracting lines
                if ctx.start.line > self.last_line:

                    # adding variable to post_variables
                    if self.post_variables.keys().__contains__(
                            str(ctx.IDENTIFIER())):
                        self.post_variables[str(
                            ctx.IDENTIFIER())]['read'] = True
                    else:
                        self.post_variables[str(ctx.IDENTIFIER())] = {
                            'read': True
                        }

                # this statement is before extracting lines
                else:
                    pass

            # this statement is inside extracting lines
            else:
                if self.mid_variables.keys().__contains__(str(
                        ctx.IDENTIFIER())):
                    self.mid_variables[str(ctx.IDENTIFIER())]['read'] = True
                else:
                    self.mid_variables[str(ctx.IDENTIFIER())] = {'read': True}
Beispiel #4
0
 def enterPrimary4(self, ctx: JavaParserLabeled.Primary4Context):
     if self.is_inside_rule is not None:
         if self.variable_info['variables'].keys().__contains__(
                 str(ctx.IDENTIFIER())):
             self.used_variables.add(str(ctx.IDENTIFIER()))