def exitClassBodyDeclaration2( self, ctx: JavaParserLabeled.ClassBodyDeclaration2Context): self.enter_class = False try: if ctx.memberDeclaration().classDeclaration().IDENTIFIER().getText( ) != self.class_identifier: return except Exception: return self.class_found = True start_index = ctx.start.tokenIndex stop_index = ctx.stop.tokenIndex # get the class body from the token_stream_rewriter class_body = self.token_stream_rewriter.getText( program_name=self.token_stream_rewriter.DEFAULT_PROGRAM_NAME, start=start_index, stop=stop_index) self.code += f"import {self.source_package}.*;" self.code += self.NEW_LINE * 2 self.code += f"// Class \"{self.class_identifier}\" moved here " \ f"from package {self.source_package} by CodART" + self.NEW_LINE + \ f"{class_body}" # delete class declaration from source class self.token_stream_rewriter.delete( program_name=self.token_stream_rewriter.DEFAULT_PROGRAM_NAME, from_idx=start_index, to_idx=stop_index) old_file = open(self.filename, 'w') old_file.write(self.token_stream_rewriter.getDefaultText().replace( "\r", "")) print("----------------------------") print("Class attributes: ", str(self.class_fields)) print("Class methods: ", str(self.class_methods)) print("----------------------------")
def exitClassBodyDeclaration2( self, ctx: JavaParserLabeled.ClassBodyDeclaration2Context): if self.detected_method: self.rewriter.replaceSingleToken(token=ctx.modifier(0).start, text="private") self.detected_method = False
def exitClassBodyDeclaration2(self, ctx: JavaParserLabeled.ClassBodyDeclaration2Context): if self.detected_field: # print(ctx.getText()) if ctx.modifier(0) is not None: if "@" in ctx.modifier(0).getText(): if ctx.modifier(1) is not None: self.rewriter.replaceSingleToken( token=ctx.modifier(1).start, text="private " ) else: self.rewriter.replaceSingleToken( ctx.memberDeclaration().getChild(0).getChild(0).start, text="private " + ctx.memberDeclaration().getChild(0).getChild(0).getText() ) else: if ctx.modifier(0).getText() == 'public' or ctx.modifier(0).getText() == 'protected': self.rewriter.replaceSingleToken( token=ctx.modifier(0).start, text="private " ) else: self.rewriter.insertBeforeToken( token=ctx.modifier(0).start, text="private " ) else: if ctx.memberDeclaration().getChild(0).getChild(0) is not None: self.rewriter.insertBeforeToken( ctx.memberDeclaration().getChild(0).getChild(0).start, text="private " ) # print("private " + ctx.memberDeclaration().getText()) self.detected_field = False