Exemple #1
0
 def enterImportDeclaration(
         self, ctx: JavaParserLabeled.ImportDeclarationContext):
     if ctx.getText() == "import" + self.package_identifier + "." + self.class_identifier + ";" \
             or ctx.getText() == "import" + self.package_identifier + ".*" + ";" \
             or ctx.getText() == "import" + self.package_identifier + ";":
         self.is_package_imported = True
         print("package " + self.package_identifier + " imported")
Exemple #2
0
 def enterImportDeclaration(
         self, ctx: JavaParserLabeled.ImportDeclarationContext):
     if ctx.qualifiedName().IDENTIFIER()[-1].getText(
     ) == self.package_identifier:
         if self.package_new_name not in self.packages_name:
             self.token_stream_rewriter.replaceIndex(
                 index=ctx.qualifiedName().start.tokenIndex +
                 (2 * len(ctx.qualifiedName().IDENTIFIER()) - 2),
                 text=self.package_new_name)
             print("package name in import changed")
Exemple #3
0
 def enterImportDeclaration(self, ctx: JavaParserLabeled.ImportDeclarationContext):
     if ctx.getText() == "import" + self.package_identifier + "." + self.class_identifier + ";" \
             or ctx.getText() == "import" + self.package_identifier + ".*" + ";" \
             or ctx.getText() == "import" + self.package_identifier + ";":
         self.is_package_imported = True
         print("package " + self.package_identifier + " imported")
     if ctx.getText() == "import" + self.package_identifier + "." + self.class_identifier + ";":
         self.token_stream_rewriter.replaceIndex(
             index=ctx.qualifiedName().start.tokenIndex + 2 * len(ctx.qualifiedName().IDENTIFIER()) - 2,
             text=self.class_new_name)
         print("class name in package changed")
Exemple #4
0
    def enterImportDeclaration(
            self, ctx: JavaParserLabeled.ImportDeclarationContext):
        # import source_package.Sample;
        if self.target_package in ctx.getText():
            self.imported = True
            if self.class_name in ctx.getText():
                if self.target_package == self.current_package:
                    replace_text = ""
                else:
                    replace_text = f"\nimport {self.target_package}.{self.class_name};\n"

                self.rewriter.replaceRangeTokens(
                    from_token=ctx.start,
                    to_token=ctx.stop,
                    text=replace_text,
                    program_name=self.rewriter.DEFAULT_PROGRAM_NAME)
        elif f"{self.source_package}.{self.class_name}" in ctx.getText():
            self.rewriter.delete(
                program_name=self.rewriter.DEFAULT_PROGRAM_NAME,
                from_idx=ctx.start.tokenIndex,
                to_idx=ctx.stop.tokenIndex)
Exemple #5
0
 def enterImportDeclaration(
         self, ctx: JavaParserLabeled.ImportDeclarationContext):
     if ctx.qualifiedName().getText() == self.package_name + '.' + self.source_class_name \
             or ctx.qualifiedName().getText() == self.package_name:
         self.has_access_to_class = True
Exemple #6
0
 def enterImportDeclaration(
         self, ctx: JavaParserLabeled.ImportDeclarationContext):
     if f"{self.target_package}.{self.child_class}" in ctx.getText():
         self.detected_package = True
     self.import_end = ctx.stop