Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjay2018-06-26 06:36:52 -0400
committerJayaprakash Arthanareeswaran2018-06-28 13:44:45 -0400
commitf668bca61ebe161adbab98cbb94df79497197a1b (patch)
tree4ef9e0ebb0cbf242500e55f93a0bb9bfa63819c8 /org.eclipse.jdt.compiler.apt
parented78da37f7c90478f2f099f0d039c9462797f2af (diff)
downloadeclipse.jdt.core-f668bca61ebe161adbab98cbb94df79497197a1b.tar.gz
eclipse.jdt.core-f668bca61ebe161adbab98cbb94df79497197a1b.tar.xz
eclipse.jdt.core-f668bca61ebe161adbab98cbb94df79497197a1b.zip
Bug 534979 - [11] Add warning in annotation processing on redefiningY20180705-0105
symbols Change-Id: I3054799f2c9f185a5e84b6ae53b7197568a1cf27 Signed-off-by: jay <jarthana@in.ibm.com>
Diffstat (limited to 'org.eclipse.jdt.compiler.apt')
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BatchFilerImpl.java18
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileManager.java59
2 files changed, 71 insertions, 6 deletions
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BatchFilerImpl.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BatchFilerImpl.java
index 31a29eadf7..d5d522dcb4 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BatchFilerImpl.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BatchFilerImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2015 BEA Systems, Inc.
+ * Copyright (c) 2006, 2018 BEA Systems, Inc.
* 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
@@ -21,6 +21,7 @@ import java.util.HashSet;
import javax.annotation.processing.Filer;
import javax.annotation.processing.FilerException;
import javax.lang.model.element.Element;
+import javax.lang.model.element.TypeElement;
import javax.tools.FileObject;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
@@ -133,8 +134,19 @@ public class BatchFilerImpl implements Filer {
@Override
public JavaFileObject createSourceFile(CharSequence name,
Element... originatingElements) throws IOException {
- JavaFileObject jfo = _fileManager.getJavaFileForOutput(
- StandardLocation.SOURCE_OUTPUT, name.toString(), JavaFileObject.Kind.SOURCE, null);
+ String moduleAndPkgString = name.toString();
+ int slash = moduleAndPkgString.indexOf('/');
+ String mod = null;
+ if (slash != -1) {
+ name = moduleAndPkgString.substring(slash + 1, name.length());
+ mod = moduleAndPkgString.substring(0, slash);
+ }
+ TypeElement typeElement = _env._elementUtils.getTypeElement(name);
+ if (typeElement != null) {
+ throw new FilerException("Source file already exists : " + moduleAndPkgString); //$NON-NLS-1$
+ }
+ Location location = mod == null ? StandardLocation.SOURCE_OUTPUT : _fileManager.getLocationForModule(StandardLocation.SOURCE_OUTPUT, mod);
+ JavaFileObject jfo = _fileManager.getJavaFileForOutput(location, name.toString(), JavaFileObject.Kind.SOURCE, null);
URI uri = jfo.toUri();
if (_createdFiles.contains(uri)) {
throw new FilerException("Source file already created : " + name); //$NON-NLS-1$
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileManager.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileManager.java
index f6a71b1b51..b12f1d7be7 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileManager.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2017 IBM Corporation and others.
+ * Copyright (c) 2006, 2018 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
@@ -1390,7 +1390,17 @@ public class EclipseFileManager implements StandardJavaFileManager {
@Override
public Location getLocationForModule(Location location, String moduleName) throws IOException {
validateModuleLocation(location, moduleName);
- return this.locationHandler.getLocation(location, moduleName);
+ Location result = this.locationHandler.getLocation(location, moduleName);
+ if (result == null && location == StandardLocation.CLASS_OUTPUT) {
+ LocationWrapper wrapper = this.locationHandler.getLocation(StandardLocation.MODULE_SOURCE_PATH, moduleName);
+ deriveOutputLocationForModules(moduleName, wrapper.paths);
+ result = getLocationForModule(location, moduleName);
+ } else if (result == null && location == StandardLocation.SOURCE_OUTPUT) {
+ LocationWrapper wrapper = this.locationHandler.getLocation(StandardLocation.MODULE_SOURCE_PATH, moduleName);
+ deriveSourceOutputLocationForModules(moduleName, wrapper.paths);
+ result = getLocationForModule(location, moduleName);
+ }
+ return result;
}
@Override
@@ -1448,7 +1458,50 @@ public class EclipseFileManager implements StandardJavaFileManager {
}
return null;
}
-
+ private void deriveOutputLocationForModules(String moduleName, Collection<? extends Path> paths) {
+ LocationWrapper wrapper = this.locationHandler.getLocation(StandardLocation.CLASS_OUTPUT, moduleName);
+ if (wrapper == null) {
+ // First get from our internally known location for legacy/unnamed location
+ wrapper = this.locationHandler.getLocation(StandardLocation.CLASS_OUTPUT, ""); //$NON-NLS-1$
+ if (wrapper == null) {
+ wrapper = this.locationHandler.getLocation(StandardLocation.CLASS_OUTPUT);
+ }
+ if (wrapper != null) {
+ Iterator<? extends Path> iterator = wrapper.paths.iterator();
+ if (iterator.hasNext()) {
+ try {
+ // Per module output location is always a singleton list
+ Path path = iterator.next().resolve(moduleName);
+ this.locationHandler.setLocation(StandardLocation.CLASS_OUTPUT, moduleName, Collections.singletonList(path));
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+ private void deriveSourceOutputLocationForModules(String moduleName, Collection<? extends Path> paths) {
+ LocationWrapper wrapper = this.locationHandler.getLocation(StandardLocation.SOURCE_OUTPUT, moduleName);
+ if (wrapper == null) {
+ // First get from our internally known location for legacy/unnamed location
+ wrapper = this.locationHandler.getLocation(StandardLocation.SOURCE_OUTPUT, ""); //$NON-NLS-1$
+ if (wrapper == null) {
+ wrapper = this.locationHandler.getLocation(StandardLocation.SOURCE_OUTPUT);
+ }
+ if (wrapper != null) {
+ Iterator<? extends Path> iterator = wrapper.paths.iterator();
+ if (iterator.hasNext()) {
+ try {
+ // Per module output location is always a singleton list
+ Path path = iterator.next().resolve(moduleName);
+ this.locationHandler.setLocation(StandardLocation.SOURCE_OUTPUT, moduleName, Collections.singletonList(path));
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
@Override
public void setLocationForModule(Location location, String moduleName, Collection<? extends Path> paths) throws IOException {
validateModuleLocation(location, moduleName);

Back to the top