Ejemplo n.º 1
0
 def exitLocalVariableDeclaration(
         self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):
     if ctx.typeType().getText() == self.source_class:
         self.aul.add_identifier(
             (ctx.variableDeclarators().variableDeclarator(
                 0).variableDeclaratorId().IDENTIFIER().getText(),
              self.scope))
Ejemplo n.º 2
0
 def enterLocalVariableDeclaration(self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):
     if self.inCreator:
         variable_type = ctx.typeType().classOrInterfaceType().IDENTIFIER(0)
         if variable_type.symbol.text in self.products_identifier:
             self.productVarTypeIndex.append(variable_type.symbol.tokenIndex)
             self.productVarValueIndex.append([variable_type.symbol.text,
                                               ctx.variableDeclarators().variableDeclarator(
                                                   0).ASSIGN().symbol.tokenIndex, ctx.stop.tokenIndex])
Ejemplo n.º 3
0
 def enterLocalVariableDeclaration(self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):
     if ctx.typeType().getText() == self.target_class:
         self.detected_instance_of_target_class.append(
             ctx.variableDeclarators().variableDeclarator(0).variableDeclaratorId().IDENTIFIER().getText())
         self.token_stream_rewriter.delete(
             program_name=self.token_stream_rewriter.DEFAULT_PROGRAM_NAME,
             from_idx=ctx.start.tokenIndex,
             to_idx=ctx.stop.tokenIndex + 1
         )
Ejemplo n.º 4
0
 def enterLocalVariableDeclaration(
         self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):
     if ctx.typeType().classOrInterfaceType():
         if ctx.typeType().classOrInterfaceType().getText(
         ) == self.source_class and self.target_class:
             self.token_stream_rewriter.replace(
                 program_name=self.token_stream_rewriter.
                 DEFAULT_PROGRAM_NAME,
                 from_idx=ctx.typeType().start.tokenIndex,
                 to_idx=ctx.typeType().stop.tokenIndex,
                 text=self.target_class)
Ejemplo n.º 5
0
    def exitLocalVariableDeclaration(
            self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):
        try:
            instance_class_name = ctx.variableDeclarators().variableDeclarator(0) \
                .variableInitializer().expression().creator() \
                .createdName().getText()

            if (self.has_access_to_class and instance_class_name == self.source_class_name) \
                    or instance_class_name == self.package_name + '.' + self.source_class_name:
                self.instances.append(
                    ctx.variableDeclarators().variableDeclarator(
                        0).variableDeclaratorId().getText())
        except:
            pass
Ejemplo n.º 6
0
 def enterLocalVariableDeclaration(
         self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):
     if not self.enter_class:
         if ctx.start.text == self.class_identifier:
             start = ctx.variableDeclarators().variableDeclarator(
                 0).ASSIGN().symbol.tokenIndex + 1
             end = ctx.stop.tokenIndex
             self.ObjectIndex.append([start, end])
Ejemplo n.º 7
0
    def exitLocalVariableDeclaration(
            self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):
        if ctx.typeType().getText() == self.source_class:
            flag = False
            for child in ctx.variableDeclarators().children:
                if child.getText() != ',':
                    id_ = child.variableDeclaratorId().IDENTIFIER().getText()
                    fields_used = self.aul.get_identifier_fields(
                        (id_, self.scope))
                    methods_used = self.aul.get_identifier_methods(
                        (id_, self.scope))

                    if len(self.intersection(
                            fields_used, self.moved_fields)) > 0 or len(
                                self.intersection(methods_used,
                                                  self.moved_methods)) > 0:
                        flag = True

            if flag:
                self.token_stream_rewriter.replaceRange(
                    from_idx=ctx.typeType().start.tokenIndex,
                    to_idx=ctx.typeType().stop.tokenIndex,
                    text=f"{self.new_class}")

                for child in ctx.variableDeclarators().children:
                    if child.getText() != ',':
                        if type(child.children[-1]) == JavaParserLabeled.VariableInitializer1Context and \
                                type(child.children[-1].children[0]) == JavaParserLabeled.Expression4Context and \
                                child.children[-1].children[0].children[0].getText() == 'new' and \
                                len(child.children[-1].children[0].children) > 1 and \
                                type(child.children[-1].children[0].children[1]) == JavaParserLabeled.Creator1Context:
                            if child.variableInitializer().expression(
                            ).creator().createdName().getText(
                            ) == self.source_class:
                                self.token_stream_rewriter.replaceRange(
                                    from_idx=child.
                                    variableInitializer().expression().creator(
                                    ).createdName().start.tokenIndex,
                                    to_idx=child.variableInitializer(
                                    ).expression().creator().createdName(
                                    ).stop.tokenIndex,
                                    text=f"{self.new_class}")
Ejemplo n.º 8
0
    def enterLocalVariableDeclaration(
            self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):

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

            # checks if this statement is not in extracting lines
            if not set(range(ctx.start.line, ctx.stop.line + 1)).issubset(
                    set(self.lines)):

                # checks if this statement is before extracting lines
                if ctx.start.line < self.last_line:

                    # adding all created variables
                    for var in ctx.variableDeclarators().variableDeclarator():
                        self.pre_variables[var.variableDeclaratorId().getText()] = \
                            {
                                'type': ctx.typeType().getText(),
                                'write': str(var.getText()).__contains__('=')
                            }

                # this statement is after extracting lines
                else:
                    pass

            # this statement is inside extracting lines
            else:

                # adding all created variables
                for var in ctx.variableDeclarators().variableDeclarator():
                    self.mid_variables[
                        var.variableDeclaratorId().getText()] = \
                        {
                            'type': ctx.typeType().getText(),
                            'write': str(var.getText()).__contains__('=')
                        }
 def enterLocalVariableDeclaration(
         self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):
     self.local_variables.append(ctx.getText())