Example #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))
Example #2
0
 def enterLocalVariableDeclaration(
         self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):
     if self.class_identifier == ctx.typeType().classOrInterfaceType(
     ).IDENTIFIER(0).getText():
         self.token_stream_rewriter.replaceIndex(
             index=ctx.typeType().classOrInterfaceType().start.tokenIndex,
             text=self.class_new_name)
         print("creator changed")
Example #3
0
    def exitLocalVariableDeclaration(self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):
        if ctx.typeType() is None:
            return

        local_variable_type = ctx.typeType().getText()
        if local_variable_type in self.file_classes:
            log_error("Forbidden", "This class has local variables that dependent on other classes")
            exit(0)
Example #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
             )
Example #5
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)
Example #6
0
 def enterLocalVariableDeclaration(
         self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):
     if self.inCreator == True:
         variableType = ctx.typeType().classOrInterfaceType().IDENTIFIER(0)
         if variableType.symbol.text in self.products_identifier:
             self.productVarTypeIndex.append(variableType.symbol.tokenIndex)
             self.productVarValueIndex.append([
                 variableType.symbol.text,
                 ctx.variableDeclarators().variableDeclarator(
                     0).ASSIGN().symbol.tokenIndex, ctx.stop.tokenIndex
             ])
Example #7
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
Example #8
0
 def enterLocalVariableDeclaration(
         self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):
     if self.enter_class == False:
         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])
Example #9
0
 def enterLocalVariableDeclaration(
         self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):
     # print('dec detected')
     if self.is_in_target_method:
         # print('inside target with :', ctx.getText())
         if set(range(ctx.start.line,
                      ctx.stop.line + 1)).issubset(set(self.lines)):
             # print('dec in extract lines')
             self.remain_lines = self.remain_lines.union(
                 range(ctx.start.line, ctx.stop.line + 1))
             # self.extract_lines =
             # print('new remain lines :', self.remain_lines)
         elif not ctx.start.line > max(self.lines):
             # print('dec not in extract lines')
             self.variable_info['variables'][ctx.variableDeclarators(
             ).variableDeclarator()[0].variableDeclaratorId().getText(
             )] = ctx.typeType().getText()
Example #10
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 == True:
                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}")
Example #11
0
    def enterLocalVariableDeclaration(
            self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):
        if self.isRelevant:
            pass

        else:
            for child in ctx.variableDeclarators().variableDeclarator():
                self.lastOccurance[
                    child.variableDeclaratorId().getText()] = ctx.parentCtx
                self.relevantVariableValue = child.variableInitializer(
                ).getText()
Example #12
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__('=')
                        }
Example #13
0
 def enterLocalVariableDeclaration(
         self, ctx: JavaParserLabeled.LocalVariableDeclarationContext):
     self.local_variables.append(ctx.getText())