diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacCompilationUnitResolver.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacCompilationUnitResolver.java index 2e8ee130a46..957f83bee08 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacCompilationUnitResolver.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacCompilationUnitResolver.java @@ -27,6 +27,7 @@ import javax.tools.FileObject; import javax.tools.JavaFileManager; import javax.tools.JavaFileObject; +import javax.tools.JavaFileObject.Kind; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourcesPlugin; @@ -43,6 +44,7 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.javac.JavacUtils; +import org.eclipse.jdt.internal.javac.VirtualFileObject; import org.eclipse.jdt.internal.javac.dom.FindNextJavadocableSibling; import com.sun.tools.javac.file.JavacFileManager; @@ -145,15 +147,16 @@ public CompilationUnit toCompilationUnit(org.eclipse.jdt.internal.compiler.env.I boolean initialNeedsToResolveBinding, IJavaProject project, List classpaths, NodeSearcher nodeSearcher, int apiLevel, Map compilerOptions, WorkingCopyOwner workingCopyOwner, WorkingCopyOwner typeRootWorkingCopyOwner, int flags, IProgressMonitor monitor) { + // For comparison + //CompilationUnit res2 = CompilationUnitResolver.FACADE.toCompilationUnit(sourceUnit, initialNeedsToResolveBinding, project, classpaths, nodeSearcher, apiLevel, compilerOptions, typeRootWorkingCopyOwner, typeRootWorkingCopyOwner, flags, monitor); + // TODO currently only parse CompilationUnit res = parse(new org.eclipse.jdt.internal.compiler.env.ICompilationUnit[] { sourceUnit}, apiLevel, compilerOptions, flags, project, monitor).get(sourceUnit); if (initialNeedsToResolveBinding) { resolveBindings(res); } - // For comparison -// CompilationUnit res2 = CompilationUnitResolver.FACADE.toCompilationUnit(sourceUnit, initialNeedsToResolveBinding, project, classpaths, nodeSearcher, apiLevel, compilerOptions, typeRootWorkingCopyOwner, typeRootWorkingCopyOwner, flags, monitor); -// //res.typeAndFlags=res2.typeAndFlags; + //new CompilationUnitComparator(apiLevel).compare(res, res2); // String res1a = res.toString(); // String res2a = res2.toString(); // @@ -181,13 +184,17 @@ private Map findTargetDOM(Map options, int level, Context context) { AST ast = AST.newAST(level, JavaCore.ENABLED.equals(options.get(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES))); String sourceModeSetting = options.get(JavaCore.COMPILER_SOURCE); diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/VirtualFileObject.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/VirtualFileObject.java new file mode 100644 index 00000000000..439d9d5a9b4 --- /dev/null +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/VirtualFileObject.java @@ -0,0 +1,100 @@ +package org.eclipse.jdt.internal.javac; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; +import java.net.URI; + +import javax.lang.model.element.Modifier; +import javax.lang.model.element.NestingKind; +import javax.tools.JavaFileObject; + +import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; + +public class VirtualFileObject implements JavaFileObject { + private ICompilationUnit sourceUnit; + private Kind kind; + public VirtualFileObject(ICompilationUnit sourceUnit, Kind kind) { + this.sourceUnit = sourceUnit; + this.kind = kind; + } + + @Override + public URI toUri() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getName() { + return new String(sourceUnit.getFileName()); + } + + @Override + public InputStream openInputStream() throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public OutputStream openOutputStream() throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Reader openReader(boolean ignoreEncodingErrors) throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { + StringBuilder sb = new StringBuilder(); + sb.append(this.sourceUnit.getContents()); + return sb; + } + + @Override + public Writer openWriter() throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public long getLastModified() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public boolean delete() { + return false; + } + + @Override + public Kind getKind() { + return this.kind; + } + + @Override + public boolean isNameCompatible(String simpleName, Kind kind) { + // TODO Auto-generated method stub + return false; + } + + @Override + public NestingKind getNestingKind() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Modifier getAccessLevel() { + // TODO Auto-generated method stub + return null; + } + +}