Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Harley2007-10-02 22:09:46 +0000
committerWalter Harley2007-10-02 22:09:46 +0000
commitd76b61af6ffe66ae65403b0c1b9f47684496cada (patch)
tree7f9bef4320bda7e8de8acde165db7c8e9d7bb011 /org.eclipse.jdt.apt.pluggable.core
parent60bf43e2f6af92e51fdf7c9da0da9b844ceaacf7 (diff)
downloadeclipse.jdt.core-d76b61af6ffe66ae65403b0c1b9f47684496cada.tar.gz
eclipse.jdt.core-d76b61af6ffe66ae65403b0c1b9f47684496cada.tar.xz
eclipse.jdt.core-d76b61af6ffe66ae65403b0c1b9f47684496cada.zip
Bug 190612: implement createResource() for IDE Filer. Refactor underlying code in order to achieve this.
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.java2
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeJavaSourceOutputStream.java (renamed from org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeJavaSourceFileWriter.java)25
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputFileObject.java122
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputJavaFileObject.java71
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputNonSourceFileObject.java92
5 files changed, 129 insertions, 183 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 828ae32e59..1251a6df11 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
@@ -98,7 +98,7 @@ public class IdeFilerImpl implements Filer {
parentFiles.add(enclosing);
}
}
- return new IdeOutputFileObject(_env, file, parentFiles);
+ return new IdeOutputNonSourceFileObject(_env, file, parentFiles);
}
/**
diff --git a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeJavaSourceFileWriter.java b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeJavaSourceOutputStream.java
index 908fd913d4..772c18d95d 100644
--- a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeJavaSourceFileWriter.java
+++ b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeJavaSourceOutputStream.java
@@ -12,8 +12,8 @@
package org.eclipse.jdt.internal.apt.pluggable.core.filer;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.StringWriter;
import java.util.Collection;
import org.eclipse.core.resources.IFile;
@@ -25,25 +25,26 @@ import org.eclipse.jdt.internal.apt.pluggable.core.Apt6Plugin;
import org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeProcessingEnvImpl;
/**
- *
+ * OutputStream used by the IdeFilerImpl to generate Java source files.
* @since 3.3
*/
-public class IdeJavaSourceFileWriter extends StringWriter {
-
+public class IdeJavaSourceOutputStream extends ByteArrayOutputStream {
+
private final IdeProcessingEnvImpl _env;
private final CharSequence _name;
private final Collection<IFile> _parentFiles;
private boolean _closed = false;
-
- public IdeJavaSourceFileWriter(IdeProcessingEnvImpl env, CharSequence name, Collection<IFile> parentFiles) {
+
+ public IdeJavaSourceOutputStream(IdeProcessingEnvImpl env, CharSequence name,
+ Collection<IFile> parentFiles)
+ {
_env = env;
- _parentFiles = parentFiles;
_name = name;
- _env.getAptProject().getGeneratedSourceFolderManager().getFolder();
+ _parentFiles = parentFiles;
}
- /**
- *
+ /* (non-Javadoc)
+ * @see java.io.ByteArrayOutputStream#close()
*/
@Override
public void close() throws IOException {
@@ -63,7 +64,6 @@ public class IdeJavaSourceFileWriter extends StringWriter {
//TODO - implement reconcile
}
else if ( phase == Phase.BUILD) {
- // TODO: Remember empty-parent situation.
result = gfm.generateFileDuringBuild(
_parentFiles, _name.toString(), this.toString(),
_env.currentProcessorSupportsRTTG(), null /* progress monitor */ );
@@ -73,7 +73,8 @@ public class IdeJavaSourceFileWriter extends StringWriter {
}
}
catch (CoreException ce) {
- Apt6Plugin.log(ce, "Unable to generate type when JavaSourceFilePrintWriter was closed"); //$NON-NLS-1$
+ Apt6Plugin.log(ce, "Unable to generate type when IdeJavaSourceOutputStream was closed"); //$NON-NLS-1$
}
}
+
}
diff --git a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputFileObject.java b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputFileObject.java
index 3f63bdc7ce..315a96c533 100644
--- a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputFileObject.java
+++ b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputFileObject.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 BEA Systems, Inc.
+ * Copyright (c) 2007 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
@@ -7,137 +7,43 @@
*
* Contributors:
* wharley@bea.com - initial API and implementation
+ *
*******************************************************************************/
package org.eclipse.jdt.internal.apt.pluggable.core.filer;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
import java.io.Reader;
-import java.io.Writer;
-import java.net.URI;
-import java.util.Collection;
-import java.util.Set;
import javax.tools.FileObject;
-import javax.tools.JavaFileManager.Location;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeProcessingEnvImpl;
+public abstract class IdeOutputFileObject implements FileObject {
-/**
- * Implementation of FileObject for generating resource files in the IDE.
- * This is used for files that are neither class files nor Java source files.
- * TODO: at present this represents a write-only (generated) file. When we
- * implement the openResource() calls in Filer, we may want to move some of
- * these methods into a base class.
- * @see IdeOutputJavaFileObject
- */
-public class IdeOutputFileObject implements FileObject
-{
- private final IdeProcessingEnvImpl _env;
- private final IFile _file;
- private final Collection<IFile> _parentFiles;
-
-
- /**
- * Create a new IdeOutputFileObject for writing. The file will not actually be written until the Writer or OutputStream is closed.
- * @param env among other roles, the ProcessingEnvironment tracks what files have been generated in a given build.
- * @param location must be an output location (see {@link Location#isOutputLocation()}).
- * @param pkg
- * @param relativeName
- * @param parentFiles
- * @see javax.tools.StandardLocation
- */
- public IdeOutputFileObject(IdeProcessingEnvImpl env, IFile file, Set<IFile> parentFiles) {
- _env = env;
- _file = file;
- _parentFiles = parentFiles;
- }
-
- /* (non-Javadoc)
- * @see javax.tools.FileObject#delete()
- */
@Override
- public boolean delete()
- {
- throw new UnsupportedOperationException("Deleting a generated file is not permitted");
+ public boolean delete() {
+ throw new IllegalStateException("Deleting a file is not permitted from within an annotation processor");
}
- /* (non-Javadoc)
- * @see javax.tools.FileObject#getCharContent(boolean)
- */
@Override
- public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException
- {
- throw new UnsupportedOperationException("Reading a generated file is not permitted");
+ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
+ throw new IllegalStateException("Generated files are write-only");
}
- /* (non-Javadoc)
- * @see javax.tools.FileObject#getLastModified()
- */
@Override
- public long getLastModified()
- {
+ public long getLastModified() {
+ //TODO
throw new UnsupportedOperationException("Not yet implemented");
}
- /* (non-Javadoc)
- * @see javax.tools.FileObject#getName()
- */
- @Override
- public String getName()
- {
- // TODO
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- /* (non-Javadoc)
- * @see javax.tools.FileObject#openInputStream()
- */
- @Override
- public InputStream openInputStream() throws IOException
- {
- throw new UnsupportedOperationException("Reading a generated file is not permitted");
- }
-
- /* (non-Javadoc)
- * @see javax.tools.FileObject#openOutputStream()
- */
- @Override
- public OutputStream openOutputStream() throws IOException
- {
- return new IdeNonSourceOutputStream(_env, _file, _parentFiles);
- }
-
- /* (non-Javadoc)
- * @see javax.tools.FileObject#openReader(boolean)
- */
@Override
- public Reader openReader(boolean ignoreEncodingErrors) throws IOException
- {
- throw new UnsupportedOperationException("Reading a generated file is not permitted");
+ public InputStream openInputStream() throws IOException {
+ throw new IllegalStateException("Opening an input stream on a generated file is not permitted");
}
- /* (non-Javadoc)
- * @see javax.tools.FileObject#openWriter()
- */
@Override
- public Writer openWriter() throws IOException
- {
- return new PrintWriter(openOutputStream());
- }
-
- /* (non-Javadoc)
- * @see javax.tools.FileObject#toUri()
- */
- @Override
- public URI toUri()
- {
- // TODO
- throw new UnsupportedOperationException("Not yet implemented");
+ public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
+ throw new IllegalStateException("Opening a reader on a generated file is not permitted");
}
-}
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputJavaFileObject.java b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputJavaFileObject.java
index f1a04bddd1..78a41ace09 100644
--- a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputJavaFileObject.java
+++ b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputJavaFileObject.java
@@ -13,9 +13,8 @@
package org.eclipse.jdt.internal.apt.pluggable.core.filer;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
-import java.io.Reader;
+import java.io.PrintWriter;
import java.io.Writer;
import java.net.URI;
import java.util.Collection;
@@ -33,7 +32,7 @@ import org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeProcessingEnvImpl
*
* @since 3.3
*/
-public class IdeOutputJavaFileObject implements JavaFileObject {
+public class IdeOutputJavaFileObject extends IdeOutputFileObject implements JavaFileObject {
private final IdeProcessingEnvImpl _env;
private final CharSequence _name;
@@ -45,9 +44,6 @@ public class IdeOutputJavaFileObject implements JavaFileObject {
_name = name;
}
- /* (non-Javadoc)
- * @see javax.tools.JavaFileObject#getAccessLevel()
- */
@Override
public Modifier getAccessLevel() {
//TODO
@@ -64,80 +60,31 @@ public class IdeOutputJavaFileObject implements JavaFileObject {
}
/* (non-Javadoc)
- * @see javax.tools.JavaFileObject#getNestingKind()
+ * @see javax.tools.FileObject#getName()
*/
@Override
- public NestingKind getNestingKind() {
- //TODO
- throw new UnsupportedOperationException("Not yet implemented");
+ public String getName() {
+ return _name.toString();
}
- /* (non-Javadoc)
- * @see javax.tools.JavaFileObject#isNameCompatible(java.lang.String, javax.tools.JavaFileObject.Kind)
- */
@Override
- public boolean isNameCompatible(String simpleName, Kind kind) {
+ public NestingKind getNestingKind() {
//TODO
throw new UnsupportedOperationException("Not yet implemented");
}
- /* (non-Javadoc)
- * @see javax.tools.FileObject#delete()
- */
- @Override
- public boolean delete() {
- throw new UnsupportedOperationException("Deleting a file is not permitted from within an annotation processor");
- }
-
- /* (non-Javadoc)
- * @see javax.tools.FileObject#getCharContent(boolean)
- */
- @Override
- public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
- //TODO
- throw new IllegalStateException("Generated files are write-only");
- }
-
- /* (non-Javadoc)
- * @see javax.tools.FileObject#getLastModified()
- */
@Override
- public long getLastModified() {
+ public boolean isNameCompatible(String simpleName, Kind kind) {
//TODO
throw new UnsupportedOperationException("Not yet implemented");
}
/* (non-Javadoc)
- * @see javax.tools.FileObject#getName()
- */
- @Override
- public String getName() {
- return _name.toString();
- }
-
- /* (non-Javadoc)
- * @see javax.tools.FileObject#openInputStream()
- */
- @Override
- public InputStream openInputStream() throws IOException {
- throw new IllegalStateException("Opening an input stream on a generated file is not permitted");
- }
-
- /* (non-Javadoc)
* @see javax.tools.FileObject#openOutputStream()
*/
@Override
public OutputStream openOutputStream() throws IOException {
- //TODO
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- /* (non-Javadoc)
- * @see javax.tools.FileObject#openReader(boolean)
- */
- @Override
- public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
- throw new IllegalStateException("Opening a reader on a generated file is not permitted");
+ return new IdeJavaSourceOutputStream(_env, _name, _parentFiles);
}
/* (non-Javadoc)
@@ -145,7 +92,7 @@ public class IdeOutputJavaFileObject implements JavaFileObject {
*/
@Override
public Writer openWriter() throws IOException {
- return new IdeJavaSourceFileWriter(_env, _name, _parentFiles);
+ return new PrintWriter(openOutputStream());
}
/* (non-Javadoc)
diff --git a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputNonSourceFileObject.java b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputNonSourceFileObject.java
new file mode 100644
index 0000000000..4612e171f1
--- /dev/null
+++ b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeOutputNonSourceFileObject.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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 API and implementation
+ *******************************************************************************/
+
+package org.eclipse.jdt.internal.apt.pluggable.core.filer;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.net.URI;
+import java.util.Collection;
+import java.util.Set;
+
+import javax.tools.JavaFileManager.Location;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeProcessingEnvImpl;
+
+/**
+ * Implementation of FileObject for generating resource files in the IDE.
+ * This is used for files that are neither class files nor Java source files.
+ * @see IdeOutputJavaFileObject
+ */
+public class IdeOutputNonSourceFileObject extends IdeOutputFileObject
+{
+ private final IdeProcessingEnvImpl _env;
+ private final IFile _file;
+ private final Collection<IFile> _parentFiles;
+
+
+ /**
+ * Create a new IdeOutputFileObject for writing. The file will not actually be written until the Writer or OutputStream is closed.
+ * @param env among other roles, the ProcessingEnvironment tracks what files have been generated in a given build.
+ * @param location must be an output location (see {@link Location#isOutputLocation()}).
+ * @param pkg
+ * @param relativeName
+ * @param parentFiles
+ * @see javax.tools.StandardLocation
+ */
+ public IdeOutputNonSourceFileObject(IdeProcessingEnvImpl env, IFile file, Set<IFile> parentFiles) {
+ _env = env;
+ _file = file;
+ _parentFiles = parentFiles;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.tools.FileObject#getName()
+ */
+ @Override
+ public String getName()
+ {
+ // TODO
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.tools.FileObject#openOutputStream()
+ */
+ @Override
+ public OutputStream openOutputStream() throws IOException
+ {
+ return new IdeNonSourceOutputStream(_env, _file, _parentFiles);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.tools.FileObject#openWriter()
+ */
+ @Override
+ public Writer openWriter() throws IOException
+ {
+ return new PrintWriter(openOutputStream());
+ }
+
+ /* (non-Javadoc)
+ * @see javax.tools.FileObject#toUri()
+ */
+ @Override
+ public URI toUri()
+ {
+ // TODO
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+}

Back to the top