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 9 Mar 2005 21:43:04 -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 9 Mar 2005 21:43:04 -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 9 Mar 2005 21:43:04 -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 9 Mar 2005 21:43:04 -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 9 Mar 2005 21:43:04 -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 9 Mar 2005 21:43:04 -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 9 Mar 2005 21:43:04 -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: model/org/eclipse/jdt/internal/compiler/SourceElementParser.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/SourceElementParser.java,v retrieving revision 1.44 diff -u -r1.44 SourceElementParser.java --- model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 7 Mar 2005 14:32:33 -0000 1.44 +++ model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 9 Mar 2005 21:43:05 -0000 @@ -765,6 +765,10 @@ notifySourceElementRequestor(importRef, false); } } else { // instanceof TypeDeclaration + TypeDeclaration typeDeclaration = (TypeDeclaration) node; + if (CharOperation.equals(typeDeclaration.name, TypeConstants.PACKAGE_INFO_NAME)) { + continue; + } notifySourceElementRequestor((TypeDeclaration)node, sourceType == null, null); } }