diff options
Diffstat (limited to 'org.eclipse.jdt.compiler.apt')
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); |