Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Harley2008-01-11 21:11:25 +0000
committerWalter Harley2008-01-11 21:11:25 +0000
commit8fea12e4bfaf9512e2895dd3e38d29d36df0b0d7 (patch)
tree3189df749b825e6c1f0951adcfc1fd7fc300c7ed /org.eclipse.jdt.apt.pluggable.core
parent4cfa9fdfcf70945208bf89f43413554ac3911276 (diff)
downloadeclipse.jdt.core-8fea12e4bfaf9512e2895dd3e38d29d36df0b0d7.tar.gz
eclipse.jdt.core-8fea12e4bfaf9512e2895dd3e38d29d36df0b0d7.tar.xz
eclipse.jdt.core-8fea12e4bfaf9512e2895dd3e38d29d36df0b0d7.zip
Bug 213540: support Filer.getResource() for Java 6 processors
Diffstat (limited to 'org.eclipse.jdt.apt.pluggable.core')
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java15
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeInputFileObject.java118
2 files changed, 127 insertions, 6 deletions
diff --git a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java
index 1251a6df11..482711797c 100644
--- a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java
+++ b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 BEA Systems, Inc.
+ * Copyright (c) 2007, 2008 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
@@ -88,7 +88,7 @@ public class IdeFilerImpl implements Filer {
if ( relativeName.length() == 0) {
throw new IllegalArgumentException("Relative name is zero length");
}
- IFile file = getOutputFileForLocation(location, pkg, relativeName);
+ IFile file = getFileFromOutputLocation(location, pkg, relativeName);
//TODO: check whether file has already been generated in this run
Set<IFile> parentFiles = new HashSet<IFile>(originatingElements.length);
@@ -127,12 +127,15 @@ public class IdeFilerImpl implements Filer {
/* (non-Javadoc)
* @see javax.annotation.processing.Filer#getResource(javax.tools.JavaFileManager.Location, java.lang.CharSequence, java.lang.CharSequence)
+ * Returns a FileObject representing the specified resource. The only supported locations
+ * are CLASS_OUTPUT and SOURCE_OUTPUT.
*/
@Override
public FileObject getResource(Location location, CharSequence pkg, CharSequence relativeName)
- throws IOException {
- //TODO
- throw new UnsupportedOperationException("Reading resource files is not yet implemented"); //$NON-NLS-1$
+ throws IOException
+ {
+ IFile file = getFileFromOutputLocation(location, pkg, relativeName);
+ return new IdeInputFileObject(file);
}
/**
@@ -142,7 +145,7 @@ public class IdeFilerImpl implements Filer {
* @param relPath must be non-null and non-empty.
* @throws IOException if the path is not valid.
*/
- protected IFile getOutputFileForLocation( Location loc, CharSequence pkg, CharSequence relPath )
+ protected IFile getFileFromOutputLocation( Location loc, CharSequence pkg, CharSequence relPath )
throws IOException
{
GeneratedSourceFolderManager gsfm = _env.getAptProject().getGeneratedSourceFolderManager();
diff --git a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeInputFileObject.java b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeInputFileObject.java
new file mode 100644
index 0000000000..599c728bbe
--- /dev/null
+++ b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeInputFileObject.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * wharley@bea.com - initial implementation
+ *
+ *******************************************************************************/
+
+package org.eclipse.jdt.internal.apt.pluggable.core.filer;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.URI;
+
+import javax.tools.FileObject;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * Implementation of a FileObject returned by Filer.getResource().
+ * @since 3.4
+ */
+public class IdeInputFileObject implements FileObject {
+
+ private final IFile _file;
+
+ public IdeInputFileObject(IFile file) {
+ _file = file;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.tools.FileObject#delete()
+ */
+ @Override
+ public boolean delete() {
+ throw new IllegalStateException("An annotation processor is not permitted to delete resources");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.tools.FileObject#getCharContent(boolean)
+ */
+ @Override
+ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
+ //TODO
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.tools.FileObject#getLastModified()
+ */
+ @Override
+ public long getLastModified() {
+ return _file.getModificationStamp();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.tools.FileObject#getName()
+ */
+ @Override
+ public String getName() {
+ return _file.getProjectRelativePath().toString();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.tools.FileObject#openInputStream()
+ */
+ @Override
+ public InputStream openInputStream() throws IOException {
+ try {
+ return _file.getContents();
+ } catch (CoreException e) {
+ throw new IOException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.tools.FileObject#openOutputStream()
+ */
+ @Override
+ public OutputStream openOutputStream() throws IOException {
+ throw new IllegalStateException("Writing to a non-generated file is not permitted");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.tools.FileObject#openReader(boolean)
+ */
+ @Override
+ public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
+ return new BufferedReader(new InputStreamReader(openInputStream()));
+ }
+
+ /* (non-Javadoc)
+ * @see javax.tools.FileObject#openWriter()
+ */
+ @Override
+ public Writer openWriter() throws IOException {
+ throw new IllegalStateException("Writing to a non-generated file is not permitted");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.tools.FileObject#toUri()
+ */
+ @Override
+ public URI toUri() {
+ return _file.getLocationURI();
+ }
+
+}

Back to the top