Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2021-08-09 09:49:25 +0000
committerManoj Palat2021-08-09 09:49:25 +0000
commit3d34612bdb25ebf3a76e18f2b01d20f0694590a1 (patch)
treefa63f9441b28d6b7068ac47da3f3a6d96131e0ab /org.eclipse.jdt.core/dom/org/eclipse/jdt
parent87e350400c3a7d43be13201711e30b6362530a5b (diff)
parent8f24e554f663ad9a5c6f2f2ab1b17f028824dae9 (diff)
downloadeclipse.jdt.core-3d34612bdb25ebf3a76e18f2b01d20f0694590a1.tar.gz
eclipse.jdt.core-3d34612bdb25ebf3a76e18f2b01d20f0694590a1.tar.xz
eclipse.jdt.core-3d34612bdb25ebf3a76e18f2b01d20f0694590a1.zip
Merge "Bug 574039 Merge branch 'master' into BETA_JAVA17" into BETA_JAVA17
Diffstat (limited to 'org.eclipse.jdt.core/dom/org/eclipse/jdt')
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java54
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java23
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/util/DOMASTUtil.java18
3 files changed, 84 insertions, 11 deletions
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 bf3d8f87c8..932c3cca07 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
@@ -27,8 +27,8 @@ import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.WorkingCopyOwner;
@@ -37,14 +37,18 @@ import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall;
-import org.eclipse.jdt.internal.compiler.batch.Main;
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
+import org.eclipse.jdt.internal.compiler.batch.Main;
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
import org.eclipse.jdt.internal.compiler.parser.RecoveryScanner;
import org.eclipse.jdt.internal.compiler.parser.RecoveryScannerData;
import org.eclipse.jdt.internal.compiler.parser.Scanner;
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
-import org.eclipse.jdt.internal.core.*;
+import org.eclipse.jdt.internal.core.BasicCompilationUnit;
+import org.eclipse.jdt.internal.core.BinaryType;
+import org.eclipse.jdt.internal.core.ClassFileWorkingCopy;
+import org.eclipse.jdt.internal.core.DefaultWorkingCopyOwner;
+import org.eclipse.jdt.internal.core.PackageFragment;
import org.eclipse.jdt.internal.core.dom.util.DOMASTUtil;
import org.eclipse.jdt.internal.core.util.CodeSnippetParsingUtil;
import org.eclipse.jdt.internal.core.util.RecordedParsingInformation;
@@ -656,6 +660,50 @@ public class ASTParser {
}
}
+
+ /**
+ * Sets the source code to be parsed.
+ *
+ *
+ * <p>This method automatically sets the project (and compiler
+ * options) based on the given compilation unit of class file, in a manner
+ * equivalent to {@link #setProject(IJavaProject) setProject(source.getJavaProject())}.</p>
+ * <p>If the source is a class file without source attachment, the creation of the
+ * ast will fail with an {@link IllegalStateException}.</p>
+ *
+ * <p>If this method is used, the user need not specify compiler options explicitly.
+ * The @param astLevel will be used for setting the corresponding values for the compiler
+ * options: {@link JavaCore#COMPILER_SOURCE}, {@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}
+ * and {@link JavaCore#COMPILER_COMPLIANCE}.</p>
+ *
+ * <p>This source is not used when the AST is built using
+ * {@link #createASTs(ICompilationUnit[], String[], ASTRequestor, IProgressMonitor)}.</p>
+ *
+ * <p>This astLevel will be used as the
+ * {@link #createASTs(ICompilationUnit[], String[], ASTRequestor, IProgressMonitor)}.</p>
+ *
+ * @param source the Java model compilation unit or class file whose corresponding source code
+ * is to be parsed, or <code>null</code> if none
+ * @param astLevel the API level; one of the <code>JLS*</code> level constants
+ * declared on {@link AST}
+ * @since 3.27
+ */
+ public void setSource(ITypeRoot source, int astLevel) {
+ this.typeRoot = source;
+ // clear the raw source
+ this.rawSource = null;
+ if (source != null) {
+ this.project = source.getJavaProject();
+ Map<String, String> options = this.project.getOptions(true);
+ options.remove(JavaCore.COMPILER_TASK_TAGS); // no need to parse task tags
+ this.compilerOptions = options;
+ String compliance = DOMASTUtil.getCompliance(astLevel);
+ this.compilerOptions.put(JavaCore.COMPILER_COMPLIANCE, compliance);
+ this.compilerOptions.put(JavaCore.COMPILER_SOURCE, compliance);
+ this.compilerOptions.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, compliance);
+ }
+ }
+
/**
* Sets the subrange of the source code to be parsed.
* By default, the entire source string will be parsed
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java
index 3ac7e77814..b11bc305a5 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2020 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -539,13 +539,11 @@ class TypeBinding implements ITypeBinding {
private ITypeBinding[] getIntersectingTypes() {
ITypeBinding[] intersectionBindings = TypeBinding.NO_TYPE_BINDINGS;
- if (this.binding instanceof IntersectionTypeBinding18) {
- ReferenceBinding[] intersectingTypes = this.binding.getIntersectingTypes();
- int l = intersectingTypes.length;
- intersectionBindings = new ITypeBinding[l];
- for (int i = 0; i < l; ++i) {
- intersectionBindings[i] = this.resolver.getTypeBinding(intersectingTypes[i]);
- }
+ ReferenceBinding[] intersectingTypes = this.binding.getIntersectingTypes();
+ int l = intersectingTypes.length;
+ intersectionBindings = new ITypeBinding[l];
+ for (int i = 0; i < l; ++i) {
+ intersectionBindings[i] = this.resolver.getTypeBinding(intersectingTypes[i]);
}
return intersectionBindings;
}
@@ -911,6 +909,15 @@ class TypeBinding implements ITypeBinding {
} else if (this.binding instanceof WildcardBinding) {
WildcardBinding wildcardBinding = (WildcardBinding) this.binding;
typeVariableBinding = wildcardBinding.typeVariable();
+ if (typeVariableBinding == null) {
+ org.eclipse.jdt.internal.compiler.lookup.TypeBinding allBounds = wildcardBinding.allBounds();
+ if (allBounds instanceof IntersectionTypeBinding18) { // doubles up as null check
+ ITypeBinding typeBinding = this.resolver.getTypeBinding(allBounds);
+ if (typeBinding instanceof TypeBinding) { // doubles up as null check
+ return ((TypeBinding) typeBinding).getIntersectingTypes();
+ }
+ }
+ }
} else if (this.binding instanceof IntersectionTypeBinding18) {
return this.bounds = getIntersectingTypes();
}
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 14bce6de52..79f93a6046 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
@@ -18,6 +18,7 @@
package org.eclipse.jdt.internal.core.dom.util;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.Modifier;
@@ -188,4 +189,21 @@ public class DOMASTUtil {
throw new IllegalArgumentException(Integer.toString(level));
}
+ 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};
+
+ /**
+ * Calculates the JavaCore Option value string corresponding to the input ast level.
+ * AST Level 4 is used for Java versions 1.4 to 1.7 and is converted to compliance level 7
+ * if input ast level is out of boundary, latest compliance will be returned
+ * @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];
+ }
+
}

Back to the top