Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSasikanth Bharadwaj2018-02-08 06:01:02 -0500
committerSasikanth Bharadwaj2018-02-08 06:01:02 -0500
commitb8996fefb00a5675c331e99e16920397a404b111 (patch)
treed50e3be8c0548b676036ae41e1963af0e8e802e8 /org.eclipse.jdt.compiler.apt
parent000d0eb78c7c9867861f7f2160676b4bed5c42c2 (diff)
parent2cadb681dd72aa94e234bc831c9ea2a850982e32 (diff)
downloadeclipse.jdt.core-b8996fefb00a5675c331e99e16920397a404b111.tar.gz
eclipse.jdt.core-b8996fefb00a5675c331e99e16920397a404b111.tar.xz
eclipse.jdt.core-b8996fefb00a5675c331e99e16920397a404b111.zip
Merge branch 'R4_7_maintenance' into BETA_JAVA_18_3
Conflicts: org.eclipse.jdt.core/META-INF/MANIFEST.MF org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java org.eclipse.jdt.core/pom.xml Change-Id: I817bfebe3b73d2b75b74c5b6ada5b9652f597346
Diffstat (limited to 'org.eclipse.jdt.compiler.apt')
-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/pom.xml2
-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
7 files changed, 203 insertions, 125 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/pom.xml b/org.eclipse.jdt.compiler.apt/pom.xml
index 25a24c1334..47287573dd 100644
--- a/org.eclipse.jdt.compiler.apt/pom.xml
+++ b/org.eclipse.jdt.compiler.apt/pom.xml
@@ -14,7 +14,7 @@
<parent>
<artifactId>eclipse.jdt.core</artifactId>
<groupId>eclipse.jdt.core</groupId>
- <version>4.7.2-SNAPSHOT</version>
+ <version>4.7.3-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.compiler.apt</artifactId>
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