Index: codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java,v retrieving revision 1.209 diff -u -r1.209 CompletionEngine.java --- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 24 Feb 2005 19:59:21 -0000 1.209 +++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 10 Mar 2005 16:07:36 -0000 @@ -3690,6 +3690,7 @@ SourceTypeBinding sourceType = types[i]; if (sourceType.sourceName == CompletionParser.FAKE_TYPE_NAME) continue; + if (sourceType.sourceName == TypeConstants.PACKAGE_INFO_NAME) continue; if (typeLength > sourceType.sourceName.length) continue; @@ -3850,6 +3851,7 @@ char[] qualifiedSourceTypeName = CharOperation.concatWith(sourceType.compoundName, '.'); if (sourceType.sourceName == CompletionParser.FAKE_TYPE_NAME) continue; + if (sourceType.sourceName == TypeConstants.PACKAGE_INFO_NAME) continue; if (typeLength > qualifiedSourceTypeName.length) continue; if (!(packageBinding == sourceType.getPackage())) continue; if (!CharOperation.prefixEquals(qualifiedName, qualifiedSourceTypeName, false)) continue; Index: codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java,v retrieving revision 1.64 diff -u -r1.64 AssistParser.java --- codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java 24 Feb 2005 19:59:21 -0000 1.64 +++ codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java 10 Mar 2005 16:07:36 -0000 @@ -294,6 +294,24 @@ super.consumeInterfaceHeader(); pushOnElementStack(K_TYPE_DELIMITER); } +protected void consumeInternalCompilationUnit() { + // InternalCompilationUnit ::= PackageDeclaration + // InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports + // InternalCompilationUnit ::= ImportDeclarations ReduceImports +} +protected void consumeInternalCompilationUnitWithTypes() { + // InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports TypeDeclarations + // InternalCompilationUnit ::= PackageDeclaration TypeDeclarations + // InternalCompilationUnit ::= TypeDeclarations + // InternalCompilationUnit ::= ImportDeclarations ReduceImports TypeDeclarations + // consume type declarations + int length; + if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) { + this.compilationUnit.types = new TypeDeclaration[length]; + this.astPtr -= length; + System.arraycopy(this.astStack, this.astPtr + 1, this.compilationUnit.types, 0, length); + } +} protected void consumeMethodBody() { super.consumeMethodBody(); popElement(K_METHOD_DELIMITER); Index: compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java,v retrieving revision 1.37 diff -u -r1.37 ASTNode.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 25 Feb 2005 13:00:36 -0000 1.37 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 10 Mar 2005 16:07:36 -0000 @@ -393,7 +393,9 @@ if (recipient != null) { switch (recipient.kind()) { case Binding.PACKAGE : - // TODO (philippe) need support for package annotations + PackageBinding packageBinding = (PackageBinding) recipient; + if ((packageBinding.tagBits & TagBits.AnnotationResolved) != 0) return; + packageBinding.tagBits |= TagBits.AnnotationResolved; break; case Binding.TYPE : case Binding.GENERIC_TYPE : Index: compiler/org/eclipse/jdt/internal/compiler/ast/Annotation.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Annotation.java,v retrieving revision 1.35 diff -u -r1.35 Annotation.java --- compiler/org/eclipse/jdt/internal/compiler/ast/Annotation.java 23 Feb 2005 02:47:28 -0000 1.35 +++ compiler/org/eclipse/jdt/internal/compiler/ast/Annotation.java 10 Mar 2005 16:07:36 -0000 @@ -237,7 +237,7 @@ // tag bits onto recipient switch (this.recipient.kind()) { case Binding.PACKAGE : - // TODO (philippe) need support for package annotations + ((PackageBinding)this.recipient).tagBits |= tagBits; break; case Binding.TYPE : case Binding.GENERIC_TYPE : Index: compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java,v retrieving revision 1.42 diff -u -r1.42 CompilationUnitDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 9 Mar 2005 14:54:55 -0000 1.42 +++ compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 10 Mar 2005 16:07:36 -0000 @@ -19,9 +19,7 @@ public class CompilationUnitDeclaration extends ASTNode implements ProblemSeverities, ReferenceContext { - - private static final char[] PACKAGE_INFO_FILE_NAME = "package-info.java".toCharArray(); //$NON-NLS-1$ - + public ImportReference currentPackage; public ImportReference[] imports; public TypeDeclaration[] types; @@ -175,6 +173,9 @@ } return; } + if (this.isPackageInfo()) { + types[0].annotations = this.currentPackage.annotations; + } try { if (types != null) { for (int i = 0, count = types.length; i < count; i++) @@ -214,6 +215,12 @@ return (currentPackage == null) && (imports == null) && (types == null); } + public boolean isPackageInfo() { + return CharOperation.equals(this.getMainTypeName(), TypeConstants.PACKAGE_INFO_NAME) + && this.currentPackage != null + && this.currentPackage.annotations != null; + } + public boolean hasErrors() { return this.ignoreFurtherInvestigation; } @@ -269,17 +276,25 @@ } public void resolve() { + int startingTypeIndex = 0; if (this.currentPackage != null) { if (this.currentPackage.annotations != null) { - if (!CharOperation.endsWith(getFileName(), PACKAGE_INFO_FILE_NAME)) { + if (CharOperation.equals(this.getMainTypeName(), TypeConstants.PACKAGE_INFO_NAME)) { + // resolve annotations + final TypeDeclaration syntheticTypeDeclaration = types[0]; + syntheticTypeDeclaration.resolve(this.scope); + resolveAnnotations(syntheticTypeDeclaration.staticInitializerScope, this.currentPackage.annotations, this.scope.fPackage); + // set the synthetic bit + syntheticTypeDeclaration.binding.modifiers |= AccSynthetic; + startingTypeIndex = 1; + } else { scope.problemReporter().invalidFileNameForPackageAnnotations(this.currentPackage.annotations[0]); } - // (TODO) resolve annotations } } try { if (types != null) { - for (int i = 0, count = types.length; i < count; i++) { + for (int i = startingTypeIndex, count = types.length; i < count; i++) { types[i].resolve(scope); } } Index: compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java,v retrieving revision 1.33 diff -u -r1.33 PackageBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java 23 Feb 2005 02:47:30 -0000 1.33 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java 10 Mar 2005 16:07:36 -0000 @@ -15,6 +15,8 @@ import org.eclipse.jdt.internal.compiler.util.HashtableOfType; public class PackageBinding extends Binding implements TypeConstants { + public long tagBits = 0; // See values in the interface TagBits below + public char[][] compoundName; PackageBinding parent; public LookupEnvironment environment; Index: compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java,v retrieving revision 1.35 diff -u -r1.35 TypeConstants.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java 23 Feb 2005 02:47:30 -0000 1.35 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java 10 Mar 2005 16:07:36 -0000 @@ -143,4 +143,7 @@ char[] SYNTHETIC_OUTER_LOCAL_PREFIX = "val$".toCharArray(); //$NON-NLS-1$ char[] SYNTHETIC_ENCLOSING_INSTANCE_PREFIX = "this$".toCharArray(); //$NON-NLS-1$ char[] SYNTHETIC_ACCESS_METHOD_PREFIX = "access$".toCharArray(); //$NON-NLS-1$ + + // synthetic package-info name + public static final char[] PACKAGE_INFO_NAME = "package-info".toCharArray(); //$NON-NLS-1$ } Index: compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java,v retrieving revision 1.287 diff -u -r1.287 Parser.java --- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 2 Mar 2005 00:03:32 -0000 1.287 +++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 10 Mar 2005 16:07:38 -0000 @@ -31,6 +31,7 @@ import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.CompilerModifiers; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeIds; import org.eclipse.jdt.internal.compiler.parser.diagnose.DiagnoseParser; import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; @@ -183,7 +184,7 @@ public JavadocParser javadocParser; // used for recovery protected int lastJavadocEnd; - + static { try{ initTables(); @@ -3483,6 +3484,14 @@ // InternalCompilationUnit ::= PackageDeclaration // InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports // InternalCompilationUnit ::= ImportDeclarations ReduceImports + if (this.compilationUnit.isPackageInfo()) { + this.compilationUnit.types = new TypeDeclaration[1]; + // create a fake interface declaration + TypeDeclaration declaration = new TypeDeclaration(compilationUnit.compilationResult); + declaration.name = TypeConstants.PACKAGE_INFO_NAME; + declaration.modifiers = AccDefault | AccInterface; + this.compilationUnit.types[0] = declaration; + } } protected void consumeInternalCompilationUnitWithTypes() { // InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports TypeDeclarations @@ -3492,8 +3501,20 @@ // consume type declarations int length; if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) { - this.astPtr -= length; - System.arraycopy(this.astStack, this.astPtr + 1, this.compilationUnit.types = new TypeDeclaration[length], 0, length); + if (this.compilationUnit.isPackageInfo()) { + this.compilationUnit.types = new TypeDeclaration[length + 1]; + this.astPtr -= length; + System.arraycopy(this.astStack, this.astPtr + 1, this.compilationUnit.types, 1, length); + // create a fake interface declaration + TypeDeclaration declaration = new TypeDeclaration(compilationUnit.compilationResult); + declaration.name = TypeConstants.PACKAGE_INFO_NAME; + declaration.modifiers = AccDefault | AccInterface; + this.compilationUnit.types[0] = declaration; + } else { + this.compilationUnit.types = new TypeDeclaration[length]; + this.astPtr -= length; + System.arraycopy(this.astStack, this.astPtr + 1, this.compilationUnit.types, 0, length); + } } } protected void consumeInvalidConstructorDeclaration() { Index: dom/org/eclipse/jdt/core/dom/ASTConverter.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java,v retrieving revision 1.196 diff -u -r1.196 ASTConverter.java --- dom/org/eclipse/jdt/core/dom/ASTConverter.java 25 Feb 2005 19:06:32 -0000 1.196 +++ dom/org/eclipse/jdt/core/dom/ASTConverter.java 10 Mar 2005 16:07:38 -0000 @@ -20,6 +20,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.core.compiler.InvalidInputException; import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword; @@ -45,6 +46,7 @@ import org.eclipse.jdt.internal.compiler.env.IGenericType; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.CompilerModifiers; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.compiler.parser.Scanner; import org.eclipse.jdt.internal.compiler.parser.TerminalTokens; @@ -1144,7 +1146,11 @@ if (types != null) { int typesLength = types.length; for (int i = 0; i < typesLength; i++) { - ASTNode type = convert(types[i]); + org.eclipse.jdt.internal.compiler.ast.TypeDeclaration declaration = types[i]; + if (CharOperation.equals(declaration.name, TypeConstants.PACKAGE_INFO_NAME)) { + continue; + } + ASTNode type = convert(declaration); if (type == null) { compilationUnit.setFlags(compilationUnit.getFlags() | ASTNode.MALFORMED); } else { @@ -2203,6 +2209,9 @@ } if (statement instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) { ASTNode result = convert((org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) statement); + if (result == null) { + return createFakeEmptyStatement(statement); + } switch(result.getNodeType()) { case ASTNode.ENUM_DECLARATION: switch(this.ast.apiLevel) { Index: eval/org/eclipse/jdt/internal/eval/CodeSnippetParser.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/CodeSnippetParser.java,v retrieving revision 1.55 diff -u -r1.55 CodeSnippetParser.java --- eval/org/eclipse/jdt/internal/eval/CodeSnippetParser.java 23 Feb 2005 02:47:29 -0000 1.55 +++ eval/org/eclipse/jdt/internal/eval/CodeSnippetParser.java 10 Mar 2005 16:07:39 -0000 @@ -222,6 +222,24 @@ typeDecl.javadoc = this.javadoc; this.javadoc = null; } +protected void consumeInternalCompilationUnit() { + // InternalCompilationUnit ::= PackageDeclaration + // InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports + // InternalCompilationUnit ::= ImportDeclarations ReduceImports +} +protected void consumeInternalCompilationUnitWithTypes() { + // InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports TypeDeclarations + // InternalCompilationUnit ::= PackageDeclaration TypeDeclarations + // InternalCompilationUnit ::= TypeDeclarations + // InternalCompilationUnit ::= ImportDeclarations ReduceImports TypeDeclarations + // consume type declarations + int length; + if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) { + this.compilationUnit.types = new TypeDeclaration[length]; + this.astPtr -= length; + System.arraycopy(this.astStack, this.astPtr + 1, this.compilationUnit.types, 0, length); + } +} protected void consumeLocalVariableDeclarationStatement() { super.consumeLocalVariableDeclarationStatement(); /* recovery */ Index: model/org/eclipse/jdt/internal/compiler/DocumentElementParser.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/DocumentElementParser.java,v retrieving revision 1.12 diff -u -r1.12 DocumentElementParser.java --- model/org/eclipse/jdt/internal/compiler/DocumentElementParser.java 28 Feb 2005 19:45:56 -0000 1.12 +++ model/org/eclipse/jdt/internal/compiler/DocumentElementParser.java 10 Mar 2005 16:07:39 -0000 @@ -712,6 +712,24 @@ typeDecl.javadoc = this.javadoc; this.javadoc = null; } +protected void consumeInternalCompilationUnit() { + // InternalCompilationUnit ::= PackageDeclaration + // InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports + // InternalCompilationUnit ::= ImportDeclarations ReduceImports +} +protected void consumeInternalCompilationUnitWithTypes() { + // InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports TypeDeclarations + // InternalCompilationUnit ::= PackageDeclaration TypeDeclarations + // InternalCompilationUnit ::= TypeDeclarations + // InternalCompilationUnit ::= ImportDeclarations ReduceImports TypeDeclarations + // consume type declarations + int length; + if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) { + this.compilationUnit.types = new TypeDeclaration[length]; + this.astPtr -= length; + System.arraycopy(this.astStack, this.astPtr + 1, this.compilationUnit.types, 0, length); + } +} /* * * INTERNAL USE-ONLY Index: model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java,v retrieving revision 1.11 diff -u -r1.11 CommentRecorderParser.java --- model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java 23 Feb 2005 02:47:31 -0000 1.11 +++ model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java 10 Mar 2005 16:07:39 -0000 @@ -11,6 +11,7 @@ package org.eclipse.jdt.internal.core.util; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.parser.Parser; import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; @@ -112,6 +113,24 @@ super.consumeInterfaceHeader(); } + protected void consumeInternalCompilationUnit() { + // InternalCompilationUnit ::= PackageDeclaration + // InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports + // InternalCompilationUnit ::= ImportDeclarations ReduceImports + } + protected void consumeInternalCompilationUnitWithTypes() { + // InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports TypeDeclarations + // InternalCompilationUnit ::= PackageDeclaration TypeDeclarations + // InternalCompilationUnit ::= TypeDeclarations + // InternalCompilationUnit ::= ImportDeclarations ReduceImports TypeDeclarations + // consume type declarations + int length; + if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) { + this.compilationUnit.types = new TypeDeclaration[length]; + this.astPtr -= length; + System.arraycopy(this.astStack, this.astPtr + 1, this.compilationUnit.types, 0, length); + } + } /** * Insure that start position is always positive. * @see org.eclipse.jdt.internal.compiler.parser.Parser#containsComment(int, int) Index: search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java,v retrieving revision 1.67 diff -u -r1.67 MatchLocatorParser.java --- search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java 23 Feb 2005 02:47:46 -0000 1.67 +++ search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java 10 Mar 2005 16:07:39 -0000 @@ -208,6 +208,24 @@ // this is always a Reference this.patternLocator.match((Reference) this.expressionStack[this.expressionPtr], this.nodeSet); } +protected void consumeInternalCompilationUnit() { + // InternalCompilationUnit ::= PackageDeclaration + // InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports + // InternalCompilationUnit ::= ImportDeclarations ReduceImports +} +protected void consumeInternalCompilationUnitWithTypes() { + // InternalCompilationUnit ::= PackageDeclaration ImportDeclarations ReduceImports TypeDeclarations + // InternalCompilationUnit ::= PackageDeclaration TypeDeclarations + // InternalCompilationUnit ::= TypeDeclarations + // InternalCompilationUnit ::= ImportDeclarations ReduceImports TypeDeclarations + // consume type declarations + int length; + if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) { + this.compilationUnit.types = new TypeDeclaration[length]; + this.astPtr -= length; + System.arraycopy(this.astStack, this.astPtr + 1, this.compilationUnit.types, 0, length); + } +} protected void consumeLocalVariableDeclaration() { super.consumeLocalVariableDeclaration();