diff options
18 files changed, 513 insertions, 35 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_17Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_17Test.java index 8edd4b034a..ff9b531af8 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_17Test.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_17Test.java @@ -1,11 +1,14 @@ /******************************************************************************* - * Copyright (c) 2021 IBM Corporation and others. + * Copyright (c) 2021, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. * SPDX-License-Identifier: EPL-2.0 * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -30,6 +33,7 @@ public class ASTConverter_17Test extends ConverterTestSetup { ICompilationUnit workingCopy; + @SuppressWarnings("deprecation") public void setUpSuite() throws Exception { super.setUpSuite(); this.ast = AST.newAST(getAST17(), false); @@ -50,6 +54,7 @@ public class ASTConverter_17Test extends ConverterTestSetup { return buildModelTestSuite(ASTConverter_17Test.class); } + @SuppressWarnings("deprecation") static int getAST17() { return AST.JLS17; } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java index c2c802f8d9..b1a3b7bfa4 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2021 IBM Corporation and others. + * Copyright (c) 2000, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -7,6 +7,9 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. * * Contributors: * IBM Corporation - initial API and implementation @@ -1331,6 +1334,8 @@ public class ASTTest extends org.eclipse.jdt.core.tests.junit.extension.TestCase case JavaCore.VERSION_14: return AST.JLS14; case JavaCore.VERSION_15: return AST.JLS15; case JavaCore.VERSION_16: return AST.JLS16; + case JavaCore.VERSION_17: return AST.JLS17; + case JavaCore.VERSION_18: return AST.JLS18; default: return AST.JLS2; } } @@ -9495,7 +9500,8 @@ public class ASTTest extends org.eclipse.jdt.core.tests.junit.extension.TestCase ASTNode.TYPE_PATTERN, ASTNode.GUARDED_PATTERN, ASTNode.NULL_PATTERN, - ASTNode.CASE_DEFAULT_EXPRESSION + ASTNode.CASE_DEFAULT_EXPRESSION, + ASTNode.TAG_PROPERTY }; // assert that nodeType values are correct: @@ -9547,7 +9553,7 @@ public class ASTTest extends org.eclipse.jdt.core.tests.junit.extension.TestCase @SuppressWarnings("deprecation") public void testASTLevels() throws Exception { - int[] apilLevels = {AST.JLS2, AST.JLS3, AST.JLS4, AST.JLS8, AST.JLS9, AST.JLS10, AST.JLS11, AST.JLS12, AST.JLS13, AST.JLS14, AST.JLS15, AST.JLS16, AST.JLS17}; + int[] apilLevels = {AST.JLS2, AST.JLS3, AST.JLS4, AST.JLS8, AST.JLS9, AST.JLS10, AST.JLS11, AST.JLS12, AST.JLS13, AST.JLS14, AST.JLS15, AST.JLS16, AST.JLS17,AST.JLS18}; for (int level : apilLevels) { try { DOMASTUtil.checkASTLevel(level); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java index 4b1cd5a75c..927900172a 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2021 IBM Corporation and others. + * Copyright (c) 2000, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -12,10 +12,6 @@ * Community Process (JCP) and is made available for testing and evaluation purposes * only. The code is not compatible with any specification of the JCP. * - * This is an implementation of an early-draft specification developed under the Java - * Community Process (JCP) and is made available for testing and evaluation purposes - * only. The code is not compatible with any specification of the JCP. - * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -267,6 +263,7 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases { /** * Internal synonym for constant AST.JSL17 + * @deprecated */ protected static final int AST_INTERNAL_JLS17 = AST.JLS17; /** diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordDeclarationTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordDeclarationTest.java index d1b83434de..cdf1ea9a76 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordDeclarationTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordDeclarationTest.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2020, 2021 IBM Corporation and others. +* Copyright (c) 2020, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -8,6 +8,10 @@ * * SPDX-License-Identifier: EPL-2.0 * +* This is an implementation of an early-draft specification developed under the Java +* Community Process (JCP) and is made available for testing and evaluation purposes +* only. The code is not compatible with any specification of the JCP. +* * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -63,7 +67,6 @@ public class ASTRewritingRecordDeclarationTest extends ASTRewritingTest { protected void setUp() throws Exception { super.setUp(); setUpProjectAbove16(); - setUpProjectAbove17(); } @SuppressWarnings("deprecation") diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java index 0238c26c9e..2e37bdc419 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2021 IBM Corporation and others. + * Copyright (c) 2019, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -7,6 +7,11 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.core.tests.rewrite.describing; @@ -53,7 +58,6 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest { protected void setUp() throws Exception { super.setUp(); super.setUpProjectAbove14(); - setUpProjectAbove17(); } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java index 8e2b199360..ef92031660 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2021 IBM Corporation and others. + * Copyright (c) 2000, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -7,6 +7,11 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.core.tests.rewrite.describing; @@ -91,9 +96,12 @@ public class ASTRewritingTest extends AbstractJavaModelTests { /** @deprecated using deprecated code */ private final static int JLS16_INTERNAL = AST.JLS16; + /** @deprecated using deprecated code */ private final static int JLS17_INTERNAL = AST.JLS17; - private final static int[] JLS_LEVELS = { JLS2_INTERNAL, JLS3_INTERNAL, JLS4_INTERNAL, JLS8_INTERNAL, JLS9_INTERNAL, JLS10_INTERNAL, JLS14_INTERNAL, JLS15_INTERNAL, JLS16_INTERNAL, JLS17_INTERNAL}; + private final static int JLS18_INTERNAL = AST.JLS18; + + private final static int[] JLS_LEVELS = { JLS2_INTERNAL, JLS3_INTERNAL, JLS4_INTERNAL, JLS8_INTERNAL, JLS9_INTERNAL, JLS10_INTERNAL, JLS14_INTERNAL, JLS15_INTERNAL, JLS16_INTERNAL, JLS17_INTERNAL, JLS18_INTERNAL}; private static final String ONLY_AST_STRING = "_only"; private static final String SINCE_AST_STRING = "_since"; @@ -255,14 +263,25 @@ public class ASTRewritingTest extends AbstractJavaModelTests { this.project1.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_16); this.project1.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_16); } + setUpProjectAbove17(); } + @SuppressWarnings("deprecation") protected void setUpProjectAbove17() throws Exception { if (this.apiLevel == AST_INTERNAL_JLS17 ) { this.project1.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_17); this.project1.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_17); this.project1.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_17); } + setUpProjectAbove18(); + } + + protected void setUpProjectAbove18() throws Exception { + if (this.apiLevel == AST_INTERNAL_JLS18 ) { + this.project1.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_18); + this.project1.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_18); + this.project1.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_18); + } } protected IJavaProject createProject(String projectName, String complianceVersion) throws CoreException { diff --git a/org.eclipse.jdt.core/.settings/.api_filters b/org.eclipse.jdt.core/.settings/.api_filters index feb17db05e..0e08e484a6 100644 --- a/org.eclipse.jdt.core/.settings/.api_filters +++ b/org.eclipse.jdt.core/.settings/.api_filters @@ -1,5 +1,13 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <component id="org.eclipse.jdt.core" version="2"> + <resource path="META-INF/MANIFEST.MF"> + <filter comment="For Java 18" id="924844039"> + <message_arguments> + <message_argument value="3.29.0"/> + <message_argument value="3.29.0"/> + </message_arguments> + </filter> + </resource> <resource path="compiler/org/eclipse/jdt/core/compiler/CategorizedProblem.java" type="org.eclipse.jdt.core.compiler.CategorizedProblem"> <filter comment="Java 14" id="576725006"> <message_arguments> @@ -189,6 +197,20 @@ </message_arguments> </filter> </resource> + <resource path="dom/org/eclipse/jdt/core/dom/TagProperty.java" type="org.eclipse.jdt.core.dom.TagProperty"> + <filter id="576725006"> + <message_arguments> + <message_argument value="IDocElement"/> + <message_argument value="TagProperty"/> + </message_arguments> + </filter> + <filter id="576778288"> + <message_arguments> + <message_argument value="ASTNode"/> + <message_argument value="TagProperty"/> + </message_arguments> + </filter> + </resource> <resource path="dom/org/eclipse/jdt/core/dom/TextElement.java" type="org.eclipse.jdt.core.dom.TextElement"> <filter id="576725006"> <message_arguments> diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java index 67b4a96cdc..88cde6419f 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java @@ -375,7 +375,7 @@ public final class AST { * programs written in all versions of the Java language * up to and including Java SE 16(aka JDK 16). * </p> - * * @deprecated Clients should use the {@link #getJLSLatest()} AST API instead. + * @deprecated Clients should use the {@link #getJLSLatest()} AST API instead. * @since 3.26 */ public static final int JLS16 = 16; @@ -390,7 +390,7 @@ public final class AST { * programs written in all versions of the Java language * up to and including Java SE 17(aka JDK 17). * </p> - * + * @deprecated Clients should use the {@link #getJLSLatest()} AST API instead. * @since 3.28 */ public static final int JLS17 = 17; @@ -2933,7 +2933,7 @@ public final class AST { /** * Creates and returns a new tag element node. - * Initially the new node has no tag name and an empty list of fragments. + * Initially the new node has no tag name and an empty list of fragments and properties. * <p> * Note that this node type is used only inside doc comments * ({@link Javadoc}). @@ -2948,6 +2948,22 @@ public final class AST { } /** + * Creates and returns a new tag property node. + * Initially the new node has no property name and value. + * <p> + * Note that this node type is used only inside doc comments + * ({@link Javadoc}). + * </p> + * + * @return a new unparented tag element node + * @since 3.29 BETA_JAVA 18 + */ + public TagElement newTagProperty() { + TagElement result = new TagElement(this); + return result; + } + + /** * Creates an unparented yield statement node owned by this AST. The yield statement has no * label/identifier/expression and is not implicit. * diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java index 06785e378f..618a0cfd7c 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2021 IBM Corporation and others. + * Copyright (c) 2000, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -7,6 +7,9 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. * * Contributors: * IBM Corporation - initial API and implementation @@ -4994,6 +4997,7 @@ class ASTConverter { } protected void recordNodes(org.eclipse.jdt.internal.compiler.ast.Javadoc javadoc, TagElement tagElement) { + // To do: for Tag property Iterator fragments = tagElement.fragments().listIterator(); while (fragments.hasNext()) { ASTNode node = (ASTNode) fragments.next(); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java index 8e508471a2..274afc464f 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2021 IBM Corporation and others. + * Copyright (c) 2000, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -8,6 +8,9 @@ * * SPDX-License-Identifier: EPL-2.0 * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -2528,7 +2531,33 @@ public class ASTMatcher { TagElement o = (TagElement) other; return ( safeEquals(node.getTagName(), o.getTagName()) - && safeSubtreeListMatch(node.fragments(), o.fragments())); + && safeSubtreeListMatch(node.fragments(), o.fragments()) + && (DOMASTUtil.isJavaDocCodeSnippetSupported(node.getAST().apiLevel)? safeSubtreeListMatch(node.tagProperties(), o.tagProperties()) : true)); + } + + /** + * Returns whether the given node and the other object match. + * <p> + * The default implementation provided by this class tests whether the + * other object is a node of the same type with structurally isomorphic + * child subtrees. Subclasses may override this method as needed. + * </p> + * + * @param node the node + * @param other the other object, or <code>null</code> + * @return <code>true</code> if the subtree matches, or + * <code>false</code> if they do not match or the other object has a + * different node type or is <code>null</code> + * @since 3.29 BETA_JAVA 18 + */ + public boolean match(TagProperty node, Object other) { + if (!(other instanceof TagProperty)) { + return false; + } + TagProperty o = (TagProperty) other; + return ( + safeEquals(node.getName(), o.getName()) + && safeEquals(node.getValue(), o.getValue())); } /** diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java index 0e8ef9c4d2..b05a39e744 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2021 IBM Corporation and others. + * Copyright (c) 2000, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -1039,6 +1039,14 @@ public abstract class ASTNode { */ public static final int CASE_DEFAULT_EXPRESSION = 109; + /** + * Node type constant indicating a node of type + * <code>TagProperty</code>. + * @see TagProperty + * @since 3.29 BETA_JAVA 18 + */ + public static final int TAG_PROPERTY = 110; + /** * Returns the node class for the corresponding node type. @@ -1232,6 +1240,8 @@ public abstract class ASTNode { return SynchronizedStatement.class; case TAG_ELEMENT : return TagElement.class; + case TAG_PROPERTY : + return TagProperty.class; case TEXT_BLOCK : return TextBlock.class; case TEXT_ELEMENT : @@ -2277,6 +2287,22 @@ public abstract class ASTNode { } } + /** + * Checks that this AST operation is not used when + * building JLS2, JLS3, JLS4, JLS8, JLS9, JLS10, JLS11, JLS12, JLS13, JSL14, JSL15, JLS16 or JLS17 level ASTs. + * <p> + * Use this method to prevent access to new properties that have been added in JLS18 + * </p> + * + * @exception UnsupportedOperationException if this operation is used below JLS18 + * @since 3.29 BETA_JAVA 18 + */ + final void unsupportedBelow18() { + if (this.ast.apiLevel < AST.JLS18_INTERNAL) { + throw new UnsupportedOperationException("Operation only supported in ASTs with level JLS17 and above"); //$NON-NLS-1$ + } + } + /** * Checks that this AST operation is not used when diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTVisitor.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTVisitor.java index d8aa3f545c..506b39b2ec 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTVisitor.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTVisitor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2021 IBM Corporation and others. + * Copyright (c) 2000, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -7,6 +7,10 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -1690,6 +1694,23 @@ public abstract class ASTVisitor { return true; } + /** + * Visits the given type-specific AST node. + * <p> + * The default implementation does nothing and return true. + * Subclasses may reimplement. + * </p> + * + * @param node the node to visit + * @return <code>true</code> if the children of this node should be + * visited, and <code>false</code> if the children of this node should + * be skipped + * @since 3.29 BETA_JAVA 18 + */ + public boolean visit(TagProperty node) { + return true; + } + /** * Visits the given type-specific AST node. @@ -3129,6 +3150,19 @@ public abstract class ASTVisitor { * </p> * * @param node the node to visit + * @since 3.29 BETA_JAVA 18 + */ + public void endVisit(TagProperty node) { + // default implementation: do nothing + } + + /** + * End of visit the given type-specific AST node. + * <p> + * The default implementation does nothing. Subclasses may reimplement. + * </p> + * + * @param node the node to visit * @since 3.24 */ public void endVisit(TextBlock node) { diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultASTVisitor.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultASTVisitor.java index f692074d69..966f215006 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultASTVisitor.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultASTVisitor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -7,7 +7,10 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - *Contributors: + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.core.dom; @@ -353,6 +356,10 @@ class DefaultASTVisitor extends ASTVisitor { endVisitNode(node); } @Override + public void endVisit(TagProperty node) { + endVisitNode(node); + } + @Override public void endVisit(TextBlock node) { endVisitNode(node); } @@ -764,6 +771,11 @@ class DefaultASTVisitor extends ASTVisitor { } @Override + public boolean visit(TagProperty node) { + return visitNode(node); + } + + @Override public boolean visit(TextBlock node) { return visitNode(node); } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TagElement.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TagElement.java index 79ee908af1..e8e1835d37 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TagElement.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TagElement.java @@ -21,6 +21,8 @@ package org.eclipse.jdt.core.dom; import java.util.ArrayList; import java.util.List; +import org.eclipse.jdt.internal.core.dom.util.DOMASTUtil; + /** * AST node for a tag within a doc comment. * Tag elements nested within another tag element are called @@ -28,6 +30,7 @@ import java.util.List; * <pre> * TagElement: * [ <b>@</b> Identifier ] { DocElement } + * {tagProperty = tagValue} * DocElement: * TextElement * Name @@ -59,6 +62,13 @@ public final class TagElement extends ASTNode implements IDocElement { new ChildListPropertyDescriptor(TagElement.class, "fragments", IDocElement.class, CYCLE_RISK); //$NON-NLS-1$ /** + * The "properties" structural property of this node type (element type: {@link TagProperty}). + * @since 3.29 BETA_JAVA 18 + */ + public static final ChildListPropertyDescriptor TAG_PROPERTIES_PROPERTY = + new ChildListPropertyDescriptor(TagElement.class, "tagProperties", TagProperty.class, CYCLE_RISK); //$NON-NLS-1$ + + /** * A list of property descriptors (element type: * {@link StructuralPropertyDescriptor}), * or null if uninitialized. @@ -66,12 +76,28 @@ public final class TagElement extends ASTNode implements IDocElement { */ private static final List PROPERTY_DESCRIPTORS; + /** + * A list of property descriptors (element type: + * {@link StructuralPropertyDescriptor}), + * or null if uninitialized. + * @since 3.29 BETA_JAVA 18 + */ + private static final List PROPERTY_DESCRIPTORS_18; + static { List propertyList = new ArrayList(3); createPropertyList(TagElement.class, propertyList); addProperty(TAG_NAME_PROPERTY, propertyList); addProperty(FRAGMENTS_PROPERTY, propertyList); PROPERTY_DESCRIPTORS = reapPropertyList(propertyList); + + propertyList = new ArrayList(4); + createPropertyList(TagElement.class, propertyList); + addProperty(TAG_NAME_PROPERTY, propertyList); + addProperty(FRAGMENTS_PROPERTY, propertyList); + addProperty(TAG_PROPERTIES_PROPERTY, propertyList); + + PROPERTY_DESCRIPTORS_18 = reapPropertyList(propertyList); } /** @@ -85,6 +111,9 @@ public final class TagElement extends ASTNode implements IDocElement { * @since 3.0 */ public static List propertyDescriptors(int apiLevel) { + if (DOMASTUtil.isJavaDocCodeSnippetSupported(apiLevel)) { + return PROPERTY_DESCRIPTORS_18; + } return PROPERTY_DESCRIPTORS; } @@ -258,6 +287,13 @@ public final class TagElement extends ASTNode implements IDocElement { new ASTNode.NodeList(FRAGMENTS_PROPERTY); /** + * The list of doc elements (element type: {@link TagProperty}). + * Defaults to an empty list. + */ + private ASTNode.NodeList tagProperties = + new ASTNode.NodeList(TAG_PROPERTIES_PROPERTY); + + /** * Creates a new AST node for a tag element owned by the given AST. * The new node has no name and an empty list of fragments. * <p> @@ -295,6 +331,8 @@ public final class TagElement extends ASTNode implements IDocElement { final List internalGetChildListProperty(ChildListPropertyDescriptor property) { if (property == FRAGMENTS_PROPERTY) { return fragments(); + } else if (property == TAG_PROPERTIES_PROPERTY) { + return tagProperties(); } // allow default implementation to flag the error return super.internalGetChildListProperty(property); @@ -311,6 +349,9 @@ public final class TagElement extends ASTNode implements IDocElement { result.setSourceRange(getStartPosition(), getLength()); result.setTagName(getTagName()); result.fragments().addAll(ASTNode.copySubtrees(target, fragments())); + if (DOMASTUtil.isJavaDocCodeSnippetSupported(target.apiLevel)) { + result.tagProperties().addAll(ASTNode.copySubtrees(target, tagProperties())); + } return result; } @@ -325,6 +366,9 @@ public final class TagElement extends ASTNode implements IDocElement { boolean visitChildren = visitor.visit(this); if (visitChildren) { acceptChildren(visitor, this.fragments); + if (DOMASTUtil.isJavaDocCodeSnippetSupported(this.getAST().apiLevel)) { + acceptChildren(visitor, this.tagProperties); + } } visitor.endVisit(this); } @@ -410,6 +454,19 @@ public final class TagElement extends ASTNode implements IDocElement { } /** + * Returns the live list of tag properties in this tag element. + * + * @return the live list of properties in this tag element + * (element type: {@link TagProperty}) + * @exception UnsupportedOperationException if this operation is used less than JLS18 + * @since 3.29 BETA_JAVA 18 + */ + public List tagProperties() { + unsupportedBelow18(); + return this.tagProperties; + } + + /** * Returns whether this tag element is nested within another * tag element. Nested tag elements appears enclosed in * "{" and "}"; certain doc tags, including "@link" and @@ -438,6 +495,6 @@ public final class TagElement extends ASTNode implements IDocElement { @Override int treeSize() { - return memSize() + this.fragments.listSize(); + return memSize() + this.fragments.listSize() + (DOMASTUtil.isJavaDocCodeSnippetSupported(this.getAST().apiLevel)? this.tagProperties.listSize(): 0); } } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TagProperty.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TagProperty.java new file mode 100644 index 0000000000..e374125f96 --- /dev/null +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TagProperty.java @@ -0,0 +1,212 @@ +/******************************************************************************* + * Copyright (c) 2022 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.dom; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jdt.internal.core.dom.util.DOMASTUtil; + +/** + * TagProperty pattern AST node type. + * + * <pre> + * TagProperty: + * Name && Value + * </pre> + * + * @since 3.29 BETA_JAVA 18 + */ + +@SuppressWarnings("rawtypes") +public class TagProperty extends ASTNode implements IDocElement{ + + TagProperty(AST ast) { + super(ast); + supportedOnlyIn18(); + } + + /** + * The "name" structural property of this node type (added in JEP 413). + */ + public static final SimplePropertyDescriptor NAME_PROPERTY = new SimplePropertyDescriptor(TagProperty.class, "name", String.class, MANDATORY); //$NON-NLS-1$); + + /** + * The "value" structural property of this node type . (added in JEP 413). + */ + public static final SimplePropertyDescriptor VALUE_PROPERTY = + new SimplePropertyDescriptor(TagProperty.class, "value", String.class, MANDATORY); //$NON-NLS-1$); + + + /** + * A list of property descriptors (element type: + * {@link StructuralPropertyDescriptor}), + * or null if uninitialized. + */ + private static final List PROPERTY_DESCRIPTORS; + + static { + List propertyList = new ArrayList(3); + createPropertyList(TagProperty.class, propertyList); + addProperty(NAME_PROPERTY, propertyList); + addProperty(VALUE_PROPERTY, propertyList); + PROPERTY_DESCRIPTORS = reapPropertyList(propertyList); + } + + /** + * The property name + */ + private String name = null; + + /** + * The property value + */ + private String value = null; + + + + + @Override + List internalStructuralPropertiesForType(int apiLevel) { + return propertyDescriptors(apiLevel); + } + + + @Override + final Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, Object newValue) { + if (property == NAME_PROPERTY) { + if (get) { + return getName(); + } else { + setName((String)newValue); + return null; + } + } else if (property == VALUE_PROPERTY) { + if (get) { + return getValue(); + } else { + setValue((String)newValue); + return null; + } + } + // allow default implementation to flag the error + return super.internalGetSetObjectProperty(property, get, newValue); + } + + @Override + int getNodeType0() { + return GUARDED_PATTERN; + } + + @Override + boolean subtreeMatch0(ASTMatcher matcher, Object other) { + return matcher.match(this, other); + } + + @Override + ASTNode clone0(AST target) { + TagProperty result = new TagProperty(target); + result.setSourceRange(getStartPosition(), getLength()); + result.setName(getName()); + result.setName(getValue()); + return result; + } + + @Override + void accept0(ASTVisitor visitor) { + visitor.visit(this); + visitor.endVisit(this); + + } + + @Override + int memSize() { + return BASE_NODE_SIZE + 2 * 4 + stringSize(this.name) + stringSize(this.value); + } + + @Override + int treeSize() { + return memSize(); + } + + + /** + * Returns a list of structural property descriptors for this node type. + * Clients must not modify the result. + * + * @param apiLevel the API level; one of the + * <code>AST.JLS*</code> constants + + * @return a list of property descriptors (element type: + * {@link StructuralPropertyDescriptor}) + */ + public static List propertyDescriptors(int apiLevel) { + if (DOMASTUtil.isJavaDocCodeSnippetSupported(apiLevel)) { + return PROPERTY_DESCRIPTORS; + } + return null; + } + + /** + * Returns the name of this tag property. + * + * @return the name + */ + public String getName() { + unsupportedBelow18(); + return this.name; + } + + /** + * Returns the value of this tag property. + * @return the value + * @exception UnsupportedOperationException if this operation is used other than JLS18 + */ + public String getValue() { + unsupportedBelow18(); + return this.value; + } + + /** + * Sets the name of this tag property. + * + * @param name + * <ul> + * @exception UnsupportedOperationException if this operation is used below JLS18 + * </ul> + */ + public void setName(String name) { + unsupportedBelow18(); + preValueChange(NAME_PROPERTY); + this.name = name; + postValueChange(NAME_PROPERTY); + } + + /** + * Sets the value of this tag property. + * @param value + * @exception UnsupportedOperationException if this operation is used below JLS18 + */ + public void setValue(String value) { + unsupportedBelow18(); + preValueChange(VALUE_PROPERTY); + this.value = value; + postValueChange(VALUE_PROPERTY); + } + +} diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypePattern.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypePattern.java index f86030863c..5f20dc71b0 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypePattern.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypePattern.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021 IBM Corporation and others. + * Copyright (c) 2021, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -142,7 +142,7 @@ public class TypePattern extends Pattern { * <li>the node already has a parent</li> * <li>a cycle in would be created</li> * </ul> - * @exception UnsupportedOperationException if this operation is used other than JLS17 + * @exception UnsupportedOperationException if this operation is used other than JLS18 * @exception UnsupportedOperationException if this expression is used with previewEnabled flag as false * @noreference This method is not intended to be referenced by clients as it is a part of Java preview feature. */ @@ -162,7 +162,7 @@ public class TypePattern extends Pattern { * Returns the pattern variable of Types Pattern. * * @return the pattern variable - * @exception UnsupportedOperationException if this operation is used other than JLS17 + * @exception UnsupportedOperationException if this operation is used other than JLS18 * @exception UnsupportedOperationException if this expression is used with previewEnabled flag as false * @noreference This method is not intended to be referenced by clients as it is a part of Java preview feature. */ diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java index 7bb27c773c..da824edf69 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2021 IBM Corporation and others. + * Copyright (c) 2000, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -7,6 +7,10 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -1730,6 +1734,13 @@ public class NaiveASTFlattener extends ASTVisitor { e.accept(this); previousRequiresWhiteSpace = !currentIncludesWhiteSpace && !(e instanceof TagElement); } + if (DOMASTUtil.isJavaDocCodeSnippetSupported(node.getAST().apiLevel())) { + for (Iterator it = node.tagProperties().iterator(); it.hasNext(); ) { + TagProperty tagProperty = (TagProperty) it.next(); + tagProperty.accept(this); + } + + } if (node.isNested()) { this.buffer.append("}");//$NON-NLS-1$ } @@ -1737,6 +1748,18 @@ public class NaiveASTFlattener extends ASTVisitor { } @Override + public boolean visit(TagProperty node) { + this.buffer.append("\n{"); //$NON-NLS-1$ + this.buffer.append(node.getName()); + this.buffer.append(" = "); //$NON-NLS-1$ + this.buffer.append(node.getValue()); + this.buffer.append("}"); //$NON-NLS-1$ + return false; + } + + + + @Override public boolean visit(TextBlock node) { this.buffer.append(node.getEscapedValue()); return false; diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/util/DOMASTUtil.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/util/DOMASTUtil.java index 625c426613..50afdf90c7 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/util/DOMASTUtil.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/util/DOMASTUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2021 IBM Corporation and others. + * Copyright (c) 2019, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -8,6 +8,10 @@ * * SPDX-License-Identifier: EPL-2.0 * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -19,6 +23,7 @@ import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.Modifier; +@SuppressWarnings("deprecation") public class DOMASTUtil { /** @@ -54,7 +59,6 @@ public class DOMASTUtil { * @see ASTNode#getNodeType() * @since 3.22 */ - @SuppressWarnings("deprecation") private static boolean isNodeTypeSupportedinAST(int apiLevel, boolean previewEnabled, int nodeType) { switch (nodeType) { case ASTNode.SWITCH_EXPRESSION: @@ -67,6 +71,8 @@ public class DOMASTUtil { return apiLevel >= AST.JLS16; case ASTNode.TYPE_PATTERN: return apiLevel == AST.getJLSLatest() && previewEnabled; + case ASTNode.TAG_PROPERTY: + return apiLevel >= AST.JLS18; } return false; } @@ -181,7 +187,11 @@ public class DOMASTUtil { return isNodeTypeSupportedinAST(apiLevel, previewEnabled, ASTNode.TYPE_PATTERN); } - @SuppressWarnings("deprecation") + public static boolean isJavaDocCodeSnippetSupported(int apiLevel) { + return isNodeTypeSupportedinAST(apiLevel, true, ASTNode.TAG_PROPERTY); + } + + public static void checkASTLevel(int level) { // Clients can use AST.getJLSLatest() if(level >=AST.JLS8 && level <= AST.getJLSLatest() ) @@ -197,7 +207,7 @@ public class DOMASTUtil { private static final String[] AST_COMPLIANCE_MAP = {"-1","-1",JavaCore.VERSION_1_2, JavaCore.VERSION_1_3, JavaCore.VERSION_1_7, //$NON-NLS-1$ //$NON-NLS-2$ JavaCore.VERSION_1_7, JavaCore.VERSION_1_7, JavaCore.VERSION_1_7, JavaCore.VERSION_1_8, JavaCore.VERSION_9, JavaCore.VERSION_10, - JavaCore.VERSION_11, JavaCore.VERSION_12, JavaCore.VERSION_13, JavaCore.VERSION_14, JavaCore.VERSION_15, JavaCore.VERSION_16, JavaCore.VERSION_17}; + JavaCore.VERSION_11, JavaCore.VERSION_12, JavaCore.VERSION_13, JavaCore.VERSION_14, JavaCore.VERSION_15, JavaCore.VERSION_16, JavaCore.VERSION_17, JavaCore.VERSION_18}; /** * Calculates the JavaCore Option value string corresponding to the input ast level. @@ -206,7 +216,6 @@ public class DOMASTUtil { * @param astLevel * @return JavaCore Option value string corresponding to the ast level */ - @SuppressWarnings("deprecation") public static String getCompliance(int astLevel) { if (astLevel < AST.JLS2 && astLevel > AST.getJLSLatest()) return JavaCore.latestSupportedJavaVersion(); return AST_COMPLIANCE_MAP[astLevel]; |