diff options
author | Markus Keller | 2016-08-22 17:43:20 +0000 |
---|---|---|
committer | Markus Keller | 2016-08-22 18:06:31 +0000 |
commit | 5c83e7a4a08150ff31eef9f7d80db9ef25943b59 (patch) | |
tree | c1647dbcca8716b21b349da4b18ed373ff8e342b /org.eclipse.jdt.core | |
parent | 89dfaeda9ff01ed8fed9fe34161c42f73eecae73 (diff) | |
download | eclipse.jdt.core-5c83e7a4a08150ff31eef9f7d80db9ef25943b59.tar.gz eclipse.jdt.core-5c83e7a4a08150ff31eef9f7d80db9ef25943b59.tar.xz eclipse.jdt.core-5c83e7a4a08150ff31eef9f7d80db9ef25943b59.zip |
Bug 487780: [1.9] [DOM] AST changes for java 9
properly deprecated JLS8
Diffstat (limited to 'org.eclipse.jdt.core')
27 files changed, 208 insertions, 164 deletions
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 797047795e..42327575f6 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 @@ -117,7 +117,7 @@ public final class AST { * </p> * * @since 3.0 - * @deprecated Clients should use the {@link #JLS8} AST API instead. + * @deprecated Clients should use the {@link #JLS9} AST API instead. */ public static final int JLS2 = 2; @@ -141,7 +141,7 @@ public final class AST { * </p> * * @since 3.1 - * @deprecated Clients should use the {@link #JLS8} AST API instead. + * @deprecated Clients should use the {@link #JLS9} AST API instead. */ public static final int JLS3 = 3; @@ -165,7 +165,7 @@ public final class AST { * </p> * * @since 3.7.1 - * @deprecated Clients should use the {@link #JLS8} AST API instead. + * @deprecated Clients should use the {@link #JLS9} AST API instead. */ public static final int JLS4 = 4; @@ -189,10 +189,18 @@ public final class AST { * </p> * * @since 3.10 + * @deprecated Clients should use the {@link #JLS9} AST API instead. */ public static final int JLS8 = 8; /** + * Internal synonym for {@link #JLS8}. Use to alleviate + * deprecation warnings. + * @since 3.13 BETA_JAVA9 + */ + /*package*/ static final int JLS8_INTERNAL = JLS8; + + /** * Constant for indicating the AST API that handles JLS9. * <p> * This API is capable of handling all constructs in the @@ -298,7 +306,7 @@ public final class AST { * Creates a new Java abstract syntax tree * (AST) following the specified set of API rules. * <p> - * Clients should use this method specifying {@link #JLS8} as the + * Clients should use this method specifying {@link #JLS9} as the * AST level in all cases, even when dealing with source of earlier JDK versions like 1.3 or 1.4. * </p> * @@ -678,8 +686,8 @@ public final class AST { * Creates a new, empty abstract syntax tree using default options. * * @see JavaCore#getDefaultOptions() - * @deprecated Clients should port their code to use the new JLS4 AST API and call - * {@link #newAST(int) AST.newAST(AST.JLS4)} instead of using this constructor. + * @deprecated Clients should port their code to use the latest JLS* AST API and call + * {@link #newAST(int) AST.newAST(AST.JLS9)} instead of using this constructor. */ public AST() { this(JavaCore.getDefaultOptions()); @@ -721,7 +729,7 @@ public final class AST { null/*taskPriorities*/, true/*taskCaseSensitive*/); break; - case JLS8 : + case JLS8_INTERNAL : this.apiLevel = level; // initialize a scanner this.scanner = new Scanner( @@ -773,8 +781,8 @@ public final class AST { * @param options the table of options (key type: <code>String</code>; * value type: <code>String</code>) * @see JavaCore#getDefaultOptions() - * @deprecated Clients should port their code to use the new JLS4 AST API and call - * {@link #newAST(int) AST.newAST(AST.JLS4)} instead of using this constructor. + * @deprecated Clients should port their code to use the latest JLS* AST API and call + * {@link #newAST(int) AST.newAST(AST.JLS9)} instead of using this constructor. */ public AST(Map options) { this(JLS2); @@ -1164,7 +1172,7 @@ public final class AST { */ public ArrayType newArrayType(Type elementType) { ArrayType result; - if (this.apiLevel < AST.JLS8) { + if (this.apiLevel < JLS8_INTERNAL) { result = new ArrayType(this); setArrayComponentType(result, elementType); return result; @@ -1208,7 +1216,7 @@ public final class AST { throw new IllegalArgumentException(); } ArrayType result; - if (this.apiLevel < AST.JLS8) { + if (this.apiLevel < JLS8_INTERNAL) { if (dimensions < 1) { throw new IllegalArgumentException(); } 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 b19fc5a096..c20728c0c2 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 @@ -476,7 +476,7 @@ class ASTConverter { protected void completeRecord(ArrayType arrayType, org.eclipse.jdt.internal.compiler.ast.ASTNode astNode) { ArrayType array = arrayType; this.recordNodes(arrayType, astNode); - if (this.ast.apiLevel() >= AST.JLS8) { + if (this.ast.apiLevel() >= AST.JLS8_INTERNAL) { this.recordNodes(arrayType.getElementType(), astNode); return; } @@ -520,7 +520,7 @@ class ASTConverter { int methodHeaderEnd = methodDeclaration.sourceEnd; int thrownExceptionsLength = thrownExceptions == null ? 0 : thrownExceptions.length; if (thrownExceptionsLength > 0) { - if (this.ast.apiLevel() < AST.JLS8) { + if (this.ast.apiLevel() < AST.JLS8_INTERNAL) { Name thrownException; int i = 0; do { @@ -544,7 +544,7 @@ class ASTConverter { } if (methodDeclaration.receiver != null) { - if(this.ast.apiLevel >= AST.JLS8) { + if(this.ast.apiLevel >= AST.JLS8_INTERNAL) { convertAndSetReceiver(methodDeclaration, methodDecl); } else { methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); @@ -590,7 +590,7 @@ class ASTConverter { // get the positions of the right parenthesis int rightParenthesisPosition = retrieveEndOfRightParenthesisPosition(end, method.bodyEnd); int extraDimensions = typeReference.extraDimensions(); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { setExtraAnnotatedDimensions(rightParenthesisPosition, method.bodyEnd, typeReference, methodDecl.extraDimensions(), extraDimensions); } else { @@ -650,7 +650,7 @@ class ASTConverter { } if (block != null) { if ((methodDeclaration.modifiers & (ClassFileConstants.AccAbstract | ClassFileConstants.AccNative)) != 0 - || (isInterface && (this.ast.apiLevel < AST.JLS8 || + || (isInterface && (this.ast.apiLevel < AST.JLS8_INTERNAL || (methodDeclaration.modifiers & (ClassFileConstants.AccStatic | ExtraCompilerModifiers.AccDefaultMethod)) == 0))) { methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); } @@ -913,7 +913,7 @@ class ASTConverter { final int typeSourceEnd = argument.type.sourceEnd; TypeReference typeReference = argument.type; final int extraDimensions = typeReference.extraDimensions(); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { setExtraAnnotatedDimensions(nameEnd + 1, typeSourceEnd, typeReference, variableDecl.extraDimensions(), extraDimensions); } else { @@ -933,7 +933,7 @@ class ASTConverter { */ if (isVarArgs) { Dimension lastDimension = null; - if (this.ast.apiLevel() >= AST.JLS8) { + if (this.ast.apiLevel() >= AST.JLS8_INTERNAL) { if (type.isArrayType()) { // should always be true List dimensions = ((ArrayType) type).dimensions(); if (!dimensions.isEmpty()) { @@ -943,7 +943,7 @@ class ASTConverter { } setTypeForSingleVariableDeclaration(variableDecl, type, extraDimensions + 1); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=391898 - if (this.ast.apiLevel() >= AST.JLS8) { + if (this.ast.apiLevel() >= AST.JLS8_INTERNAL) { if (lastDimension != null) { // should always be true List annotations = lastDimension.annotations(); Iterator iter = annotations.iterator(); @@ -1016,7 +1016,7 @@ class ASTConverter { if (type.isArrayType()) { arrayType = (ArrayType) type; if (expression.annotationsOnDimensions != null) { - if (this.ast.apiLevel() < AST.JLS8) { + if (this.ast.apiLevel() < AST.JLS8_INTERNAL) { arrayType.setFlags(arrayType.getFlags() | ASTNode.MALFORMED); } else { setTypeAnnotationsAndSourceRangeOnArray(arrayType, expression.annotationsOnDimensions); @@ -2215,7 +2215,7 @@ class ASTConverter { } public Expression convert(org.eclipse.jdt.internal.compiler.ast.LambdaExpression lambda) { - if (this.ast.apiLevel < AST.JLS8) { + if (this.ast.apiLevel < AST.JLS8_INTERNAL) { return createFakeNullLiteral(lambda); } final LambdaExpression lambdaExpression = new LambdaExpression(this.ast); @@ -2573,7 +2573,7 @@ class ASTConverter { } public Expression convert(org.eclipse.jdt.internal.compiler.ast.ReferenceExpression reference) { - if (this.ast.apiLevel < AST.JLS8) { + if (this.ast.apiLevel < AST.JLS8_INTERNAL) { return createFakeNullLiteral(reference); } Expression result = null; @@ -2863,7 +2863,7 @@ class ASTConverter { tryStatement.setFlags(tryStatement.getFlags() | ASTNode.MALFORMED); break; case AST.JLS4_INTERNAL: - case AST.JLS8: + case AST.JLS8_INTERNAL: for (int i = 0; i < resourcesLength; i++) { if (!(statement.resources[i] instanceof LocalDeclaration)) { tryStatement.setFlags(tryStatement.getFlags() | ASTNode.MALFORMED); @@ -3183,7 +3183,7 @@ class ASTConverter { private ArrayType convertToArray(Type elementType, int sourceStart, int length, int dimensions, org.eclipse.jdt.internal.compiler.ast.Annotation[][] annotationsOnDimensions) { ArrayType arrayType = this.ast.newArrayType(elementType, dimensions); if (length > 0) arrayType.setSourceRange(sourceStart, length); - if (this.ast.apiLevel() < AST.JLS8) { + if (this.ast.apiLevel() < AST.JLS8_INTERNAL) { if (annotationsOnDimensions != null) { arrayType.setFlags(arrayType.getFlags() | ASTNode.MALFORMED); } @@ -3296,7 +3296,7 @@ class ASTConverter { variableDecl.setName(name); TypeReference typeReference = localDeclaration.type; final int extraDimensions = typeReference.extraDimensions(); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { setExtraAnnotatedDimensions(nameEnd + 1, localDeclaration.declarationSourceEnd, typeReference, variableDecl.extraDimensions(), extraDimensions); } else { @@ -3344,7 +3344,7 @@ class ASTConverter { int end = start; TypeReference typeReference = fieldDeclaration.type; int extraDimensions = typeReference.extraDimensions(); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { setExtraAnnotatedDimensions(fieldDeclaration.sourceEnd + 1, fieldDeclaration.declarationSourceEnd, typeReference, variableDeclarationFragment.extraDimensions(), extraDimensions); } else { @@ -3388,7 +3388,7 @@ class ASTConverter { org.eclipse.jdt.internal.compiler.ast.Expression initialization = localDeclaration.initialization; TypeReference typeReference = localDeclaration.type; int extraDimension = typeReference.extraDimensions(); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { setExtraAnnotatedDimensions(localDeclaration.sourceEnd + 1, this.compilationUnitSourceLength, typeReference, variableDeclarationFragment.extraDimensions(), extraDimension); } else { @@ -3934,7 +3934,7 @@ class ASTConverter { } boolean createNameQualifiedType = typeAnnotations != null && typeAnnotations[firstTypeIndex] != null; - if (createNameQualifiedType && this.ast.apiLevel >= AST.JLS8) { + if (createNameQualifiedType && this.ast.apiLevel >= AST.JLS8_INTERNAL) { NameQualifiedType nameQualifiedType = new NameQualifiedType(this.ast); nameQualifiedType.setQualifier(name); nameQualifiedType.setName(createSimpleName(typeReference, positions, tokens, firstTypeIndex)); @@ -5659,7 +5659,7 @@ class ASTConverter { fieldDeclaration.setType(type); } } else { - if (type.isArrayType() && (this.ast.apiLevel() < AST.JLS8)) { + if (type.isArrayType() && (this.ast.apiLevel() < AST.JLS8_INTERNAL)) { // update positions of the component types of the array type int dimensions = ((ArrayType) type).getDimensions(); updateInnerPositions(type, dimensions); @@ -5677,7 +5677,7 @@ class ASTConverter { private ArrayType extractSubArrayType(ArrayType arrayType, int remainingDimensions, int dimensionsToRemove) { ArrayType subArrayType = arrayType; int start = subArrayType.getStartPosition(); - if (this.ast.apiLevel() < AST.JLS8) { + if (this.ast.apiLevel() < AST.JLS8_INTERNAL) { while (dimensionsToRemove > 0 ) { subArrayType = (ArrayType) componentType(subArrayType); dimensionsToRemove--; 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 088f31425a..070bb52684 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 @@ -335,7 +335,7 @@ public class ASTMatcher { } ArrayType o = (ArrayType) other; int level = node.getAST().apiLevel; - if (level < AST.JLS8) { + if (level < AST.JLS8_INTERNAL) { return safeSubtreeMatch(componentType(node), componentType(o)); } return safeSubtreeMatch(node.getElementType(), o.getElementType()) @@ -1474,12 +1474,12 @@ public class ASTMatcher { // n.b. compare return type even for constructors && safeSubtreeMatch(node.internalGetReturnType(), o.internalGetReturnType())) && safeSubtreeMatch(node.getName(), o.getName()) - && (level >= AST.JLS8 + && (level >= AST.JLS8_INTERNAL ? safeSubtreeMatch(node.getReceiverType(), o.getReceiverType()) && safeSubtreeMatch(node.getReceiverQualifier(), o.getReceiverQualifier()) : true) && safeSubtreeListMatch(node.parameters(), o.parameters()) - && (level >= AST.JLS8 + && (level >= AST.JLS8_INTERNAL ? safeSubtreeListMatch(node.extraDimensions(), o.extraDimensions()) && safeSubtreeListMatch(node.thrownExceptionTypes(), o.thrownExceptionTypes()) : node.getExtraDimensions() == o.getExtraDimensions() @@ -1776,7 +1776,7 @@ public class ASTMatcher { } PrimitiveType o = (PrimitiveType) other; int level = node.getAST().apiLevel; - return (level >= AST.JLS8 ? safeSubtreeListMatch(node.annotations(), o.annotations()) : true) + return (level >= AST.JLS8_INTERNAL ? safeSubtreeListMatch(node.annotations(), o.annotations()) : true) && node.getPrimitiveTypeCode() == o.getPrimitiveTypeCode(); } @@ -1825,7 +1825,7 @@ public class ASTMatcher { QualifiedType o = (QualifiedType) other; int level = node.getAST().apiLevel; return safeSubtreeMatch(node.getQualifier(), o.getQualifier()) - && (level >= AST.JLS8 ? safeSubtreeListMatch(node.annotations(), o.annotations()) : true) + && (level >= AST.JLS8_INTERNAL ? safeSubtreeListMatch(node.annotations(), o.annotations()) : true) && safeSubtreeMatch(node.getName(), o.getName()); } @@ -1893,7 +1893,7 @@ public class ASTMatcher { } SimpleType o = (SimpleType) other; int level = node.getAST().apiLevel; - return (level >= AST.JLS8 ? safeSubtreeListMatch(node.annotations(), o.annotations()) : true) + return (level >= AST.JLS8_INTERNAL ? safeSubtreeListMatch(node.annotations(), o.annotations()) : true) && safeSubtreeMatch(node.getName(), o.getName()); } @@ -1949,14 +1949,14 @@ public class ASTMatcher { ? safeSubtreeListMatch(node.modifiers(), o.modifiers()) : node.getModifiers() == o.getModifiers()) && safeSubtreeMatch(node.getType(), o.getType()) - && (level >= AST.JLS8 && node.isVarargs() + && (level >= AST.JLS8_INTERNAL && node.isVarargs() ? safeSubtreeListMatch(node.varargsAnnotations(), o.varargsAnnotations()) : true) && (level >= AST.JLS3_INTERNAL ? node.isVarargs() == o.isVarargs() : true) && safeSubtreeMatch(node.getName(), o.getName()) - && ((level >= AST.JLS8) + && ((level >= AST.JLS8_INTERNAL) ? safeSubtreeListMatch(node.extraDimensions(), o.extraDimensions()) : node.getExtraDimensions() == o.getExtraDimensions()) && safeSubtreeMatch(node.getInitializer(), o.getInitializer()); @@ -2424,7 +2424,7 @@ public class ASTMatcher { } TypeParameter o = (TypeParameter) other; int level = node.getAST().apiLevel; - return (level >= AST.JLS8 ? safeSubtreeListMatch(node.modifiers(), o.modifiers()) : true) + return (level >= AST.JLS8_INTERNAL ? safeSubtreeListMatch(node.modifiers(), o.modifiers()) : true) && safeSubtreeMatch(node.getName(), o.getName()) && safeSubtreeListMatch(node.typeBounds(), o.typeBounds()); } @@ -2511,7 +2511,7 @@ public class ASTMatcher { VariableDeclarationFragment o = (VariableDeclarationFragment) other; int level = node.getAST().apiLevel; return safeSubtreeMatch(node.getName(), o.getName()) - && (level >= AST.JLS8 + && (level >= AST.JLS8_INTERNAL ? safeSubtreeListMatch(node.extraDimensions(), o.extraDimensions()) : node.getExtraDimensions() == o.getExtraDimensions()) && safeSubtreeMatch(node.getInitializer(), o.getInitializer()); @@ -2596,7 +2596,7 @@ public class ASTMatcher { } WildcardType o = (WildcardType) other; int level = node.getAST().apiLevel; - return (level >= AST.JLS8 ? safeSubtreeListMatch(node.annotations(), o.annotations()) : true) + return (level >= AST.JLS8_INTERNAL ? safeSubtreeListMatch(node.annotations(), o.annotations()) : true) && node.isUpperBound() == o.isUpperBound() && safeSubtreeMatch(node.getBound(), o.getBound()); } 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 73e9b9daae..a665aed19d 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 @@ -1964,7 +1964,7 @@ public abstract class ASTNode { * @since 3.10 */ final void unsupportedIn2_3_4() { - if (this.ast.apiLevel < AST.JLS8) { + if (this.ast.apiLevel < AST.JLS8_INTERNAL) { throw new UnsupportedOperationException("Operation only supported in JLS8 and later AST"); //$NON-NLS-1$ } } @@ -1998,7 +1998,7 @@ public abstract class ASTNode { */ // In API Javadocs, add: * @deprecated In the JLS8 API, this method is replaced by {@link #replacement()}. final void supportedOnlyIn2_3_4() { - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { throw new UnsupportedOperationException("Operation only supported in JLS2, JLS3 and JLS4 ASTs"); //$NON-NLS-1$ } } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java index 61b5b5c752..a65aa9ba85 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java @@ -229,7 +229,7 @@ public class ASTParser { case AST.JLS2_INTERNAL: case AST.JLS3_INTERNAL: case AST.JLS4_INTERNAL: - case AST.JLS8: + case AST.JLS8_INTERNAL: case AST.JLS9: break; default: diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AnnotatableType.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AnnotatableType.java index 4d33f984a8..626f1779d3 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AnnotatableType.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AnnotatableType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -75,7 +75,7 @@ public abstract class AnnotatableType extends Type { */ AnnotatableType(AST ast) { super(ast); - if (ast.apiLevel >= AST.JLS8) { + if (ast.apiLevel >= AST.JLS8_INTERNAL) { this.annotations = new ASTNode.NodeList(getAnnotationsProperty()); } } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ArrayType.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ArrayType.java index 7c4f63be23..6873d00a5f 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ArrayType.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ArrayType.java @@ -144,7 +144,7 @@ public class ArrayType extends Type { */ ArrayType(AST ast) { super(ast); - if (ast.apiLevel >= AST.JLS8) { + if (ast.apiLevel >= AST.JLS8_INTERNAL) { this.dimensions = new ASTNode.NodeList(DIMENSIONS_PROPERTY); // single dimension array is the default this.dimensions().add(this.ast.newDimension()); @@ -224,7 +224,7 @@ public class ArrayType extends Type { */ ASTNode clone0(AST target) { ArrayType result; - if (this.ast.apiLevel < AST.JLS8) { + if (this.ast.apiLevel < AST.JLS8_INTERNAL) { result = new ArrayType(target); result.setComponentType((Type) getComponentType().clone(target)); } else { @@ -252,7 +252,7 @@ public class ArrayType extends Type { boolean visitChildren = visitor.visit(this); if (visitChildren) { // visit children in normal left to right reading order - if (this.ast.apiLevel < AST.JLS8) { + if (this.ast.apiLevel < AST.JLS8_INTERNAL) { acceptChild(visitor, getComponentType()); } else { acceptChild(visitor, getElementType()); @@ -332,7 +332,7 @@ public class ArrayType extends Type { * @return the element type node */ public Type getElementType() { - if (this.ast.apiLevel() < AST.JLS8) { + if (this.ast.apiLevel() < AST.JLS8_INTERNAL) { Type t = getComponentType(); while (t.isArrayType()) { t = ((ArrayType) t).getComponentType(); @@ -376,7 +376,7 @@ public class ArrayType extends Type { * @return the number of dimensions (always positive) */ public int getDimensions() { - if (this.ast.apiLevel() >= AST.JLS8) { + if (this.ast.apiLevel() >= AST.JLS8_INTERNAL) { return dimensions().size(); } Type t = getComponentType(); @@ -419,7 +419,7 @@ public class ArrayType extends Type { int treeSize() { return memSize() - + (this.type == null ? 0 : (this.ast.apiLevel() < AST.JLS8 ? getComponentType().treeSize() : getElementType().treeSize()) + + (this.type == null ? 0 : (this.ast.apiLevel() < AST.JLS8_INTERNAL ? getComponentType().treeSize() : getElementType().treeSize()) + (this.dimensions == null ? 0 : this.dimensions.listSize())); } } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DocCommentParser.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DocCommentParser.java index 1136b3497f..abf5fe18bf 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DocCommentParser.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DocCommentParser.java @@ -144,7 +144,7 @@ class DocCommentParser extends AbstractCommentParser { } } argument.setType(argType); - if (this.ast.apiLevel > AST.JLS8) { + if (this.ast.apiLevel > AST.JLS8_INTERNAL) { argument.setVarargs(isVarargs); } argument.setSourceRange(argStart, argEnd - argStart + 1); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodDeclaration.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodDeclaration.java index c8eedbfa84..88fce6cc96 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodDeclaration.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodDeclaration.java @@ -254,7 +254,7 @@ public class MethodDeclaration extends BodyDeclaration { public static List propertyDescriptors(int apiLevel) { if (apiLevel == AST.JLS2_INTERNAL) { return PROPERTY_DESCRIPTORS_2_0; - } else if (apiLevel < AST.JLS8) { + } else if (apiLevel < AST.JLS8_INTERNAL) { return PROPERTY_DESCRIPTORS_3_0; } else { return PROPERTY_DESCRIPTORS_8_0; @@ -379,7 +379,7 @@ public class MethodDeclaration extends BodyDeclaration { if (ast.apiLevel >= AST.JLS3_INTERNAL) { this.typeParameters = new ASTNode.NodeList(TYPE_PARAMETERS_PROPERTY); } - if (ast.apiLevel < AST.JLS8) { + if (ast.apiLevel < AST.JLS8_INTERNAL) { this.thrownExceptions = new ASTNode.NodeList(THROWN_EXCEPTIONS_PROPERTY); } else { this.extraDimensions = new ASTNode.NodeList(EXTRA_DIMENSIONS2_PROPERTY); @@ -575,18 +575,18 @@ public class MethodDeclaration extends BodyDeclaration { } result.setConstructor(isConstructor()); result.setName((SimpleName) getName().clone(target)); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { result.setReceiverType((Type) ASTNode.copySubtree(target, getReceiverType())); result.setReceiverQualifier((SimpleName) ASTNode.copySubtree(target, getReceiverQualifier())); } result.parameters().addAll( ASTNode.copySubtrees(target, parameters())); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { result.extraDimensions().addAll(ASTNode.copySubtrees(target, extraDimensions())); } else { result.setExtraDimensions(getExtraDimensions()); } - if (this.ast.apiLevel() >= AST.JLS8) { + if (this.ast.apiLevel() >= AST.JLS8_INTERNAL) { result.thrownExceptionTypes().addAll(ASTNode.copySubtrees(target, thrownExceptionTypes())); } else { result.thrownExceptions().addAll(ASTNode.copySubtrees(target, thrownExceptions())); @@ -621,12 +621,12 @@ public class MethodDeclaration extends BodyDeclaration { } // n.b. visit return type even for constructors acceptChild(visitor, getName()); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { acceptChild(visitor, this.optionalReceiverType); acceptChild(visitor, this.optionalReceiverQualifier); } acceptChildren(visitor, this.parameters); - if (this.ast.apiLevel() >= AST.JLS8) { + if (this.ast.apiLevel() >= AST.JLS8_INTERNAL) { acceptChildren(visitor, this.extraDimensions); acceptChildren(visitor, this.thrownExceptionTypes); } else { @@ -1169,7 +1169,7 @@ public class MethodDeclaration extends BodyDeclaration { + (this.optionalReceiverQualifier == null ? 0 : this.optionalReceiverQualifier.treeSize()) + (this.returnType == null ? 0 : this.returnType.treeSize()) + this.parameters.listSize() - + (this.ast.apiLevel < AST.JLS8 + + (this.ast.apiLevel < AST.JLS8_INTERNAL ? this.thrownExceptions.listSize() : this.extraDimensions.listSize() + this.thrownExceptionTypes.listSize()) + (this.optionalBody == null ? 0 : getBody().treeSize()); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/PrimitiveType.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/PrimitiveType.java index 93fc3e6242..f2ee6220d2 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/PrimitiveType.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/PrimitiveType.java @@ -285,7 +285,7 @@ public class PrimitiveType extends AnnotatableType { ASTNode clone0(AST target) { PrimitiveType result = new PrimitiveType(target); result.setSourceRange(getStartPosition(), getLength()); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { result.annotations().addAll( ASTNode.copySubtrees(target, annotations())); } @@ -308,7 +308,7 @@ public class PrimitiveType extends AnnotatableType { boolean visitChildren = visitor.visit(this); if (visitChildren) { // visit children in normal left to right reading order - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { acceptChildren(visitor, this.annotations); } } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/QualifiedType.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/QualifiedType.java index 9ea8dcc78f..37a32840fb 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/QualifiedType.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/QualifiedType.java @@ -231,7 +231,7 @@ public class QualifiedType extends AnnotatableType { QualifiedType result = new QualifiedType(target); result.setSourceRange(getStartPosition(), getLength()); result.setQualifier((Type) ((ASTNode) getQualifier()).clone(target)); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { result.annotations().addAll( ASTNode.copySubtrees(target, annotations())); } @@ -255,7 +255,7 @@ public class QualifiedType extends AnnotatableType { if (visitChildren) { // visit children in normal left to right reading order acceptChild(visitor, getQualifier()); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { acceptChildren(visitor, this.annotations); } acceptChild(visitor, getName()); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SimpleType.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SimpleType.java index 33d123dc2e..77370b7f58 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SimpleType.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SimpleType.java @@ -174,7 +174,7 @@ public class SimpleType extends AnnotatableType { ASTNode clone0(AST target) { SimpleType result = new SimpleType(target); result.setSourceRange(getStartPosition(), getLength()); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { result.annotations().addAll( ASTNode.copySubtrees(target, annotations())); } @@ -197,7 +197,7 @@ public class SimpleType extends AnnotatableType { boolean visitChildren = visitor.visit(this); if (visitChildren) { // visit children in normal left to right reading order - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { acceptChildren(visitor, this.annotations); } acceptChild(visitor, getName()); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SingleVariableDeclaration.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SingleVariableDeclaration.java index 99ca7a157c..187ad5fa24 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SingleVariableDeclaration.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SingleVariableDeclaration.java @@ -171,7 +171,7 @@ public class SingleVariableDeclaration extends VariableDeclaration { public static List propertyDescriptors(int apiLevel) { if (apiLevel == AST.JLS2_INTERNAL) { return PROPERTY_DESCRIPTORS_2_0; - } else if (apiLevel < AST.JLS8) { + } else if (apiLevel < AST.JLS8_INTERNAL) { return PROPERTY_DESCRIPTORS_3_0; } else { return PROPERTY_DESCRIPTORS_8_0; @@ -231,7 +231,7 @@ public class SingleVariableDeclaration extends VariableDeclaration { super(ast); if (ast.apiLevel >= AST.JLS3_INTERNAL) { this.modifiers = new ASTNode.NodeList(MODIFIERS2_PROPERTY); - if (ast.apiLevel >= AST.JLS8) { + if (ast.apiLevel >= AST.JLS8_INTERNAL) { this.varargsAnnotations = new ASTNode.NodeList(VARARGS_ANNOTATIONS_PROPERTY); } } @@ -385,12 +385,12 @@ public class SingleVariableDeclaration extends VariableDeclaration { result.setVarargs(isVarargs()); } result.setType((Type) getType().clone(target)); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { result.varargsAnnotations().addAll( ASTNode.copySubtrees(target, varargsAnnotations())); } result.setName((SimpleName) getName().clone(target)); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { result.extraDimensions().addAll( ASTNode.copySubtrees(target, this.extraDimensions())); } else { @@ -420,11 +420,11 @@ public class SingleVariableDeclaration extends VariableDeclaration { acceptChildren(visitor, this.modifiers); } acceptChild(visitor, getType()); - if (this.ast.apiLevel >= AST.JLS8 && isVarargs()) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL && isVarargs()) { acceptChildren(visitor, this.varargsAnnotations); } acceptChild(visitor, getName()); - if (this.ast.apiLevel >= AST.JLS8){ + if (this.ast.apiLevel >= AST.JLS8_INTERNAL){ acceptChildren(visitor, this.extraDimensions); } acceptChild(visitor, getInitializer()); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeParameter.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeParameter.java index 60e4f29163..9b569e0afe 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeParameter.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeParameter.java @@ -130,7 +130,7 @@ public class TypeParameter extends ASTNode { TypeParameter(AST ast) { super(ast); unsupportedIn2(); - if (ast.apiLevel >= AST.JLS8) { + if (ast.apiLevel >= AST.JLS8_INTERNAL) { this.modifiers = new ASTNode.NodeList(MODIFIERS_PROPERTY); } } @@ -185,7 +185,7 @@ public class TypeParameter extends ASTNode { ASTNode clone0(AST target) { TypeParameter result = new TypeParameter(target); result.setSourceRange(getStartPosition(), getLength()); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { result.modifiers().addAll( ASTNode.copySubtrees(target, modifiers())); } @@ -210,7 +210,7 @@ public class TypeParameter extends ASTNode { boolean visitChildren = visitor.visit(this); if (visitChildren) { // visit children in normal left to right reading order - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { acceptChildren(visitor, this.modifiers); } acceptChild(visitor, getName()); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableDeclaration.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableDeclaration.java index 2a40ccb58b..3195f7e458 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableDeclaration.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableDeclaration.java @@ -196,7 +196,7 @@ public abstract class VariableDeclaration extends ASTNode { */ VariableDeclaration(AST ast) { super(ast); - if (ast.apiLevel >= AST.JLS8) { + if (ast.apiLevel >= AST.JLS8_INTERNAL) { this.extraDimensions = new ASTNode.NodeList(getExtraDimensions2Property()); } } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableDeclarationFragment.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableDeclarationFragment.java index 0405c65fbe..bd714100f7 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableDeclarationFragment.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableDeclarationFragment.java @@ -105,7 +105,7 @@ public class VariableDeclarationFragment extends VariableDeclaration { * @since 3.0 */ public static List propertyDescriptors(int apiLevel) { - if (apiLevel >= AST.JLS8) { + if (apiLevel >= AST.JLS8_INTERNAL) { return PROPERTY_DESCRIPTORS_8_0; } else { return PROPERTY_DESCRIPTORS; @@ -230,7 +230,7 @@ public class VariableDeclarationFragment extends VariableDeclaration { VariableDeclarationFragment result = new VariableDeclarationFragment(target); result.setSourceRange(getStartPosition(), getLength()); result.setName((SimpleName) getName().clone(target)); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { result.extraDimensions().addAll( ASTNode.copySubtrees(target, extraDimensions())); } else { @@ -257,7 +257,7 @@ public class VariableDeclarationFragment extends VariableDeclaration { if (visitChildren) { // visit children in normal left to right reading order acceptChild(visitor, getName()); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { acceptChildren(visitor, this.extraDimensions); } acceptChild(visitor, getInitializer()); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/WildcardType.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/WildcardType.java index ab4572d947..18ba40d3a8 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/WildcardType.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/WildcardType.java @@ -199,7 +199,7 @@ public class WildcardType extends AnnotatableType { ASTNode clone0(AST target) { WildcardType result = new WildcardType(target); result.setSourceRange(getStartPosition(), getLength()); - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { result.annotations().addAll( ASTNode.copySubtrees(target, annotations())); } @@ -222,7 +222,7 @@ public class WildcardType extends AnnotatableType { boolean visitChildren = visitor.visit(this); if (visitChildren) { // visit children in normal left to right reading order - if (this.ast.apiLevel >= AST.JLS8) { + if (this.ast.apiLevel >= AST.JLS8_INTERNAL) { acceptChildren(visitor, this.annotations); } acceptChild(visitor, getBound()); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java index cfe425b3f5..4cb4138c16 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java @@ -172,6 +172,9 @@ public final class ImportRewrite { private static final char STATIC_PREFIX= 's'; private static final char NORMAL_PREFIX= 'n'; + /** @deprecated using deprecated code */ + private static final int JLS8_INTERNAL = AST.JLS8; + private final ImportRewriteContext defaultContext; private final ICompilationUnit compilationUnit; @@ -1367,7 +1370,7 @@ public final class ImportRewrite { private Type getArrayType(Type elementType, AST ast, ImportRewriteContext context, ITypeBinding normalizedBinding) { int noDimensions = normalizedBinding.getDimensions(); ArrayType arrayType = ast.newArrayType(elementType, noDimensions); - if (ast.apiLevel() >= AST.JLS8) { + if (ast.apiLevel() >= JLS8_INTERNAL) { for (int i = 0; i < noDimensions; i++) { IAnnotationBinding[] typeAnnotations = normalizedBinding.getTypeAnnotations(); if (typeAnnotations.length > 0) { 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 2b079e4564..44352be790 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, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -64,6 +64,14 @@ public class NaiveASTFlattener extends ASTVisitor { private static final int JLS4 = AST.JLS4; /** + * Internal synonym for {@link AST#JLS8}. Use to alleviate + * deprecation warnings. + * @deprecated + * @since 3.13 BETA_JAVA9 + */ + private static final int JLS8 = AST.JLS8; + + /** * The string buffer into which the serialized representation of the AST is * written. */ @@ -221,7 +229,7 @@ public class NaiveASTFlattener extends ASTVisitor { } private void visitTypeAnnotations(AnnotatableType node) { - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8) { visitAnnotationsList(node.annotations()); } } @@ -367,7 +375,7 @@ public class NaiveASTFlattener extends ASTVisitor { * @see ASTVisitor#visit(ArrayType) */ public boolean visit(ArrayType node) { - if (node.getAST().apiLevel() < AST.JLS8) { + if (node.getAST().apiLevel() < JLS8) { visitComponentType(node); this.buffer.append("[]");//$NON-NLS-1$ } else { @@ -1048,7 +1056,7 @@ public class NaiveASTFlattener extends ASTVisitor { } node.getName().accept(this); this.buffer.append("(");//$NON-NLS-1$ - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8) { Type receiverType = node.getReceiverType(); if (receiverType != null) { receiverType.accept(this); @@ -1073,7 +1081,7 @@ public class NaiveASTFlattener extends ASTVisitor { } this.buffer.append(")");//$NON-NLS-1$ int size = node.getExtraDimensions(); - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8) { List dimensions = node.extraDimensions(); for (int i = 0; i < size; i++) { visit((Dimension) dimensions.get(i)); @@ -1083,7 +1091,7 @@ public class NaiveASTFlattener extends ASTVisitor { this.buffer.append("[]"); //$NON-NLS-1$ } } - if (node.getAST().apiLevel() < AST.JLS8) { + if (node.getAST().apiLevel() < JLS8) { if (!thrownExceptions(node).isEmpty()) { this.buffer.append(" throws ");//$NON-NLS-1$ for (Iterator it = thrownExceptions(node).iterator(); it.hasNext(); ) { @@ -1402,7 +1410,7 @@ public class NaiveASTFlattener extends ASTVisitor { node.getType().accept(this); if (node.getAST().apiLevel() >= JLS3) { if (node.isVarargs()) { - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8) { List annotations = node.varargsAnnotations(); if (annotations.size() > 0) { this.buffer.append(' '); @@ -1415,7 +1423,7 @@ public class NaiveASTFlattener extends ASTVisitor { this.buffer.append(" ");//$NON-NLS-1$ node.getName().accept(this); int size = node.getExtraDimensions(); - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8) { List dimensions = node.extraDimensions(); for (int i = 0; i < size; i++) { visit((Dimension) dimensions.get(i)); @@ -1811,7 +1819,7 @@ public class NaiveASTFlattener extends ASTVisitor { * @since 3.1 */ public boolean visit(TypeParameter node) { - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8) { printModifiers(node.modifiers()); } node.getName().accept(this); @@ -1871,7 +1879,7 @@ public class NaiveASTFlattener extends ASTVisitor { public boolean visit(VariableDeclarationFragment node) { node.getName().accept(this); int size = node.getExtraDimensions(); - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8) { List dimensions = node.extraDimensions(); for (int i = 0; i < size; i++) { visit((Dimension) dimensions.get(i)); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java index 7a967d0f57..bb8273dc36 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java @@ -117,6 +117,9 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { private static final SimplePropertyDescriptor INTERNAL_VDS_MODIFIERS_PROPERTY = VariableDeclarationStatement.MODIFIERS_PROPERTY; /** @deprecated using deprecated code */ + private static final ChildListPropertyDescriptor INTERNAL_TRY_STATEMENT_RESOURCES_PROPERTY = TryStatement.RESOURCES_PROPERTY; + + /** @deprecated using deprecated code */ private static final int JLS2_INTERNAL = AST.JLS2; /** @deprecated using deprecated code */ @@ -125,6 +128,11 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { /** @deprecated using deprecated code */ private static final int JLS4_INTERNAL = AST.JLS4; + /** @deprecated using deprecated code */ + private static final int JLS8_INTERNAL = AST.JLS8; + + private static final int JLS9_INTERNAL = AST.JLS9; + TextEdit currentEdit; final RewriteEventStore eventStore; // used from inner classes @@ -1855,7 +1863,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { private int rewriteMethodReceiver(MethodDeclaration method, int offset) throws CoreException { offset= getScanner().getTokenEndOffset(TerminalTokens.TokenNameLPAREN, offset); - if (method.getAST().apiLevel() < AST.JLS8) { + if (method.getAST().apiLevel() < JLS8_INTERNAL) { return offset; } @@ -2038,9 +2046,9 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { pos= rewriteNodeList(node, MethodDeclaration.PARAMETERS_PROPERTY, pos, Util.EMPTY_STRING, ", "); //$NON-NLS-1$ pos= getScanner().getTokenEndOffset(TerminalTokens.TokenNameRPAREN, pos); - ChildListPropertyDescriptor exceptionsProperty = apiLevel < AST.JLS8 ? INTERNAL_METHOD_THROWN_EXCEPTIONS_PROPERTY : MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY; + ChildListPropertyDescriptor exceptionsProperty = apiLevel < JLS8_INTERNAL ? INTERNAL_METHOD_THROWN_EXCEPTIONS_PROPERTY : MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY; - if (apiLevel < AST.JLS8) { + if (apiLevel < JLS8_INTERNAL) { int extraDims= rewriteExtraDimensions(node, INTERNAL_METHOD_EXTRA_DIMENSIONS_PROPERTY, pos); boolean hasExceptionChanges= isChanged(node, exceptionsProperty); @@ -2145,7 +2153,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { ArrayType arrayType= (ArrayType) getOriginalValue(node, ArrayCreation.TYPE_PROPERTY); ArrayType replacingType= arrayType; int nOldBrackets= getDimensions(arrayType); // number of total brackets - boolean astLevelGTE8 = node.getAST().apiLevel() >= AST.JLS8; + boolean astLevelGTE8 = node.getAST().apiLevel() >= JLS8_INTERNAL; boolean typeReplaced = false; TextEditGroup editGroup= null; @@ -2318,7 +2326,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { } private Type getElementType(ArrayType parent) { - if (parent.getAST().apiLevel() >= AST.JLS8) { + if (parent.getAST().apiLevel() >= JLS8_INTERNAL) { return (Type) getOriginalValue(parent, ArrayType.ELEMENT_TYPE_PROPERTY); } Type t = (Type) getOriginalValue(parent, INTERNAL_ARRAY_COMPONENT_TYPE_PROPERTY); @@ -2329,7 +2337,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { } private int getDimensions(ArrayType parent) { - if (parent.getAST().apiLevel() >= AST.JLS8) { + if (parent.getAST().apiLevel() >= JLS8_INTERNAL) { return ((List) getOriginalValue(parent, ArrayType.DIMENSIONS_PROPERTY)).size(); } Type t = (Type) getOriginalValue(parent, INTERNAL_ARRAY_COMPONENT_TYPE_PROPERTY); @@ -2365,7 +2373,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { if (!hasChildrenChanges(node)) { return doVisitUnchangedChildren(node); } - if (node.getAST().apiLevel() < AST.JLS8) { + if (node.getAST().apiLevel() < JLS8_INTERNAL) { rewriteRequiredNode(node, INTERNAL_ARRAY_COMPONENT_TYPE_PROPERTY); } else { int pos = rewriteRequiredNode(node, ArrayType.ELEMENT_TYPE_PROPERTY); @@ -3208,7 +3216,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { if (!hasChildrenChanges(node)) { return doVisitUnchangedChildren(node); } - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8_INTERNAL) { rewriteTypeAnnotations(node, PrimitiveType.ANNOTATIONS_PROPERTY, node.getStartPosition()); } PrimitiveType.Code newCode= (PrimitiveType.Code) getNewValue(node, PrimitiveType.PRIMITIVE_TYPE_CODE_PROPERTY); @@ -3250,7 +3258,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { if (!hasChildrenChanges(node)) { return doVisitUnchangedChildren(node); } - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8_INTERNAL) { rewriteTypeAnnotations(node, SimpleType.ANNOTATIONS_PROPERTY, node.getStartPosition()); } rewriteRequiredNode(node, SimpleType.NAME_PROPERTY); @@ -3276,7 +3284,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { if (isChanged(node, SingleVariableDeclaration.VARARGS_PROPERTY)) { TextEditGroup editGroup = getEditGroup(node, SingleVariableDeclaration.VARARGS_PROPERTY); if (getNewValue(node, SingleVariableDeclaration.VARARGS_PROPERTY).equals(Boolean.TRUE)) { - if (apiLevel >= AST.JLS8) { + if (apiLevel >= JLS8_INTERNAL) { pos= rewriteVarargsAnnotations(node, SingleVariableDeclaration.VARARGS_ANNOTATIONS_PROPERTY, pos); } int indent= getIndent(node.getStartPosition()); @@ -3286,7 +3294,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { } else { try { int ellipsisEnd; - int noOfAnnotations = apiLevel >= AST.JLS8 ? node.varargsAnnotations().size() : 0; + int noOfAnnotations = apiLevel >= JLS8_INTERNAL ? node.varargsAnnotations().size() : 0; if (noOfAnnotations > 0) { Annotation annotation= (Annotation) node.varargsAnnotations().get(noOfAnnotations - 1); int annotationEndPosition= annotation.getStartPosition() + annotation.getLength(); @@ -3300,7 +3308,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { } } } else { - if (apiLevel >= AST.JLS8 && node.isVarargs()) { + if (apiLevel >= JLS8_INTERNAL && node.isVarargs()) { pos = rewriteVarargsAnnotations(node, SingleVariableDeclaration.VARARGS_ANNOTATIONS_PROPERTY, pos); } } @@ -3312,7 +3320,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { } pos= rewriteRequiredNode(node, SingleVariableDeclaration.NAME_PROPERTY); - if (apiLevel < AST.JLS8) { + if (apiLevel < JLS8_INTERNAL) { int extraDims= rewriteExtraDimensions(node, INTERNAL_VARIABLE_EXTRA_DIMENSIONS_PROPERTY, pos); if (extraDims > 0) { @@ -3619,7 +3627,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { int pos= node.getStartPosition(); int level = node.getAST().apiLevel(); if (level >= JLS4_INTERNAL) { - StructuralPropertyDescriptor desc = level < AST.JLS9 ? TryStatement.RESOURCES_PROPERTY : TryStatement.RESOURCES2_PROPERTY; + StructuralPropertyDescriptor desc = level < JLS9_INTERNAL ? INTERNAL_TRY_STATEMENT_RESOURCES_PROPERTY : TryStatement.RESOURCES2_PROPERTY; if (isChanged(node, desc)) { int indent= getIndent(node.getStartPosition()); String prefix= this.formatter.TRY_RESOURCES.getPrefix(indent); @@ -3713,7 +3721,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { int pos= rewriteRequiredNode(node, VariableDeclarationFragment.NAME_PROPERTY); - if (node.getAST().apiLevel() < AST.JLS8) { + if (node.getAST().apiLevel() < JLS8_INTERNAL) { int extraDims= rewriteExtraDimensions(node, INTERNAL_FRAGMENT_EXTRA_DIMENSIONS_PROPERTY, pos); if (extraDims > 0) { int kind= getChangeKind(node, VariableDeclarationFragment.INITIALIZER_PROPERTY); @@ -4216,7 +4224,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { return doVisitUnchangedChildren(node); } int pos = rewriteRequiredNode(node, QualifiedType.QUALIFIER_PROPERTY); - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8_INTERNAL) { try { pos = getScanner().getTokenEndOffset(TerminalTokens.TokenNameDOT, pos); rewriteTypeAnnotations(node, QualifiedType.ANNOTATIONS_PROPERTY, pos); @@ -4273,7 +4281,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { return doVisitUnchangedChildren(node); } int pos; - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8_INTERNAL) { pos = rewriteModifiers2(node, TypeParameter.MODIFIERS_PROPERTY, node.getStartPosition()); } pos= rewriteRequiredNode(node, TypeParameter.NAME_PROPERTY); @@ -4287,7 +4295,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { if (!hasChildrenChanges(node)) { return doVisitUnchangedChildren(node); } - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8_INTERNAL) { rewriteTypeAnnotations(node, WildcardType.ANNOTATIONS_PROPERTY, node.getStartPosition()); } try { diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java index 6ed75403b2..5a25ea89bf 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java @@ -74,6 +74,9 @@ public class ASTRewriteFlattener extends ASTVisitor { private static final SimplePropertyDescriptor INTERNAL_VDS_MODIFIERS_PROPERTY = VariableDeclarationStatement.MODIFIERS_PROPERTY; /** @deprecated using deprecated code */ + private static final ChildListPropertyDescriptor INTERNAL_TRY_STATEMENT_RESOURCES_PROPERTY = TryStatement.RESOURCES_PROPERTY; + + /** @deprecated using deprecated code */ private static final int JLS2_INTERNAL = AST.JLS2; /** @deprecated using deprecated code */ @@ -82,6 +85,11 @@ public class ASTRewriteFlattener extends ASTVisitor { /** @deprecated using deprecated code */ private static final int JLS4_INTERNAL = AST.JLS4; + /** @deprecated using deprecated code */ + private static final int JLS8_INTERNAL = AST.JLS8; + + private static final int JLS9_INTERNAL = AST.JLS9; + public static String asString(ASTNode node, RewriteEventStore store) { ASTRewriteFlattener flattener= new ASTRewriteFlattener(store); @@ -201,7 +209,7 @@ public class ASTRewriteFlattener extends ASTVisitor { } private void visitExtraDimensions(ASTNode node, SimplePropertyDescriptor dimensions, ChildListPropertyDescriptor dimensionsInfo) { - if (node.getAST().apiLevel() < AST.JLS8) { + if (node.getAST().apiLevel() < JLS8_INTERNAL) { int extraDimensions= getIntAttribute(node, dimensions); for (int i = 0; i < extraDimensions; i++) { this.result.append("[]"); //$NON-NLS-1$ @@ -242,7 +250,7 @@ public class ASTRewriteFlattener extends ASTVisitor { // get the element type and count dimensions Type elementType; int dimensions; - boolean astLevelGTE8 = node.getAST().apiLevel() >= AST.JLS8; + boolean astLevelGTE8 = node.getAST().apiLevel() >= JLS8_INTERNAL; if (astLevelGTE8) { elementType = (Type) getChildNode(arrayType, ArrayType.ELEMENT_TYPE_PROPERTY); dimensions = getChildList(arrayType, ArrayType.DIMENSIONS_PROPERTY).size(); @@ -301,7 +309,7 @@ public class ASTRewriteFlattener extends ASTVisitor { * @see ASTVisitor#visit(ArrayType) */ public boolean visit(ArrayType node) { - if (node.getAST().apiLevel() < AST.JLS8) { + if (node.getAST().apiLevel() < JLS8_INTERNAL) { getChildNode(node, INTERNAL_ARRAY_COMPONENT_TYPE_PROPERTY).accept(this); this.result.append("[]"); //$NON-NLS-1$ } else { @@ -741,7 +749,7 @@ public class ASTRewriteFlattener extends ASTVisitor { getChildNode(node, MethodDeclaration.NAME_PROPERTY).accept(this); this.result.append('('); // receiver parameter - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8_INTERNAL) { ASTNode receiverType = getChildNode(node, MethodDeclaration.RECEIVER_TYPE_PROPERTY); if (receiverType != null) { receiverType.accept(this); @@ -762,7 +770,7 @@ public class ASTRewriteFlattener extends ASTVisitor { this.result.append(')'); visitExtraDimensions(node, INTERNAL_METHOD_EXTRA_DIMENSIONS_PROPERTY, MethodDeclaration.EXTRA_DIMENSIONS2_PROPERTY); - ChildListPropertyDescriptor exceptionsProperty = node.getAST().apiLevel() < AST.JLS8 ? + ChildListPropertyDescriptor exceptionsProperty = node.getAST().apiLevel() < JLS8_INTERNAL ? INTERNAL_METHOD_THROWN_EXCEPTIONS_PROPERTY : MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY; visitList(node, exceptionsProperty, String.valueOf(','), " throws ", Util.EMPTY_STRING); //$NON-NLS-1$ ASTNode body= getChildNode(node, MethodDeclaration.BODY_PROPERTY); @@ -859,7 +867,7 @@ public class ASTRewriteFlattener extends ASTVisitor { * @see ASTVisitor#visit(PrimitiveType) */ public boolean visit(PrimitiveType node) { - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8_INTERNAL) { visitList(node, PrimitiveType.ANNOTATIONS_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' ')); } this.result.append(getAttribute(node, PrimitiveType.PRIMITIVE_TYPE_CODE_PROPERTY).toString()); @@ -902,7 +910,7 @@ public class ASTRewriteFlattener extends ASTVisitor { * @see ASTVisitor#visit(SimpleType) */ public boolean visit(SimpleType node) { - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8_INTERNAL) { visitList(node, SimpleType.ANNOTATIONS_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' ')); } node.getName().accept(this); @@ -919,7 +927,7 @@ public class ASTRewriteFlattener extends ASTVisitor { visitList(node, SingleVariableDeclaration.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' ')); } getChildNode(node, SingleVariableDeclaration.TYPE_PROPERTY).accept(this); - if (node.getAST().apiLevel() >= AST.JLS8 && node.isVarargs()) { + if (node.getAST().apiLevel() >= JLS8_INTERNAL && node.isVarargs()) { visitList(node, SingleVariableDeclaration.VARARGS_ANNOTATIONS_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' ')); } if (node.getAST().apiLevel() >= JLS3_INTERNAL) { @@ -1067,8 +1075,7 @@ public class ASTRewriteFlattener extends ASTVisitor { this.result.append("try "); //$NON-NLS-1$ int level = node.getAST().apiLevel(); if (level >= JLS4_INTERNAL) { - @SuppressWarnings("deprecation") - StructuralPropertyDescriptor desc = level < AST.JLS9 ? TryStatement.RESOURCES_PROPERTY : TryStatement.RESOURCES2_PROPERTY; + StructuralPropertyDescriptor desc = level < JLS9_INTERNAL ? INTERNAL_TRY_STATEMENT_RESOURCES_PROPERTY : TryStatement.RESOURCES2_PROPERTY; visitList(node, desc, String.valueOf(';'), String.valueOf('('), String.valueOf(')')); } getChildNode(node, TryStatement.BODY_PROPERTY).accept(this); @@ -1453,7 +1460,7 @@ public class ASTRewriteFlattener extends ASTVisitor { public boolean visit(NameQualifiedType node) { getChildNode(node, NameQualifiedType.QUALIFIER_PROPERTY).accept(this); this.result.append('.'); - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8_INTERNAL) { visitList(node, NameQualifiedType.ANNOTATIONS_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' ')); } getChildNode(node, NameQualifiedType.NAME_PROPERTY).accept(this); @@ -1479,7 +1486,7 @@ public class ASTRewriteFlattener extends ASTVisitor { public boolean visit(QualifiedType node) { getChildNode(node, QualifiedType.QUALIFIER_PROPERTY).accept(this); this.result.append('.'); - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8_INTERNAL) { visitList(node, QualifiedType.ANNOTATIONS_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' ')); } getChildNode(node, QualifiedType.NAME_PROPERTY).accept(this); @@ -1528,7 +1535,7 @@ public class ASTRewriteFlattener extends ASTVisitor { * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TypeParameter) */ public boolean visit(TypeParameter node) { - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8_INTERNAL) { visitList(node, TypeParameter.MODIFIERS_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' ')); } getChildNode(node, TypeParameter.NAME_PROPERTY).accept(this); @@ -1540,7 +1547,7 @@ public class ASTRewriteFlattener extends ASTVisitor { * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.WildcardType) */ public boolean visit(WildcardType node) { - if (node.getAST().apiLevel() >= AST.JLS8) { + if (node.getAST().apiLevel() >= JLS8_INTERNAL) { visitList(node, WildcardType.ANNOTATIONS_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' ')); } this.result.append('?'); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/compiler/ReconcileContext.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/compiler/ReconcileContext.java index 38eca3b072..9b2d9d6641 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/compiler/ReconcileContext.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/compiler/ReconcileContext.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2013 IBM Corporation and others. + * Copyright (c) 2005, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -88,20 +88,9 @@ public ReconcileContext(ReconcileWorkingCopyOperation operation, CompilationUnit * with JLS4 level. */ public org.eclipse.jdt.core.dom.CompilationUnit getAST3() throws JavaModelException { - if (this.operation.astLevel != AST.JLS3 || !this.operation.resolveBindings) { - // create AST (optionally resolving bindings) - ASTParser parser = ASTParser.newParser(AST.JLS3); - parser.setCompilerOptions(this.workingCopy.getJavaProject().getOptions(true)); - if (JavaProject.hasJavaNature(this.workingCopy.getJavaProject().getProject())) - parser.setResolveBindings(true); - parser.setStatementsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0); - parser.setBindingsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0); - parser.setSource(this.workingCopy); - parser.setIgnoreMethodBodies((this.operation.reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0); - return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor); - } - return this.operation.makeConsistent(this.workingCopy); + return getAST(AST.JLS3); } + /** * Returns a resolved AST with {@link AST#JLS4 JLS4} level. * It is created from the current state of the working copy. @@ -128,20 +117,9 @@ public org.eclipse.jdt.core.dom.CompilationUnit getAST3() throws JavaModelExcept * @since 3.7.1 */ public org.eclipse.jdt.core.dom.CompilationUnit getAST4() throws JavaModelException { - if (this.operation.astLevel != AST.JLS4 || !this.operation.resolveBindings) { - // create AST (optionally resolving bindings) - ASTParser parser = ASTParser.newParser(AST.JLS4); - parser.setCompilerOptions(this.workingCopy.getJavaProject().getOptions(true)); - if (JavaProject.hasJavaNature(this.workingCopy.getJavaProject().getProject())) - parser.setResolveBindings(true); - parser.setStatementsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0); - parser.setBindingsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0); - parser.setSource(this.workingCopy); - parser.setIgnoreMethodBodies((this.operation.reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0); - return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor); - } - return this.operation.makeConsistent(this.workingCopy); + return getAST(AST.JLS4); } + /** * Returns a resolved AST with {@link AST#JLS8 JLS8} level. * It is created from the current state of the working copy. @@ -163,12 +141,43 @@ public org.eclipse.jdt.core.dom.CompilationUnit getAST4() throws JavaModelExcept * <ul> * <li> The working copy does not exist (ELEMENT_DOES_NOT_EXIST)</li> * </ul> + * @deprecated JLS8 has been deprecated. This method has been replaced by {@link #getAST(int)} which returns an AST + * with the given level. * @since 3.10 */ public org.eclipse.jdt.core.dom.CompilationUnit getAST8() throws JavaModelException { - if (this.operation.astLevel != AST.JLS8 || !this.operation.resolveBindings) { + return getAST(AST.JLS8); +} + +/** + * Returns a resolved AST with the given AST level. + * It is created from the current state of the working copy. + * Creates one if none exists yet. + * Returns <code>null</code> if the current state of the working copy + * doesn't allow the AST to be created (e.g. if the working copy's content + * cannot be parsed). + * <p> + * If the AST level requested during reconciling is not the latest available AST level + * or if binding resolutions was not requested, then a different AST is created. + * Note that this AST does not become the current AST and it is only valid for + * the requestor. + * </p> + * + * @param level the API level; one of the <code>.JLS*</code> level constants + * declared on {@link AST} + * @return the AST created from the current state of the working copy, + * or <code>null</code> if none could be created + * @exception JavaModelException if the contents of the working copy + * cannot be accessed. Reasons include: + * <ul> + * <li> The working copy does not exist (ELEMENT_DOES_NOT_EXIST)</li> + * </ul> + * @since 3.13 BETA_JAVA9 + */ +public org.eclipse.jdt.core.dom.CompilationUnit getAST(int level) throws JavaModelException { + if (this.operation.astLevel != level || !this.operation.resolveBindings) { // create AST (optionally resolving bindings) - ASTParser parser = ASTParser.newParser(AST.JLS8); + ASTParser parser = ASTParser.newParser(level); parser.setCompilerOptions(this.workingCopy.getJavaProject().getOptions(true)); if (JavaProject.hasJavaNature(this.workingCopy.getJavaProject().getProject())) parser.setResolveBindings(true); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/CompilationUnitSorter.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/CompilationUnitSorter.java index c301b3bea2..c1f5ec1c3b 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/CompilationUnitSorter.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/CompilationUnitSorter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -52,6 +52,7 @@ public final class CompilationUnitSorter { case AST.JLS3 : case AST.JLS4 : case AST.JLS8 : + case AST.JLS9 : break; default : throw new IllegalArgumentException(); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CopyResourceElementsOperation.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CopyResourceElementsOperation.java index 1b7c9ec2f6..fb9a39bef9 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CopyResourceElementsOperation.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CopyResourceElementsOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -87,7 +87,7 @@ public class CopyResourceElementsOperation extends MultiOperation implements Suf initializeASTParser(); } private void initializeASTParser() { - this.parser = ASTParser.newParser(AST.JLS8); + this.parser = ASTParser.newParser(AST.JLS9); } /** * Returns the children of <code>source</code> which are affected by this operation. diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateElementInCUOperation.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateElementInCUOperation.java index cbb38dbdbd..199fbfa004 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateElementInCUOperation.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateElementInCUOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -261,7 +261,7 @@ public abstract class CreateElementInCUOperation extends JavaModelOperation { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); // create an AST for the compilation unit - ASTParser parser = ASTParser.newParser(AST.JLS8); + ASTParser parser = ASTParser.newParser(AST.JLS9); parser.setSource(cu); return (CompilationUnit) parser.createAST(this.progressMonitor); } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateTypeMemberOperation.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateTypeMemberOperation.java index d1e230e235..48a4e2544c 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateTypeMemberOperation.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreateTypeMemberOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -78,7 +78,7 @@ protected StructuralPropertyDescriptor getChildPropertyDescriptor(ASTNode parent protected ASTNode generateElementAST(ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException { if (this.createdNode == null) { this.source = removeIndentAndNewLines(this.source, cu); - ASTParser parser = ASTParser.newParser(AST.JLS8); + ASTParser parser = ASTParser.newParser(AST.JLS9); parser.setSource(this.source.toCharArray()); parser.setProject(getCompilationUnit().getJavaProject()); parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); @@ -165,7 +165,7 @@ protected String generateSyntaxIncorrectAST() { buff.append(lineSeparator + " public class A {" + lineSeparator); //$NON-NLS-1$ buff.append(this.source); buff.append(lineSeparator).append('}'); - ASTParser parser = ASTParser.newParser(AST.JLS8); + ASTParser parser = ASTParser.newParser(AST.JLS9); parser.setSource(buff.toString().toCharArray()); CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null); TypeDeclaration typeDeclaration = (TypeDeclaration) compilationUnit.types().iterator().next(); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeleteElementsOperation.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeleteElementsOperation.java index 593a89073f..0bc605c956 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeleteElementsOperation.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeleteElementsOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -81,7 +81,7 @@ public class DeleteElementsOperation extends MultiOperation { } private void initASTParser() { - this.parser = ASTParser.newParser(AST.JLS8); + this.parser = ASTParser.newParser(AST.JLS9); } /** |