コード例 #1
0
 def enterExpression(self, ctx: JavaParser.ExpressionContext):
     if self.current_method is not None:
         if ctx.methodCall() is not None:
             txt = ctx.getText()
             ids = txt[:txt.find('(')].split('.')
             self.current_method.body_local_vars_and_expr_names.append(
                 MethodInvocation(ids, ctx))
         else:
             names = ctx.getText().split('.')
             should_add = True
             for name in names:
                 if not re.match("^[A-Za-z0-9_]*$", name):
                     should_add = False
             if should_add:
                 self.current_method.body_local_vars_and_expr_names.append(
                     ExpressionName(names, ctx))
コード例 #2
0
    def enterExpression(self, ctx: JavaParser.ExpressionContext):
        text = ctx.getText()

        # if we reached expression this.field
        if text == f"this.{self.field_name}":
            self.usages.append(ctx)
            return

        # if we reached expression Source.field
        if text == f"{self.source_class}.{self.field_name}":
            self.usages.append(ctx)
            return

        if text != self.field_name:
            return

        # if we reached field and there is no local declaration with the same name as field
        if len(self.stack) == 0:
            self.usages.append(ctx)
コード例 #3
0
 def propagate_field(self, ctx: JavaParser.ExpressionContext,
                     target_name: str):
     index = ctx.DOT().symbol.tokenIndex
     self.rewriter.replaceRange(ctx.start.tokenIndex, index - 1,
                                target_name)