Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 164109 Details for
Bug 308256
DiagnosticListener always supplies Diagnostic.getSource()==null
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix
patch_308256_3.txt (text/plain), 7.82 KB, created by
Olivier Thomann
on 2010-04-07 14:30:46 EDT
(
hide
)
Description:
Proposed fix
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2010-04-07 14:30:46 EDT
Size:
7.82 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.compiler.tool >Index: src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java,v >retrieving revision 1.12 >diff -u -r1.12 EclipseCompilerImpl.java >--- src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java 9 Oct 2009 13:01:17 -0000 1.12 >+++ src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java 7 Apr 2010 18:26:05 -0000 >@@ -206,15 +206,9 @@ > } > @Override > public JavaFileObject getSource() { >- try { >- if (EclipseCompilerImpl.this.fileManager.hasLocation(StandardLocation.SOURCE_PATH)) { >- return EclipseCompilerImpl.this.fileManager.getJavaFileForInput( >- StandardLocation.SOURCE_PATH, >- new String(originatingFileName), >- JavaFileObject.Kind.SOURCE); >- } >- } catch (IOException e) { >- // ignore >+ File f = new File(new String(originatingFileName)); >+ if (f.exists()) { >+ return new EclipseFileObject(null, f.toURI(), JavaFileObject.Kind.SOURCE, null); > } > return null; > } >@@ -282,15 +276,9 @@ > } > @Override > public JavaFileObject getSource() { >- try { >- if (EclipseCompilerImpl.this.fileManager.hasLocation(StandardLocation.SOURCE_PATH)) { >- return EclipseCompilerImpl.this.fileManager.getJavaFileForInput( >- StandardLocation.SOURCE_PATH, >- new String(originatingFileName), >- JavaFileObject.Kind.SOURCE); >- } >- } catch (IOException e) { >- // ignore >+ File f = new File(new String(originatingFileName)); >+ if (f.exists()) { >+ return new EclipseFileObject(null, f.toURI(), JavaFileObject.Kind.SOURCE, null); > } > return null; > } >#P org.eclipse.jdt.compiler.tool.tests >Index: src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java,v >retrieving revision 1.22 >diff -u -r1.22 CompilerToolTests.java >--- src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java 3 Feb 2010 20:46:57 -0000 1.22 >+++ src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java 7 Apr 2010 18:26:05 -0000 >@@ -26,6 +26,7 @@ > import java.util.ServiceLoader; > import java.util.Set; > >+import javax.tools.Diagnostic; > import javax.tools.FileObject; > import javax.tools.ForwardingJavaFileManager; > import javax.tools.JavaCompiler; >@@ -65,6 +66,8 @@ > suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler3")); > suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler4")); > suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler5")); >+ suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler6")); >+ suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler7")); > suite.addTest(new CompilerToolTests("testCleanUp")); > return suite; > } >@@ -688,6 +691,125 @@ > assertTrue("delete failed", inputFile.delete()); > } > >+ public void testCompilerOneClassWithEclipseCompiler6() { >+ String tmpFolder = System.getProperty("java.io.tmpdir"); >+ File packageFolder = new File(tmpFolder, "p"); >+ if (!packageFolder.mkdirs()) { >+ return; >+ } >+ File inputFile = new File(packageFolder, "X.java"); >+ BufferedWriter writer = null; >+ try { >+ writer = new BufferedWriter(new FileWriter(inputFile)); >+ writer.write( >+ "package p;\n" + >+ "public class X extends File {}"); >+ writer.flush(); >+ writer.close(); >+ } catch (IOException e) { >+ // ignore >+ } finally { >+ if (writer != null) { >+ try { >+ writer.close(); >+ } catch (IOException e) { >+ // ignore >+ } >+ } >+ } >+ // System compiler >+ StandardJavaFileManager manager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset()); >+ List<File> files = new ArrayList<File>(); >+ files.add(inputFile); >+ Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files); >+ >+ List<String> options = new ArrayList<String>(); >+ options.add("-d"); >+ options.add(tmpFolder); >+ options.add("-sourcepath"); >+ options.add(tmpFolder); >+ ByteArrayOutputStream errBuffer = new ByteArrayOutputStream(); >+ PrintWriter err = new PrintWriter(errBuffer); >+ CompilerInvocationDiagnosticListener compilerInvocationDiagnosticListener = new CompilerInvocationDiagnosticListener(err) { >+ @Override >+ public void report(Diagnostic<? extends JavaFileObject> diagnostic) { >+ JavaFileObject source = diagnostic.getSource(); >+ assertNotNull("No source", source); >+ super.report(diagnostic); >+ } >+ }; >+ CompilationTask task = Compiler.getTask(null, manager, compilerInvocationDiagnosticListener, options, null, units); >+ // check the classpath location >+ Boolean result = task.call(); >+ err.flush(); >+ err.close(); >+ assertFalse(errBuffer.toString().isEmpty()); >+ assertTrue(compilerInvocationDiagnosticListener.kind != CompilerInvocationDiagnosticListener.NONE); >+ if (!result.booleanValue()) { >+ assertFalse("Compilation did not fail", false); >+ } >+ // check that the .class file exist for X >+ assertTrue("delete failed", inputFile.delete()); >+ assertTrue("delete failed", packageFolder.delete()); >+ } >+ >+ public void testCompilerOneClassWithEclipseCompiler7() { >+ String tmpFolder = System.getProperty("java.io.tmpdir"); >+ File inputFile = new File(tmpFolder, "X.java"); >+ BufferedWriter writer = null; >+ try { >+ writer = new BufferedWriter(new FileWriter(inputFile)); >+ writer.write( >+ "package p;\n" + >+ "public class X extends File {}"); >+ writer.flush(); >+ writer.close(); >+ } catch (IOException e) { >+ // ignore >+ } finally { >+ if (writer != null) { >+ try { >+ writer.close(); >+ } catch (IOException e) { >+ // ignore >+ } >+ } >+ } >+ // System compiler >+ StandardJavaFileManager manager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset()); >+ List<File> files = new ArrayList<File>(); >+ files.add(inputFile); >+ Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files); >+ >+ List<String> options = new ArrayList<String>(); >+ options.add("-d"); >+ options.add(tmpFolder); >+ options.add("-sourcepath"); >+ options.add(tmpFolder); >+ ByteArrayOutputStream errBuffer = new ByteArrayOutputStream(); >+ PrintWriter err = new PrintWriter(errBuffer); >+ CompilerInvocationDiagnosticListener compilerInvocationDiagnosticListener = new CompilerInvocationDiagnosticListener(err) { >+ @Override >+ public void report(Diagnostic<? extends JavaFileObject> diagnostic) { >+ JavaFileObject source = diagnostic.getSource(); >+ assertNotNull("No source", source); >+ super.report(diagnostic); >+ } >+ }; >+ CompilationTask task = Compiler.getTask(null, manager, compilerInvocationDiagnosticListener, options, null, units); >+ // check the classpath location >+ Boolean result = task.call(); >+ err.flush(); >+ err.close(); >+ assertFalse(errBuffer.toString().isEmpty()); >+ assertTrue(compilerInvocationDiagnosticListener.kind != CompilerInvocationDiagnosticListener.NONE); >+ if (!result.booleanValue()) { >+ assertFalse("Compilation did not fail", false); >+ } >+ // check that the .class file exist for X >+ assertTrue("delete failed", inputFile.delete()); >+ } >+ > public void testFileManager() { > String tmpFolder = System.getProperty("java.io.tmpdir"); > File dir = new File(tmpFolder, "src" + System.currentTimeMillis());
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 308256
: 164109