Index: com/sun/source/util/TreePath.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/source/util/TreePath.java,v retrieving revision 1.1.2.3 retrieving revision 1.5 diff -u -r1.1.2.3 -r1.5 --- com/sun/source/util/TreePath.java 15 Aug 2007 10:23:04 -0000 1.1.2.3 +++ com/sun/source/util/TreePath.java 17 Aug 2007 13:18:17 -0000 1.5 @@ -120,19 +120,20 @@ public Iterator iterator() { return new Iterator() { public boolean hasNext() { - return curr.parent != null; + return curr != null; } public Tree next() { + Tree t = curr.leaf; curr = curr.parent; - return curr.leaf; + return t; } public void remove() { throw new UnsupportedOperationException(); } - private TreePath curr; + private TreePath curr = TreePath.this; }; } Index: com/sun/source/util/TreeScanner.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/source/util/TreeScanner.java,v retrieving revision 1.1.2.6 retrieving revision 1.11 diff -u -r1.1.2.6 -r1.11 --- com/sun/source/util/TreeScanner.java 15 Aug 2007 10:23:04 -0000 1.1.2.6 +++ com/sun/source/util/TreeScanner.java 17 Sep 2007 05:26:06 -0000 1.11 @@ -140,6 +140,7 @@ r = scanAndReduce(node.getParameters(), p, r); r = scanAndReduce(node.getThrows(), p, r); r = scanAndReduce(node.getBody(), p, r); + r = scanAndReduce(node.getDefaultValue(), p, r); return r; } @@ -376,6 +377,6 @@ } public R visitErroneous(ErroneousTree node, P p) { - return null; + return scan(node.getErrorTrees(), p); } } Index: com/sun/tools/javac/api/JavacScope.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/api/JavacScope.java,v retrieving revision 1.1.2.2 retrieving revision 1.5 diff -u -r1.1.2.2 -r1.5 --- com/sun/tools/javac/api/JavacScope.java 15 Aug 2007 10:23:10 -0000 1.1.2.2 +++ com/sun/tools/javac/api/JavacScope.java 17 Aug 2007 13:18:19 -0000 1.5 @@ -39,6 +39,7 @@ import com.sun.source.util.TreePath; import com.sun.source.util.Trees; import com.sun.tools.javac.code.Scope; +import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.comp.Attr; import com.sun.tools.javac.comp.AttrContext; @@ -94,7 +95,12 @@ return null; } public Iterable getLocalElements() { - return env.toplevel.starImportScope.getElements(); + List l = List.nil(); + for (Symbol symbol : env.toplevel.starImportScope.getElements()) { + if (env.toplevel.starImportScope.lookup(symbol.name).scope != null) + l = l.prepend(symbol); + } + return l; } }; } @@ -102,7 +108,7 @@ public TypeElement getEnclosingClass() { // hide the dummy class that javac uses to enclose the top level declarations - return (env.outer == null || env.outer == env ? null : env.enclClass.sym); + return (env.outer == null || env.outer == env || env.baseClause ? null : env.enclClass.sym); } public ExecutableElement getEnclosingMethod() { Index: com/sun/tools/javac/api/JavacTaskImpl.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/api/JavacTaskImpl.java,v retrieving revision 1.1.2.11 retrieving revision 1.43 diff -u -r1.1.2.11 -r1.43 --- com/sun/tools/javac/api/JavacTaskImpl.java 15 Aug 2007 10:23:10 -0000 1.1.2.11 +++ com/sun/tools/javac/api/JavacTaskImpl.java 22 Aug 2007 12:38:02 -0000 1.43 @@ -160,19 +160,17 @@ private void prepareCompiler() throws IOException { if (!used.getAndSet(true)) { beginContext(); - compilerMain.setOptions(Options.instance(context)); + Options options = Options.instance(context); + compilerMain.setOptions(options); compilerMain.filenames = new ListBuffer(); List filenames = compilerMain.processArgs(CommandLine.parse(args)); if (!filenames.isEmpty()) throw new IllegalArgumentException("Malformed arguments " + filenames.toString(" ")); compiler = JavaCompiler.instance(context); - // force the use of the scanner that captures Javadoc comments - com.sun.tools.javac.parser.DocCommentScanner.Factory.preRegister(context); - compiler.keepComments = true; - compiler.genEndPos = true; // NOTE: this value will be updated after annotation processing compiler.initProcessAnnotations(processors); notYetEntered = new HashMap(); + compiler.initNotYetEntered(notYetEntered); for (JavaFileObject file: fileObjects) notYetEntered.put(file, null); genList = new ListBuffer>(); @@ -234,6 +232,40 @@ this.taskListener = taskListener; } + public Iterable parse (JavaFileObject... files) throws IOException { + prepareCompiler(); + java.util.List trees = new java.util.LinkedList (); + this.fileObjects = List.nil(); + + for (JavaFileObject file : files) { + CompilationUnitTree tree = getTreeForFile (file); + if (tree != null) { + trees.add(tree); + } + else { + this.fileObjects = this.fileObjects.append(file); + if (notYetEntered != null) { + assert !notYetEntered.containsKey(file); + notYetEntered.put(file, null); + } + } + } + if (!this.fileObjects.isEmpty()) { + Iterable newTrees = this.parse(); + for (CompilationUnitTree newTree : newTrees) { + trees.add (newTree); + } + } + return trees; + } + + private CompilationUnitTree getTreeForFile (final JavaFileObject file) { + assert file != null; + Enter enter = Enter.instance(context); + CompilationUnitTree tree = enter.getCompilationUnit(file); + return tree; + } + /** * Parse the specified files returning a list of abstract syntax trees. * @@ -339,6 +371,42 @@ compiler.log.flush(); } } + + + public Iterable enterTrees (final Iterable trees) throws IOException { + final java.util.List toEnter = new java.util.ArrayList (); + final java.util.List result = new java.util.ArrayList (); + for (CompilationUnitTree tree : trees) { + final java.util.Collection te = this.getEnteredElement(tree); + if (te.isEmpty()) { + toEnter.add (tree); + } + else { + result.addAll(te); + } + } + if (!toEnter.isEmpty()) { + final Iterable classes = this.enter(toEnter); + for (TypeElement te : classes) { + result.add (te); + } + } + return result; + } + + + private java.util.Collection getEnteredElement (final CompilationUnitTree tree) { + assert tree != null; + final java.util.List> todo = compiler.todo.toList(); + final java.util.List result = new java.util.ArrayList(); + for (Env env : todo) { + if (env.toplevel.getSourceFile().toUri().equals (((JCCompilationUnit)tree).getSourceFile().toUri())) { + this.notYetEntered.remove (((JCCompilationUnit)tree).getSourceFile()); + result.add(((JCClassDecl)env.tree).sym); + } + } + return result; + } /** * Complete all analysis. @@ -446,6 +514,35 @@ } return results; } + + public void generateTypeElements (Iterable classes) throws IOException { + assert classes != null; + try { + analyze (classes); + Filter f = new Filter() { + public void process(Env env) { + compiler.generate(compiler.desugar(List.of(env))); + } + }; + f.run(genList, classes); + } finally { + compiler.log.flush(); + } + } + + public void finish () { + if (notYetEntered != null && !notYetEntered.isEmpty()) { + this.notYetEntered.clear(); + } + if (this.compiler != null && this.compiler.todo != null && !this.compiler.todo.isEmpty()) { + this.compiler.todo.clear(); + } + if (this.genList != null && !this.genList.isEmpty()) { + assert genList.size() == 1; + this.genList.clear(); + } + endContext(); + } public TypeMirror getTypeMirror(Iterable path) { // TODO: Should complete attribution if necessary @@ -471,8 +568,8 @@ return TreeInfo.pathFor((JCTree) node, (JCTree.JCCompilationUnit) unit).reverse(); } - abstract class Filter { - void run(ListBuffer> list, Iterable classes) { + public static abstract class Filter { + public void run(ListBuffer> list, Iterable classes) { Set set = new HashSet(); for (TypeElement item: classes) set.add(item); @@ -491,7 +588,7 @@ list.prepend(l.head); } - abstract void process(Env env); + public abstract void process(Env env); } /** @@ -525,12 +622,145 @@ try { Scanner scanner = scannerFactory.newScanner((expr+"\u0000").toCharArray(), expr.length()); - Parser parser = parserFactory.newParser(scanner, false, false); + Parser parser = parserFactory.newParser(scanner, false, false, true); JCTree tree = parser.type(); return attr.attribType(tree, (Symbol.TypeSymbol)scope); } finally { compiler.log.useSource(prev); } } + + public JCStatement parseStatement(CharSequence stmt, SourcePositions[] pos) { + if (stmt == null || (pos != null && pos.length != 1)) + throw new IllegalArgumentException(); + compiler = JavaCompiler.instance(context); + JavaFileObject prev = compiler.log.useSource(null); + Scanner.Factory scannerFactory = Scanner.Factory.instance(context); + Parser.Factory parserFactory = Parser.Factory.instance(context); + try { + Scanner scanner = scannerFactory.newScanner(stmt); + Parser parser = parserFactory.newParser(scanner, false, true, true); + if (pos != null) + pos[0] = new ParserSourcePositions(parser); + return parser.statement(); + } finally { + compiler.log.useSource(prev); + } + } + + public JCExpression parseExpression(CharSequence expr, SourcePositions[] pos) { + if (expr == null || (pos != null && pos.length != 1)) + throw new IllegalArgumentException(); + compiler = JavaCompiler.instance(context); + JavaFileObject prev = compiler.log.useSource(null); + Scanner.Factory scannerFactory = Scanner.Factory.instance(context); + Parser.Factory parserFactory = Parser.Factory.instance(context); + try { + Scanner scanner = scannerFactory.newScanner(expr); + Parser parser = parserFactory.newParser(scanner, false, true, true); + if (pos != null) + pos[0] = new ParserSourcePositions(parser); + return parser.expression(); + } finally { + compiler.log.useSource(prev); + } + } + + public JCExpression parseVariableInitializer(CharSequence init, SourcePositions[] pos) { + if (init == null || (pos != null && pos.length != 1)) + throw new IllegalArgumentException(); + compiler = JavaCompiler.instance(context); + JavaFileObject prev = compiler.log.useSource(null); + Scanner.Factory scannerFactory = Scanner.Factory.instance(context); + Parser.Factory parserFactory = Parser.Factory.instance(context); + try { + Scanner scanner = scannerFactory.newScanner(init); + Parser parser = parserFactory.newParser(scanner, false, true, true); + if (pos != null) + pos[0] = new ParserSourcePositions(parser); + return parser.variableInitializer(); + } finally { + compiler.log.useSource(prev); + } + } + + public JCBlock parseStaticBlock(CharSequence block, SourcePositions[] pos) { + if (block == null || (pos != null && pos.length != 1)) + throw new IllegalArgumentException(); + compiler = JavaCompiler.instance(context); + JavaFileObject prev = compiler.log.useSource(null); + Scanner.Factory scannerFactory = Scanner.Factory.instance(context); + Parser.Factory parserFactory = Parser.Factory.instance(context); + try { + Scanner scanner = scannerFactory.newScanner(block); + Parser parser = parserFactory.newParser(scanner, false, true, true); + if (pos != null) + pos[0] = new ParserSourcePositions(parser); + List trees = parser.classOrInterfaceBodyDeclaration(null, false); + return trees.head != null && trees.head.getTag() == JCTree.BLOCK ? (JCBlock)trees.head : null; + } finally { + compiler.log.useSource(prev); + } + } + + public Type attributeTree(JCTree tree, Envenv) { + Log log = Log.instance(context); + Attr attr = Attr.instance(context); + JavaFileObject prev = log.useSource(null); + try { + if (tree instanceof JCExpression) + return attr.attribExpr(tree, env, Type.noType); + return attr.attribStat(tree, env); + } finally { + log.useSource(prev); + } + } + + public JavacScope attributeTreeTo(JCTree tree, Envenv, JCTree to) { + Log log = Log.instance(context); + Attr attr = Attr.instance(context); + JavaFileObject prev = log.useSource(null); + try { + Env ret = tree instanceof JCExpression ? attr.attribExprToTree(tree, env, to) : attr.attribStatToTree(tree, env, to); + return new JavacScope(ret); + } finally { + log.useSource(prev); + } + } + + private class ParserSourcePositions implements SourcePositions { + + private Parser parser; + + private ParserSourcePositions(Parser parser) { + this.parser = parser; + } + + public long getStartPosition(CompilationUnitTree file, Tree tree) { + return parser.getStartPos((JCTree)tree); + } + public long getEndPosition(CompilationUnitTree file, Tree tree) { + return parser.getEndPos((JCTree)tree); + } + } + + //Debug methods + public String dumpTodo () { + StringBuilder result = new StringBuilder (); + if (compiler != null && compiler.todo != null) { + for (Env env : compiler.todo.toList()) { + result.append(((JCClassDecl)env.tree).sym.toString() + " from: " +env.toplevel.sourcefile.toUri()); + } + } + return result.toString(); + } + + public java.util.List> getTodo () { + if (compiler != null && compiler.todo != null) { + return new java.util.ArrayList> (compiler.todo.toList()); + } + return java.util.Collections.>emptyList(); + } + } Index: com/sun/tools/javac/api/JavacTrees.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/api/JavacTrees.java,v retrieving revision 1.1.2.6 retrieving revision 1.13 diff -u -r1.1.2.6 -r1.13 --- com/sun/tools/javac/api/JavacTrees.java 15 Aug 2007 10:23:10 -0000 1.1.2.6 +++ com/sun/tools/javac/api/JavacTrees.java 17 Aug 2007 13:18:19 -0000 1.13 @@ -45,7 +45,6 @@ import com.sun.source.util.TreePath; import com.sun.source.util.Trees; import com.sun.tools.javac.code.Symbol.ClassSymbol; -import com.sun.tools.javac.code.Symbol.TypeSymbol; import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.comp.Attr; import com.sun.tools.javac.comp.AttrContext; @@ -139,20 +138,7 @@ } public JCTree getTree(Element element) { - Symbol symbol = (Symbol) element; - TypeSymbol enclosing = symbol.enclClass(); - Env env = enter.getEnv(enclosing); - if (env == null) - return null; - JCClassDecl classNode = env.enclClass; - if (classNode != null) { - if (TreeInfo.symbolFor(classNode) == element) - return classNode; - for (JCTree node : classNode.getMembers()) - if (TreeInfo.symbolFor(node) == element) - return node; - } - return null; + return getTree(element, null); } public JCTree getTree(Element e, AnnotationMirror a) { @@ -237,6 +223,7 @@ Copier copier = new Copier(treeMaker.forToplevel(unit)); Env env = null; + JCClassDecl clazz = null; JCMethodDecl method = null; JCVariableDecl field = null; @@ -256,15 +243,18 @@ break; case CLASS: // System.err.println("CLASS: " + ((JCClassDecl)tree).sym.getSimpleName()); - env = enter.getClassEnv(((JCClassDecl)tree).sym); + clazz = (JCClassDecl)tree; + env = enter.getClassEnv(clazz.sym); break; case METHOD: // System.err.println("METHOD: " + ((JCMethodDecl)tree).sym.getSimpleName()); method = (JCMethodDecl)tree; + clazz = null; break; case VARIABLE: // System.err.println("FIELD: " + ((JCVariableDecl)tree).sym.getSimpleName()); field = (JCVariableDecl)tree; + clazz = null; break; case BLOCK: { // System.err.println("BLOCK: "); @@ -272,19 +262,24 @@ env = memberEnter.getMethodEnv(method, env); JCTree body = copier.copy((JCTree)tree, (JCTree) path.getLeaf()); env = attribStatToTree(body, env, copier.leafCopy); + clazz = null; return env; } default: // System.err.println("DEFAULT: " + tree.getKind()); + if (clazz != null) { + env = memberEnter.getBaseEnv(clazz, env); + clazz = null; + } if (field != null && field.getInitializer() == tree) { env = memberEnter.getInitEnv(field, env); JCExpression expr = copier.copy((JCExpression)tree, (JCTree) path.getLeaf()); env = attribExprToTree(expr, env, copier.leafCopy); - return env; } + return env; } } - return field != null ? memberEnter.getInitEnv(field, env) : env; + return env; } private Env attribStatToTree(JCTree stat, Envenv, JCTree tree) { Index: com/sun/tools/javac/code/Flags.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/code/Flags.java,v retrieving revision 1.1.1.1.2.6 retrieving revision 1.8 diff -u -r1.1.1.1.2.6 -r1.8 --- com/sun/tools/javac/code/Flags.java 15 Aug 2007 10:23:05 -0000 1.1.1.1.2.6 +++ com/sun/tools/javac/code/Flags.java 17 Aug 2007 13:18:18 -0000 1.8 @@ -219,6 +219,8 @@ */ public static final long PROPRIETARY = 1L<<38; + public static final long FROMCLASS = 1L<<39; + /** Modifier masks. */ public static final int Index: com/sun/tools/javac/code/Symbol.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/code/Symbol.java,v retrieving revision 1.2.2.11 retrieving revision 1.25 diff -u -r1.2.2.11 -r1.25 --- com/sun/tools/javac/code/Symbol.java 15 Aug 2007 10:23:06 -0000 1.2.2.11 +++ com/sun/tools/javac/code/Symbol.java 1 Nov 2007 12:07:31 -0000 1.25 @@ -43,6 +43,7 @@ import com.sun.tools.javac.jvm.*; import com.sun.tools.javac.model.*; import com.sun.tools.javac.tree.JCTree; +import javax.lang.model.util.ElementScanner6; import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Kinds.*; @@ -264,7 +265,7 @@ public ClassSymbol enclClass() { Symbol c = this; while (c != null && - ((c.kind & TYP) == 0 || c.type.tag != CLASS)) { + ((c.kind & TYP) == 0 || (c.type.tag != CLASS && c.type.tag != ERROR))) { c = c.owner; } return (ClassSymbol)c; @@ -554,8 +555,10 @@ public java.util.List getEnclosedElements() { List list = List.nil(); for (Scope.Entry e = members().elems; e != null; e = e.sibling) { - if (e.sym != null && (e.sym.flags() & SYNTHETIC) == 0 && e.sym.owner == this) - list = list.prepend(e.sym); + try { + if (e.sym != null && (e.sym.flags() & SYNTHETIC) == 0 && e.sym.owner == this) + list = list.prepend(e.sym); + } catch (CompletionFailure cf) {} } return list; } @@ -717,12 +720,16 @@ } public long flags() { - if (completer != null) complete(); + try { + if (completer != null) complete(); + } catch (CompletionFailure cf) {} return flags_field; } public Scope members() { - if (completer != null) complete(); + try { + if (completer != null) complete(); + } catch (CompletionFailure cf) {} return members_field; } @@ -785,7 +792,9 @@ } public List getInterfaces() { - complete(); + try { + complete(); + } catch (CompletionFailure cf) {} if (type instanceof ClassType) { ClassType t = (ClassType)type; if (t.interfaces_field == null) // FIXME: shouldn't be null @@ -797,7 +806,9 @@ } public Type getSuperclass() { - complete(); + try { + complete(); + } catch (CompletionFailure cf) {} if (type instanceof ClassType) { ClassType t = (ClassType)type; if (t.supertype_field == null) // FIXME: shouldn't be null @@ -824,7 +835,9 @@ } public NestingKind getNestingKind() { - complete(); + try { + complete(); + } catch (CompletionFailure cf) {} if (owner.kind == PCK) return NestingKind.TOP_LEVEL; else if (name.isEmpty()) @@ -968,6 +981,8 @@ data = null; // to make sure we don't evaluate this twice. try { data = eval.call(); + } catch (Attr.BreakAttr bk) { + throw bk; } catch (Exception ex) { throw new AssertionError(ex); } @@ -979,6 +994,43 @@ assert !(data instanceof Env) : this; this.data = data; } + + public void setName(Name name) { + this.name = name; + } + } + + /** A class for variable symbols representing method parameters that allows for + * lazy name resolution + */ + public static class ParamSymbol extends VarSymbol { + + private boolean initialized = false; + + public ParamSymbol(long flags, Name name, Type type, Symbol owner) { + super(flags, name, type, owner); + } + + public Name getSimpleName() { + if (!initialized) { + ClassSymbol enclClass = this.enclClass(); + new ElementScanner6() { + @Override + public Void visitVariable(VariableElement e, Void p) { + if (e instanceof ParamSymbol) + ((ParamSymbol)e).initialized = true; + return super.visitVariable(e, p); + } + }.scan(enclClass); + name.table.loader.loadTreeFor(enclClass); + } + return super.getSimpleName(); + } + + public void setName(Name name) { + if (this.name != name) + super.setName(this.name.table.fromString(name)); + } } /** A class for method symbols. @@ -1089,7 +1141,7 @@ * @param origin The class of which the implementation is a member. */ public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) { - for (TypeSymbol c = origin; c != null; c = types.supertype(c.type).tsym) { + for (TypeSymbol c = origin; c != null && c.type.tag != TypeTags.ERROR; c = types.supertype(c.type).tsym) { for (Scope.Entry e = c.members().lookup(name); e.scope != null; e = e.next()) { @@ -1196,17 +1248,22 @@ if (params == null) { List names = savedParameterNames; savedParameterNames = null; + ListBuffer buf = new ListBuffer(); if (names == null) { names = List.nil(); int i = 0; for (Type t : type.getParameterTypes()) names = names.prepend(name.table.fromString("arg" + i++)); names = names.reverse(); - } - ListBuffer buf = new ListBuffer(); - for (Type t : type.getParameterTypes()) { - buf.append(new VarSymbol(PARAMETER, names.head, t, this)); - names = names.tail; + for (Type t : type.getParameterTypes()) { + buf.append(new ParamSymbol(PARAMETER, names.head, t, this)); + names = names.tail; + } + } else { + for (Type t : type.getParameterTypes()) { + buf.append(new VarSymbol(PARAMETER, names.head, t, this)); + names = names.tail; + } } params = buf.toList(); } @@ -1222,6 +1279,8 @@ return ElementKind.CONSTRUCTOR; else if (name == name.table.clinit) return ElementKind.STATIC_INIT; + else if ((flags_field & BLOCK) != 0) + return (flags_field & STATIC) != 0 ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT; else return ElementKind.METHOD; } Index: com/sun/tools/javac/code/Symtab.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/code/Symtab.java,v retrieving revision 1.1.1.1.2.9 retrieving revision 1.11 diff -u -r1.1.1.1.2.9 -r1.11 --- com/sun/tools/javac/code/Symtab.java 15 Aug 2007 10:23:05 -0000 1.1.1.1.2.9 +++ com/sun/tools/javac/code/Symtab.java 17 Aug 2007 13:18:18 -0000 1.11 @@ -63,16 +63,16 @@ /** Builtin types. */ - public static final Type byteType = new Type(TypeTags.BYTE, null); - public static final Type charType = new Type(TypeTags.CHAR, null); - public static final Type shortType = new Type(TypeTags.SHORT, null); - public static final Type intType = new Type(TypeTags.INT, null); - public static final Type longType = new Type(TypeTags.LONG, null); - public static final Type floatType = new Type(TypeTags.FLOAT, null); - public static final Type doubleType = new Type(TypeTags.DOUBLE, null); - public static final Type booleanType = new Type(TypeTags.BOOLEAN, null); - public static final Type botType = new BottomType(); - public static final JCNoType voidType = new JCNoType(TypeTags.VOID); + public final Type byteType = new Type(TypeTags.BYTE, null); + public final Type charType = new Type(TypeTags.CHAR, null); + public final Type shortType = new Type(TypeTags.SHORT, null); + public final Type intType = new Type(TypeTags.INT, null); + public final Type longType = new Type(TypeTags.LONG, null); + public final Type floatType = new Type(TypeTags.FLOAT, null); + public final Type doubleType = new Type(TypeTags.DOUBLE, null); + public final Type booleanType = new Type(TypeTags.BOOLEAN, null); + public final Type botType = new BottomType(); + public final JCNoType voidType = new JCNoType(TypeTags.VOID); private final Name.Table names; private final ClassReader reader; Index: com/sun/tools/javac/code/Type.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/code/Type.java,v retrieving revision 1.2.2.12 retrieving revision 1.16 diff -u -r1.2.2.12 -r1.16 --- com/sun/tools/javac/code/Type.java 15 Aug 2007 10:23:05 -0000 1.2.2.12 +++ com/sun/tools/javac/code/Type.java 17 Aug 2007 13:18:18 -0000 1.16 @@ -633,7 +633,9 @@ public List getTypeArguments() { if (typarams_field == null) { - complete(); + try { + complete(); + } catch (CompletionFailure e) {} if (typarams_field == null) typarams_field = List.nil(); } @@ -933,15 +935,20 @@ * points to the first class or interface bound. */ public Type bound = null; + public Type lower; - public TypeVar(Name name, Symbol owner) { + public TypeVar(Name name, Symbol owner, Type lower) { super(TYPEVAR, null); tsym = new TypeSymbol(0, name, this, owner); + assert lower != null; + this.lower = lower; } - public TypeVar(TypeSymbol tsym, Type bound) { + public TypeVar(TypeSymbol tsym, Type upper, Type lower) { super(TYPEVAR, tsym); - this.bound = bound; + assert lower != null; + this.lower = lower; + this.bound = upper; } @Override @@ -954,7 +961,7 @@ int rank_field = -1; public Type getLowerBound() { - return Symtab.botType; + return lower; } public TypeKind getKind() { @@ -972,7 +979,6 @@ */ public static class CapturedType extends TypeVar { - public Type lower; public WildcardType wildcard; public CapturedType(Name name, @@ -980,10 +986,8 @@ Type upper, Type lower, WildcardType wildcard) { - super(name, owner); - assert lower != null; + super(name, owner, lower); this.bound = upper; - this.lower = lower; this.wildcard = wildcard; } @@ -992,10 +996,6 @@ return v.visitCapturedType(this, s); } - public Type getLowerBound() { - return lower; - } - @Override public String toString() { return "capture#" Index: com/sun/tools/javac/code/Types.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/code/Types.java,v retrieving revision 1.2.2.12 retrieving revision 1.24 diff -u -r1.2.2.12 -r1.24 --- com/sun/tools/javac/code/Types.java 15 Aug 2007 10:23:05 -0000 1.2.2.12 +++ com/sun/tools/javac/code/Types.java 1 Nov 2007 15:39:18 -0000 1.24 @@ -33,6 +33,8 @@ import com.sun.tools.javac.jvm.ClassReader; import com.sun.tools.javac.comp.Infer; import com.sun.tools.javac.comp.Check; +import java.util.logging.Logger; +import javax.lang.model.type.TypeKind; import static com.sun.tools.javac.code.Type.*; import static com.sun.tools.javac.code.TypeTags.*; @@ -70,6 +72,7 @@ final Symtab syms; final Name.Table names; + final boolean allowGenerics; final boolean allowBoxing; final ClassReader reader; final Source source; @@ -89,9 +92,10 @@ context.put(typesKey, this); syms = Symtab.instance(context); names = Name.Table.instance(context); - allowBoxing = Source.instance(context).allowBoxing(); reader = ClassReader.instance(context); source = Source.instance(context); + allowGenerics = source.allowGenerics(); + allowBoxing = source.allowBoxing(); chk = Check.instance(context); capturedName = names.fromString(""); } @@ -255,7 +259,7 @@ @Override public Type visitErrorType(ErrorType t, Symbol sym) { - return t; + return t.tsym == sym || t.tsym.name == names.any ? t : null; } }; // @@ -412,8 +416,13 @@ } @Override - public Boolean visitClassType(ClassType t, Type s) { - Type sup = asSuper(t, s.tsym); + public Boolean visitClassType(ClassType t, Type s) { + final Symbol _ssym = s.tsym; + if (_ssym == null) { + TypeKind _skind = s.getKind(); + Logger.getLogger(Types.class.getName()).warning("Types.visitClassType type: [" + s.toString() + ","+ _skind +"] has a null symbol."); //NOI18N + } + Type sup = asSuper(t, _ssym); return sup != null && sup.tsym == s.tsym // You're not allowed to write @@ -461,7 +470,7 @@ @Override public Boolean visitErrorType(ErrorType t, Type s) { - return true; + return t == s || t.tsym.name == names.any; } }; @@ -516,7 +525,7 @@ public boolean isSuperType(Type t, Type s) { switch (t.tag) { case ERROR: - return true; + return t == s || t.tsym.name == names.any; case UNDETVAR: { UndetVar undet = (UndetVar)t; if (t == s || @@ -676,7 +685,7 @@ @Override public Boolean visitErrorType(ErrorType t, Type s) { - return true; + return t == s || t.tsym.name == names.any || ((s.getKind() == TypeKind.ERROR || s.tsym.type.getKind() == TypeKind.ERROR) && (s.tsym.name == names.any || t.tsym.getQualifiedName() == s.tsym.getQualifiedName())); } }; // @@ -715,7 +724,7 @@ return isSameType(t, s); } case ERROR: - return true; + return t == s || t.tsym.name == names.any; default: return containsType(s, t); } @@ -827,7 +836,7 @@ @Override public Boolean visitErrorType(ErrorType t, Type s) { - return true; + return t == s || t.tsym.name == names.any; } }; @@ -887,7 +896,7 @@ public Boolean visitType(Type t, Type s) { if (s.tag == ERROR) - return true; + return t == s || s.tsym.name == names.any; switch (t.tag) { case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT: @@ -1060,7 +1069,7 @@ @Override public Boolean visitErrorType(ErrorType t, Type s) { - return true; + return t == s || t.tsym.name == names.any; } }; // @@ -1326,7 +1335,7 @@ @Override public Type visitErrorType(ErrorType t, Symbol sym) { - return t; + return t.tsym == sym || t.tsym.name == names.any ? t : null; } }; @@ -1351,7 +1360,7 @@ case TYPEVAR: return asSuper(t, sym); case ERROR: - return t; + return t.tsym == sym || t.tsym.name == names.any ? t : null; default: return null; } @@ -1381,7 +1390,7 @@ case TYPEVAR: return asSuper(t, sym); case ERROR: - return t; + return t.tsym == sym || t.tsym.name == names.any ? t : null; default: return null; } @@ -1396,6 +1405,8 @@ * @param sym a symbol */ public Type memberType(Type t, Symbol sym) { + if (!allowGenerics && sym.kind != Kinds.TYP && !sym.isConstructor()) + return sym.externalType(this); return (sym.flags() & STATIC) != 0 ? sym.type : memberType.visit(t, sym); @@ -1417,7 +1428,8 @@ Symbol owner = sym.owner; long flags = sym.flags(); if (((flags & STATIC) == 0) && owner.type.isParameterized()) { - Type base = asOuterSuper(t, owner); + Type asOuterSuper = asOuterSuper(t, owner); + Type base = asOuterSuper != null ? capture(asOuterSuper) : null; if (base != null) { List ownerParams = owner.type.allparams(); List baseParams = base.allparams(); @@ -1459,7 +1471,7 @@ */ public boolean isAssignable(Type t, Type s, Warner warn) { if (t.tag == ERROR) - return true; + return t.tsym.name == names.any; if (t.tag <= INT && t.constValue() != null) { int value = ((Number)t.constValue()).intValue(); switch (s.tag) { @@ -2095,7 +2107,7 @@ ListBuffer newTvars = lb(); // create new type variables without bounds for (Type t : tvars) { - newTvars.append(new TypeVar(t.tsym, null)); + newTvars.append(new TypeVar(t.tsym, null, syms.botType)); } // the new bounds should use the new type variables in place // of the old @@ -2120,7 +2132,7 @@ if (bound1 == t.bound) return t; else - return new TypeVar(t.tsym, bound1); + return new TypeVar(t.tsym, bound1, syms.botType); } // @@ -2155,8 +2167,8 @@ } return tvars1; } - static private Mapping newInstanceFun = new Mapping("newInstanceFun") { - public Type apply(Type t) { return new TypeVar(t.tsym, t.getUpperBound()); } + private Mapping newInstanceFun = new Mapping("newInstanceFun") { + public Type apply(Type t) { return new TypeVar(t.tsym, t.getUpperBound(), syms.botType); } }; // @@ -2172,7 +2184,10 @@ ClassType cls = (ClassType)t; if (cls.rank_field < 0) { Name fullname = cls.tsym.getQualifiedName(); - if (fullname == fullname.table.java_lang_Object) + if (fullname == null) { + Logger.getLogger(Types.class.getName()).fine("fullname==null"); + } + if (fullname != null && fullname == fullname.table.java_lang_Object) cls.rank_field = 0; else { int r = rank(supertype(cls)); @@ -2201,7 +2216,12 @@ return tvar.rank_field; } case ERROR: - return 0; + case NONE: //Works around type with non filled supertype_field, it happens when the supertype is created but + return 0; //it's symbol is not completed, it is assigned to other symbols and when it is completed it completion + //throws an CompletionFailure. The type is replaced by ErrorType rather than to filling the original + //type the original type stays unfilled and has supertype NONE. Another possibility is to catch CompletionFailure + //in the MemberEnter when supertype is computed (863) - works fine, but the same is is required also for ClassReader, + //when the supertype_field is set it's type has to be comleted - which is hard to do since ClassReader is not reentrant. default: throw new AssertionError(); } Index: com/sun/tools/javac/comp/Annotate.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/comp/Annotate.java,v retrieving revision 1.1.1.1.2.7 retrieving revision 1.10 diff -u -r1.1.1.1.2.7 -r1.10 --- com/sun/tools/javac/comp/Annotate.java 15 Aug 2007 10:23:05 -0000 1.1.1.1.2.7 +++ com/sun/tools/javac/comp/Annotate.java 17 Aug 2007 13:18:18 -0000 1.10 @@ -151,7 +151,7 @@ List args = a.args; if (args.length() == 1 && args.head.getTag() != JCTree.ASSIGN) { // special case: elided "value=" assumed - args.head = make.at(args.head.pos). + args.head = make.at(TreeInfo.getStartPos(args.head)). Assign(make.Ident(names.value), args.head); } ListBuffer> buf = @@ -215,7 +215,7 @@ if ((expected.tsym.flags() & Flags.ANNOTATION) != 0) { if (tree.getTag() != JCTree.ANNOTATION) { log.error(tree.pos(), "annotation.value.must.be.annotation"); - expected = syms.errorType; + return new Attribute.Error(expected); } return enterAnnotation((JCAnnotation)tree, expected, env); } Index: com/sun/tools/javac/comp/Attr.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/comp/Attr.java,v retrieving revision 1.2.2.14 retrieving revision 1.52 diff -u -r1.2.2.14 -r1.52 --- com/sun/tools/javac/comp/Attr.java 15 Aug 2007 10:23:05 -0000 1.2.2.14 +++ com/sun/tools/javac/comp/Attr.java 23 Oct 2007 13:21:03 -0000 1.52 @@ -81,6 +81,7 @@ final Target target; final Types types; final Annotate annotate; + private final CancelService cancelService; public static Attr instance(Context context) { Attr instance = context.get(attrKey); @@ -117,6 +118,7 @@ relax = (options.get("-retrofit") != null || options.get("-relax") != null); useBeforeDeclarationWarning = options.get("useBeforeDeclarationWarning") != null; + cancelService = CancelService.instance(context); } /** Switch: relax some constraints for retrofit mode. @@ -168,17 +170,25 @@ * @param pt The expected type (or: prototype) of the tree */ Type check(JCTree tree, Type owntype, int ownkind, int pkind, Type pt) { - if (owntype.tag != ERROR && pt.tag != METHOD && pt.tag != FORALL) { + tree.type = owntype; + if (pt.tag != METHOD && pt.tag != FORALL) { if ((ownkind & ~pkind) == 0) { - owntype = chk.checkType(tree.pos(), owntype, pt); + if (owntype.tag != ERROR) { + owntype = chk.checkType(tree.pos(), owntype, pt); + if (owntype.tag != ERROR) { + tree.type = owntype; + } + } else { + chk.checkType(tree.pos(), owntype, pt); + } } else { log.error(tree.pos(), "unexpected.type", Resolve.kindNames(pkind), Resolve.kindName(ownkind)); - owntype = syms.errType; + if ((ownkind & ~pkind) == 0) + owntype = syms.errType; } } - tree.type = owntype; return owntype; } @@ -325,7 +335,7 @@ private JCTree breakTree = null; - private static class BreakAttr extends RuntimeException { + public static class BreakAttr extends RuntimeException { static final long serialVersionUID = -6924771130405446405L; private Env env; private BreakAttr(Env env) { @@ -546,6 +556,7 @@ } public void visitClassDef(JCClassDecl tree) { + cancelService.abortIfCanceled(); // Local classes have not been entered yet, so we need to do it now: if ((env.info.scope.owner.kind & (VAR | MTH)) != 0) enter.classEnter(tree, env); @@ -575,6 +586,7 @@ } public void visitMethodDef(JCMethodDecl tree) { + cancelService.abortIfCanceled(); MethodSymbol m = tree.sym; Lint lint = env.info.lint.augment(m.attributes_field, m.flags()); @@ -744,6 +756,7 @@ } public void visitBlock(JCBlock tree) { + cancelService.abortIfCanceled(); if (env.info.scope.owner.kind == TYP) { // Block is a static or instance initializer; // let the owner of the environment be a freshly @@ -851,6 +864,8 @@ boolean hasDefault = false; // Is there a default label? for (List l = tree.cases; l.nonEmpty(); l = l.tail) { JCCase c = l.head; + if (c == breakTree) + throw new BreakAttr(env); Env caseEnv = switchEnv.dup(c, env.info.dup(switchEnv.info.scope.dup())); if (c.pat != null) { @@ -933,7 +948,7 @@ Env catchEnv = env.dup(c, env.info.dup(env.info.scope.dup())); Type ctype = attribStat(c.param, catchEnv); - if (c.param.type.tsym.kind == Kinds.VAR) { + if (c.param.sym.kind == Kinds.VAR) { c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER); } chk.checkType(c.param.vartype.pos(), @@ -1152,9 +1167,11 @@ // it conforms to result type of enclosing method. Symbol m = env.enclMethod.sym; if (m.type.getReturnType().tag == VOID) { - if (tree.expr != null) + if (tree.expr != null) { log.error(tree.expr.pos(), "cant.ret.val.from.meth.decl.void"); + attribExpr(tree.expr, env, m.type.getReturnType()); + } } else if (tree.expr == null) { log.error(tree.pos(), "missing.ret.val"); } else { @@ -1200,7 +1217,7 @@ if (isConstructorCall) { // We are seeing a ...this(...) or ...super(...) call. // Check that this is the first statement in a constructor. - if (checkFirstConstructorStat(tree, env)) { + if (breakTree != null || checkFirstConstructorStat(tree, env)) { // Record the fact // that this is a constructor call (using isSelfCall). @@ -1277,8 +1294,13 @@ } else { // Otherwise, we are seeing a regular method call. // Attribute the arguments, yielding list of argument types, ... - argtypes = attribArgs(tree.args, localEnv); - typeargtypes = attribTypes(tree.typeargs, localEnv); + try { + argtypes = attribArgs(tree.args, localEnv); + typeargtypes = attribTypes(tree.typeargs, localEnv); + } catch (BreakAttr bae) { + attribExpr(tree.meth, localEnv); + throw bae; + } // ... and attribute the method using as a prototype a methodtype // whose formal argument types is exactly the list of actual @@ -1522,7 +1544,7 @@ Symbol sym = rs.resolveConstructor( tree.pos(), localEnv, clazztype, argtypes, typeargtypes, true, tree.varargsElement != null); - assert sym.kind < AMBIGUOUS || tree.constructor.type.isErroneous(); + assert sym.kind < AMBIGUOUS || tree.constructor == null || tree.constructor.type == null || tree.constructor.type.isErroneous(); tree.constructor = sym; } @@ -1835,6 +1857,8 @@ tree.name == names._class) { skind = TYP; + } else if (tree.name == names.error) { + skind = ERR; } else { if ((pkind & PCK) != 0) skind = skind | PCK; if ((pkind & TYP) != 0) skind = skind | TYP | PCK; @@ -1853,7 +1877,8 @@ elt = ((ArrayType)elt).elemtype; if (elt.tag == TYPEVAR) { log.error(tree.pos(), "type.var.cant.be.deref"); - result = syms.errType; + result = tree.type = syms.errType; + tree.sym = syms.errSymbol; return; } } @@ -1969,6 +1994,7 @@ pos, site, name, true); case ARRAY: case CLASS: + case ERROR: if (pt.tag == METHOD || pt.tag == FORALL) { return rs.resolveQualifiedMethod( pos, env, site, name, pt.getParameterTypes(), pt.getTypeArguments()); @@ -2009,9 +2035,6 @@ } else { return sym; } - case ERROR: - // preserve identifier names through errors - return new ErrorType(name, site.tsym).tsym; default: // The qualifier expression is of a primitive type -- only // .class is allowed for these. @@ -2061,7 +2084,6 @@ int pkind, Type pt, boolean useVarargs) { - if (pt.isErroneous()) return syms.errType; Type owntype; // The computed type of this identifier occurrence. switch (sym.kind) { case TYP: @@ -2455,7 +2477,7 @@ Type clazztype = chk.checkClassType(tree.clazz.pos(), attribType(tree.clazz, env)); // Attribute type parameters - List actuals = attribTypes(tree.arguments, env); + List actuals = attribTypes(tree.arguments, env); if (clazztype.tag == CLASS) { List formals = clazztype.tsym.type.getTypeArguments(); @@ -2495,6 +2517,8 @@ } owntype = syms.errType; } + } else if (clazztype.tag == ERROR) { + owntype = clazztype; } result = check(tree, owntype, TYP, pkind, pt); } @@ -2581,7 +2605,7 @@ public void visitErroneous(JCErroneous tree) { if (tree.errs != null) for (JCTree err : tree.errs) - attribTree(err, env, ERR, pt); + attribTree(err, env, ERR - PCK, pt); result = tree.type = syms.errType; } @@ -2610,7 +2634,9 @@ * @param c The class symbol whose definition will be attributed. */ void attribClass(ClassSymbol c) throws CompletionFailure { - if (c.type.tag == ERROR) return; + if (c.type.tag == ERROR) { + return; + } // Check for cycles in the inheritance graph, which can arise from // ill-formed class files. Index: com/sun/tools/javac/comp/Check.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/comp/Check.java,v retrieving revision 1.2.2.10 retrieving revision 1.16 diff -u -r1.2.2.10 -r1.16 --- com/sun/tools/javac/comp/Check.java 15 Aug 2007 10:23:05 -0000 1.2.2.10 +++ com/sun/tools/javac/comp/Check.java 25 Sep 2007 08:31:17 -0000 1.16 @@ -44,6 +44,7 @@ import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.TypeTags.*; +import javax.lang.model.element.ElementKind; /** Type checking helper class for the attribution phase. * @@ -71,6 +72,8 @@ // from the context, and then is set/reset as needed by Attr as it // visits all the various parts of the trees during attribution. private Lint lint; + + private final boolean ideMode; public static Check instance(Context context) { Check instance = context.get(checkKey); @@ -104,6 +107,8 @@ deprecationHandler = new MandatoryWarningHandler(log,verboseDeprecated, "deprecated"); uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked, "unchecked"); + + ideMode = options.get("ide") != null; } /** Switch: generics enabled? @@ -175,7 +180,7 @@ */ public Type completionError(DiagnosticPosition pos, CompletionFailure ex) { log.error(pos, "cant.access", ex.sym, ex.errmsg); - if (ex instanceof ClassReader.BadClassFile) throw new Abort(); + if (!ideMode && (ex instanceof ClassReader.BadClassFile)) throw new Abort(); else return syms.errType; } @@ -320,6 +325,15 @@ if (compiled.get(flatname) == null) return flatname; } } + + + Name localClassName (final ClassSymbol enclClass, final Name name, final int index) { + Name flatname = names. + fromString("" + enclClass.flatname + + target.syntheticNameChar() + index + + name); + return flatname; + } /* ************************************************************************* * Type Checking @@ -331,7 +345,7 @@ * @param found The type that was found. * @param req The type that was required. */ - Type checkType(DiagnosticPosition pos, Type found, Type req) { + public Type checkType(DiagnosticPosition pos, Type found, Type req) { if (req.tag == ERROR) return req; if (found.tag == FORALL) @@ -1556,6 +1570,13 @@ void checkImplementations(JCClassDecl tree, ClassSymbol ic) { ClassSymbol origin = tree.sym; for (List l = types.closure(ic.type); l.nonEmpty(); l = l.tail) { + ElementKind kind = l.head.tsym.getKind(); + + if (!kind.isClass() && !kind.isInterface()) { + //not a class: an error should have already been reported, ignore. + continue; + } + ClassSymbol lc = (ClassSymbol)l.head.tsym; if ((allowGenerics || origin != lc) && (lc.flags() & ABSTRACT) != 0) { for (Scope.Entry e=lc.members().elems; e != null; e=e.sibling) { Index: com/sun/tools/javac/comp/Enter.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/comp/Enter.java,v retrieving revision 1.2.2.10 retrieving revision 1.27 diff -u -r1.2.2.10 -r1.27 --- com/sun/tools/javac/comp/Enter.java 15 Aug 2007 10:23:05 -0000 1.2.2.10 +++ com/sun/tools/javac/comp/Enter.java 27 Sep 2007 12:59:47 -0000 1.27 @@ -25,8 +25,8 @@ package com.sun.tools.javac.comp; +import java.net.URI; import java.util.*; -import java.util.Set; import javax.tools.JavaFileObject; import javax.tools.JavaFileManager; @@ -103,6 +103,8 @@ MemberEnter memberEnter; Lint lint; JavaFileManager fileManager; + private final CancelService cancelService; + private final Source source; private final Todo todo; @@ -124,6 +126,7 @@ memberEnter = MemberEnter.instance(context); annotate = Annotate.instance(context); lint = Lint.instance(context); + cancelService = CancelService.instance(context); predefClassDef = make.ClassDef( make.Modifiers(PUBLIC), @@ -131,6 +134,8 @@ predefClassDef.sym = syms.predefClass; todo = Todo.instance(context); fileManager = context.get(JavaFileManager.class); + + source = Source.instance(context); } /** A hashtable mapping classes and packages to the environments current @@ -138,6 +143,9 @@ */ Map> typeEnvs = new HashMap>(); + + private final Map compilationUnits = + new HashMap (); /** Accessor for typeEnvs */ @@ -145,6 +153,10 @@ return typeEnvs.get(sym); } + public JCCompilationUnit getCompilationUnit (JavaFileObject fobj) { + return this.compilationUnits.get(fobj.toUri()); + } + public Env getClassEnv(TypeSymbol sym) { Env localEnv = getEnv(sym); Env lintEnv = localEnv; @@ -307,6 +319,7 @@ } } } + compilationUnits.put(tree.sourcefile.toUri(), tree); classEnter(tree.defs, env); if (addEnv) { todo.append(env); @@ -316,9 +329,12 @@ } public void visitClassDef(JCClassDecl tree) { + cancelService.abortIfCanceled(); Symbol owner = env.info.scope.owner; Scope enclScope = enterScope(env); - ClassSymbol c; + ClassSymbol c = null; + boolean doEnterClass = true; + boolean reattr=false, noctx=false; if (owner.kind == PCK) { // We are seeing a toplevel class. PackageSymbol packge = (PackageSymbol)owner; @@ -331,36 +347,84 @@ "class.public.should.be.in.file", tree.name); } } else { - if (tree.name.len != 0 && - !chk.checkUniqueClassName(tree.pos(), tree.name, enclScope)) { - result = null; - return; - } - if (owner.kind == TYP) { - // We are seeing a member class. - c = reader.enterClass(tree.name, (TypeSymbol)owner); - if ((owner.flags_field & INTERFACE) != 0) { - tree.mods.flags |= PUBLIC | STATIC; - } - } else { - // We are seeing a local class. - c = reader.defineClass(tree.name, owner); - c.flatname = chk.localClassName(c); - if (c.name.len != 0) - chk.checkTransparentClass(tree.pos(), c, env.info.scope); - } + if ((enclScope.owner.flags_field & FROMCLASS) != 0) { + for (Scope.Entry e = enclScope.lookup(tree.name); e.scope == enclScope; e = e.next()) { + if (e.sym.kind == TYP) { + c = (ClassSymbol)e.sym; + break; + } + } + if (c == null) { + ClassSymbol cs = enclScope.owner.outermostClass(); + JavaFileObject classSource = cs != null ? cs.classfile : null; + + throw new CouplingAbort(classSource, tree); + } + if (owner.kind == TYP) { + if ((owner.flags_field & INTERFACE) != 0) { + tree.mods.flags |= PUBLIC | STATIC; + } + } + + doEnterClass = false; + } else { + if (tree.name.len != 0 && + !chk.checkUniqueClassName(tree.pos(), tree.name, enclScope)) { + result = new ErrorType(tree.name, (TypeSymbol)owner); + tree.sym = (ClassSymbol)result.tsym; + Env localEnv = classEnv(tree, env); + typeEnvs.put(tree.sym, localEnv); + return; + } + if (owner.kind == TYP) { + // We are seeing a member class. + c = reader.enterClass(tree.name, (TypeSymbol)owner); + if ((owner.flags_field & INTERFACE) != 0) { + tree.mods.flags |= PUBLIC | STATIC; + } + Symbol q = owner; + while(q != null && q.kind == TYP) { + q = q.owner; + } + if (q != null && q.kind != PCK && chk.compiled.get(c.flatname) != null) { + reattr = true; + } + } else { + // We are seeing a local class. + if (tree.index == -1) { + c = reader.defineClass(tree.name, owner); + c.flatname = chk.localClassName(c); + noctx = true; + } + else { + Name flatname = chk.localClassName(owner.enclClass(), tree.name, tree.index); + if ((c=chk.compiled.get(flatname)) != null) { + reattr = true; + } + else { + c = reader.enterClass(flatname, tree.name, owner); + } + } + if (c.name.len != 0) + chk.checkTransparentClass(tree.pos(), c, env.info.scope); + } + } } tree.sym = c; // Enter class into `compiled' table and enclosing scope. - if (chk.compiled.get(c.flatname) != null) { - duplicateClass(tree.pos(), c); - result = new ErrorType(tree.name, (TypeSymbol)owner); - tree.sym = (ClassSymbol)result.tsym; - return; - } - chk.compiled.put(c.flatname, c); - enclScope.enter(c); + if (!reattr && !noctx) { + if (chk.compiled.get(c.flatname) != null) { + duplicateClass(tree.pos(), c); + result = new ErrorType(tree.name, (TypeSymbol)owner); + tree.sym = (ClassSymbol)result.tsym; + return; + } + chk.compiled.put(c.flatname, c); + } + if (doEnterClass) { + enclScope.enter(c); + } // Set up an environment for class block and store in `typeEnvs' // table, to be retrieved later in memberEnter and attribution. @@ -368,29 +432,63 @@ typeEnvs.put(c, localEnv); // Fill out class fields. - c.completer = memberEnter; - c.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, c, tree); - c.sourcefile = env.toplevel.sourcefile; - c.members_field = new Scope(c); - - ClassType ct = (ClassType)c.type; - if (owner.kind != PCK && (c.flags_field & STATIC) == 0) { - // We are seeing a local or inner class. - // Set outer_field of this class to closest enclosing class - // which contains this class in a non-static context - // (its "enclosing instance class"), provided such a class exists. - Symbol owner1 = owner; - while ((owner1.kind & (VAR | MTH)) != 0 && - (owner1.flags_field & STATIC) == 0) { - owner1 = owner1.owner; - } - if (owner1.kind == TYP) { - ct.setEnclosingType(owner1.type); - } - } - - // Enter type parameters. - ct.typarams_field = classEnter(tree.typarams, localEnv); + boolean notYetCompleted = c.completer != null; + c.completer = memberEnter; + c.sourcefile = env.toplevel.sourcefile; + if ((c.flags_field & FROMCLASS) == 0 && ((enclScope.owner.flags_field & FROMCLASS) == 0 || notYetCompleted)) { + c.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, c, tree); + c.members_field = new Scope(c); + ClassType ct = (ClassType)c.type; + if (owner.kind != PCK && (c.flags_field & STATIC) == 0) { + // We are seeing a local or inner class. + // Set outer_field of this class to closest enclosing class + // which contains this class in a non-static context + // (its "enclosing instance class"), provided such a class exists. + Symbol owner1 = owner; + while ((owner1.kind & (VAR | MTH)) != 0 && + (owner1.flags_field & STATIC) == 0) { + owner1 = owner1.owner; + } + if (owner1.kind == TYP) { + ct.setEnclosingType(owner1.type); + } + } + // Enter type parameters. + ct.typarams_field = classEnter(tree.typarams, localEnv); + } else { + ClassType ct = (ClassType)c.type; + boolean wasNull = false; + if (ct.typarams_field != null) { + for (List l = ct.typarams_field; l.nonEmpty(); l = l.tail) + localEnv.info.scope.enter(l.head.tsym); + } else { + wasNull = true; + } + List classEnter = classEnter(tree.typarams, localEnv); + if (wasNull) { + if (!classEnter.isEmpty()) { + //the symbol from class does not have any type parameters, + //but the symbol in the source code does: + if (source.allowGenerics()) { + ClassSymbol cs = env.info.scope.owner.outermostClass(); + JavaFileObject classSource = cs != null ? cs.classfile : null; + + throw new CouplingAbort(classSource, tree); + } else { + //XXX: the class file might have been loaded using source level == 1.4, + //but the source contains the type parameters - error was reported + //trying to recover: + ct.typarams_field = classEnter; + } + } else { + ct.typarams_field = List.nil(); + } + } + if (c.members_field == null) { + c.members_field = new Scope(c); + c.flags_field &= ~FROMCLASS; + } + } // Add non-local class to uncompleted, to make sure it will be // completed later. @@ -421,14 +519,31 @@ * is unique. */ public void visitTypeParameter(JCTypeParameter tree) { - TypeVar a = (tree.type != null) - ? (TypeVar)tree.type - : new TypeVar(tree.name, env.info.scope.owner); - tree.type = a; - if (chk.checkUnique(tree.pos(), a.tsym, env.info.scope)) { - env.info.scope.enter(a.tsym); - } - result = a; + result = null; + if ((env.info.scope.owner.flags_field & FROMCLASS) != 0) { + for (Scope.Entry e = env.info.scope.lookup(tree.name); e.scope == env.info.scope; e = e.next()) { + if (e.sym.kind == TYP) { + result = e.sym.type; + tree.type = result; + break; + } + } + if (result == null) { + ClassSymbol cs = env.info.scope.owner.outermostClass(); + JavaFileObject classSource = cs != null ? cs.classfile : null; + + throw new CouplingAbort(classSource, tree); + } + } else { + TypeVar a = (tree.type != null) + ? (TypeVar)tree.type + : new TypeVar(tree.name, env.info.scope.owner, syms.botType); + tree.type = a; + if (chk.checkUnique(tree.pos(), a.tsym, env.info.scope)) { + env.info.scope.enter(a.tsym); + } + result = a; + } } /** Default class enter visitor method: do nothing. Index: com/sun/tools/javac/comp/Lower.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/comp/Lower.java,v retrieving revision 1.1.1.1.2.11 retrieving revision 1.12 diff -u -r1.1.1.1.2.11 -r1.12 --- com/sun/tools/javac/comp/Lower.java 15 Aug 2007 10:23:05 -0000 1.1.1.1.2.11 +++ com/sun/tools/javac/comp/Lower.java 17 Aug 2007 13:18:18 -0000 1.12 @@ -561,10 +561,10 @@ * @param flags The class symbol's flags * @param owner The class symbol's owner */ - ClassSymbol makeEmptyClass(long flags, ClassSymbol owner) { + ClassSymbol makeEmptyClass(long flags, ClassSymbol owner, int index) { // Create class symbol. ClassSymbol c = reader.defineClass(names.empty, owner); - c.flatname = chk.localClassName(c); + c.flatname = chk.localClassName(owner,names.empty,index); c.sourcefile = owner.sourcefile; c.completer = null; c.members_field = new Scope(c); @@ -1116,7 +1116,7 @@ "1"); ClassSymbol ctag = chk.compiled.get(flatname); if (ctag == null) - ctag = makeEmptyClass(STATIC | SYNTHETIC, topClass); + ctag = makeEmptyClass(STATIC | SYNTHETIC, topClass, 1); return ctag; } @@ -1482,7 +1482,7 @@ if (e.sym.kind == TYP && e.sym.name == names.empty && (e.sym.flags() & INTERFACE) == 0) return (ClassSymbol) e.sym; - return makeEmptyClass(STATIC | SYNTHETIC, clazz); + return makeEmptyClass(STATIC | SYNTHETIC, clazz, 1); } /** Return symbol for "class$" method. If there is no method definition Index: com/sun/tools/javac/comp/MemberEnter.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/comp/MemberEnter.java,v retrieving revision 1.2.2.11 retrieving revision 1.28 diff -u -r1.2.2.11 -r1.28 --- com/sun/tools/javac/comp/MemberEnter.java 15 Aug 2007 10:23:05 -0000 1.2.2.11 +++ com/sun/tools/javac/comp/MemberEnter.java 27 Sep 2007 12:59:47 -0000 1.28 @@ -43,6 +43,7 @@ import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.TypeTags.*; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; +import javax.lang.model.element.Modifier; /** This is the second phase of Enter, in which classes are completed * by entering their members into the class scope using @@ -74,8 +75,10 @@ private final Annotate annotate; private final Types types; private final Target target; + private final CancelService cancelService; private final boolean skipAnnotations; + private final boolean ideMode; public static MemberEnter instance(Context context) { MemberEnter instance = context.get(memberEnterKey); @@ -98,8 +101,11 @@ annotate = Annotate.instance(context); types = Types.instance(context); target = Target.instance(context); + Options options = Options.instance(context); skipAnnotations = - Options.instance(context).get("skipAnnotations") != null; + options.get("skipAnnotations") != null; + ideMode = options.get("ide") != null; + cancelService = CancelService.instance(context); } /** A queue for classes whose members still need to be entered into the @@ -135,7 +141,12 @@ // If we can't find java.lang, exit immediately. if (((PackageSymbol)tsym).fullname.equals(names.java_lang)) { JCDiagnostic msg = JCDiagnostic.fragment("fatal.err.no.java.lang"); - throw new FatalError(msg); + if (ideMode) { + throw new CompletionFailure(tsym, msg.toString()); + } + else { + throw new FatalError (msg); + } } else { log.error(pos, "doesnt.exist", tsym); } @@ -170,7 +181,9 @@ return; // also import inherited names - importFrom(types.supertype(tsym.type).tsym); + Type sup = types.supertype(tsym.type); + if (sup != null) + importFrom(sup.tsym); for (Type t : types.interfaces(tsym.type)) importFrom(t.tsym); @@ -199,7 +212,9 @@ return; // also import inherited names - importFrom(types.supertype(tsym.type).tsym); + Type sup = types.supertype(tsym.type); + if (sup != null) + importFrom(sup.tsym); for (Type t : types.interfaces(tsym.type)) importFrom(t.tsym); @@ -335,7 +350,7 @@ * scope to add to. */ private void importNamed(DiagnosticPosition pos, Symbol tsym, Env env) { - if (tsym.kind == TYP && + if ((tsym.kind == TYP || tsym.kind == ERR) && chk.checkUniqueImport(pos, tsym, env.toplevel.namedImportScope)) env.toplevel.namedImportScope.enter(tsym, tsym.owner.members()); } @@ -495,6 +510,7 @@ } public void visitTopLevel(JCCompilationUnit tree) { + cancelService.abortIfCanceled(); if (tree.starImportScope.elems != null) { // we must have already processed this toplevel return; @@ -527,6 +543,7 @@ // process the non-static imports and the static imports of types. public void visitImport(JCImport tree) { + cancelService.abortIfCanceled(); JCTree imp = tree.qualid; Name name = TreeInfo.name(imp); TypeSymbol p; @@ -563,6 +580,7 @@ } public void visitMethodDef(JCMethodDecl tree) { + cancelService.abortIfCanceled(); Scope enclScope = enter.enterScope(env); MethodSymbol m = new MethodSymbol(0, tree.name, null, enclScope.owner); m.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, m, tree); @@ -574,23 +592,81 @@ tree.restype, tree.thrown, localEnv); - // Set m.params - ListBuffer params = new ListBuffer(); - JCVariableDecl lastParam = null; - for (List l = tree.params; l.nonEmpty(); l = l.tail) { - JCVariableDecl param = lastParam = l.head; - assert param.sym != null; - params.append(param.sym); - } - m.params = params.toList(); - - // mark the method varargs, if necessary - if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0) - m.flags_field |= Flags.VARARGS; - - localEnv.info.scope.leave(); - if (chk.checkUnique(tree.pos(), m, enclScope)) { - enclScope.enter(m); + if ((enclScope.owner.flags_field & FROMCLASS) != 0) { + for (Scope.Entry e = enclScope.lookup(tree.name); e.scope == enclScope; e = e.next()) { + if (e.sym.kind == MTH && (types.isSameType(m.type, e.sym.type) || m.name == names.init && (m.owner.name.isEmpty() || (m.owner.owner.kind & (VAR | MTH)) != 0))) { + treeCleaner.scan(tree); + tree.sym = (MethodSymbol)e.sym; + localEnv = methodEnv(tree, env); + tree.sym.flags_field |= FROMCLASS; + if (tree.sym.type.tag == FORALL) { + for(List tvars = ((ForAll)tree.sym.type).tvars; tvars.nonEmpty(); tvars = tvars.tail) + localEnv.info.scope.enter(tvars.head.tsym); + } + List p = tree.sym.params(); + if (p != null) { + List l = tree.params; + while(l.nonEmpty() && p.nonEmpty()) { + p.head.setName(l.head.name); + if (l.head.getModifiers() != null && l.head.getModifiers().getFlags().contains(Modifier.FINAL)) { + //copy the final flag, as the symbol might have come from the classfile: + p.head.flags_field |= FINAL; + } + localEnv.info.scope.enter(p.head); + p = p.tail; + l = l.tail; + } + while(p.nonEmpty()) { + p.head.setName(p.head.name); + p = p.tail; + } + } + tree.sym.type = signature(tree.typarams, tree.params, + tree.restype, tree.thrown, + localEnv); + tree.sym.flags_field &= ~FROMCLASS; + localEnv.info.scope.leave(); + + // Set m.params + ListBuffer params = new ListBuffer(); + JCVariableDecl lastParam = null; + for (List l = tree.params; l.nonEmpty(); l = l.tail) { + JCVariableDecl param = lastParam = l.head; + assert param.sym != null; + params.append(param.sym); + } + tree.sym.params = params.toList(); + + // mark the method varargs, if necessary + if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0) + tree.sym.flags_field |= Flags.VARARGS; + + break; + } + } + if (tree.sym == m) { + ClassSymbol cs = enclScope.owner.outermostClass(); + JavaFileObject classSource = cs != null ? cs.classfile : null; + throw new CouplingAbort(classSource, tree); + } + } else { + localEnv.info.scope.leave(); + // Set m.params + ListBuffer params = new ListBuffer(); + JCVariableDecl lastParam = null; + for (List l = tree.params; l.nonEmpty(); l = l.tail) { + JCVariableDecl param = lastParam = l.head; + assert param.sym != null; + params.append(param.sym); + } + m.params = params.toList(); + + // mark the method varargs, if necessary + if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0) + m.flags_field |= Flags.VARARGS; + + if (chk.checkUnique(tree.pos(), m, enclScope)) + enclScope.enter(m); } annotateLater(tree.mods.annotations, localEnv, m); if (tree.defaultValue != null) @@ -611,6 +687,7 @@ } public void visitVarDef(JCVariableDecl tree) { + cancelService.abortIfCanceled(); Env localEnv = env; if ((tree.mods.flags & STATIC) != 0 || (env.info.scope.owner.flags() & INTERFACE) != 0) { @@ -619,9 +696,26 @@ } attr.attribType(tree.vartype, localEnv); Scope enclScope = enter.enterScope(env); - VarSymbol v = - new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner); - v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree); + VarSymbol v = null; + boolean doEnterSymbol = true; + if ((enclScope.owner.flags_field & FROMCLASS) != 0) { + for (Scope.Entry e = enclScope.lookup(tree.name); e.scope == enclScope; e = e.next()) { + if (e.sym.kind == VAR && types.isSameType(tree.vartype.type, e.sym.type)) { + v = (VarSymbol)e.sym; + break; + } + } + if (v == null) { + ClassSymbol cs = enclScope.owner.outermostClass(); + JavaFileObject classSource = cs != null ? cs.classfile : null; + throw new CouplingAbort(classSource, tree); + } + doEnterSymbol = false; + } + if (v == null) { + v = new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner); + v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree); + } tree.sym = v; if (tree.init != null) { v.flags_field |= HASINIT; @@ -630,7 +724,8 @@ } if (chk.checkUnique(tree.pos(), v, enclScope)) { chk.checkTransparentVar(tree.pos(), v, enclScope); - enclScope.enter(v); + if (doEnterSymbol) + enclScope.enter(v); } annotateLater(tree.mods.annotations, localEnv, v); v.pos = tree.pos; @@ -666,6 +761,11 @@ memberEnter(tree.errs, env); } + public Env getBaseEnv(JCClassDecl tree, Env env) { + Env bEnv = baseEnv(tree, env); + return bEnv; + } + public Env getMethodEnv(JCMethodDecl tree, Env env) { Env mEnv = methodEnv(tree, env); mEnv.info.lint = mEnv.info.lint.augment(tree.sym.attributes_field, tree.sym.flags()); @@ -963,6 +1063,10 @@ } catch (CompletionFailure ex) { chk.completionError(tree.pos(), ex); + } catch (Attr.BreakAttr br) { + halfcompleted.clear(); + isFirst = true; + throw br; } finally { log.useSource(prev); } @@ -1105,4 +1209,52 @@ List typeargs = typarams.nonEmpty() ? make.Types(typarams) : null; return make.Exec(make.Apply(typeargs, meth, make.Idents(params))); } + + private static TreeScanner treeCleaner = new TreeScanner() { + public void scan(JCTree node) { + super.scan(node); + if (node != null) + node.type = null; + } + public void visitTopLevel(JCCompilationUnit node) { + node.packge = null; + super.visitTopLevel(node); + } + public void visitClassDef(JCClassDecl node) { + node.sym = null; + super.visitClassDef(node); + } + public void visitMethodDef(JCMethodDecl node) { + node.sym = null; + super.visitMethodDef(node); + } + public void visitVarDef(JCVariableDecl node) { + node.sym = null; + super.visitVarDef(node); + } + public void visitNewClass(JCNewClass node) { + node.constructor = null; + super.visitNewClass(node); + } + public void visitAssignop(JCAssignOp node) { + node.operator = null; + super.visitAssignop(node); + } + public void visitUnary(JCUnary node) { + node.operator = null; + super.visitUnary(node); + } + public void visitBinary(JCBinary node) { + node.operator = null; + super.visitBinary(node); + } + public void visitSelect(JCFieldAccess node) { + node.sym = null; + super.visitSelect(node); + } + public void visitIdent(JCIdent node) { + node.sym = null; + super.visitIdent(node); + } + }; } Index: com/sun/tools/javac/comp/Resolve.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/comp/Resolve.java,v retrieving revision 1.2.2.10 retrieving revision 1.24 diff -u -r1.2.2.10 -r1.24 --- com/sun/tools/javac/comp/Resolve.java 15 Aug 2007 10:23:05 -0000 1.2.2.10 +++ com/sun/tools/javac/comp/Resolve.java 3 Oct 2007 16:22:53 -0000 1.24 @@ -63,6 +63,7 @@ public final boolean boxingEnabled; // = source.allowBoxing(); public final boolean varargsEnabled; // = source.allowVarargs(); private final boolean debugResolve; + private final boolean ideMode; public static Resolve instance(Context context) { Resolve instance = context.get(resolveKey); @@ -98,6 +99,7 @@ varargsEnabled = source.allowVarargs(); Options options = Options.instance(context); debugResolve = options.get("debugresolve") != null; + this.ideMode = options.get("ide") != null; } /** error symbols, which are returned when resolution fails @@ -115,7 +117,7 @@ /** An environment is "static" if its static level is greater than * the one of its outer environment */ - static boolean isStatic(Env env) { + public static boolean isStatic(Env env) { return env.info.staticLevel > env.outer.info.staticLevel; } @@ -857,8 +859,13 @@ ClassSymbol c = reader.loadClass(name); return isAccessible(env, c) ? c : new AccessError(c); } catch (ClassReader.BadClassFile err) { - throw err; - } catch (CompletionFailure ex) { + if (ideMode) { + return typeNotFound; + } + else { + throw err; + } + } catch (CompletionFailure ex) { return typeNotFound; } } @@ -1084,21 +1091,38 @@ List typeargtypes) { if (sym.kind >= AMBIGUOUS) { // printscopes(site.tsym.members());//DEBUG - if (!site.isErroneous() && - !Type.isErroneous(argtypes) && - (typeargtypes==null || !Type.isErroneous(typeargtypes))) - ((ResolveError)sym).report(log, pos, site, name, argtypes, typeargtypes); + if (!isErroneous(site) && + !isErroneous(argtypes) && + (typeargtypes==null || !isErroneous(typeargtypes))) + ((ResolveError)sym).report(log, pos, site, name, argtypes, typeargtypes); do { sym = ((ResolveError)sym).sym; } while (sym.kind >= AMBIGUOUS); if (sym == syms.errSymbol // preserve the symbol name through errors || ((sym.kind & ERRONEOUS) == 0 // make sure an error symbol is returned - && (sym.kind & TYP) != 0)) - sym = new ErrorType(name, qualified?site.tsym:syms.noSymbol).tsym; + && (sym.kind & TYP) != 0)) { + if (!site.isErroneous() && !Type.isErroneous(argtypes) && + (typeargtypes==null || !Type.isErroneous(typeargtypes))) + sym = new ErrorType(name, qualified?site.tsym:syms.noSymbol).tsym; + else + sym = syms.errSymbol; + } } return sym; } + private boolean isErroneous(Type t) { + return t.isErroneous() && t.tsym.name == names.any; + } + + private boolean isErroneous(List ts) { + for (List l = ts; l.nonEmpty(); l = l.tail) + if (isErroneous(l.head)) return true; + return false; + } + + + /** Same as above, but without type arguments and arguments. */ Symbol access(Symbol sym, Index: com/sun/tools/javac/comp/TransTypes.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/comp/TransTypes.java,v retrieving revision 1.1.1.1.2.7 retrieving revision 1.11 diff -u -r1.1.1.1.2.7 -r1.11 --- com/sun/tools/javac/comp/TransTypes.java 15 Aug 2007 10:23:05 -0000 1.1.1.1.2.7 +++ com/sun/tools/javac/comp/TransTypes.java 30 Oct 2007 17:03:01 -0000 1.11 @@ -400,6 +400,21 @@ // if (isSpecialization(l.head)) addBridges(pos, l.head.tsym, origin, bridges); } + + + public void getBridges (DiagnosticPosition pos, ClassSymbol origin, ListBuffer bridges) { + + Env myEnv = enter.typeEnvs.get(origin); + if (myEnv == null) + return; + Env oldEnv = env; + try { + env = myEnv; + addBridges (pos, origin, bridges); + } finally { + env = oldEnv; + } + } /* ************************************************************************ * Visitor methods Index: com/sun/tools/javac/jvm/ClassReader.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/jvm/ClassReader.java,v retrieving revision 1.2.2.13 retrieving revision 1.32 diff -u -r1.2.2.13 -r1.32 --- com/sun/tools/javac/jvm/ClassReader.java 15 Aug 2007 10:23:06 -0000 1.2.2.13 +++ com/sun/tools/javac/jvm/ClassReader.java 29 Oct 2007 13:30:07 -0000 1.32 @@ -69,7 +69,7 @@ protected static final Context.Key classReaderKey = new Context.Key(); - Annotate annotate; + protected Annotate annotate; /** Switch: verbose output. */ @@ -87,15 +87,19 @@ /** Switch: read GJ signature information. */ - boolean allowGenerics; + protected boolean allowGenerics; + + /** Switch: Allow GJ covariant return types. + */ + protected boolean allowCovRetTypes; /** Switch: read varargs attribute. */ - boolean allowVarargs; + protected boolean allowVarargs; /** Switch: allow annotations. */ - boolean allowAnnotations; + protected boolean allowAnnotations; /** Switch: preserve parameter names from the variable table. */ @@ -231,7 +235,7 @@ verbose = options.get("-verbose") != null; checkClassFile = options.get("-checkclassfile") != null; Source source = Source.instance(context); - allowGenerics = source.allowGenerics(); + allowGenerics = allowCovRetTypes = source.allowGenerics(); allowVarargs = source.allowVarargs(); allowAnnotations = source.allowAnnotations(); saveParameterNames = options.get("save-parameter-names") != null; @@ -248,7 +252,7 @@ /** Add member to class unless it is synthetic. */ - private void enterMember(ClassSymbol c, Symbol sym) { + protected void enterMember(ClassSymbol c, Symbol sym) { if ((sym.flags_field & (SYNTHETIC|BRIDGE)) != SYNTHETIC) c.members_field.enter(sym); } @@ -776,7 +780,7 @@ Name name = names.fromUtf(signature, start, sigp - start); TypeVar tvar; if (sigEnterPhase) { - tvar = new TypeVar(name, currentOwner); + tvar = new TypeVar(name, currentOwner, syms.botType); typevars.enter(tvar.tsym); } else { tvar = (TypeVar)findTypeVar(name); @@ -815,7 +819,7 @@ // we don't know for sure if this owner is correct. It could // be a method and there is no way to tell before reading the // enclosing method attribute. - TypeVar t = new TypeVar(name, currentOwner); + TypeVar t = new TypeVar(name, currentOwner, syms.botType); missingTypeVariables = missingTypeVariables.prepend(t); // System.err.println("Missing type var " + name); return t; @@ -862,7 +866,7 @@ sym.flags_field |= SYNTHETIC; } else if (attrName == names.Bridge) { sym.flags_field |= BRIDGE; - if (!allowGenerics) + if (!allowCovRetTypes) sym.flags_field &= ~SYNTHETIC; } else if (attrName == names.Deprecated) { sym.flags_field |= DEPRECATED; @@ -945,7 +949,7 @@ self.name = simpleBinaryName(self.flatname, c.flatname) ; self.owner = m != null ? m : c; if (self.name.len == 0) - self.fullname = null; + self.fullname = self.name; else self.fullname = ClassSymbol.formFullName(self.name, self.owner); @@ -969,7 +973,7 @@ } // See java.lang.Class - private Name simpleBinaryName(Name self, Name enclosing) { + protected Name simpleBinaryName(Name self, Name enclosing) { String simpleBinaryName = self.toString().substring(enclosing.toString().length()); if (simpleBinaryName.length() < 1 || simpleBinaryName.charAt(0) != '$') throw badClassFile("bad.enclosing.method", self); @@ -1011,7 +1015,7 @@ } /** Similar to Types.isSameType but avoids completion */ - private boolean isSameBinaryType(MethodType mt1, MethodType mt2) { + protected boolean isSameBinaryType(MethodType mt1, MethodType mt2) { List types1 = types.erasure(mt1.getParameterTypes()) .prepend(types.erasure(mt1.getReturnType())); List types2 = mt2.getParameterTypes().prepend(mt2.getReturnType()); @@ -1216,7 +1220,7 @@ void visitCompoundAnnotationProxy(CompoundAnnotationProxy proxy); } - static class EnumAttributeProxy extends Attribute { + protected static class EnumAttributeProxy extends Attribute { Type enumType; Name enumerator; public EnumAttributeProxy(Type enumType, Name enumerator) { @@ -1230,9 +1234,9 @@ } } - static class ArrayAttributeProxy extends Attribute { + protected static class ArrayAttributeProxy extends Attribute { List values; - ArrayAttributeProxy(List values) { + public ArrayAttributeProxy(List values) { super(null); this.values = values; } @@ -1244,7 +1248,7 @@ /** A temporary proxy representing a compound attribute. */ - static class CompoundAnnotationProxy extends Attribute { + protected static class CompoundAnnotationProxy extends Attribute { final List> values; public CompoundAnnotationProxy(Type type, List> values) { @@ -1416,14 +1420,14 @@ } } - class AnnotationDefaultCompleter extends AnnotationDeproxy implements Annotate.Annotator { + protected class AnnotationDefaultCompleter extends AnnotationDeproxy implements Annotate.Annotator { final MethodSymbol sym; final Attribute value; final JavaFileObject classFile = currentClassFile; public String toString() { return " ClassReader store default for " + sym.owner + "." + sym + " is " + value; } - AnnotationDefaultCompleter(MethodSymbol sym, Attribute value) { + public AnnotationDefaultCompleter(MethodSymbol sym, Attribute value) { this.sym = sym; this.value = value; } @@ -1439,14 +1443,14 @@ } } - class AnnotationCompleter extends AnnotationDeproxy implements Annotate.Annotator { + protected class AnnotationCompleter extends AnnotationDeproxy implements Annotate.Annotator { final Symbol sym; final List l; final JavaFileObject classFile; public String toString() { return " ClassReader annotate " + sym.owner + "." + sym + " with " + l; } - AnnotationCompleter(Symbol sym, List l) { + public AnnotationCompleter(Symbol sym, List l) { this.sym = sym; this.l = l; this.classFile = currentClassFile; @@ -1684,7 +1688,7 @@ if ((flags & ACC_BRIDGE) != 0) { flags &= ~ACC_BRIDGE; flags |= BRIDGE; - if (!allowGenerics) + if (!allowCovRetTypes) flags &= ~SYNTHETIC; } if ((flags & ACC_VARARGS) != 0) { @@ -1730,6 +1734,23 @@ } return c; } + + public ClassSymbol enterClass(Name flatname, Name name, Symbol owner) { + ClassSymbol c = classes.get(flatname); + if (c == null) { + c = defineClass(name, owner); + c.flatname = flatname; + classes.put(flatname, c); + } else if ((c.name != name || c.owner != owner) && c.owner.kind == PCK) { + // reassign fields of classes that might have been loaded with + // their flat names. + c.owner.members().remove(c); + c.name = name; + c.owner = owner; + c.fullname = ClassSymbol.formFullName(name, owner); + } + return c; + } /** * Creates a new toplevel class symbol with given flat name and @@ -1836,7 +1857,7 @@ /** Fill in definition of class `c' from corresponding class or * source file. */ - private void fillIn(ClassSymbol c) { + protected void fillIn(ClassSymbol c) { if (completionFailureName == c.fullname) { throw new CompletionFailure(c, "user-selected completion failure by class name"); } @@ -1878,6 +1899,7 @@ missingTypeVariables = List.nil(); foundTypeVariables = List.nil(); filling = false; + c.flags_field |= FROMCLASS; } } else { if (sourceCompleter != null) { @@ -1901,14 +1923,14 @@ } } // where - private static byte[] readInputStream(byte[] buf, InputStream s) throws IOException { + static byte[] readInputStream(byte[] buf, InputStream s) throws IOException { try { buf = ensureCapacity(buf, s.available()); int r = s.read(buf); int bp = 0; while (r != -1) { bp += r; - buf = ensureCapacity(buf, bp); + buf = ensureCapacity(buf, buf.length == bp ? bp + 1 : bp); //see ClassReaderTest r = s.read(buf, bp, buf.length - bp); } return buf; @@ -2035,7 +2057,7 @@ if (c.owner == p) // it might be an inner class p.members_field.enter(c); } - } else if (c.classfile != null && (c.flags_field & seen) == 0) { + } else if (c.classfile != null && ((c.flags_field & seen) == 0 || isSigOverClass(c.classfile, file))) { // if c.classfile == null, we are currently compiling this class // and no further action is necessary. // if (c.flags_field & seen) != 0, we have already encountered @@ -2045,6 +2067,12 @@ } c.flags_field |= seen; } + + private boolean isSigOverClass (final JavaFileObject a, final JavaFileObject b) { + String patha = a.getName().toLowerCase(); + String pathb = b.getName().toLowerCase(); + return pathb.endsWith(".sig") && patha.endsWith(".class"); //NOI18N + } /** Implement policy to choose to derive information from a source * file or a class file when both are present. May be overridden @@ -2168,10 +2196,12 @@ case SOURCE: { // TODO pass binaryName to includeClassFile String binaryName = fileManager.inferBinaryName(currentLoc, fo); - String simpleName = binaryName.substring(binaryName.lastIndexOf(".") + 1); - if (SourceVersion.isIdentifier(simpleName) || - simpleName.equals("package-info")) - includeClassFile(p, fo); + if (binaryName != null) { + String simpleName = binaryName.substring(binaryName.lastIndexOf(".") + 1); + if (SourceVersion.isIdentifier(simpleName) || + simpleName.equals("package-info")) + includeClassFile(p, fo); + } break; } default: Index: com/sun/tools/javac/main/JavaCompiler.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/main/JavaCompiler.java,v retrieving revision 1.2.2.15 retrieving revision 1.28 diff -u -r1.2.2.15 -r1.28 --- com/sun/tools/javac/main/JavaCompiler.java 15 Aug 2007 10:23:06 -0000 1.2.2.15 +++ com/sun/tools/javac/main/JavaCompiler.java 27 Aug 2007 15:11:46 -0000 1.28 @@ -292,6 +292,8 @@ protected boolean implicitSourceFilesRead; protected Context context; + + protected Map notYetEntered; /** Construct a new compiler using a shared context. */ @@ -348,7 +350,7 @@ lineDebugInfo = options.get("-g:") == null || options.get("-g:lines") != null; genEndPos = options.get("-Xjcov") != null || - context.get(DiagnosticListener.class) != null; + (context.get(DiagnosticListener.class) != null && options.get("backgroundCompilation") == null); devVerbose = options.get("dev") != null; processPcks = options.get("process.packages") != null; @@ -653,15 +655,19 @@ if (completionFailureName == c.fullname) { throw new CompletionFailure(c, "user-selected completion failure by class name"); } - JCCompilationUnit tree; + JCCompilationUnit tree = null; JavaFileObject filename = c.classfile; JavaFileObject prev = log.useSource(filename); try { - tree = parse(filename, filename.getCharContent(false)); + if (notYetEntered != null) + tree = notYetEntered.remove(filename); + if (tree == null) + tree = parse(filename, filename.getCharContent(false)); } catch (IOException e) { log.error("error.reading.file", filename, e); tree = make.TopLevel(List.nil(), null, List.nil()); + tree.sourcefile = filename; } finally { log.useSource(prev); } @@ -779,7 +785,7 @@ while (todo.nonEmpty()) generate(desugar(flow(attribute(todo.next())))); break; - + default: assert false: "unknown compile policy"; } @@ -856,6 +862,10 @@ } return roots; } + + public void initNotYetEntered(Map notYetEntered) { + this.notYetEntered = notYetEntered; + } /** * Set to true to enable skeleton annotation processing code. Index: com/sun/tools/javac/model/JavacElements.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/model/JavacElements.java,v retrieving revision 1.1.2.11 retrieving revision 1.22 diff -u -r1.1.2.11 -r1.22 --- com/sun/tools/javac/model/JavacElements.java 15 Aug 2007 10:23:05 -0000 1.1.2.11 +++ com/sun/tools/javac/model/JavacElements.java 17 Aug 2007 13:18:19 -0000 1.22 @@ -68,6 +68,7 @@ private Types types; private Enter enter; private ClassReader reader; + private LazyTreeLoader loader; private static final Context.Key KEY = new Context.Key(); @@ -101,6 +102,7 @@ types = Types.instance(context); enter = Enter.instance(context); reader = ClassReader.instance(context); + loader = LazyTreeLoader.instance(context); } @@ -155,6 +157,41 @@ ? nameToSymbol(strName, ClassSymbol.class) : null; } + + + public ClassSymbol getTypeElementByBinaryName (final CharSequence binaryName) { + final String strName = binaryName instanceof String ? (String) binaryName : binaryName.toString(); + int index = strName.indexOf('$'); //NOI18N + final String owner = index < 0 ? strName : strName.substring(0,index); + return SourceVersion.isName(owner) + ? binaryNameToClassSymbol(strName, owner) + : null; + } + + private ClassSymbol binaryNameToClassSymbol (final String binaryName, final String owner) { + final Name name = names.fromString(binaryName); + ClassSymbol sym = syms.classes.get(name); + try { + if (sym == null) { + javaCompiler.resolveIdent(owner); + sym = syms.classes.get(name); + } + + if (sym != null) { + sym.complete(); + return (sym.kind != Kinds.ERR && + sym.exists() && + name.equals(sym.flatName())) + ? sym + : null; + } + else if (syms.classes.get(owner) != null) { + throw new AssertionError ("Cannot resolve: " + name + "resolved othermost: " + owner); //NOI18N + } + } catch (CompletionFailure e) { + } + return null; + } /** * Returns a symbol given the type's or packages's canonical name, @@ -408,7 +445,7 @@ */ public FilteredMemberList getAllMembers(TypeElement element) { Symbol sym = cast(Symbol.class, element); - Scope scope = sym.members().dupUnshared(); + Scope scope = new Scope(sym); List closure = types.closure(sym.asType()); for (Type t : closure) addMembers(scope, t); @@ -418,20 +455,27 @@ private void addMembers(Scope scope, Type type) { members: for (Scope.Entry e = type.asElement().members().elems; e != null; e = e.sibling) { - Scope.Entry overrider = scope.lookup(e.sym.getSimpleName()); + ElementKind kind = e.sym.getKind(); + boolean isAbstract = (e.sym.flags() & Flags.ABSTRACT) != 0; + if (kind == ElementKind.METHOD && isAbstract) { + MethodSymbol impl = ((MethodSymbol)e.sym).implementation((TypeSymbol)scope.owner, types, false); + if (impl != null && impl != e.sym) + continue members; + } + Scope.Entry overrider = scope.lookup(e.sym.getSimpleName()); while (overrider.scope != null) { if (overrider.sym.kind == e.sym.kind && (overrider.sym.flags() & Flags.SYNTHETIC) == 0) { if (overrider.sym.getKind() == ElementKind.METHOD - && overrides((ExecutableElement)overrider.sym, (ExecutableElement)e.sym, (TypeElement)type.asElement())) { + && (overrides((ExecutableElement)overrider.sym, (ExecutableElement)e.sym, (TypeElement)type.asElement()) + || isAbstract && types.isSubSignature(types.memberType(scope.owner.type, e.sym), types.memberType(scope.owner.type, overrider.sym)))) { continue members; } } overrider = overrider.next(); } boolean derived = e.sym.getEnclosingElement() != scope.owner; - ElementKind kind = e.sym.getKind(); boolean initializer = kind == ElementKind.CONSTRUCTOR || kind == ElementKind.INSTANCE_INIT || kind == ElementKind.STATIC_INIT; @@ -579,14 +623,19 @@ private Pair getTreeAndTopLevel(Element e) { Symbol sym = cast(Symbol.class, e); Env enterEnv = getEnterEnv(sym); - if (enterEnv == null) - return null; + if (enterEnv == null) { + if (!loader.loadTreeFor(sym.enclClass())) + return null; + enterEnv = getEnterEnv(sym); + if (enterEnv == null) + return null; + } JCTree tree = TreeInfo.declarationFor(sym, enterEnv.tree); if (tree == null || enterEnv.toplevel == null) return null; return new Pair(tree, enterEnv.toplevel); } - + /** * Returns the best approximation for the tree node and compilation unit * corresponding to the given element, annotation and value. Index: com/sun/tools/javac/model/LazyTreeLoader.java =================================================================== RCS file: com/sun/tools/javac/model/LazyTreeLoader.java diff -N com/sun/tools/javac/model/LazyTreeLoader.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ com/sun/tools/javac/model/LazyTreeLoader.java 9 May 2007 11:47:59 -0000 1.1 @@ -0,0 +1,28 @@ +package com.sun.tools.javac.model; + +import com.sun.tools.javac.code.Symbol.ClassSymbol; +import com.sun.tools.javac.util.Context; + +/** + * + * @author Dusan Balek + */ +public class LazyTreeLoader { + + /** The context key for the parameter name resolver. */ + protected static final Context.Key lazyTreeLoaderKey = + new Context.Key(); + + public static LazyTreeLoader instance(Context context) { + LazyTreeLoader instance = context.get(lazyTreeLoaderKey); + if (instance == null) { + instance = new LazyTreeLoader(); + context.put(lazyTreeLoaderKey, instance); + } + return instance; + } + + public boolean loadTreeFor(ClassSymbol clazz) { + return false; + } +} Index: com/sun/tools/javac/parser/DocCommentScanner.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/parser/DocCommentScanner.java,v retrieving revision 1.1.2.1 retrieving revision 1.2 diff -u -r1.1.2.1 -r1.2 --- com/sun/tools/javac/parser/DocCommentScanner.java 15 Aug 2007 10:23:04 -0000 1.1.2.1 +++ com/sun/tools/javac/parser/DocCommentScanner.java 17 Aug 2007 13:18:19 -0000 1.2 @@ -448,7 +448,7 @@ * * @return a LineMap */ public Position.LineMap getLineMap() { - char[] buf = getRawCharacters(); - return Position.makeLineMap(buf, buf.length, true); + char[] buf = getVeryRawCharacters(); + return Position.makeLineMap(buf, buf.length, '\n', true); } } Index: com/sun/tools/javac/parser/EndPosParser.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/parser/EndPosParser.java,v retrieving revision 1.1.1.1.2.7 retrieving revision 1.13 diff -u -r1.1.1.1.2.7 -r1.13 --- com/sun/tools/javac/parser/EndPosParser.java 15 Aug 2007 10:23:04 -0000 1.1.1.1.2.7 +++ com/sun/tools/javac/parser/EndPosParser.java 17 Aug 2007 13:18:19 -0000 1.13 @@ -29,6 +29,7 @@ import java.util.HashMap; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.TreeInfo; +import com.sun.tools.javac.util.CancelService; import com.sun.tools.javac.util.Position; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.Version; @@ -47,8 +48,8 @@ @Version("@(#)EndPosParser.java 1.13 07/05/05") public class EndPosParser extends Parser { - public EndPosParser(Factory fac, Lexer S, boolean keepDocComments) { - super(fac, S, keepDocComments); + public EndPosParser(Factory fac, Lexer S, boolean keepDocComments, CancelService cancelService) { + super(fac, S, keepDocComments, cancelService); this.S = S; endPositions = new HashMap(); } Index: com/sun/tools/javac/parser/Parser.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/parser/Parser.java,v retrieving revision 1.5.2.14 retrieving revision 1.62 diff -u -r1.5.2.14 -r1.62 --- com/sun/tools/javac/parser/Parser.java 15 Aug 2007 10:23:04 -0000 1.5.2.14 +++ com/sun/tools/javac/parser/Parser.java 29 Oct 2007 09:56:18 -0000 1.62 @@ -50,6 +50,55 @@ */ @Version("@(#)Parser.java 1.108 07/06/14") public class Parser { + + + /** + *Represents a scope for anon class number assignment + */ + private static class AnonScope { + public boolean localClass; + private final Name parentDecl; + private int currentNumber; + private Map localClasses; + + public AnonScope (final Name name) { + this (name, 1); + } + + public AnonScope (final Name name, final int startNumber) { + assert name != null; + this.parentDecl = name; + this.currentNumber = startNumber; + } + + public int assignNumber () { + int ret = this.currentNumber; + if (this.currentNumber != -1) { + this.currentNumber++; + } + return ret; + } + + public int assignLocalNumber (final Name name) { + if (localClasses == null) { + localClasses = new HashMap (); + } + Integer num = localClasses.get(name); + if (num == null) { + num = 1; + } + else { + num += 1; + } + localClasses.put(name, num); + return num.intValue(); + } + + @Override + public String toString () { + return String.format("%s : %d",this.parentDecl.toString(), this.currentNumber); + } + } /** A factory for creating parsers. */ public static class Factory { @@ -71,6 +120,7 @@ final Source source; final Name.Table names; final Options options; + private final CancelService cancelSevice; /** Create a new parser factory. */ protected Factory(Context context) { @@ -81,6 +131,7 @@ this.keywords = Keywords.instance(context); this.source = Source.instance(context); this.options = Options.instance(context); + this.cancelSevice = CancelService.instance(context); } /** @@ -88,14 +139,33 @@ * @param S Lexer for getting tokens while parsing * @param keepDocComments true if javadoc comments should be kept * @param genEndPos true if end positions should be generated + */ + public Parser newParser(Lexer S, boolean keepDocComments, boolean genEndPos) { + return newParser (S, keepDocComments, genEndPos, false); + } + + /** + * Create a new Parser. + * @param S Lexer for getting tokens while parsing + * @param keepDocComments true if javadoc comments should be kept + * @param genEndPos true if end positions should be generated + * @param partial true if parser parses only a part of source file */ - public Parser newParser(Lexer S, boolean keepDocComments, boolean genEndPos) { + public Parser newParser(Lexer S, boolean keepDocComments, boolean genEndPos, boolean partial) { + Parser p; if (!genEndPos) - return new Parser(this, S, keepDocComments); + p = new Parser(this, S, keepDocComments, cancelSevice); else - return new EndPosParser(this, S, keepDocComments); + p = new EndPosParser(this, S, keepDocComments, cancelSevice); + + if (partial) { + p.anonScopes.push(new AnonScope(names.empty,-1)); + } + return p; } } + + final Stack anonScopes = new Stack (); /** The number of precedence levels of infix operators. */ @@ -121,12 +191,15 @@ /** The name table. */ private Name.Table names; + + private final CancelService cancelService; /** Construct a parser from a given scanner, tree factory and log. */ protected Parser(Factory fac, Lexer S, - boolean keepDocComments) { + boolean keepDocComments, + CancelService cancelService) { this.S = S; S.nextToken(); // prime the pump this.F = fac.F; @@ -142,9 +215,11 @@ this.allowForeach = source.allowForeach(); this.allowStaticImport = source.allowStaticImport(); this.allowAnnotations = source.allowAnnotations(); + this.allowStringFolding = options.get("disableStringFolding") == null; //NOI18N this.keepDocComments = keepDocComments; if (keepDocComments) docComments = new HashMap(); this.errorTree = F.Erroneous(); + this.cancelService = cancelService; } /** Switch: Should generics be recognized? @@ -175,10 +250,14 @@ */ boolean allowAnnotations; + /** Switch: should we fold strings? + */ + boolean allowStringFolding; + /** Switch: should we keep docComments? */ boolean keepDocComments; - + /** When terms are parsed, the mode determines which is expected: * mode = EXPR : an expression * mode = TYPE : a type @@ -233,7 +312,6 @@ case VOLATILE: case SYNCHRONIZED: case STRICTFP: - case LT: case BYTE: case SHORT: case CHAR: @@ -265,6 +343,8 @@ case ELSE: case FINALLY: case CATCH: + case THIS: + case SUPER: if (stopAtStatement) return; break; @@ -274,16 +354,20 @@ } private JCErroneous syntaxError(int pos, String key, Object... arg) { - return syntaxError(pos, null, key, arg); + return syntaxError(pos, List.nil(), key, arg); } private JCErroneous syntaxError(int pos, List errs, String key, Object... arg) { setErrorEndPos(pos); reportSyntaxError(pos, key, arg); - return toP(F.at(pos).Erroneous(errs)); + if (errs != null) { + JCTree last = errs.last(); + if (last != null) + storeEnd(last, pos); + } + return toP(F.at(S.prevEndPos()).Erroneous(errs)); } - private int errorPos = Position.NOPOS; /** * Report a syntax error at given position using the given * argument unless one was already reported at the same position. @@ -296,9 +380,6 @@ log.error(pos, key, arg); } S.errPos(pos); - if (S.pos() == errorPos) - S.nextToken(); // guarantee progress - errorPos = S.pos(); } @@ -331,7 +412,7 @@ /** Report an illegal start of expression/type error at given position. */ JCExpression illegal(int pos) { - setErrorEndPos(S.pos()); + setErrorEndPos(pos); if ((mode & EXPR) != 0) return syntaxError(pos, "illegal.start.of.expr"); else @@ -494,8 +575,7 @@ * | FALSE * | NULL */ - JCExpression literal(Name prefix) { - int pos = S.pos(); + JCExpression literal(Name prefix, int pos) { JCExpression t = errorTree; switch (S.token()) { case INTLITERAL: @@ -581,6 +661,8 @@ } //where boolean isZero(String s) { + if (s.length() == 1) + return '0' == s.charAt(0); char[] cs = s.toCharArray(); int base = ((Character.toLowerCase(s.charAt(1)) == 'x') ? 16 : 10); int i = ((base==16) ? 2 : 0); @@ -775,6 +857,8 @@ * by a single literal representing the concatenated string. */ protected StringBuffer foldStrings(JCTree tree) { + if (!allowStringFolding) + return null; List buf = List.nil(); while (true) { if (tree.getTag() == JCTree.LITERAL) { @@ -856,6 +940,10 @@ int pos = S.pos(); JCExpression t; List typeArgs = typeArgumentsOpt(EXPR); + if (typeArgs != null && S.pos() <= errorEndPos) { + // error recovery + return F.at(pos).Erroneous(typeArgs); + } switch (S.token()) { case QUES: if ((mode & TYPE) != 0 && (mode & (TYPEARG|NOPARAMS)) == TYPEARG) { @@ -872,7 +960,7 @@ (S.token() == INTLITERAL || S.token() == LONGLITERAL) && S.radix() == 10) { mode = EXPR; - t = literal(names.hyphen); + t = literal(names.hyphen, pos); } else { t = term3(); return F.at(pos).Unary(unoptag(token), t); @@ -954,7 +1042,7 @@ case SUPER: if ((mode & EXPR) != 0) { mode = EXPR; - t = to(superSuffix(typeArgs, F.at(pos).Ident(names._super))); + t = superSuffix(typeArgs, to(F.at(pos).Ident(names._super))); typeArgs = null; } else return illegal(); break; @@ -963,7 +1051,7 @@ case TRUE: case FALSE: case NULL: if (typeArgs == null && (mode & EXPR) != 0) { mode = EXPR; - t = literal(names.empty); + t = literal(names.empty, S.pos()); } else return illegal(); break; case NEW: @@ -1389,6 +1477,7 @@ } else if (S.token() == LPAREN) { return classCreatorRest(newpos, null, typeArgs, t); } else { + errorEndPos = S.pos(); reportSyntaxError(S.pos(), "expected2", keywords.token2string(LPAREN), keywords.token2string(LBRACKET)); @@ -1419,7 +1508,7 @@ if (S.token() == LBRACE) { return arrayInitializer(newpos, elemtype); } else { - return syntaxError(S.pos(), "array.dimension.missing"); + return syntaxError(S.pos(), List.of(toP(F.at(newpos).NewArray(elemtype, List.nil(), null))), "array.dimension.missing"); } } else { ListBuffer dims = new ListBuffer(); @@ -1449,10 +1538,18 @@ List args = arguments(); JCClassDecl body = null; if (S.token() == LBRACE) { - int pos = S.pos(); - List defs = classOrInterfaceBody(names.empty, false); - JCModifiers mods = F.at(Position.NOPOS).Modifiers(0); - body = toP(F.at(pos).AnonymousClassDef(mods, defs)); + this.anonScopes.push(new AnonScope(names.empty)); + int pos = 0; + List defs = null; + JCModifiers mods = null; + try { + pos = S.pos(); + defs = classOrInterfaceBody(names.empty, false); + mods = F.at(Position.NOPOS).Modifiers(0); + } finally { + this.anonScopes.pop(); + } + body = toP(F.at(pos).AnonymousClassDef(mods, defs, this.anonScopes.peek().assignNumber())); } return toP(F.at(newpos).NewClass(encl, typeArgs, t, args, body)); } @@ -1471,6 +1568,8 @@ if (S.token() == RBRACE) break; elems.append(variableInitializer()); } + if (S.pos() <= errorEndPos) + skip(false, true, true, true); } accept(RBRACE); return toP(F.at(newpos).NewArray(t, List.nil(), elems.toList())); @@ -1555,7 +1654,13 @@ case ABSTRACT: case STRICTFP: { String dc = S.docComment(); JCModifiers mods = modifiersOpt(); - stats.append(classOrInterfaceOrEnumDeclaration(mods, dc)); + if (S.token() == INTERFACE || + S.token() == CLASS || + allowEnums && S.token() == ENUM) { + stats.append(classOrInterfaceOrEnumDeclaration(mods, dc)); + } else { + setErrorEndPos(S.pos()); + } break; } case INTERFACE: @@ -1593,12 +1698,12 @@ stats.appendList(variableDeclarators(mods, t, new ListBuffer())); // A "LocalVariableDeclarationStatement" subsumes the terminating semicolon - storeEnd(stats.elems.last(), S.endPos()); accept(SEMI); + storeEnd(stats.elems.last(), S.prevEndPos()); } else { // This Exec is an "ExpressionStatement"; it subsumes the terminating semicolon - stats.append(to(F.at(pos).Exec(checkExprStat(t)))); accept(SEMI); + stats.append(toP(F.at(pos).Exec(checkExprStat(t)))); } } @@ -1664,14 +1769,22 @@ accept(COLON); JCExpression expr = expression(); accept(RPAREN); + if (errorEndPos >= S.pos()) //error recovery + storeEnd(expr, errorEndPos); JCStatement body = statement(); return F.at(pos).ForeachLoop(var, expr, body); } else { accept(SEMI); + if (errorEndPos >= S.pos() && inits.length() > 0) //error recovery + storeEnd(inits.last(), errorEndPos); JCExpression cond = S.token() == SEMI ? null : expression(); accept(SEMI); + if (errorEndPos >= S.pos()) //error recovery + storeEnd(cond, errorEndPos); List steps = S.token() == RPAREN ? List.nil() : forUpdate(); accept(RPAREN); + if (errorEndPos >= S.pos() && steps.length() > 0) //error recovery + storeEnd(steps.last(), errorEndPos); JCStatement body = statement(); return F.at(pos).ForLoop(inits, cond, steps, body); } @@ -1785,6 +1898,8 @@ } else { // This Exec is an "ExpressionStatement"; it subsumes the terminating semicolon JCExpressionStatement stat = to(F.at(pos).Exec(checkExprStat(expr))); + if (S.token() != SEMI) // Error recovery + storeEnd(stat, S.pos()); accept(SEMI); return stat; } @@ -1956,17 +2071,22 @@ } flags |= flag; } - switch (S.token()) { - case ENUM: flags |= Flags.ENUM; break; - case INTERFACE: flags |= Flags.INTERFACE; break; - default: break; - } /* A modifiers tree with no modifier tokens or annotations * has no text position. */ if (flags == 0 && annotations.isEmpty()) pos = Position.NOPOS; + switch (S.token()) { + case ENUM: + if (this.allowEnums) { + flags |= Flags.ENUM; + } + break; + case INTERFACE: flags |= Flags.INTERFACE; break; + default: break; + } + JCModifiers mods = F.at(pos).Modifiers(flags, annotations.toList()); if (pos != Position.NOPOS) storeEnd(mods, S.prevEndPos()); @@ -1980,9 +2100,11 @@ // accept(AT); // AT consumed by caller checkAnnotations(); JCTree ident = qualident(); + int identEndPos = S.prevEndPos(); + boolean hasParens = S.token() == LPAREN; List fieldValues = annotationFieldValuesOpt(); JCAnnotation ann = F.at(pos).Annotation(ident, fieldValues); - storeEnd(ann, S.prevEndPos()); + storeEnd(ann, hasParens ? S.prevEndPos() : identEndPos); return ann; } @@ -2128,51 +2250,53 @@ /** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration} */ public JCTree.JCCompilationUnit compilationUnit() { - int pos = S.pos(); - JCExpression pid = null; - String dc = S.docComment(); - JCModifiers mods = null; - List packageAnnotations = List.nil(); - if (S.token() == MONKEYS_AT) - mods = modifiersOpt(); - - if (S.token() == PACKAGE) { - if (mods != null) { - checkNoMods(mods.flags); - packageAnnotations = mods.annotations; - mods = null; - } - S.nextToken(); - pid = qualident(); - accept(SEMI); - } - ListBuffer defs = new ListBuffer(); - boolean checkForImports = true; - while (S.token() != EOF) { - if (S.pos() <= errorEndPos) { - // error recovery - skip(checkForImports, false, false, false); - if (S.token() == EOF) - break; + try { + int pos = S.pos(); + JCExpression pid = null; + String dc = S.docComment(); + JCModifiers mods = null; + List packageAnnotations = List.nil(); + if (S.token() == MONKEYS_AT) + mods = modifiersOpt(); + + if (S.token() == PACKAGE) { + if (mods != null) { + checkNoMods(mods.flags); + packageAnnotations = mods.annotations; + mods = null; + } + S.nextToken(); + pid = qualident(); + accept(SEMI); } - if (checkForImports && mods == null && S.token() == IMPORT) { - defs.append(importDeclaration()); - } else { - JCTree def = typeDeclaration(mods); - if (def instanceof JCExpressionStatement) - def = ((JCExpressionStatement)def).expr; - defs.append(def); - if (def instanceof JCClassDecl) - checkForImports = false; - mods = null; + ListBuffer defs = new ListBuffer(); + boolean checkForImports = true; + while (S.token() != EOF) { + if (S.pos() <= errorEndPos) { + // error recovery + skip(checkForImports, false, false, false); + if (S.token() == EOF) + break; + } + if (checkForImports && mods == null && S.token() == IMPORT) { + defs.append(importDeclaration()); + } else { + JCTree def = typeDeclaration(mods); + defs.append(def); + if (def instanceof JCClassDecl) + checkForImports = false; + mods = null; + } } + JCTree.JCCompilationUnit toplevel = F.at(pos).TopLevel(packageAnnotations, pid, defs.toList()); + attach(toplevel, dc); + if (defs.elems.isEmpty()) + storeEnd(toplevel, S.prevEndPos()); + if (keepDocComments) toplevel.docComments = docComments; + return toplevel; + } finally { + this.anonScopes.clear(); } - JCTree.JCCompilationUnit toplevel = F.at(pos).TopLevel(packageAnnotations, pid, defs.toList()); - attach(toplevel, dc); - if (defs.elems.isEmpty()) - storeEnd(toplevel, S.prevEndPos()); - if (keepDocComments) toplevel.docComments = docComments; - return toplevel; } /** ImportDeclaration = IMPORT [ STATIC ] Ident { "." Ident } [ "." "*" ] ";" @@ -2247,6 +2371,7 @@ if (S.token() == ENUM) { log.error(S.pos(), "enums.not.supported.in.source", source.name); allowEnums = true; + mods.flags|=Flags.ENUM; return enumDeclaration(mods, dc); } int pos = S.pos(); @@ -2269,6 +2394,9 @@ * @param dc The documentation comment for the class, or null. */ JCClassDecl classDeclaration(JCModifiers mods, String dc) { + if (cancelService != null) { + cancelService.abortIfCanceled(); + } int pos = S.pos(); accept(CLASS); Name name = ident(); @@ -2285,9 +2413,18 @@ S.nextToken(); implementing = typeList(); } - List defs = classOrInterfaceBody(name, false); + List defs = null; + this.anonScopes.push (new AnonScope(name)); + try { + defs = classOrInterfaceBody(name, false); + } finally { + this.anonScopes.pop(); + } JCClassDecl result = toP(F.at(pos).ClassDef( - mods, name, typarams, extending, implementing, defs)); + mods, name, typarams, extending, implementing, defs)); + if (!this.anonScopes.isEmpty() && this.anonScopes.peek().localClass) { + result.index = this.anonScopes.peek().assignLocalNumber(name); + } attach(result, dc); return result; } @@ -2298,6 +2435,9 @@ * @param dc The documentation comment for the interface, or null. */ JCClassDecl interfaceDeclaration(JCModifiers mods, String dc) { + if (cancelService != null) { + cancelService.abortIfCanceled(); + } int pos = S.pos(); accept(INTERFACE); Name name = ident(); @@ -2309,9 +2449,18 @@ S.nextToken(); extending = typeList(); } - List defs = classOrInterfaceBody(name, true); + List defs = null; + this.anonScopes.push (new AnonScope (name)); + try { + defs = classOrInterfaceBody(name, true); + } finally { + this.anonScopes.pop(); + } JCClassDecl result = toP(F.at(pos).ClassDef( mods, name, typarams, null, extending, defs)); + if (!this.anonScopes.isEmpty() && this.anonScopes.peek().localClass) { + result.index = this.anonScopes.peek().assignLocalNumber(name); + } attach(result, dc); return result; } @@ -2321,22 +2470,40 @@ * @param dc The documentation comment for the enum, or null. */ JCClassDecl enumDeclaration(JCModifiers mods, String dc) { - int pos = S.pos(); - accept(ENUM); - Name name = ident(); - + if (cancelService != null) { + cancelService.abortIfCanceled(); + } + int pos = S.pos(); + accept(ENUM); + JCModifiers newMods = + F.at(mods.pos).Modifiers(mods.flags|Flags.ENUM, mods.annotations); + storeEnd(newMods, getEndPos(mods)); + Name name = ident(); + return enumDeclaration(newMods, dc, pos, name); + } + + JCClassDecl enumDeclaration(JCModifiers mods, String dc, int pos, Name name) { List implementing = List.nil(); if (S.token() == IMPLEMENTS) { S.nextToken(); implementing = typeList(); } - List defs = enumBody(name); - JCModifiers newMods = - F.at(mods.pos).Modifiers(mods.flags|Flags.ENUM, mods.annotations); + List defs = null; + this.anonScopes.push(new AnonScope (name)); + try { + defs = enumBody(name); + } finally { + this.anonScopes.pop(); + } + JCClassDecl result = toP(F.at(pos). - ClassDef(newMods, name, List.nil(), + ClassDef(mods, name, List.nil(), null, implementing, defs)); + if (!this.anonScopes.isEmpty() && this.anonScopes.peek().localClass) { + result.index = this.anonScopes.peek().assignLocalNumber(name); + } + attach(result, dc); return result; } @@ -2346,6 +2513,12 @@ */ List enumBody(Name enumName) { accept(LBRACE); + if (S.pos() <= errorEndPos) { + // error recovery + skip(false, true, false, false); + if (S.token() == LBRACE) + S.nextToken(); + } ListBuffer defs = new ListBuffer(); if (S.token() == COMMA) { S.nextToken(); @@ -2398,11 +2571,18 @@ List args = (S.token() == LPAREN) ? arguments() : List.nil(); JCClassDecl body = null; - if (S.token() == LBRACE) { - JCModifiers mods1 = F.at(Position.NOPOS).Modifiers(Flags.ENUM | Flags.STATIC); - List defs = classOrInterfaceBody(names.empty, false); - body = toP(F.at(identPos).AnonymousClassDef(mods1, defs)); - } + if (S.token() == LBRACE) { + JCModifiers mods1 = null; + List defs = null; + this.anonScopes.push(new AnonScope(names.empty)); + try { + mods1 = F.at(Position.NOPOS).Modifiers(Flags.ENUM | Flags.STATIC); + defs = classOrInterfaceBody(names.empty, false); + } finally { + this.anonScopes.pop(); + } + body = toP(F.at(identPos).AnonymousClassDef(mods1, defs, this.anonScopes.peek().assignNumber())); + } if (args.isEmpty() && body == null) createPos = Position.NOPOS; JCIdent ident = F.at(Position.NOPOS).Ident(enumName); @@ -2443,6 +2623,8 @@ defs.appendList(classOrInterfaceBodyDeclaration(className, isInterface)); if (S.pos() <= errorEndPos) { // error recovery + if (S.token() == LBRACE && isInterface) + S.nextToken(); skip(false, true, true, false); } } @@ -2467,10 +2649,12 @@ * | ModifiersOpt Type Ident * ( ConstantDeclaratorsRest | InterfaceMethodDeclaratorRest ";" ) */ - List classOrInterfaceBodyDeclaration(Name className, boolean isInterface) { - if (S.token() == SEMI) { + public List classOrInterfaceBodyDeclaration(Name className, boolean isInterface) { + if (S.token() == SEMI) { + JCTree block = F.at(S.pos()).Block(0, List.nil()); + storeEnd(block, S.endPos()); S.nextToken(); - return List.of(F.at(Position.NOPOS).Block(0, List.nil())); + return List.of(block); } else { String dc = S.docComment(); int pos = S.pos(); @@ -2482,8 +2666,14 @@ } else if (S.token() == LBRACE && !isInterface && (mods.flags & Flags.StandardFlags & ~Flags.STATIC) == 0 && mods.annotations.isEmpty()) { - return List.of(block(pos, mods.flags)); - } else { + final AnonScope as = this.anonScopes.peek(); + as.localClass=true; + try { + return List.of(block(pos, mods.flags)); + } finally { + as.localClass=false; + } + } else { pos = S.pos(); List typarams = typeParametersOpt(); // Hack alert: if there are type arguments but no Modifiers, the start @@ -2496,7 +2686,7 @@ Name name = S.name(); pos = S.pos(); JCExpression type; - boolean isVoid = S.token() == VOID; + boolean isVoid = token == VOID; if (isVoid) { type = to(F.at(pos).TypeIdent(TypeTags.VOID)); S.nextToken(); @@ -2504,8 +2694,12 @@ type = type(); } if (S.token() == LPAREN && !isInterface && type.getTag() == JCTree.IDENT) { - if (isInterface || name != className) + if (isInterface || name != className) { log.error(pos, "invalid.meth.decl.ret.type.req"); + return List.of(methodDeclaratorRest( + pos, mods, null, name, typarams, + isInterface, true, dc)); + } return List.of(methodDeclaratorRest( pos, mods, null, names.init, typarams, isInterface, true, dc)); @@ -2516,19 +2710,26 @@ return List.of(methodDeclaratorRest( pos, mods, type, name, typarams, isInterface, isVoid, dc)); + } else if (token == ENUM && typarams.isEmpty() && (S.token() == LBRACE || S.token() == IMPLEMENTS)) { + log.error(pos, "enums.not.supported.in.source", source.name); + allowEnums = true; + JCModifiers newMods = + F.at(mods.pos).Modifiers(mods.flags|Flags.ENUM, mods.annotations); + storeEnd(newMods, getEndPos(mods)); + return List.of(enumDeclaration(newMods, dc, pos, name)); } else if (!isVoid && typarams.isEmpty()) { List defs = variableDeclaratorsRest(pos, mods, type, name, isInterface, dc, new ListBuffer()).toList(); - storeEnd(defs.last(), S.endPos()); accept(SEMI); + storeEnd(defs.last(), S.prevEndPos()); return defs; } else { pos = S.pos(); List err = isVoid ? List.of(toP(F.at(pos).MethodDef(mods, name, type, typarams, List.nil(), List.nil(), null, null))) - : null; + : List.nil(); return List.of(syntaxError(S.pos(), err, "expected", keywords.token2string(LPAREN))); } } @@ -2554,6 +2755,9 @@ List typarams, boolean isInterface, boolean isVoid, String dc) { + if (cancelService != null) { + cancelService.abortIfCanceled(); + } List params = formalParameters(); if (!isVoid) type = bracketsOpt(type); List thrown = List.nil(); @@ -2564,7 +2768,13 @@ JCBlock body = null; JCExpression defaultValue; if (S.token() == LBRACE) { - body = block(); + final AnonScope as = this.anonScopes.peek(); + as.localClass=true; + try { + body = block(); + } finally { + as.localClass=false; + } defaultValue = null; } else { if (S.token() == DEFAULT) { @@ -2578,7 +2788,13 @@ // error recovery skip(false, true, false, false); if (S.token() == LBRACE) { - body = block(); + final AnonScope as = this.anonScopes.peek(); + as.localClass=true; + try { + body = block(); + } finally { + as.localClass=false; + } } } } Index: com/sun/tools/javac/parser/Scanner.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/parser/Scanner.java,v retrieving revision 1.2.2.10 retrieving revision 1.17 diff -u -r1.2.2.10 -r1.17 --- com/sun/tools/javac/parser/Scanner.java 15 Aug 2007 10:23:04 -0000 1.2.2.10 +++ com/sun/tools/javac/parser/Scanner.java 17 Aug 2007 13:18:19 -0000 1.17 @@ -146,6 +146,7 @@ private int bp; private int buflen; private int eofPos; + private char replacedCharacter; /** The current character. */ @@ -206,7 +207,7 @@ eofPos = inputLength; if (inputLength == input.length) { if (input.length > 0 && Character.isWhitespace(input[input.length - 1])) { - inputLength--; + replacedCharacter = input[--inputLength]; } else { char[] newInput = new char[inputLength + 1]; System.arraycopy(input, 0, newInput, 0, input.length); @@ -748,6 +749,8 @@ */ public void nextToken() { + if (token == EOF) + return; try { prevEndPos = endPos; sp = 0; @@ -1050,6 +1053,20 @@ return chars; } + /**for DocCommentScanner*/ + protected char[] getVeryRawCharacters() { + if (buf.length == buflen) { + char[] chars = new char[buflen]; + System.arraycopy(buf, 0, chars, 0, buflen); + return chars; + } else { + char[] chars = new char[buflen + 1]; + System.arraycopy(buf, 0, chars, 0, buflen); + chars[buflen] = replacedCharacter; + return chars; + } + } + /** * Returns a copy of a character array subset of the input buffer. * The returned array begins at the beginIndex and @@ -1117,7 +1134,7 @@ * * @return a LineMap */ public Position.LineMap getLineMap() { - return Position.makeLineMap(buf, buflen, false); + return Position.makeLineMap(buf, buflen, replacedCharacter, false); } } Index: com/sun/tools/javac/tree/JCTree.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/tree/JCTree.java,v retrieving revision 1.1.2.10 retrieving revision 1.15 diff -u -r1.1.2.10 -r1.15 --- com/sun/tools/javac/tree/JCTree.java 15 Aug 2007 10:23:10 -0000 1.1.2.10 +++ com/sun/tools/javac/tree/JCTree.java 17 Aug 2007 13:18:18 -0000 1.15 @@ -27,9 +27,7 @@ import java.util.*; -import java.io.File; import java.io.IOException; -import java.io.PrintWriter; import java.io.StringWriter; import javax.lang.model.element.Modifier; import javax.lang.model.type.TypeKind; @@ -566,6 +564,8 @@ public List implementing; public List defs; public ClassSymbol sym; + public int index; + protected JCClassDecl(JCModifiers mods, Name name, List typarams, @@ -581,7 +581,11 @@ this.implementing = implementing; this.defs = defs; this.sym = sym; + this.index = -1; } + + + @Override public void accept(Visitor v) { v.visitClassDef(this); } Index: com/sun/tools/javac/tree/TreeCopier.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/tree/TreeCopier.java,v retrieving revision 1.1.2.2 retrieving revision 1.5 diff -u -r1.1.2.2 -r1.5 --- com/sun/tools/javac/tree/TreeCopier.java 15 Aug 2007 10:23:10 -0000 1.1.2.2 +++ com/sun/tools/javac/tree/TreeCopier.java 17 Aug 2007 13:18:18 -0000 1.5 @@ -30,7 +30,6 @@ import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; -import java.util.Map; /** * Creates a copy of a tree, using a given TreeMaker. @@ -140,7 +139,9 @@ JCTree extending = copy(t.extending, p); List implementing = copy(t.implementing, p); List defs = copy(t.defs, p); - return M.at(t.pos).ClassDef(mods, t.name, typarams, extending, implementing, defs); + JCTree.JCClassDecl classDecl = M.at(t.pos).ClassDef(mods, t.name, typarams, extending, implementing, defs); + classDecl.index = t.index; + return classDecl; } public JCTree visitConditionalExpression(ConditionalExpressionTree node, P p) { Index: com/sun/tools/javac/tree/TreeInfo.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/tree/TreeInfo.java,v retrieving revision 1.2.2.10 retrieving revision 1.25 diff -u -r1.2.2.10 -r1.25 --- com/sun/tools/javac/tree/TreeInfo.java 15 Aug 2007 10:23:10 -0000 1.2.2.10 +++ com/sun/tools/javac/tree/TreeInfo.java 17 Aug 2007 13:18:18 -0000 1.25 @@ -35,7 +35,6 @@ import com.sun.tools.javac.tree.JCTree.*; import static com.sun.tools.javac.code.Flags.*; -import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition; /** Utility class containing inspector methods for trees. * @@ -269,10 +268,17 @@ case(JCTree.MINUS): case(JCTree.MUL): case(JCTree.DIV): case(JCTree.MOD): return getStartPos(((JCBinary) tree).lhs); + case(JCTree.MODIFIERS): { + JCModifiers node = (JCModifiers)tree; + if (node.annotations.nonEmpty()) + return Math.min(node.pos, getStartPos(node.annotations.head)); + return node.pos; + } case(JCTree.CLASSDEF): { JCClassDecl node = (JCClassDecl)tree; - if (node.mods.pos != Position.NOPOS) - return node.mods.pos; + int pos = getStartPos(node.mods); + if (pos != Position.NOPOS) + return pos; break; } case(JCTree.CONDEXPR): @@ -283,8 +289,9 @@ return getStartPos(((JCArrayAccess) tree).indexed); case(JCTree.METHODDEF): { JCMethodDecl node = (JCMethodDecl)tree; - if (node.mods.pos != Position.NOPOS) - return node.mods.pos; + int pos = getStartPos(node.mods); + if (pos != Position.NOPOS) + return pos; if (node.typarams.nonEmpty()) // List.nil() used for no typarams return getStartPos(node.typarams.head); return node.restype == null ? node.pos : getStartPos(node.restype); @@ -302,16 +309,29 @@ return getStartPos(((JCUnary) tree).arg); case(JCTree.VARDEF): { JCVariableDecl node = (JCVariableDecl)tree; - if (node.mods.pos != Position.NOPOS) { - return node.mods.pos; - } else { + int pos = getStartPos(node.mods); + if (pos != Position.NOPOS) { + return pos; + } else if (node.vartype.getTag() == JCTree.IDENT && ((JCIdent)node.vartype).pos == Position.NOPOS) { + return node.pos; + } else { return getStartPos(node.vartype); } } + case(JCTree.NEWCLASS): { + JCNewClass node = (JCNewClass)tree; + if (node.encl != null && node.encl.pos != Position.NOPOS) { + return node.encl.pos; + } + return node.pos; + } case(JCTree.ERRONEOUS): { JCErroneous node = (JCErroneous)tree; - if (node.errs != null && node.errs.nonEmpty()) - return getStartPos(node.errs.head); + for (List l = node.errs; l.nonEmpty(); l = l.tail) { + int pos = getStartPos(node.errs.head); + if (pos != Position.NOPOS) + return pos; + } } } return tree.pos; @@ -397,6 +417,8 @@ return getEndPos(((JCUnary) tree).arg, endPositions); case(JCTree.WHILELOOP): return getEndPos(((JCWhileLoop) tree).body, endPositions); + case(JCTree.ASSIGN): + return getEndPos(((JCAssign) tree).rhs, endPositions); case(JCTree.ERRONEOUS): { JCErroneous node = (JCErroneous)tree; if (node.errs != null && node.errs.nonEmpty()) @@ -476,7 +498,11 @@ if (that.sym == sym) result = that; else super.visitVarDef(that); } - } + public void visitTypeParameter(JCTypeParameter that) { + if (that.type.tsym == sym) result = that; + else super.visitTypeParameter(that); + } + } DeclScanner s = new DeclScanner(); tree.accept(s); return s.result; @@ -597,12 +623,26 @@ public static Symbol symbolFor(JCTree node) { node = skipParens(node); switch (node.getTag()) { + case JCTree.TOPLEVEL: + return ((JCCompilationUnit) node).packge; case JCTree.CLASSDEF: return ((JCClassDecl) node).sym; case JCTree.METHODDEF: return ((JCMethodDecl) node).sym; case JCTree.VARDEF: return ((JCVariableDecl) node).sym; + case JCTree.IDENT: + return ((JCIdent) node).sym; + case JCTree.SELECT: + return ((JCFieldAccess) node).sym; + case JCTree.NEWCLASS: + return ((JCNewClass) node).constructor; + case JCTree.APPLY: + return symbolFor(((JCMethodInvocation) node).meth); + case JCTree.TYPEAPPLY: + return symbolFor(((JCTypeApply) node).clazz); + case JCTree.TYPEPARAMETER: + return ((JCTypeParameter) node).type.tsym; default: return null; } Index: com/sun/tools/javac/tree/TreeMaker.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/tree/TreeMaker.java,v retrieving revision 1.5.2.10 retrieving revision 1.20 diff -u -r1.5.2.10 -r1.20 --- com/sun/tools/javac/tree/TreeMaker.java 15 Aug 2007 10:23:10 -0000 1.5.2.10 +++ com/sun/tools/javac/tree/TreeMaker.java 17 Aug 2007 13:18:18 -0000 1.20 @@ -486,15 +486,18 @@ ****************************************************************************/ public JCClassDecl AnonymousClassDef(JCModifiers mods, - List defs) + List defs, + int index) { - return ClassDef(mods, + final JCTree.JCClassDecl classDecl = ClassDef(mods, names.empty, List.nil(), null, List.nil(), defs); - } + classDecl.index = index; + return classDecl; + } public LetExpr LetExpr(JCVariableDecl def, JCTree expr) { LetExpr tree = new LetExpr(List.of(def), expr); @@ -855,7 +858,8 @@ boolean isUnqualifiable(Symbol sym) { if (sym.name == names.empty || sym.owner == null || - sym.owner.kind == MTH || sym.owner.kind == VAR) { + sym.owner.kind == MTH || sym.owner.kind == VAR + || (sym.owner.kind == PCK && sym.owner.name == names.empty)) { return true; } else if (sym.kind == TYP && toplevel != null) { Scope.Entry e; Index: com/sun/tools/javac/util/CancelAbort.java =================================================================== RCS file: com/sun/tools/javac/util/CancelAbort.java diff -N com/sun/tools/javac/util/CancelAbort.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ com/sun/tools/javac/util/CancelAbort.java 10 May 2007 10:47:58 -0000 1.1 @@ -0,0 +1,12 @@ +package com.sun.tools.javac.util; + +/** + * + * @author Tomas Zezula + */ +public final class CancelAbort extends Abort { + + CancelAbort() { + } + +} Index: com/sun/tools/javac/util/CancelService.java =================================================================== RCS file: com/sun/tools/javac/util/CancelService.java diff -N com/sun/tools/javac/util/CancelService.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ com/sun/tools/javac/util/CancelService.java 10 May 2007 10:47:58 -0000 1.1 @@ -0,0 +1,37 @@ +package com.sun.tools.javac.util; + +/** + * + * @author Tomas Zezula + */ +public class CancelService { + + + /** The context key for the parameter name resolver. */ + protected static final Context.Key cancelServiceKey = + new Context.Key(); + + public static CancelService instance(Context context) { + CancelService instance = context.get(cancelServiceKey); + if (instance == null) { + instance = new CancelService(); + context.put(cancelServiceKey, instance); + } + return instance; + } + + protected CancelService() { + } + + + public boolean isCanceled () { + return false; + } + + public final void abortIfCanceled () { + if (isCanceled()) { + throw new CancelAbort (); + } + } + +} Index: com/sun/tools/javac/util/CouplingAbort.java =================================================================== RCS file: com/sun/tools/javac/util/CouplingAbort.java diff -N com/sun/tools/javac/util/CouplingAbort.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ com/sun/tools/javac/util/CouplingAbort.java 29 Dec 2006 16:36:23 -0000 1.1 @@ -0,0 +1,33 @@ +package com.sun.tools.javac.util; + +import com.sun.source.tree.Tree; +import javax.tools.JavaFileObject; + +/** + * + * @author jlahoda + */ +public class CouplingAbort extends Abort { + + private JavaFileObject classFile; + private Tree t; + + /** Creates a new instance of CouplingAbort */ + public CouplingAbort(JavaFileObject classFile, Tree t) { + this.classFile = classFile; + this.t = t; + + wasCouplingError = true; + } + + public JavaFileObject getClassFile() { + return classFile; + } + + public Tree getTree() { + return t; + } + + public static boolean wasCouplingError; + +} Index: com/sun/tools/javac/util/Name.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/util/Name.java,v retrieving revision 1.2.2.11 retrieving revision 1.15 diff -u -r1.2.2.11 -r1.15 --- com/sun/tools/javac/util/Name.java 15 Aug 2007 10:23:05 -0000 1.2.2.11 +++ com/sun/tools/javac/util/Name.java 17 Aug 2007 13:18:19 -0000 1.15 @@ -25,6 +25,7 @@ package com.sun.tools.javac.util; +import com.sun.tools.javac.model.LazyTreeLoader; import java.lang.ref.SoftReference; @@ -356,13 +357,13 @@ // maintain a freelist of recently used name tables for reuse. private static List> freelist = List.nil(); - static private synchronized Table make() { + static private synchronized Table make(Context context) { while (freelist.nonEmpty()) { Table t = freelist.head.get(); freelist = freelist.tail; if (t != null) return t; } - return new Table(); + return new Table(context); } static private synchronized void dispose(Table t) { @@ -379,11 +380,15 @@ public static Table instance(Context context) { Table instance = context.get(namesKey); if (instance == null) { - instance = make(); + instance = make(context); context.put(namesKey, instance); } return instance; } + + /** The tree loader + */ + public LazyTreeLoader loader; /** The hash table for names. */ @@ -406,7 +411,8 @@ * needs to be a power of two. * @param nameSize the initial size of the name table. */ - public Table(int hashSize, int nameSize) { + public Table(Context context, int hashSize, int nameSize) { + loader = LazyTreeLoader.instance(context); hashMask = hashSize - 1; hashes = new Name[hashSize]; names = new byte[nameSize]; @@ -514,8 +520,8 @@ finalize = fromString("finalize"); } - public Table() { - this(0x8000, 0x20000); + public Table(Context context) { + this(context, 0x8000, 0x20000); } /** Create a name from the bytes in cs[start..start+len-1]. Index: com/sun/tools/javac/util/Position.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javac/util/Position.java,v retrieving revision 1.1.1.1.2.4 retrieving revision 1.7 diff -u -r1.1.1.1.2.4 -r1.7 --- com/sun/tools/javac/util/Position.java 15 Aug 2007 10:23:05 -0000 1.1.1.1.2.4 +++ com/sun/tools/javac/util/Position.java 17 Aug 2007 13:18:19 -0000 1.7 @@ -72,10 +72,10 @@ * @param max Number of characters to read * @param expandTabs If true, expand tabs when calculating columns */ - public static LineMap makeLineMap(char[] src, int max, boolean expandTabs) { + public static LineMap makeLineMap(char[] src, int max, char replacedCharacter, boolean expandTabs) { LineMapImpl lineMap = expandTabs ? - new LineTabMapImpl(max) : new LineMapImpl(); - lineMap.build(src, max); + new LineTabMapImpl(src.length) : new LineMapImpl(); + lineMap.build(src, max, replacedCharacter); return lineMap; } @@ -148,19 +148,20 @@ protected LineMapImpl() {} - protected void build(char[] src, int max) { + protected void build(char[] src, int max, char replacedCharacter) { int c = 0; int i = 0; - int[] linebuf = new int[max]; - while (i < max) { - linebuf[c++] = i; + int[] linebuf = new int[src.length + 1]; + linebuf[c++] = i; + while (i < src.length) { do { - char ch = src[i]; + char ch = i == max ? replacedCharacter : src[i]; if (ch == '\r' || ch == '\n') { - if (ch == '\r' && (i+1) < max && src[i+1] == '\n') + if (ch == '\r' && (i+1) < src.length && (i == max ? replacedCharacter : src[i+1]) == '\n') i += 2; else ++i; + linebuf[c++] = i; break; } else if (ch == '\t') Index: com/sun/tools/javadoc/AnnotationDescImpl.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javadoc/AnnotationDescImpl.java,v retrieving revision 1.1.2.3 retrieving revision 1.5 diff -u -r1.1.2.3 -r1.5 --- com/sun/tools/javadoc/AnnotationDescImpl.java 15 Aug 2007 10:23:04 -0000 1.1.2.3 +++ com/sun/tools/javadoc/AnnotationDescImpl.java 17 Aug 2007 13:18:17 -0000 1.5 @@ -61,7 +61,8 @@ */ public AnnotationTypeDoc annotationType() { ClassSymbol atsym = (ClassSymbol)annotation.type.tsym; - return (AnnotationTypeDoc)env.getClassDoc(atsym); + ClassDocImpl classDoc = env.getClassDoc(atsym); + return classDoc instanceof AnnotationTypeDoc ? (AnnotationTypeDoc)classDoc : null; } /** Index: com/sun/tools/javadoc/AnnotationTypeDocImpl.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javadoc/AnnotationTypeDocImpl.java,v retrieving revision 1.1.2.5 retrieving revision 1.6 diff -u -r1.1.2.5 -r1.6 --- com/sun/tools/javadoc/AnnotationTypeDocImpl.java 15 Aug 2007 10:23:04 -0000 1.1.2.5 +++ com/sun/tools/javadoc/AnnotationTypeDocImpl.java 17 Aug 2007 13:18:17 -0000 1.6 @@ -51,11 +51,11 @@ public class AnnotationTypeDocImpl extends ClassDocImpl implements AnnotationTypeDoc { - AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym) { + public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym) { this(env, sym, null, null, null); } - AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym, + public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym, String doc, JCClassDecl tree, Position.LineMap lineMap) { super(env, sym, doc, tree, lineMap); } Index: com/sun/tools/javadoc/AnnotationTypeElementDocImpl.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javadoc/AnnotationTypeElementDocImpl.java,v retrieving revision 1.1.2.5 retrieving revision 1.6 diff -u -r1.1.2.5 -r1.6 --- com/sun/tools/javadoc/AnnotationTypeElementDocImpl.java 15 Aug 2007 10:23:04 -0000 1.1.2.5 +++ com/sun/tools/javadoc/AnnotationTypeElementDocImpl.java 17 Aug 2007 13:18:17 -0000 1.6 @@ -46,11 +46,11 @@ public class AnnotationTypeElementDocImpl extends MethodDocImpl implements AnnotationTypeElementDoc { - AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym) { + public AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym) { super(env, sym); } - AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym, + public AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym, String doc, JCMethodDecl tree, Position.LineMap lineMap) { super(env, sym, doc, tree, lineMap); } Index: com/sun/tools/javadoc/DocEnv.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javadoc/DocEnv.java,v retrieving revision 1.1.2.6 retrieving revision 1.9 diff -u -r1.1.2.6 -r1.9 --- com/sun/tools/javadoc/DocEnv.java 15 Aug 2007 10:23:04 -0000 1.1.2.6 +++ com/sun/tools/javadoc/DocEnv.java 17 Aug 2007 13:18:17 -0000 1.9 @@ -91,7 +91,7 @@ final Symbol externalizableSym; /** Access filter (public, protected, ...). */ - ModifierFilter showAccess; + protected ModifierFilter showAccess; private ClassDocImpl runtimeException; @@ -110,20 +110,20 @@ boolean docClasses = false; /** Does the doclet only expect pre-1.5 doclet API? */ - boolean legacyDoclet = true; + protected boolean legacyDoclet = true; /** * Set this to true if you would like to not emit any errors, warnings and * notices. */ private boolean silent = false; - + /** * Constructor * * @param context Context for this javadoc instance. */ - private DocEnv(Context context) { + protected DocEnv(Context context) { context.put(docEnvKey, this); messager = Messager.instance0(context); @@ -525,7 +525,7 @@ messager.exit(); } - private Map packageMap = + protected Map packageMap = new HashMap(); /** * Return the PackageDoc of this package symbol. @@ -553,12 +553,12 @@ } - private Map classMap = + protected Map classMap = new HashMap(); /** * Return the ClassDoc (or a subtype) of this class symbol. */ - ClassDocImpl getClassDoc(ClassSymbol clazz) { + public ClassDocImpl getClassDoc(ClassSymbol clazz) { ClassDocImpl result = classMap.get(clazz); if (result != null) return result; if (isAnnotationType(clazz)) { @@ -573,7 +573,7 @@ /** * Create the ClassDoc (or a subtype) for a class symbol. */ - void makeClassDoc(ClassSymbol clazz, String docComment, JCClassDecl tree, Position.LineMap lineMap) { + protected void makeClassDoc(ClassSymbol clazz, String docComment, JCClassDecl tree, Position.LineMap lineMap) { ClassDocImpl result = classMap.get(clazz); if (result != null) { if (docComment != null) result.setRawCommentText(docComment); @@ -588,20 +588,20 @@ classMap.put(clazz, result); } - private static boolean isAnnotationType(ClassSymbol clazz) { + protected static boolean isAnnotationType(ClassSymbol clazz) { return ClassDocImpl.isAnnotationType(clazz); } - private static boolean isAnnotationType(JCClassDecl tree) { + protected static boolean isAnnotationType(JCClassDecl tree) { return (tree.mods.flags & Flags.ANNOTATION) != 0; } - private Map fieldMap = + protected Map fieldMap = new HashMap(); /** * Return the FieldDoc of this var symbol. */ - FieldDocImpl getFieldDoc(VarSymbol var) { + public FieldDocImpl getFieldDoc(VarSymbol var) { FieldDocImpl result = fieldMap.get(var); if (result != null) return result; result = new FieldDocImpl(this, var); @@ -611,7 +611,7 @@ /** * Create a FieldDoc for a var symbol. */ - void makeFieldDoc(VarSymbol var, String docComment, JCVariableDecl tree, Position.LineMap lineMap) { + protected void makeFieldDoc(VarSymbol var, String docComment, JCVariableDecl tree, Position.LineMap lineMap) { FieldDocImpl result = fieldMap.get(var); if (result != null) { if (docComment != null) result.setRawCommentText(docComment); @@ -622,13 +622,13 @@ } } - private Map methodMap = + protected Map methodMap = new HashMap(); /** * Create a MethodDoc for this MethodSymbol. * Should be called only on symbols representing methods. */ - void makeMethodDoc(MethodSymbol meth, String docComment, + protected void makeMethodDoc(MethodSymbol meth, String docComment, JCMethodDecl tree, Position.LineMap lineMap) { MethodDocImpl result = (MethodDocImpl)methodMap.get(meth); if (result != null) { @@ -656,7 +656,7 @@ * Create the ConstructorDoc for a MethodSymbol. * Should be called only on symbols representing constructors. */ - void makeConstructorDoc(MethodSymbol meth, String docComment, + protected void makeConstructorDoc(MethodSymbol meth, String docComment, JCMethodDecl tree, Position.LineMap lineMap) { ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth); if (result != null) { @@ -684,7 +684,7 @@ * Create the AnnotationTypeElementDoc for a MethodSymbol. * Should be called only on symbols representing annotation type elements. */ - void makeAnnotationTypeElementDoc(MethodSymbol meth, + protected void makeAnnotationTypeElementDoc(MethodSymbol meth, String docComment, JCMethodDecl tree, Position.LineMap lineMap) { AnnotationTypeElementDocImpl result = (AnnotationTypeElementDocImpl)methodMap.get(meth); Index: com/sun/tools/javadoc/DocImpl.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javadoc/DocImpl.java,v retrieving revision 1.1.2.4 retrieving revision 1.6 diff -u -r1.1.2.4 -r1.6 --- com/sun/tools/javadoc/DocImpl.java 15 Aug 2007 10:23:04 -0000 1.1.2.4 +++ com/sun/tools/javadoc/DocImpl.java 17 Aug 2007 13:18:17 -0000 1.6 @@ -87,7 +87,7 @@ * So subclasses have the option to do lazy initialization of * "documentation" string. */ - String documentation() { + protected String documentation() { if (documentation == null) documentation = ""; return documentation; } Index: com/sun/tools/javadoc/JavadocClassReader.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javadoc/JavadocClassReader.java,v retrieving revision 1.1.2.5 retrieving revision 1.9 diff -u -r1.1.2.5 -r1.9 --- com/sun/tools/javadoc/JavadocClassReader.java 15 Aug 2007 10:23:04 -0000 1.1.2.5 +++ com/sun/tools/javadoc/JavadocClassReader.java 21 Aug 2007 12:08:13 -0000 1.9 @@ -38,19 +38,19 @@ /** Javadoc uses an extended class reader that records package.html entries * @author Neal Gafter */ -class JavadocClassReader extends ClassReader { +public class JavadocClassReader extends ClassReader { public static JavadocClassReader instance0(Context context) { ClassReader instance = context.get(classReaderKey); if (instance == null) - instance = new JavadocClassReader(context); + instance = new JavadocClassReader(context, true); return (JavadocClassReader)instance; } public static void preRegister(final Context context) { context.put(classReaderKey, new Context.Factory() { public ClassReader make() { - return new JavadocClassReader(context); + return new JavadocClassReader(context, true); } }); } @@ -62,8 +62,10 @@ private EnumSet noSource = EnumSet.of(JavaFileObject.Kind.CLASS, JavaFileObject.Kind.HTML); - private JavadocClassReader(Context context) { + public JavadocClassReader(Context context, boolean loadDocEnv) { super(context, true); + + if (loadDocEnv) docenv = DocEnv.instance(context); } @@ -72,6 +74,9 @@ */ @Override protected EnumSet getPackageFileKinds() { + if (docenv == null) + return super.getPackageFileKinds(); + else return docenv.docClasses ? noSource : all; } @@ -80,8 +85,11 @@ */ @Override protected void extraFileActions(PackageSymbol pack, JavaFileObject fo) { + if (docenv == null) + return ; + CharSequence fileName = Old199.getName(fo); - if (docenv != null && fileName.equals("package.html")) { + if (docenv != null && fileName != null && fileName.equals("package.html")) { if (fo instanceof JavacFileManager.ZipFileObject) { JavacFileManager.ZipFileObject zfo = (JavacFileManager.ZipFileObject) fo; String zipName = zfo.getZipName(); Index: com/sun/tools/javadoc/JavadocMemberEnter.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javadoc/JavadocMemberEnter.java,v retrieving revision 1.1.2.5 retrieving revision 1.6 diff -u -r1.1.2.5 -r1.6 --- com/sun/tools/javadoc/JavadocMemberEnter.java 15 Aug 2007 10:23:04 -0000 1.1.2.5 +++ com/sun/tools/javadoc/JavadocMemberEnter.java 17 Aug 2007 13:18:17 -0000 1.6 @@ -38,7 +38,7 @@ * done by javac. * @author Neal Gafter */ -class JavadocMemberEnter extends MemberEnter { +public class JavadocMemberEnter extends MemberEnter { public static JavadocMemberEnter instance0(Context context) { MemberEnter instance = context.get(memberEnterKey); if (instance == null) Index: com/sun/tools/javadoc/PackageDocImpl.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/com/sun/tools/javadoc/PackageDocImpl.java,v retrieving revision 1.1.2.8 retrieving revision 1.8 diff -u -r1.1.2.8 -r1.8 --- com/sun/tools/javadoc/PackageDocImpl.java 15 Aug 2007 10:23:04 -0000 1.1.2.8 +++ com/sun/tools/javadoc/PackageDocImpl.java 17 Aug 2007 13:18:17 -0000 1.8 @@ -107,7 +107,7 @@ /** * Do lazy initialization of "documentation" string. */ - String documentation() { + protected String documentation() { if (documentation != null) return documentation; if (zipDocPath != null) { try { Index: javax/tools/ToolProvider.java =================================================================== RCS file: /cvs/retouche/retouche/Jsr199/src/javax/tools/ToolProvider.java,v retrieving revision 1.1.2.8 retrieving revision 1.10 diff -u -r1.1.2.8 -r1.10 --- javax/tools/ToolProvider.java 15 Aug 2007 10:23:09 -0000 1.1.2.8 +++ javax/tools/ToolProvider.java 17 Aug 2007 13:18:19 -0000 1.10 @@ -143,7 +143,8 @@ throws MalformedURLException, ClassNotFoundException { try { - return enableAsserts(Class.forName(defaultJavaCompilerName, false, null)); + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + return enableAsserts(Class.forName(defaultJavaCompilerName, false, cl)); } catch (ClassNotFoundException e) { trace(FINE, e); }