From 9fa5766ae352ffc8a92ff38fa754bbc18dcb6da1 Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Thu, 23 May 2024 15:39:31 +0200 Subject: [PATCH] Updated JDT UI to AST changes around AbstractUnnamedTypeDeclaration Requires https://github.com/eclipse-jdt/eclipse.jdt.core/pull/2483 See https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2481 --- .../corext/dom/HierarchicalASTVisitor.java | 29 +++++-------------- .../core/HierarchicalASTVisitorTest.java | 19 ------------ .../ui/refactoring/reorg/PasteAction.java | 9 +++--- 3 files changed, 12 insertions(+), 45 deletions(-) diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/HierarchicalASTVisitor.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/HierarchicalASTVisitor.java index d2906230079..2243e1c93b9 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/HierarchicalASTVisitor.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/HierarchicalASTVisitor.java @@ -115,11 +115,11 @@ public void endVisit(BodyDeclaration node) { //---- Begin AbstractTypeDeclaration Hierarchy --------------------------- public boolean visit(AbstractTypeDeclaration node) { - return visit((AbstractUnnamedTypeDeclaration)node); + return visit((BodyDeclaration)node); } public void endVisit(AbstractTypeDeclaration node) { - endVisit((AbstractUnnamedTypeDeclaration)node); + endVisit((BodyDeclaration)node); } @Override @@ -154,37 +154,24 @@ public void endVisit(TypeDeclaration node) { //---- End AbstractTypeDeclaration Hierarchy --------------------------- - //---- Begin AbstractUnnamedTypeDeclaration Hierarchy --------------------------- - - public boolean visit(AbstractUnnamedTypeDeclaration node) { + @Override + public boolean visit(AnnotationTypeMemberDeclaration node) { return visit((BodyDeclaration)node); } - public void endVisit(AbstractUnnamedTypeDeclaration node) { + @Override + public void endVisit(AnnotationTypeMemberDeclaration node) { endVisit((BodyDeclaration)node); } @Override public boolean visit(ImplicitTypeDeclaration node) { - return visit((AbstractUnnamedTypeDeclaration)node); + return visit((AbstractTypeDeclaration)node); } @Override public void endVisit(ImplicitTypeDeclaration node) { - endVisit((AbstractUnnamedTypeDeclaration)node); - } - - //---- End AbstractUnnamedTypeDeclaration Hierarchy --------------------------- - - - @Override - public boolean visit(AnnotationTypeMemberDeclaration node) { - return visit((BodyDeclaration)node); - } - - @Override - public void endVisit(AnnotationTypeMemberDeclaration node) { - endVisit((BodyDeclaration)node); + endVisit((AbstractTypeDeclaration)node); } @Override diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/HierarchicalASTVisitorTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/HierarchicalASTVisitorTest.java index 07d7a9842dd..4ca3d82da70 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/HierarchicalASTVisitorTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/HierarchicalASTVisitorTest.java @@ -32,7 +32,6 @@ import org.eclipse.jdt.core.dom.AbstractTagElement; import org.eclipse.jdt.core.dom.AbstractTextElement; import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; -import org.eclipse.jdt.core.dom.AbstractUnnamedTypeDeclaration; import org.eclipse.jdt.core.dom.AnnotatableType; import org.eclipse.jdt.core.dom.Annotation; import org.eclipse.jdt.core.dom.BodyDeclaration; @@ -168,24 +167,6 @@ public void superEndVisit(AbstractTextElement node) { super.visit(node); } - @Override - public boolean visit(AbstractUnnamedTypeDeclaration node) { - registerCall(AbstractUnnamedTypeDeclaration.class); - return false; - } - @SuppressWarnings("unused") // called reflectively - public void superVisit(AbstractUnnamedTypeDeclaration node) { - super.visit(node); - } - @Override - public void endVisit(AbstractUnnamedTypeDeclaration node) { - registerCall(AbstractUnnamedTypeDeclaration.class); - } - @SuppressWarnings("unused") // called reflectively - public void superEndVisit(AbstractUnnamedTypeDeclaration node) { - super.visit(node); - } - @Override public boolean visit(Comment node) { registerCall(Comment.class); diff --git a/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/PasteAction.java b/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/PasteAction.java index d499f03fc29..8389340e841 100644 --- a/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/PasteAction.java +++ b/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/PasteAction.java @@ -108,7 +108,6 @@ import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; -import org.eclipse.jdt.core.dom.AbstractUnnamedTypeDeclaration; import org.eclipse.jdt.core.dom.Block; import org.eclipse.jdt.core.dom.BodyDeclaration; import org.eclipse.jdt.core.dom.CompilationUnit; @@ -429,14 +428,14 @@ private static List parseAsTypes(String text, CompilationUnit unit) { } ArrayList cus= new ArrayList<>(); - List types= unit.types(); + List types= unit.types(); int startOffset= 0; String typeName= null; int maxVisibility= JdtFlags.VISIBILITY_CODE_INVALID; // Public types must be in separate CUs: - for (AbstractUnnamedTypeDeclaration type : types) { + for (AbstractTypeDeclaration type : types) { if (typeName == null) { // first in group: maxVisibility= JdtFlags.getVisibilityCode(type); @@ -468,8 +467,8 @@ private static List parseAsTypes(String text, CompilationUnit unit) { return cus; } - private static String getTypeName(AbstractUnnamedTypeDeclaration type) { - return type instanceof AbstractTypeDeclaration named? named.getName().getIdentifier() : ""; //$NON-NLS-1$ + private static String getTypeName(AbstractTypeDeclaration type) { + return type.getName().getIdentifier(); } private ParsedCu(String text, int kind, String typeName, String packageName) {