Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jdt.compiler.apt/.classpath3
-rw-r--r--org.eclipse.jdt.compiler.apt/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jdt.compiler.apt/build.properties4
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseProcessingEnvImpl.java2
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl.java129
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl9.java186
6 files changed, 202 insertions, 124 deletions
diff --git a/org.eclipse.jdt.compiler.apt/.classpath b/org.eclipse.jdt.compiler.apt/.classpath
index f9ab0b3e57..01836c4842 100644
--- a/org.eclipse.jdt.compiler.apt/.classpath
+++ b/org.eclipse.jdt.compiler.apt/.classpath
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
- <classpathentry kind="lib" path="lib/java9api.jar"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/org.eclipse.jdt.compiler.apt/META-INF/MANIFEST.MF b/org.eclipse.jdt.compiler.apt/META-INF/MANIFEST.MF
index 5d72d6f334..ce33c9404d 100644
--- a/org.eclipse.jdt.compiler.apt/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.compiler.apt/META-INF/MANIFEST.MF
@@ -12,5 +12,3 @@ Export-Package: org.eclipse.jdt.internal.compiler.apt.dispatch;x-friends:="org.e
org.eclipse.jdt.internal.compiler.apt.util;x-friends:="org.eclipse.jdt.apt.pluggable.core",
org.eclipse.jdt.internal.compiler.lookup;x-friends:="org.eclipse.jdt.apt.pluggable.core"
Import-Package: org.eclipse.jdt.internal.compiler.tool;resolution:=optional
-Bundle-ClassPath: lib/java9api.jar,
- .
diff --git a/org.eclipse.jdt.compiler.apt/build.properties b/org.eclipse.jdt.compiler.apt/build.properties
index 958fe58146..cb4935b695 100644
--- a/org.eclipse.jdt.compiler.apt/build.properties
+++ b/org.eclipse.jdt.compiler.apt/build.properties
@@ -12,11 +12,11 @@ customBuildCallbacks=customBuildCallbacks.xml
bin.includes = .,\
META-INF/,\
about.html,\
- compiler_apt_fragment.properties,\
- lib/java9api.jar
+ compiler_apt_fragment.properties
src.includes = about.html
jars.compile.order = .
output.. = bin/
source.. = src/
+
jars.extra.classpath = lib/java9api.jar
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseProcessingEnvImpl.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseProcessingEnvImpl.java
index a7b2a2d63e..2976050c6f 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseProcessingEnvImpl.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseProcessingEnvImpl.java
@@ -56,7 +56,7 @@ public abstract class BaseProcessingEnvImpl implements ProcessingEnvironment {
_addedUnits = new ArrayList<>();
_addedClassFiles = new ArrayList<>();
_deletedUnits = new ArrayList<>();
- _elementUtils = new ElementsImpl(this);
+ _elementUtils = ElementsImpl.create(this);
_typeUtils = new TypesImpl(this);
_factory = new Factory(this);
_errorRaised = false;
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl.java
index d0b883a66f..4c92045169 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl.java
@@ -27,13 +27,12 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import javax.lang.model.AnnotatedConstruct;
+import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
-import javax.lang.model.element.ModuleElement;
import javax.lang.model.element.Name;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
@@ -52,34 +51,38 @@ import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
import org.eclipse.jdt.internal.compiler.lookup.MethodVerifier;
-import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding;
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
-import org.eclipse.jdt.internal.compiler.util.HashtableOfModule;
/**
- * Utilities for working with language elements.
+ * Utilities for working with java8 and earlier language elements.
* There is one of these for every ProcessingEnvironment.
+ *
+ * @see ElementsImpl9
*/
public class ElementsImpl implements Elements {
// Used for parsing Javadoc comments: matches initial delimiter, followed by whitespace
private static final Pattern INITIAL_DELIMITER = Pattern.compile("^\\s*/\\*+"); //$NON-NLS-1$
- private final BaseProcessingEnvImpl _env;
+ protected final BaseProcessingEnvImpl _env;
/*
* The processing env creates and caches an ElementsImpl. Other clients should
* not create their own; they should ask the env for it.
*/
- public ElementsImpl(BaseProcessingEnvImpl env) {
+ protected ElementsImpl(BaseProcessingEnvImpl env) {
_env = env;
}
+ public static ElementsImpl create(BaseProcessingEnvImpl env) {
+ return (SourceVersion.latest().compareTo(SourceVersion.RELEASE_8) <= 0)? new ElementsImpl(env): new ElementsImpl9(env);
+ }
+
/**
* Return all the annotation mirrors on this element, including inherited annotations.
* Annotations are inherited only if the annotation type is meta-annotated with @Inherited,
@@ -614,27 +617,9 @@ public class ElementsImpl implements Elements {
*/
@Override
public TypeElement getTypeElement(CharSequence name) {
+ LookupEnvironment le = _env.getLookupEnvironment();
final char[][] compoundName = CharOperation.splitOn('.', name.toString().toCharArray());
- Set<? extends ModuleElement> allModuleElements = getAllModuleElements();
- for (ModuleElement moduleElement : allModuleElements) {
- TypeElement t = getTypeElement(compoundName, ((ModuleElementImpl) moduleElement).binding);
- if (t != null) {
- return t;
- }
- }
- return null;
- }
-
- @Override
- public TypeElement getTypeElement(ModuleElement module, CharSequence name) {
- ModuleBinding mBinding = ((ModuleElementImpl) module).binding;
- final char[][] compoundName = CharOperation.splitOn('.', name.toString().toCharArray());
- return getTypeElement(compoundName, mBinding);
- }
-
- private TypeElement getTypeElement(final char[][] compoundName, ModuleBinding mBinding) {
- LookupEnvironment le = mBinding == null ? _env.getLookupEnvironment() : mBinding.environment;
- ReferenceBinding binding = mBinding == null ? le.getType(compoundName) : le.getType(compoundName, mBinding);
+ ReferenceBinding binding = le.getType(compoundName);
// If we didn't find the binding, maybe it's a nested type;
// try finding the top-level type and then working downwards.
if (null == binding) {
@@ -735,94 +720,4 @@ public class ElementsImpl implements Elements {
return false;
}
- @Override
- public
- PackageElement getPackageElement(ModuleElement module, CharSequence name) {
- ModuleBinding mBinding = ((ModuleElementImpl) module).binding;
- final char[][] compoundName = CharOperation.splitOn('.', name.toString().toCharArray());
- PackageBinding p = null;
- if (mBinding != null) {
-
- int length = compoundName.length;
- if (length > 1) {
- char[][] parent = new char[compoundName.length - 1][];
- System.arraycopy(compoundName, 0, parent, 0, length - 1);
- p = mBinding.getPackage(parent, compoundName[length - 1]);
- } else {
- p = mBinding.getTopLevelPackage(compoundName[0]);
- }
- } else {
- p = _env.getLookupEnvironment().createPackage(compoundName);
- }
- if (p == null || !p.isValidBinding())
- return null;
- return (PackageElement) _env.getFactory().newElement(p);
- }
-
- @Override
- public ModuleElement getModuleElement(CharSequence name) {
- LookupEnvironment lookup = _env.getLookupEnvironment();
- ModuleBinding binding = lookup.getModule(name.length() == 0 ? ModuleBinding.UNNAMED : name.toString().toCharArray());
- //TODO: Surely there has to be a better way than calling toString().toCharArray()?
- if (binding == null) {
- return null;
- }
- return new ModuleElementImpl(_env, binding);
- }
-
- @Override
- public Set<? extends ModuleElement> getAllModuleElements() {
- LookupEnvironment lookup = _env.getLookupEnvironment();
- HashtableOfModule knownModules = lookup.knownModules;
- ModuleBinding[] modules = knownModules.valueTable;
- if (modules == null || modules.length == 0) {
- return Collections.emptySet();
- }
- Set<ModuleElement> mods = new HashSet<>(modules.length);
- for (ModuleBinding moduleBinding : modules) {
- if (moduleBinding == null)
- continue;
- ModuleElement element = (ModuleElement) _env.getFactory().newElement(moduleBinding);
- mods.add(element);
- }
- mods.add((ModuleElement) _env.getFactory().newElement(lookup.UnNamedModule));
- return mods;
- }
-
- @Override
- public Origin getOrigin(Element e) {
- return Origin.EXPLICIT;
- }
-
- @Override
- public Origin getOrigin(AnnotatedConstruct c, AnnotationMirror a) {
- return Origin.EXPLICIT;
- }
-
- @Override
- public Origin getOrigin(ModuleElement m, ModuleElement.Directive directive) {
- return Origin.EXPLICIT;
- }
-
- @Override
- public boolean isBridge(ExecutableElement e) {
- MethodBinding methodBinding = (MethodBinding) ((ExecutableElementImpl) e)._binding;
- return methodBinding.isBridge();
- }
-
- @Override
- public ModuleElement getModuleOf(Element elem) {
- if (elem instanceof ModuleElement) {
- return (ModuleElement) elem;
- }
- Element parent = elem.getEnclosingElement();
- while (parent != null) {
- if (parent instanceof ModuleElement) {
- return (ModuleElement) parent;
- }
- parent = parent.getEnclosingElement();
- }
- return null;
- }
-
}
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl9.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl9.java
new file mode 100644
index 0000000000..990fbec478
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl9.java
@@ -0,0 +1,186 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2017 BEA Systems, Inc. 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Igor Fedorenko - extracted from ElementsImpl
+ *******************************************************************************/
+package org.eclipse.jdt.internal.compiler.apt.model;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.lang.model.AnnotatedConstruct;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.ModuleElement;
+import javax.lang.model.element.PackageElement;
+import javax.lang.model.element.TypeElement;
+
+import org.eclipse.jdt.core.compiler.CharOperation;
+import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseProcessingEnvImpl;
+import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
+import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
+import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding;
+import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
+import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
+import org.eclipse.jdt.internal.compiler.util.HashtableOfModule;
+
+/**
+ * Utilities for working with java9 language elements.
+ * There is one of these for every ProcessingEnvironment.
+ */
+public class ElementsImpl9 extends ElementsImpl {
+
+ public ElementsImpl9(BaseProcessingEnvImpl env) {
+ super(env);
+ }
+
+ @Override
+ public TypeElement getTypeElement(CharSequence name) {
+ final char[][] compoundName = CharOperation.splitOn('.', name.toString().toCharArray());
+ Set<? extends ModuleElement> allModuleElements = getAllModuleElements();
+ for (ModuleElement moduleElement : allModuleElements) {
+ TypeElement t = getTypeElement(compoundName, ((ModuleElementImpl) moduleElement).binding);
+ if (t != null) {
+ return t;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public TypeElement getTypeElement(ModuleElement module, CharSequence name) {
+ ModuleBinding mBinding = ((ModuleElementImpl) module).binding;
+ final char[][] compoundName = CharOperation.splitOn('.', name.toString().toCharArray());
+ return getTypeElement(compoundName, mBinding);
+ }
+
+ private TypeElement getTypeElement(final char[][] compoundName, ModuleBinding mBinding) {
+ LookupEnvironment le = mBinding == null ? _env.getLookupEnvironment() : mBinding.environment;
+ ReferenceBinding binding = mBinding == null ? le.getType(compoundName) : le.getType(compoundName, mBinding);
+ // If we didn't find the binding, maybe it's a nested type;
+ // try finding the top-level type and then working downwards.
+ if (null == binding) {
+ ReferenceBinding topLevelBinding = null;
+ int topLevelSegments = compoundName.length;
+ while (--topLevelSegments > 0) {
+ char[][] topLevelName = new char[topLevelSegments][];
+ for (int i = 0; i < topLevelSegments; ++i) {
+ topLevelName[i] = compoundName[i];
+ }
+ topLevelBinding = le.getType(topLevelName);
+ if (null != topLevelBinding) {
+ break;
+ }
+ }
+ if (null == topLevelBinding) {
+ return null;
+ }
+ binding = topLevelBinding;
+ for (int i = topLevelSegments; null != binding && i < compoundName.length; ++i) {
+ binding = binding.getMemberType(compoundName[i]);
+ }
+ }
+ if (null == binding) {
+ return null;
+ }
+ return new TypeElementImpl(_env, binding, null);
+ }
+
+
+ @Override
+ public Origin getOrigin(Element e) {
+ return Origin.EXPLICIT;
+ }
+
+ @Override
+ public Origin getOrigin(AnnotatedConstruct c, AnnotationMirror a) {
+ return Origin.EXPLICIT;
+ }
+
+ @Override
+ public Origin getOrigin(ModuleElement m, ModuleElement.Directive directive) {
+ return Origin.EXPLICIT;
+ }
+
+ @Override
+ public boolean isBridge(ExecutableElement e) {
+ MethodBinding methodBinding = (MethodBinding) ((ExecutableElementImpl) e)._binding;
+ return methodBinding.isBridge();
+ }
+
+ @Override
+ public ModuleElement getModuleOf(Element elem) {
+ if (elem instanceof ModuleElement) {
+ return (ModuleElement) elem;
+ }
+ Element parent = elem.getEnclosingElement();
+ while (parent != null) {
+ if (parent instanceof ModuleElement) {
+ return (ModuleElement) parent;
+ }
+ parent = parent.getEnclosingElement();
+ }
+ return null;
+ }
+
+ @Override
+ public ModuleElement getModuleElement(CharSequence name) {
+ LookupEnvironment lookup = _env.getLookupEnvironment();
+ ModuleBinding binding = lookup.getModule(name.length() == 0 ? ModuleBinding.UNNAMED : name.toString().toCharArray());
+ //TODO: Surely there has to be a better way than calling toString().toCharArray()?
+ if (binding == null) {
+ return null;
+ }
+ return new ModuleElementImpl(_env, binding);
+ }
+
+ @Override
+ public Set<? extends ModuleElement> getAllModuleElements() {
+ LookupEnvironment lookup = _env.getLookupEnvironment();
+ HashtableOfModule knownModules = lookup.knownModules;
+ ModuleBinding[] modules = knownModules.valueTable;
+ if (modules == null || modules.length == 0) {
+ return Collections.emptySet();
+ }
+ Set<ModuleElement> mods = new HashSet<>(modules.length);
+ for (ModuleBinding moduleBinding : modules) {
+ if (moduleBinding == null)
+ continue;
+ ModuleElement element = (ModuleElement) _env.getFactory().newElement(moduleBinding);
+ mods.add(element);
+ }
+ mods.add((ModuleElement) _env.getFactory().newElement(lookup.UnNamedModule));
+ return mods;
+ }
+
+ @Override
+ public
+ PackageElement getPackageElement(ModuleElement module, CharSequence name) {
+ ModuleBinding mBinding = ((ModuleElementImpl) module).binding;
+ final char[][] compoundName = CharOperation.splitOn('.', name.toString().toCharArray());
+ PackageBinding p = null;
+ if (mBinding != null) {
+
+ int length = compoundName.length;
+ if (length > 1) {
+ char[][] parent = new char[compoundName.length - 1][];
+ System.arraycopy(compoundName, 0, parent, 0, length - 1);
+ p = mBinding.getPackage(parent, compoundName[length - 1]);
+ } else {
+ p = mBinding.getTopLevelPackage(compoundName[0]);
+ }
+ } else {
+ p = _env.getLookupEnvironment().createPackage(compoundName);
+ }
+ if (p == null || !p.isValidBinding())
+ return null;
+ return (PackageElement) _env.getFactory().newElement(p);
+ }
+}

Back to the top