Exemple #1
0
    def enterTypeDeclaration(self,
                             ctx: JavaParserLabeled.TypeDeclarationContext):

        if self.objective_class == ctx.classDeclaration().IDENTIFIER().getText(
        ):
            for i in range(0, len(ctx.classOrInterfaceModifier())):
                if ctx.classOrInterfaceModifier(i).getText() == "abstract":
                    self.token_stream_rewriter.replaceRange(
                        from_idx=ctx.classOrInterfaceModifier(
                            i).start.tokenIndex,
                        to_idx=ctx.classOrInterfaceModifier(i).stop.tokenIndex,
                        text="")
Exemple #2
0
    def exitTypeDeclaration(self,
                            ctx: JavaParserLabeled.TypeDeclarationContext):
        if ctx.classDeclaration() is not None:
            if not self.has_import or self.need_import:
                index = ctx.start.tokenIndex

                # delete class declaration from source class
                self.token_stream_rewriter.insertBefore(
                    program_name=self.token_stream_rewriter.
                    DEFAULT_PROGRAM_NAME,
                    index=index,
                    text="import " + self.target_package + '.' +
                    self.class_identifier + ';' + self.NEW_LINE)
Exemple #3
0
    def exitTypeDeclaration(self, ctx: JavaParserLabeled.TypeDeclarationContext):
        if ctx.classDeclaration() is not None:
            self.enter_class = False
            if ctx.classDeclaration().IDENTIFIER().getText() != self.class_identifier:
                return

            self.enter_class = True
            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
            )

            print("----------------------------")
            print("Class attributes: ", str(self.class_fields))
            print("Class methods: ", str(self.class_methods))
            print("----------------------------")