def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): if ctx.IDENTIFIER().getText() == self.class_name: self.implement_token_index = ctx.IDENTIFIER().symbol.tokenIndex if ctx.EXTENDS() is not None: self.implement_state.append(ctx.EXTENDS().getText()) self.implement_token_index = ctx.typeType().stop.tokenIndex if ctx.IMPLEMENTS() is not None: self.implement_state.append(ctx.IMPLEMENTS().getText()) self.implement_token_index = ctx.typeList().typeType()[-1].stop.tokenIndex
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): if ctx.IDENTIFIER().getText() == self.creator_identifier: self.inCreator = True self.CretorStartIndex = ctx.classBody().start.tokenIndex self.currentClass = ctx.IDENTIFIER().symbol.text elif ctx.IDENTIFIER().getText() in self.products_identifier: self.inProducts = True self.productsClassIndex.append(ctx.IDENTIFIER().symbol.tokenIndex) self.currentClass = ctx.IDENTIFIER().symbol.text
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): print(ctx.IDENTIFIER().getText()) if self.objective_class == ctx.IDENTIFIER().getText(): print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&") print(ctx.CLASS().getText()) self.token_stream_rewriter.replaceRange(from_idx=0, to_idx=0, text="abstract " + ctx.CLASS().getText())
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): if ctx.IDENTIFIER().getText() == self.SuperClass_identifier: self.InSuperClass = True elif ctx.IDENTIFIER().getText() in self.SubClass_identifier: self.InSubClass = True elif ctx.IDENTIFIER().getText() == "Main": self.InMainClass = True if ctx.EXTENDS().__str__() == "extends": # SubClass Headers Rename self.token_stream_rewriter.insertAfter(ctx.start.tokenIndex + 4, "implements") self.token_stream_rewriter.deleteIndex(ctx.start.tokenIndex + 4)
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): if len(self.interface_info['name']) > 0: return # Todo: requires better handling if not hasattr(ctx.parentCtx, 'classOrInterfaceModifier'): return if ctx.parentCtx.classOrInterfaceModifier() is not None: if len(ctx.parentCtx.classOrInterfaceModifier()) > 0: if ctx.parentCtx.classOrInterfaceModifier()[0].getText() == "public": self.current_class = ctx.IDENTIFIER().getText() self.interface_info['name'] = self.current_class else: self.current_class = ctx.IDENTIFIER().getText() self.interface_info['name'] = self.current_class
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): print("Propagation started, please wait...") class_identifier = ctx.IDENTIFIER().getText() if class_identifier in self.propagated_class_name: self.is_class = True else: self.is_class = False if class_identifier in self.propagated_class_name: self.token_stream_rewriter.replaceRange( from_idx=ctx.start.tokenIndex, to_idx=ctx.typeType().stop.tokenIndex, text=ctx.CLASS().getText() + ' ' + ctx.IDENTIFIER().getText())
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): classIdentifier = ctx.IDENTIFIER().getText() ctxParent = ctx.parentCtx if self.Method: for i in range(len(self.Methods)): if self.Methods[i].split('/')[0] == classIdentifier: self.IsSourceClassForMethods[i] = True if self.Field: for i in range(len(self.Fields)): if self.Fields[i].split('/')[0] == classIdentifier: self.IsSourceClassForFields[i] = True if self.Variable: for i in range(len(self.Variables)): if self.Variables[i].split('/')[0] == classIdentifier: self.IsSourceClassForVariables[i] = True if self.Parameter: for i in range(len(self.Parameters)): if self.Parameters[i].split('/')[0] == classIdentifier: self.IsSourceClassForParameters[i] = True if self.Class and self.ClassIndex < len(self.Classes) and self.Classes[ self.ClassIndex] == classIdentifier: startIndex = ctxParent.start.tokenIndex stopIndex = ctxParent.stop.tokenIndex self.CodeRewrite.delete(self.CodeRewrite.DEFAULT_PROGRAM_NAME, startIndex, stopIndex) self.ClassIndex += 1
def exitClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): class_identifier = ctx.IDENTIFIER().getText() if class_identifier == self.source_class: self.is_source_class = False elif self.is_source_class is True: self.inner_class_count -= 1
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): class_identifier = ctx.IDENTIFIER().getText() if class_identifier == self.source_class: self.is_source_class = True else: self.is_source_class = False
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): class_identifier = ctx.IDENTIFIER().getText() if class_identifier == self.target_class: self.is_target_class = True self.target_class_data = {'constructors': []} else: self.is_target_class = False
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): if ctx.IDENTIFIER().getText() == self.class_identifier: self.enter_class = True new_code = "\n\tprivate static " + self.class_identifier + " Instance = null;\n\t" self.token_stream_rewriter.insertAfter( ctx.classBody().start.tokenIndex + 1, new_code) self.addInstance = True
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): print("Propagation started, please wait...") class_identifier = ctx.IDENTIFIER().getText() if class_identifier in self.propagated_class_name: self.is_class = True else: self.is_class = False
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): if self.is_package_imported or self.in_selected_package: if ctx.IDENTIFIER().getText() == self.class_identifier: self.token_stream_rewriter.replaceIndex( index=ctx.start.tokenIndex + 2, text=self.class_new_name) change_file_name(self.class_identifier, self.class_new_name) print("class name : " + self.class_identifier + " in class declaration changed ")
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): """check if the class is the source class Args: ctx (JavaParserLabeled.ClassDeclarationContext) """ print("Refactoring started, please wait...") self.is_source_class = ( ctx.IDENTIFIER().getText() == self.source_class)
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): class_identifier = ctx.IDENTIFIER().getText() if class_identifier in self.propagated_class_name: self.is_class = True else: # Enter other class self.is_class = False
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): class_identifier = ctx.IDENTIFIER().getText() if class_identifier in self.children_class: self.is_children_class = True else: # Enter another class self.is_children_class = False
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): class_identifier = ctx.IDENTIFIER().getText() if class_identifier == self.child_class: self.is_source_class = True self.fieldcode += self.NEW_LINE * 2 self.fieldcode += f"// child class({self.child_class}) fields: " + self.NEW_LINE else: self.is_source_class = False
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): # self.target_class = ctx.IDENTIFIER().getText() # have_constructor = False # if ctx.IDENTIFIER().getText() == class_identifier = ctx.IDENTIFIER().getText() if class_identifier == self.target_class: self.is_target_class = True # print("class name " + ctx.IDENTIFIER().getText()) else: self.is_target_class = False
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): if self.package_identifier is None \ and not self.in_some_package \ or self.package_identifier is not None \ and self.in_selected_package: if ctx.IDENTIFIER().getText() == self.class_identifier: print("Class Found") self.in_selected_class = True self.token_stream_rewriter.replaceIndex( index=ctx.start.tokenIndex + 2, text=self.class_new_name) self.changed = True
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): class_identifier = ctx.IDENTIFIER().getText() if class_identifier in self.parent_class: self.is_parent_class = True elif class_identifier in self.child_class: self.is_child_class = True else: print("enter other class") self.is_parent_class = False
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): print("self.objective_class: ", self.objective_class) class_identifier = ctx.IDENTIFIER().getText() ctxparent = ctx.parentCtx if self.objective_class == class_identifier: start_index = ctxparent.start.tokenIndex stop_index = ctxparent.stop.tokenIndex self.token_stream_rewriter.delete( program_name=self.token_stream_rewriter.DEFAULT_PROGRAM_NAME, from_idx=start_index, to_idx=stop_index) self.detected_method = None
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): """ It checks if it is source class, we generate the declaration of the new class, by appending some text to self.code. """ class_identifier = ctx.IDENTIFIER().getText() if class_identifier == self.source_class: self.is_source_class = True self.code += self.NEW_LINE * 2 self.code += f"// New class({self.new_class}) generated by CodART" + self.NEW_LINE self.code += f"class {self.new_class} extends {self.source_class}{self.NEW_LINE}" + "{" + self.NEW_LINE self.code += f"public {self.new_class}()" + "{ }" + self.NEW_LINE else: self.is_source_class = False
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): name = ctx.IDENTIFIER().getText() if name == self.class_name: self.in_class = True
def exitClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): class_name = ctx.IDENTIFIER().getText() if self.is_source_class and class_name == self.source_class: self.is_source_class = False
def exitClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): if self.is_package_imported or self.in_selected_package: if ctx.IDENTIFIER().getText() == self.class_identifier: self.in_class = False
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): self.current_class = ctx.IDENTIFIER().getText()
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): if ctx.IDENTIFIER().getText() != self.class_identifier: return self.enter_class = True
def enterClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): if ctx.IDENTIFIER().getText() == self.source_class_name: self.in_source_class = True
def exitClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): if ctx.IDENTIFIER().getText() == self.source_class: self.in_class = False
def exitClassDeclaration(self, ctx: JavaParserLabeled.ClassDeclarationContext): clas.append(ctx.getText()) if ctx.IDENTIFIER().getText() == self.class_name: found_class.append(ctx.IDENTIFIER().getText())