### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.builder Index: src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java,v retrieving revision 1.9 diff -u -r1.9 ParticipantBuildTests.java --- src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java 26 Jan 2006 20:08:11 -0000 1.9 +++ src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java 9 Feb 2006 18:32:45 -0000 @@ -368,7 +368,7 @@ ITypeBinding typeBinding = typeDecl.resolveBinding(); if (typeBinding == null) continue; typeBinding = typeBinding.getAnnotations()[0].getAnnotationType(); - IResolvedAnnotation targetValue = typeBinding.getAnnotations()[0]; + IAnnotationBinding targetValue = typeBinding.getAnnotations()[0]; IMethodBinding method = targetValue.getDeclaredMemberValuePairs()[0].getMethodBinding(); if (!"value".equals(method.getName())) problems.add(new ParticipantProblem("method " + method.getName() + " not found", file.getName())); #P org.eclipse.jdt.core Index: dom/org/eclipse/jdt/core/dom/TypeBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java,v retrieving revision 1.112 diff -u -r1.112 TypeBinding.java --- dom/org/eclipse/jdt/core/dom/TypeBinding.java 10 Jan 2006 21:01:06 -0000 1.112 +++ dom/org/eclipse/jdt/core/dom/TypeBinding.java 9 Feb 2006 18:32:55 -0000 @@ -32,7 +32,6 @@ import org.eclipse.jdt.internal.compiler.ast.Wildcard; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.env.IDependent; -import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding; import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.Binding; @@ -75,15 +74,15 @@ this.resolver = resolver; } - public IResolvedAnnotation[] getAnnotations() { - IResolvedAnnotation[] domInstances = ResolvedAnnotation.NoAnnotations; + public IAnnotationBinding[] getAnnotations() { + IAnnotationBinding[] domInstances = AnnotationBinding.NoAnnotations; if (this.binding.isAnnotationType() || this.binding.isClass() || this.binding.isEnum() || this.binding.isInterface()) { org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding refType = (org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) this.binding; - AnnotationBinding[] internalAnnotations = refType.getAnnotations(); + org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] internalAnnotations = refType.getAnnotations(); int length = internalAnnotations == null ? 0 : internalAnnotations.length; if (length > 0) { - domInstances = new ResolvedAnnotation[length]; + domInstances = new AnnotationBinding[length]; for (int i = 0; i < length; i++) domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]); } Index: dom/org/eclipse/jdt/core/dom/MethodBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodBinding.java,v retrieving revision 1.69 diff -u -r1.69 MethodBinding.java --- dom/org/eclipse/jdt/core/dom/MethodBinding.java 1 Feb 2006 19:46:18 -0000 1.69 +++ dom/org/eclipse/jdt/core/dom/MethodBinding.java 9 Feb 2006 18:32:54 -0000 @@ -20,7 +20,6 @@ import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.Signature; import org.eclipse.jdt.core.compiler.CharOperation; -import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; import org.eclipse.jdt.internal.compiler.lookup.MethodVerifier; @@ -102,12 +101,12 @@ return name; } - public IResolvedAnnotation[] getAnnotations() { - AnnotationBinding[] annotations = this.binding.getAnnotations(); + public IAnnotationBinding[] getAnnotations() { + org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] annotations = this.binding.getAnnotations(); int length; if (annotations == null || (length = annotations.length) == 0) - return ResolvedAnnotation.NoAnnotations; - IResolvedAnnotation[] domInstances = new ResolvedAnnotation[length]; + return AnnotationBinding.NoAnnotations; + IAnnotationBinding[] domInstances = new AnnotationBinding[length]; for (int i = 0; i < length; i++) domInstances[i] = this.resolver.getAnnotationInstance(annotations[i]); return domInstances; @@ -123,12 +122,12 @@ return declaringClass; } - public IResolvedAnnotation[] getParameterAnnotations(int index) { - AnnotationBinding[] annotations = this.binding.getParameterAnnotations(index); + public IAnnotationBinding[] getParameterAnnotations(int index) { + org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] annotations = this.binding.getParameterAnnotations(index); int length; if (annotations == null || (length = annotations.length) == 0) - return ResolvedAnnotation.NoAnnotations; - IResolvedAnnotation[] domInstances =new ResolvedAnnotation[length]; + return AnnotationBinding.NoAnnotations; + IAnnotationBinding[] domInstances =new AnnotationBinding[length]; for (int i = 0; i < length; i++) domInstances[i] = this.resolver.getAnnotationInstance(annotations[i]); return domInstances; @@ -166,7 +165,7 @@ public Object getDefaultValue() { if (isAnnotationMember()) - return ResolvedMemberValuePair.buildDOMValue(this.binding.getDefaultValue(), this.resolver); + return MemberValuePairBinding.buildDOMValue(this.binding.getDefaultValue(), this.resolver); return null; } Index: dom/org/eclipse/jdt/core/dom/Annotation.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/Annotation.java,v retrieving revision 1.12 diff -u -r1.12 Annotation.java --- dom/org/eclipse/jdt/core/dom/Annotation.java 10 Jan 2006 21:01:06 -0000 1.12 +++ dom/org/eclipse/jdt/core/dom/Annotation.java 9 Feb 2006 18:32:51 -0000 @@ -175,7 +175,7 @@ * @return the resolved annotation, or null if the annotation cannot be resolved * @since 3.2 */ - public IResolvedAnnotation resolveAnnotation() { + public IAnnotationBinding resolveAnnotationBinding() { return this.ast.getBindingResolver().resolveAnnotation(this); } } Index: dom/org/eclipse/jdt/core/dom/ResolvedDefaultValuePair.java =================================================================== RCS file: dom/org/eclipse/jdt/core/dom/ResolvedDefaultValuePair.java diff -N dom/org/eclipse/jdt/core/dom/ResolvedDefaultValuePair.java --- dom/org/eclipse/jdt/core/dom/ResolvedDefaultValuePair.java 10 Jan 2006 21:01:06 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 BEA Systems, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * tyeung@bea.com - initial API and implementation - *******************************************************************************/ -package org.eclipse.jdt.core.dom; - -import org.eclipse.jdt.core.dom.BindingResolver; -import org.eclipse.jdt.core.dom.IMethodBinding; -import org.eclipse.jdt.core.dom.IResolvedMemberValuePair; - -/** - * Member value pair which compose of default values. - */ -class ResolvedDefaultValuePair implements IResolvedMemberValuePair { - - private org.eclipse.jdt.internal.compiler.lookup.MethodBinding method; - private Object domValue; - private BindingResolver bindingResolver; - -static void appendValue(Object value, StringBuffer buffer) { - if (value instanceof Object[]) { - Object[] values = (Object[]) value; - buffer.append('{'); - for (int i = 0, l = values.length; i < l; i++) { - if (i != 0) - buffer.append(", "); //$NON-NLS-1$ - appendValue(values[i], buffer); - } - buffer.append('}'); - } else if (value instanceof ITypeBinding) { - buffer.append(((ITypeBinding) value).getName()); - buffer.append(".class"); //$NON-NLS-1$ - } else { - buffer.append(value); - } -} - -ResolvedDefaultValuePair(org.eclipse.jdt.internal.compiler.lookup.MethodBinding binding, BindingResolver resolver) { - this.method = binding; - this.domValue = ResolvedMemberValuePair.buildDOMValue(binding.getDefaultValue(), resolver); - this.bindingResolver = resolver; -} - -public String getName() { - return new String(this.method.selector); -} - -public IMethodBinding getMethodBinding() { - return this.bindingResolver.getMethodBinding(this.method); -} - -public Object getValue() { - return this.domValue; -} - -public boolean isDefault() { - return true; -} - -public String toString() { - StringBuffer buffer = new StringBuffer(); - toString(buffer); - return buffer.toString(); -} - -public void toString(StringBuffer buffer) { - buffer.append(getName()); - buffer.append(" = "); //$NON-NLS-1$ - appendValue(getValue(), buffer); -} -} Index: dom/org/eclipse/jdt/core/dom/IResolvedMemberValuePair.java =================================================================== RCS file: dom/org/eclipse/jdt/core/dom/IResolvedMemberValuePair.java diff -N dom/org/eclipse/jdt/core/dom/IResolvedMemberValuePair.java --- dom/org/eclipse/jdt/core/dom/IResolvedMemberValuePair.java 10 Jan 2006 21:01:06 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 BEA Systems, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * tyeung@bea.com - initial API and implementation - *******************************************************************************/ -package org.eclipse.jdt.core.dom; - -/** - * Represents a resolved instance of an annotation's member value pair. - * Resolved annotation are computed along with other bindings; these objects - * correspond to {@link MemberValuePair} nodes. - * - * @since 3.2 - */ -public interface IResolvedMemberValuePair { -/** - * Returns the name of the annotation type member. - * - * @return the name of the member - */ -public String getName(); - -/** - * Returns the method binding corresponding to the named annotation type member. - * - * @return the method binding for the annotation type member - */ -public IMethodBinding getMethodBinding(); - -/** - * Returns the resolved value. Resolved values are represented as follows: - * - * - * @return the resolved value, or null if none exists - */ -public Object getValue(); - -/** - * @return true iff this member value pair's value is the default value. - * Returns false otherwise. - */ -public boolean isDefault(); -} Index: dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java,v retrieving revision 1.140 diff -u -r1.140 DefaultBindingResolver.java --- dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java 10 Jan 2006 21:01:06 -0000 1.140 +++ dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java 9 Feb 2006 18:32:53 -0000 @@ -43,11 +43,11 @@ import org.eclipse.jdt.internal.compiler.ast.ThisReference; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.impl.Constant; -import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; +import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair; import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; @@ -178,7 +178,7 @@ return (ASTNode) this.bindingsToAstNodes.get(binding); } - synchronized ASTNode findDeclaringNode(IResolvedAnnotation instance) { + synchronized ASTNode findDeclaringNode(IAnnotationBinding instance) { if (instance == null) return null; return (ASTNode) this.bindingsToAstNodes.get(instance); @@ -250,6 +250,18 @@ } return null; } + + synchronized IMemberValuePairBinding getMemberValuePairBinding(ElementValuePair valuePair) { + if (valuePair == null) return null; + IMemberValuePairBinding binding = + (IMemberValuePairBinding) this.bindingTables.compilerBindingsToASTBindings.get(valuePair); + if (binding != null) + return binding; + binding = new MemberValuePairBinding(valuePair, this); + this.bindingTables.compilerBindingsToASTBindings.put(valuePair, binding); + return binding; + } + /* * Method declared on BindingResolver. */ @@ -355,13 +367,13 @@ return null; } - synchronized IResolvedAnnotation getAnnotationInstance(AnnotationBinding internalInstance) { + synchronized IAnnotationBinding getAnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding internalInstance) { if (internalInstance == null) return null; - IResolvedAnnotation domInstance = - (IResolvedAnnotation) this.bindingTables.compilerBindingsToASTBindings.get(internalInstance); + IAnnotationBinding domInstance = + (IAnnotationBinding) this.bindingTables.compilerBindingsToASTBindings.get(internalInstance); if (domInstance != null) return domInstance; - domInstance = new ResolvedAnnotation(internalInstance, this); + domInstance = new AnnotationBinding(internalInstance, this); this.bindingTables.compilerBindingsToASTBindings.put(internalInstance, domInstance); return domInstance; } @@ -1550,13 +1562,13 @@ return null; } - synchronized IResolvedAnnotation resolveAnnotation(final Annotation domASTNode) { + synchronized IAnnotationBinding resolveAnnotation(final Annotation domASTNode) { Object oldNode = this.newAstToOldAst.get(domASTNode); if (oldNode instanceof org.eclipse.jdt.internal.compiler.ast.Annotation) { org.eclipse.jdt.internal.compiler.ast.Annotation internalAstNode = (org.eclipse.jdt.internal.compiler.ast.Annotation) oldNode; - IResolvedAnnotation domAnnotation = this.getAnnotationInstance(internalAstNode.getCompilerAnnotation()); + IAnnotationBinding domAnnotation = this.getAnnotationInstance(internalAstNode.getCompilerAnnotation()); if (domAnnotation == null) return null; this.bindingsToAstNodes.put(domAnnotation, domASTNode); Index: dom/org/eclipse/jdt/core/dom/ResolvedMemberValuePair.java =================================================================== RCS file: dom/org/eclipse/jdt/core/dom/ResolvedMemberValuePair.java diff -N dom/org/eclipse/jdt/core/dom/ResolvedMemberValuePair.java --- dom/org/eclipse/jdt/core/dom/ResolvedMemberValuePair.java 25 Jan 2006 14:53:00 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 BEA Systems, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * tyeung@bea.com - initial API and implementation - *******************************************************************************/ -package org.eclipse.jdt.core.dom; - -import org.eclipse.jdt.internal.compiler.impl.Constant; -import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; -import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair; -import org.eclipse.jdt.internal.compiler.lookup.TypeIds; - -/** - * Internal class. - */ -class ResolvedMemberValuePair implements IResolvedMemberValuePair { - static final ResolvedMemberValuePair[] NoPair = new ResolvedMemberValuePair[0]; - private static final Object NoValue = new Object(); - private static final Object[] EmptyArray = new Object[0]; - - private ElementValuePair internalPair; - private Object value = null; - private BindingResolver bindingResolver; - -static Object buildDOMValue(final Object internalObject, BindingResolver resolver) { - if (internalObject == null) - return null; - - if (internalObject instanceof Constant) { - Constant constant = (Constant) internalObject; - switch (constant.typeID()) { - case TypeIds.T_boolean: - return Boolean.valueOf(constant.booleanValue()); - case TypeIds.T_byte: - return new Byte(constant.byteValue()); - case TypeIds.T_char: - return new Character(constant.charValue()); - case TypeIds.T_double: - return new Double(constant.doubleValue()); - case TypeIds.T_float: - return new Float(constant.floatValue()); - case TypeIds.T_int: - return new Integer(constant.intValue()); - case TypeIds.T_long: - return new Long(constant.longValue()); - case TypeIds.T_short: - return new Short(constant.shortValue()); - case TypeIds.T_JavaLangString: - return constant.stringValue(); - } - } else if (internalObject instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) { - return resolver.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) internalObject); - } else if (internalObject instanceof AnnotationBinding) { - return resolver.getAnnotationInstance((AnnotationBinding) internalObject); - } else if (internalObject instanceof org.eclipse.jdt.internal.compiler.lookup.FieldBinding) { - return resolver.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.FieldBinding) internalObject); - } else if (internalObject instanceof Object[]) { - Object[] elements = (Object[]) internalObject; - int length = elements.length; - Object[] values = length == 0 ? EmptyArray : new Object[length]; - for (int i = 0; i < length; i++) - values[i] = buildDOMValue(elements[i], resolver); - return values; - } - throw new IllegalStateException(internalObject.toString()); // should never get here -} - -ResolvedMemberValuePair(ElementValuePair pair, BindingResolver resolver) { - this.internalPair = pair; - this.bindingResolver = resolver; -} - -public IMethodBinding getMethodBinding() { - return this.bindingResolver.getMethodBinding(this.internalPair.getMethodBinding()); -} - -public String getName() { - if (this.internalPair == null) - return null; - final char[] membername = this.internalPair.getName(); - return membername == null ? null : new String(membername); -} - -public Object getValue() { - if (value == null) - init(); - return value == NoValue ? null : this.value; -} - -private void init() { - this.value = buildDOMValue(this.internalPair.getValue(), this.bindingResolver); - if (this.value == null) - this.value = NoValue; -} - -char[] internalName() { - return this.internalPair == null ? null : this.internalPair.getName(); -} - -public boolean isDefault() { - return false; -} - -public String toString() { - StringBuffer buffer = new StringBuffer(); - toString(buffer); - return buffer.toString(); -} - -public void toString(StringBuffer buffer) { - buffer.append(getName()); - buffer.append(" = "); //$NON-NLS-1$ - ResolvedDefaultValuePair.appendValue(getValue(), buffer); -} -} Index: dom/org/eclipse/jdt/core/dom/CompilationUnit.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnit.java,v retrieving revision 1.79 diff -u -r1.79 CompilationUnit.java --- dom/org/eclipse/jdt/core/dom/CompilationUnit.java 10 Jan 2006 21:01:06 -0000 1.79 +++ dom/org/eclipse/jdt/core/dom/CompilationUnit.java 9 Feb 2006 18:32:52 -0000 @@ -298,6 +298,8 @@ *
  • enum constant - an EnumConstantDeclaration
  • *
  • type variable - a TypeParameter
  • *
  • capture binding - none
  • + *
  • annotation binding - an Annotation
  • + *
  • member value pair binding - an MemberValuePair
  • * * For parameterized or raw type bindings, the declaring node is * that of the corresponding generic type. And for parameterized or raw @@ -324,24 +326,6 @@ /** * Finds the corresponding AST node in the given compilation unit from - * which the given resolved annotation originated. Returns null - * if the resolved annotation does not correspond to any node in this compilation unit. - * - * This method always returns null when the resolved annotation - * comes from a different AST. - * - * @param resolvedAnnotation the resolved annotation - * @return the corresponding node where the given resolved annotation is declared, - * or null if the resolved annotation does not correspond to a node in this - * compilation unit or if bindings were not requested when this AST was built - * @since 3.2 - */ - public ASTNode findDeclaringNode(IResolvedAnnotation resolvedAnnotation) { - return this.ast.getBindingResolver().findDeclaringNode(resolvedAnnotation); - } - - /** - * Finds the corresponding AST node in the given compilation unit from * which the binding with the given key originated. Returns * null if the corresponding node cannot be determined. * This method always returns null if bindings were not requested Index: dom/org/eclipse/jdt/core/dom/PackageBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/PackageBinding.java,v retrieving revision 1.29 diff -u -r1.29 PackageBinding.java --- dom/org/eclipse/jdt/core/dom/PackageBinding.java 10 Jan 2006 21:01:06 -0000 1.29 +++ dom/org/eclipse/jdt/core/dom/PackageBinding.java 9 Feb 2006 18:32:54 -0000 @@ -25,7 +25,6 @@ import org.eclipse.jdt.internal.compiler.env.INameEnvironment; import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding; -import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.core.NameLookup; import org.eclipse.jdt.internal.core.SearchableEnvironment; @@ -49,18 +48,18 @@ this.resolver = resolver; } - public IResolvedAnnotation[] getAnnotations() { + public IAnnotationBinding[] getAnnotations() { try { INameEnvironment nameEnvironment = this.binding.environment.nameEnvironment; if (!(nameEnvironment instanceof SearchableEnvironment)) - return ResolvedAnnotation.NoAnnotations; + return AnnotationBinding.NoAnnotations; NameLookup nameLookup = ((SearchableEnvironment) nameEnvironment).nameLookup; if (nameLookup == null) - return ResolvedAnnotation.NoAnnotations; + return AnnotationBinding.NoAnnotations; final String pkgName = getName(); IPackageFragment[] pkgs = nameLookup.findPackageFragments(pkgName, false/*exact match*/); if (pkgs == null) - return ResolvedAnnotation.NoAnnotations; + return AnnotationBinding.NoAnnotations; for (int i = 0, len = pkgs.length; i < len; i++) { int fragType = pkgs[i].getKind(); @@ -80,14 +79,14 @@ if (pkgDecl != null) { List annos = pkgDecl.annotations(); if (annos == null || annos.isEmpty()) - return ResolvedAnnotation.NoAnnotations; - IResolvedAnnotation[] result = new IResolvedAnnotation[annos.size()]; + return AnnotationBinding.NoAnnotations; + IAnnotationBinding[] result = new IAnnotationBinding[annos.size()]; int index=0; for (Iterator it = annos.iterator(); it.hasNext(); index++) { - result[index] = ((Annotation) it.next()).resolveAnnotation(); + result[index] = ((Annotation) it.next()).resolveAnnotationBinding(); // not resolving bindings if (result[index] == null) - return ResolvedAnnotation.NoAnnotations; + return AnnotationBinding.NoAnnotations; } return result; } @@ -99,25 +98,25 @@ if (answer != null && answer.isBinaryType()) { IBinaryType type = answer.getBinaryType(); IBinaryAnnotation[] binaryAnnotations = type.getAnnotations(); - AnnotationBinding[] binaryInstances = + org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] binaryInstances = BinaryTypeBinding.createAnnotations(binaryAnnotations, this.binding.environment); - AnnotationBinding[] allInstances = - AnnotationBinding.addStandardAnnotations(binaryInstances, type.getTagBits(), this.binding.environment); + org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] allInstances = + org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding.addStandardAnnotations(binaryInstances, type.getTagBits(), this.binding.environment); int total = allInstances.length; - IResolvedAnnotation[] domInstances = new ResolvedAnnotation[total]; + IAnnotationBinding[] domInstances = new AnnotationBinding[total]; for (int a = 0; a < total; a++) { domInstances[a] = this.resolver.getAnnotationInstance(allInstances[a]); if (domInstances[a] == null) // not resolving binding - return ResolvedAnnotation.NoAnnotations; + return AnnotationBinding.NoAnnotations; } return domInstances; } } } } catch(JavaModelException e) { - return ResolvedAnnotation.NoAnnotations; + return AnnotationBinding.NoAnnotations; } - return ResolvedAnnotation.NoAnnotations; + return AnnotationBinding.NoAnnotations; } /* Index: dom/org/eclipse/jdt/core/dom/IMethodBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/IMethodBinding.java,v retrieving revision 1.29 diff -u -r1.29 IMethodBinding.java --- dom/org/eclipse/jdt/core/dom/IMethodBinding.java 1 Feb 2006 21:09:34 -0000 1.29 +++ dom/org/eclipse/jdt/core/dom/IMethodBinding.java 9 Feb 2006 18:32:54 -0000 @@ -93,13 +93,13 @@ * is not the binding for an annotation type member. *

    * Resolved values are represented as follows (same as for - * {@link IResolvedMemberValuePair#getValue()}): + * {@link IMemberValuePairBinding#getValue()}): *

    @@ -122,7 +122,7 @@ * not a valid index * @since 3.2 */ - public IResolvedAnnotation[] getParameterAnnotations(int paramIndex); + public IAnnotationBinding[] getParameterAnnotations(int paramIndex); /** * Returns a list of type bindings representing the formal parameter types, Index: dom/org/eclipse/jdt/core/dom/BindingResolver.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/BindingResolver.java,v retrieving revision 1.40 diff -u -r1.40 BindingResolver.java --- dom/org/eclipse/jdt/core/dom/BindingResolver.java 10 Jan 2006 21:01:06 -0000 1.40 +++ dom/org/eclipse/jdt/core/dom/BindingResolver.java 9 Feb 2006 18:32:51 -0000 @@ -11,9 +11,9 @@ package org.eclipse.jdt.core.dom; -import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; +import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair; import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; /** @@ -105,7 +105,7 @@ * @return the corresponding node where the bindings is declared, * or null if none */ - ASTNode findDeclaringNode(IResolvedAnnotation instance) { + ASTNode findDeclaringNode(IAnnotationBinding instance) { return null; } @@ -137,6 +137,20 @@ IMethodBinding getMethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding) { return null; } + + /** + * Returns the new member value pair binding corresponding to the given old value pair binding. + *

    + * The default implementation of this method returns null. + * Subclasses may reimplement. + *

    + * + * @param valuePair the old value pair binding + * @return the new member value pair binding + */ + IMemberValuePairBinding getMemberValuePairBinding(ElementValuePair valuePair) { + return null; + } /** * Returns the new package binding corresponding to the given old package binding. @@ -190,7 +204,7 @@ * @param instance the old annotation * @return the new DOM annotation */ - IResolvedAnnotation getAnnotationInstance(AnnotationBinding instance) { + IAnnotationBinding getAnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding instance) { return null; } @@ -818,7 +832,7 @@ /** * Resolves the given annotation instance and returns the DOM representation for it. *

    - * The implementation of {@link Annotation#resolveAnnotation()} + * The implementation of {@link Annotation#resolveAnnotationBinding()} * forwards to this method. *

    *

    @@ -830,7 +844,7 @@ * @return the DOM annotation representation for the given ast node, or * null if none is available */ - IResolvedAnnotation resolveAnnotation(Annotation annotation) { + IAnnotationBinding resolveAnnotation(Annotation annotation) { return null; } Index: dom/org/eclipse/jdt/core/dom/ResolvedAnnotation.java =================================================================== RCS file: dom/org/eclipse/jdt/core/dom/ResolvedAnnotation.java diff -N dom/org/eclipse/jdt/core/dom/ResolvedAnnotation.java --- dom/org/eclipse/jdt/core/dom/ResolvedAnnotation.java 16 Jan 2006 20:52:23 -0000 1.3 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 BEA Systems, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * tyeung@bea.com - initial API and implementation - *******************************************************************************/ -package org.eclipse.jdt.core.dom; - -import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; -import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair; -import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; -import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; -import org.eclipse.jdt.internal.compiler.util.*; - -/** - * Internal class - */ -class ResolvedAnnotation implements IResolvedAnnotation { - static final ResolvedAnnotation[] NoAnnotations = new ResolvedAnnotation[0]; - private AnnotationBinding internalAnnotation; - private BindingResolver bindingResolver; - - ResolvedAnnotation(AnnotationBinding annotation, BindingResolver resolver) { - if (annotation == null) - throw new IllegalStateException(); - internalAnnotation = annotation; - bindingResolver = resolver; - } - - public ITypeBinding getAnnotationType() { - ITypeBinding binding = this.bindingResolver.getTypeBinding(this.internalAnnotation.getAnnotationType()); - if (binding == null || !binding.isAnnotation()) - return null; - return binding; - } - - public IResolvedMemberValuePair[] getDeclaredMemberValuePairs() { - ElementValuePair[] internalPairs = this.internalAnnotation.getElementValuePairs(); - int length = internalPairs.length; - IResolvedMemberValuePair[] pairs = length == 0 ? ResolvedMemberValuePair.NoPair : new ResolvedMemberValuePair[length]; - for (int i = 0; i < length; i++) - pairs[i] = new ResolvedMemberValuePair(internalPairs[i], this.bindingResolver); - return pairs; - } - - public IResolvedMemberValuePair[] getAllMemberValuePairs() { - IResolvedMemberValuePair[] pairs = getDeclaredMemberValuePairs(); - ReferenceBinding typeBinding = this.internalAnnotation.getAnnotationType(); - if (typeBinding == null) return pairs; - MethodBinding[] methods = typeBinding.methods(); - int methodLength = methods == null ? 0 : methods.length; - if (methodLength == 0) return pairs; - - int declaredLength = pairs.length; - if (declaredLength == methodLength) - return pairs; - - HashtableOfObject table = new HashtableOfObject(declaredLength); - for (int i = 0; i < declaredLength; i++) - table.put(((ResolvedMemberValuePair) pairs[i]).internalName(), pairs[i]); - - // handle case of more methods than declared members - IResolvedMemberValuePair[] allPairs = new IResolvedMemberValuePair[methodLength]; - for (int i = 0; i < methodLength; i++) { - Object pair = table.get(methods[i].selector); - allPairs[i] = pair == null ? new ResolvedDefaultValuePair(methods[i], this.bindingResolver) : (IResolvedMemberValuePair) pair; - } - return allPairs; - } - - public String toString() { - ITypeBinding type = getAnnotationType(); - final StringBuffer buffer = new StringBuffer(); - buffer.append('@'); - if (type != null) - buffer.append(type.getName()); - buffer.append('('); - IResolvedMemberValuePair[] pairs = getDeclaredMemberValuePairs(); - for (int i = 0, len = pairs.length; i < len; i++) { - if (i != 0) - buffer.append(", "); //$NON-NLS-1$ - buffer.append(pairs[i].toString()); - } - buffer.append(')'); - return buffer.toString(); - } -} Index: dom/org/eclipse/jdt/core/dom/IBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/IBinding.java,v retrieving revision 1.26 diff -u -r1.26 IBinding.java --- dom/org/eclipse/jdt/core/dom/IBinding.java 8 Feb 2006 11:10:51 -0000 1.26 +++ dom/org/eclipse/jdt/core/dom/IBinding.java 9 Feb 2006 18:32:54 -0000 @@ -68,6 +68,26 @@ public static final int METHOD = 4; /** + * Kind constant (value 5) indicating an annotation binding. + * Bindings of this kind can be safely cast to IAnnotationBinding. + * + * @see #getKind() + * @see IAnnotationBinding + * @since 3.2 + */ + public static final int ANNOTATION = 5; + + /** + * Kind constant (value 6) indicating a member value pair binding. + * Bindings of this kind can be safely cast to IMemberValuePairBinding. + * + * @see #getKind() + * @see IMemberValuePairBinding + * @since 3.2 + */ + public static final int MEMBER_VALUE_PAIR = 6; + + /** * Return the resolved annotations associated with this binding. *

    * * @return the list of resolved annotations, or the empty list if there are no * annotations associated with the object * @since 3.2 */ - public IResolvedAnnotation[] getAnnotations(); + public IAnnotationBinding[] getAnnotations(); /** - * Returns the kind of bindings this is. - * - * @return one of the kind constants: - * PACKAGE, + * Returns the kind of bindings this is. That is one of the kind constants: + * PACKAGE, * TYPE, * VARIABLE, - * or METHOD. + * METHOD, + * ANNOTATION, + * or MEMBER_VALUE_PAIR. + *

    + * Note that additional kinds might be added in the + * future, so clients should not assume this list is exhaustive and + * should program defensively, e.g. by having a reasonable default + * in a switch statement. + *

    + * @return one of the kind constants */ public int getKind(); @@ -166,8 +195,9 @@ *
  • the "length" field of an array type
  • *
  • the default constructor of a source class
  • *
  • the constructor of an anonymous class
  • + *
  • member value pairs
  • * - * For all other kind of type, method, variable, and package bindings, + * For all other kind of type, method, variable, annotation and package bindings, * this method returns non-null. *

    * @@ -231,6 +261,9 @@ * type * *

    + *

    Note that the key for annotation bindings and member value pair bindings is + * not yet implemented. This returns null for these 2 kinds of bindings. + *

    * * @return the key for this binding */ Index: dom/org/eclipse/jdt/core/dom/VariableBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableBinding.java,v retrieving revision 1.49 diff -u -r1.49 VariableBinding.java --- dom/org/eclipse/jdt/core/dom/VariableBinding.java 30 Jan 2006 19:01:13 -0000 1.49 +++ dom/org/eclipse/jdt/core/dom/VariableBinding.java 9 Feb 2006 18:32:56 -0000 @@ -16,7 +16,6 @@ import org.eclipse.jdt.core.util.IModifierConstants; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.Constant; -import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; import org.eclipse.jdt.internal.compiler.lookup.TagBits; import org.eclipse.jdt.internal.compiler.lookup.TypeIds; @@ -43,12 +42,12 @@ this.binding = binding; } - public IResolvedAnnotation[] getAnnotations() { - AnnotationBinding[] internalAnnotations = this.binding.getAnnotations(); + public IAnnotationBinding[] getAnnotations() { + org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] internalAnnotations = this.binding.getAnnotations(); // the variable is not an enum constant nor a field nor an argument. int length = internalAnnotations == null ? 0 : internalAnnotations.length; - IResolvedAnnotation[] domInstances = - length == 0 ? ResolvedAnnotation.NoAnnotations : new ResolvedAnnotation[length]; + IAnnotationBinding[] domInstances = + length == 0 ? AnnotationBinding.NoAnnotations : new AnnotationBinding[length]; for (int i = 0; i < length; i++) domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]); return domInstances; Index: dom/org/eclipse/jdt/core/dom/ASTConverter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java,v retrieving revision 1.229 diff -u -r1.229 ASTConverter.java --- dom/org/eclipse/jdt/core/dom/ASTConverter.java 8 Feb 2006 12:51:13 -0000 1.229 +++ dom/org/eclipse/jdt/core/dom/ASTConverter.java 9 Feb 2006 18:32:50 -0000 @@ -2025,7 +2025,7 @@ markerAnnotation.setSourceRange(start, end - start + 1); if (this.resolveBindings) { recordNodes(markerAnnotation, annotation); - markerAnnotation.resolveAnnotation(); + markerAnnotation.resolveAnnotationBinding(); } return markerAnnotation; } @@ -2088,7 +2088,7 @@ normalAnnotation.setSourceRange(start, end - start + 1); if (this.resolveBindings) { recordNodes(normalAnnotation, annotation); - normalAnnotation.resolveAnnotation(); + normalAnnotation.resolveAnnotationBinding(); } return normalAnnotation; } @@ -2328,7 +2328,7 @@ singleMemberAnnotation.setSourceRange(start, end - start + 1); if (this.resolveBindings) { recordNodes(singleMemberAnnotation, annotation); - singleMemberAnnotation.resolveAnnotation(); + singleMemberAnnotation.resolveAnnotationBinding(); } return singleMemberAnnotation; } Index: dom/org/eclipse/jdt/core/dom/IResolvedAnnotation.java =================================================================== RCS file: dom/org/eclipse/jdt/core/dom/IResolvedAnnotation.java diff -N dom/org/eclipse/jdt/core/dom/IResolvedAnnotation.java --- dom/org/eclipse/jdt/core/dom/IResolvedAnnotation.java 10 Jan 2006 21:01:06 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 BEA Systems, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * tyeung@bea.com - initial API and implementation - *******************************************************************************/ -package org.eclipse.jdt.core.dom; - -/** - * Represents an resolved annotation. Resolved annotation are computed along with other - * bindings; they correspond to {@link Annotation} nodes. - * - * @since 3.2 - */ -public interface IResolvedAnnotation { -/** - * Returns the type of the annotation. The resulting type binding will always - * return true to ITypeBinding.isAnnotation(). - * - * @return the type of the annotation - */ -ITypeBinding getAnnotationType(); - -/** - * Returns the list of declared member value pairs for this annotation. - * Returns an empty list for a MarkerAnnotation, a one element - * list for a SingleMemberAnnotation, and one entry for each - * of the explicitly listed values in a NormalAnnotation. - *

    - * Note that the list only includes entries for annotation type members that are - * explicitly mentioned in the annotation. The list does not include any - * annotation type members with default values that are merely implied. - * Use {@link #getAllMemberValuePairs()} to get those as well. - *

    - * - * @return a possibly empty list of resolved member value pairs - */ -IResolvedMemberValuePair[] getDeclaredMemberValuePairs(); - -/** - * Returns the complete list of member value pairs for this annotation, including - * ones explicitly listed in the annotation as well as entries for - * annotation type members with default values that are implied. - * - * @return a possibly empty list of resolved member value pairs - */ -IResolvedMemberValuePair[] getAllMemberValuePairs(); -} Index: dom/org/eclipse/jdt/core/dom/IAnnotationBinding.java =================================================================== RCS file: dom/org/eclipse/jdt/core/dom/IAnnotationBinding.java diff -N dom/org/eclipse/jdt/core/dom/IAnnotationBinding.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dom/org/eclipse/jdt/core/dom/IAnnotationBinding.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2005 BEA Systems, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * tyeung@bea.com - initial API and implementation + * IBM Corporation - changed interface to extend IBinding + * IBM Corporation - renamed from IResolvedAnnotation to IAnnotationBinding + *******************************************************************************/ +package org.eclipse.jdt.core.dom; + +/** + * Represents an resolved annotation. Resolved annotation are computed along with other + * bindings; they correspond to {@link Annotation} nodes. + *

    + * This interface is not intended to be implemented by clients. + *

    + * + * @since 3.2 + */ +public interface IAnnotationBinding extends IBinding { + + /** + * Returns the complete list of member value pairs for this annotation, including + * ones explicitly listed in the annotation as well as entries for + * annotation type members with default values that are implied. + * + * @return a possibly empty list of resolved member value pairs + */ + IMemberValuePairBinding[] getAllMemberValuePairs(); + + /** + * Returns the type of the annotation. The resulting type binding will always + * return true to ITypeBinding.isAnnotation(). + * + * @return the type of the annotation + */ + ITypeBinding getAnnotationType(); + + /** + * Returns the list of declared member value pairs for this annotation. + * Returns an empty list for a MarkerAnnotation, a one element + * list for a SingleMemberAnnotation, and one entry for each + * of the explicitly listed values in a NormalAnnotation. + *

    + * Note that the list only includes entries for annotation type members that are + * explicitly mentioned in the annotation. The list does not include any + * annotation type members with default values that are merely implied. + * Use {@link #getAllMemberValuePairs()} to get those as well. + *

    + * + * @return a possibly empty list of resolved member value pairs + */ + IMemberValuePairBinding[] getDeclaredMemberValuePairs(); + + /** + * Returns the name of the annotation type. + * + * @return the name of the annotation type + */ + public String getName(); + +} Index: dom/org/eclipse/jdt/core/dom/IMemberValuePairBinding.java =================================================================== RCS file: dom/org/eclipse/jdt/core/dom/IMemberValuePairBinding.java diff -N dom/org/eclipse/jdt/core/dom/IMemberValuePairBinding.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dom/org/eclipse/jdt/core/dom/IMemberValuePairBinding.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2005 BEA Systems, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * tyeung@bea.com - initial API and implementation + * IBM Corporation - changed interface to extend IBinding + * IBM Corporation - renamed from IResolvedMemberValuePair to IMemberValuePairBinding + *******************************************************************************/ +package org.eclipse.jdt.core.dom; + +/** + * Represents a resolved instance of an annotation's member value pair. + * Resolved annotation are computed along with other bindings; these objects + * correspond to {@link MemberValuePair} nodes. + *

    + * This interface is not intended to be implemented by clients. + *

    + * + * @since 3.2 + */ +public interface IMemberValuePairBinding extends IBinding { +/** + * Returns the name of the annotation type member. + * + * @return the name of the member + */ +public String getName(); + +/** + * Returns the method binding corresponding to the named annotation type member. + * + * @return the method binding for the annotation type member + */ +public IMethodBinding getMethodBinding(); + +/** + * Returns the resolved value. Resolved values are represented as follows: + * + * + * @return the resolved value, or null if none exists + */ +public Object getValue(); + +/** + * @return true iff this member value pair's value is the default value. + * Returns false otherwise. + */ +public boolean isDefault(); +} Index: dom/org/eclipse/jdt/core/dom/DefaultValuePairBinding.java =================================================================== RCS file: dom/org/eclipse/jdt/core/dom/DefaultValuePairBinding.java diff -N dom/org/eclipse/jdt/core/dom/DefaultValuePairBinding.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dom/org/eclipse/jdt/core/dom/DefaultValuePairBinding.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2005 BEA Systems, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * tyeung@bea.com - initial API and implementation + * IBM Corporation - implemented methods from IBinding + * IBM Corporation - renamed from ResolvedDefaultValuePair to DefaultValuePairBinding + *******************************************************************************/ +package org.eclipse.jdt.core.dom; + +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.dom.BindingResolver; +import org.eclipse.jdt.core.dom.IMethodBinding; +import org.eclipse.jdt.core.dom.IMemberValuePairBinding; + +/** + * Member value pair which compose of default values. + */ +class DefaultValuePairBinding implements IMemberValuePairBinding { + + private org.eclipse.jdt.internal.compiler.lookup.MethodBinding method; + private Object domValue; + private BindingResolver bindingResolver; + + static void appendValue(Object value, StringBuffer buffer) { + if (value instanceof Object[]) { + Object[] values = (Object[]) value; + buffer.append('{'); + for (int i = 0, l = values.length; i < l; i++) { + if (i != 0) + buffer.append(", "); //$NON-NLS-1$ + appendValue(values[i], buffer); + } + buffer.append('}'); + } else if (value instanceof ITypeBinding) { + buffer.append(((ITypeBinding) value).getName()); + buffer.append(".class"); //$NON-NLS-1$ + } else { + buffer.append(value); + } + } + + DefaultValuePairBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding binding, BindingResolver resolver) { + this.method = binding; + this.domValue = MemberValuePairBinding.buildDOMValue(binding.getDefaultValue(), resolver); + this.bindingResolver = resolver; + } + + public IAnnotationBinding[] getAnnotations() { + return AnnotationBinding.NoAnnotations; + } + + public IJavaElement getJavaElement() { + return null; + } + + public String getKey() { + // TODO when implementing, update spec in IBinding + return null; + } + + public int getKind() { + return IBinding.MEMBER_VALUE_PAIR; + } + + public IMethodBinding getMethodBinding() { + return this.bindingResolver.getMethodBinding(this.method); + } + + public int getModifiers() { + return -1; + } + + public String getName() { + return new String(this.method.selector); + } + + public Object getValue() { + return this.domValue; + } + + public boolean isDefault() { + return true; + } + + public boolean isDeprecated() { + return false; + } + + public boolean isEqualTo(IBinding binding) { + if (this == binding) + return true; + if (binding.getKind() != IBinding.MEMBER_VALUE_PAIR) + return false; + IMemberValuePairBinding other = (IMemberValuePairBinding) binding; + if (!getMethodBinding().isEqualTo(other.getMethodBinding())) + return false; + Object value = getValue(); + if (value == null) + return other.getValue() == null; + return value.equals(other.getValue()); + } + + public boolean isSynthetic() { + return false; + } + + public String toString() { + StringBuffer buffer = new StringBuffer(); + toString(buffer); + return buffer.toString(); + } + + public void toString(StringBuffer buffer) { + buffer.append(getName()); + buffer.append(" = "); //$NON-NLS-1$ + appendValue(getValue(), buffer); + } +} Index: dom/org/eclipse/jdt/core/dom/AnnotationBinding.java =================================================================== RCS file: dom/org/eclipse/jdt/core/dom/AnnotationBinding.java diff -N dom/org/eclipse/jdt/core/dom/AnnotationBinding.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dom/org/eclipse/jdt/core/dom/AnnotationBinding.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,153 @@ +/******************************************************************************* + * Copyright (c) 2005 BEA Systems, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * tyeung@bea.com - initial API and implementation + * IBM Corporation - implemented methods from IBinding + * IBM Corporation - renamed from ResolvedAnnotation to AnnotationBinding + *******************************************************************************/ +package org.eclipse.jdt.core.dom; + +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair; +import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; +import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; +import org.eclipse.jdt.internal.compiler.util.*; + +/** + * Internal class + */ +class AnnotationBinding implements IAnnotationBinding { + static final AnnotationBinding[] NoAnnotations = new AnnotationBinding[0]; + private org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding internalAnnotation; + private BindingResolver bindingResolver; + + AnnotationBinding(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding annotation, BindingResolver resolver) { + if (annotation == null) + throw new IllegalStateException(); + internalAnnotation = annotation; + bindingResolver = resolver; + } + + public IAnnotationBinding[] getAnnotations() { + return NoAnnotations; + } + + public ITypeBinding getAnnotationType() { + ITypeBinding binding = this.bindingResolver.getTypeBinding(this.internalAnnotation.getAnnotationType()); + if (binding == null || !binding.isAnnotation()) + return null; + return binding; + } + + public IMemberValuePairBinding[] getDeclaredMemberValuePairs() { + ElementValuePair[] internalPairs = this.internalAnnotation.getElementValuePairs(); + int length = internalPairs.length; + IMemberValuePairBinding[] pairs = length == 0 ? MemberValuePairBinding.NoPair : new MemberValuePairBinding[length]; + for (int i = 0; i < length; i++) + pairs[i] = this.bindingResolver.getMemberValuePairBinding(internalPairs[i]); + return pairs; + } + + public IMemberValuePairBinding[] getAllMemberValuePairs() { + IMemberValuePairBinding[] pairs = getDeclaredMemberValuePairs(); + ReferenceBinding typeBinding = this.internalAnnotation.getAnnotationType(); + if (typeBinding == null) return pairs; + MethodBinding[] methods = typeBinding.methods(); + int methodLength = methods == null ? 0 : methods.length; + if (methodLength == 0) return pairs; + + int declaredLength = pairs.length; + if (declaredLength == methodLength) + return pairs; + + HashtableOfObject table = new HashtableOfObject(declaredLength); + for (int i = 0; i < declaredLength; i++) + table.put(((MemberValuePairBinding) pairs[i]).internalName(), pairs[i]); + + // handle case of more methods than declared members + IMemberValuePairBinding[] allPairs = new IMemberValuePairBinding[methodLength]; + for (int i = 0; i < methodLength; i++) { + Object pair = table.get(methods[i].selector); + allPairs[i] = pair == null ? new DefaultValuePairBinding(methods[i], this.bindingResolver) : (IMemberValuePairBinding) pair; + } + return allPairs; + } + + public IJavaElement getJavaElement() { + ITypeBinding annotationType = getAnnotationType(); + if (annotationType == null) + return null; + return annotationType.getJavaElement(); + } + + public String getKey() { + // TODO when implementing, update spec in IBinding + return null; + } + + public int getKind() { + return IBinding.ANNOTATION; + } + + public int getModifiers() { + return -1; + } + + public String getName() { + ITypeBinding annotationType = getAnnotationType(); + if (annotationType == null) + return new String(this.internalAnnotation.getAnnotationType().sourceName()); + else + return annotationType.getName(); + } + + public boolean isDeprecated() { + return false; + } + + public boolean isEqualTo(IBinding binding) { + if (this == binding) + return true; + if (binding.getKind() != IBinding.ANNOTATION) + return false; + IAnnotationBinding other = (IAnnotationBinding) binding; + if (!getAnnotationType().isEqualTo(other.getAnnotationType())) + return false; + IMemberValuePairBinding[] memberValuePairs = getDeclaredMemberValuePairs(); + IMemberValuePairBinding[] otherMemberValuePairs = other.getDeclaredMemberValuePairs(); + if (memberValuePairs.length != otherMemberValuePairs.length) + return false; + for (int i = 0, length = memberValuePairs.length; i < length; i++) { + if (!memberValuePairs[i].isEqualTo(otherMemberValuePairs[i])) + return false; + } + return true; + } + + public boolean isSynthetic() { + return false; + } + + public String toString() { + ITypeBinding type = getAnnotationType(); + final StringBuffer buffer = new StringBuffer(); + buffer.append('@'); + if (type != null) + buffer.append(type.getName()); + buffer.append('('); + IMemberValuePairBinding[] pairs = getDeclaredMemberValuePairs(); + for (int i = 0, len = pairs.length; i < len; i++) { + if (i != 0) + buffer.append(", "); //$NON-NLS-1$ + buffer.append(pairs[i].toString()); + } + buffer.append(')'); + return buffer.toString(); + } + +} Index: dom/org/eclipse/jdt/core/dom/MemberValuePairBinding.java =================================================================== RCS file: dom/org/eclipse/jdt/core/dom/MemberValuePairBinding.java diff -N dom/org/eclipse/jdt/core/dom/MemberValuePairBinding.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dom/org/eclipse/jdt/core/dom/MemberValuePairBinding.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,164 @@ +/******************************************************************************* + * Copyright (c) 2005 BEA Systems, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * tyeung@bea.com - initial API and implementation + * IBM Corporation - implemented methods from IBinding + * IBM Corporation - renamed from ResolvedMemberValuePair to MemberValuePairBinding + *******************************************************************************/ +package org.eclipse.jdt.core.dom; + +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.internal.compiler.impl.Constant; +import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair; +import org.eclipse.jdt.internal.compiler.lookup.TypeIds; + +/** + * Internal class. + */ +class MemberValuePairBinding implements IMemberValuePairBinding { + static final MemberValuePairBinding[] NoPair = new MemberValuePairBinding[0]; + private static final Object NoValue = new Object(); + private static final Object[] EmptyArray = new Object[0]; + + private ElementValuePair internalPair; + private Object value = null; + private BindingResolver bindingResolver; + + static Object buildDOMValue(final Object internalObject, BindingResolver resolver) { + if (internalObject == null) + return null; + + if (internalObject instanceof Constant) { + Constant constant = (Constant) internalObject; + switch (constant.typeID()) { + case TypeIds.T_boolean: + return Boolean.valueOf(constant.booleanValue()); + case TypeIds.T_byte: + return new Byte(constant.byteValue()); + case TypeIds.T_char: + return new Character(constant.charValue()); + case TypeIds.T_double: + return new Double(constant.doubleValue()); + case TypeIds.T_float: + return new Float(constant.floatValue()); + case TypeIds.T_int: + return new Integer(constant.intValue()); + case TypeIds.T_long: + return new Long(constant.longValue()); + case TypeIds.T_short: + return new Short(constant.shortValue()); + case TypeIds.T_JavaLangString: + return constant.stringValue(); + } + } else if (internalObject instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) { + return resolver.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) internalObject); + } else if (internalObject instanceof org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding) { + return resolver.getAnnotationInstance((org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding) internalObject); + } else if (internalObject instanceof org.eclipse.jdt.internal.compiler.lookup.FieldBinding) { + return resolver.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.FieldBinding) internalObject); + } else if (internalObject instanceof Object[]) { + Object[] elements = (Object[]) internalObject; + int length = elements.length; + Object[] values = length == 0 ? EmptyArray : new Object[length]; + for (int i = 0; i < length; i++) + values[i] = buildDOMValue(elements[i], resolver); + return values; + } + throw new IllegalStateException(internalObject.toString()); // should never get here + } + + MemberValuePairBinding(ElementValuePair pair, BindingResolver resolver) { + this.internalPair = pair; + this.bindingResolver = resolver; + } + + public IAnnotationBinding[] getAnnotations() { + return AnnotationBinding.NoAnnotations; + } + + public IJavaElement getJavaElement() { + return null; + } + + public String getKey() { + // TODO when implementing, update spec in IBinding + return null; + } + + public int getKind() { + return IBinding.MEMBER_VALUE_PAIR; + } + + public IMethodBinding getMethodBinding() { + return this.bindingResolver.getMethodBinding(this.internalPair.getMethodBinding()); + } + + public int getModifiers() { + return -1; + } + + public String getName() { + if (this.internalPair == null) + return null; + final char[] membername = this.internalPair.getName(); + return membername == null ? null : new String(membername); + } + + public Object getValue() { + if (value == null) + init(); + return value == NoValue ? null : this.value; + } + + private void init() { + this.value = buildDOMValue(this.internalPair.getValue(), this.bindingResolver); + if (this.value == null) + this.value = NoValue; + } + + char[] internalName() { + return this.internalPair == null ? null : this.internalPair.getName(); + } + + public boolean isDefault() { + return false; + } + + public boolean isDeprecated() { + return false; + } + + public boolean isEqualTo(IBinding binding) { + if (this == binding) + return true; + if (binding.getKind() != IBinding.MEMBER_VALUE_PAIR) + return false; + IMemberValuePairBinding other = (IMemberValuePairBinding) binding; + if (!getMethodBinding().isEqualTo(other.getMethodBinding())) + return false; + if (this.value == null) + return other.getValue() == null; + return this.value.equals(other.getValue()); + } + + public boolean isSynthetic() { + return false; + } + + public String toString() { + StringBuffer buffer = new StringBuffer(); + toString(buffer); + return buffer.toString(); + } + + public void toString(StringBuffer buffer) { + buffer.append(getName()); + buffer.append(" = "); //$NON-NLS-1$ + DefaultValuePairBinding.appendValue(getValue(), buffer); + } +} #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java,v retrieving revision 1.187 diff -u -r1.187 ASTConverter15Test.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 6 Feb 2006 16:25:20 -0000 1.187 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 9 Feb 2006 18:33:04 -0000 @@ -6276,7 +6276,7 @@ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression; IMethodBinding binding = classInstanceCreation.resolveConstructorBinding(); assertNotNull("Should not be null", binding); - IResolvedAnnotation[] annotations = binding.getAnnotations(); + IAnnotationBinding[] annotations = binding.getAnnotations(); assertNotNull("Should not be null", annotations); assertEquals("Should be empty", 0, annotations.length); } @@ -6308,8 +6308,8 @@ assertEquals("Wrong size", 2, modifiers.size()); assertTrue("Wrong type", modifiers.get(0) instanceof NormalAnnotation); NormalAnnotation normalAnnotation = (NormalAnnotation) modifiers.get(0); - IResolvedAnnotation resolvedAnnotation = normalAnnotation.resolveAnnotation(); - IResolvedMemberValuePair[] pairs = resolvedAnnotation.getDeclaredMemberValuePairs(); + IAnnotationBinding annotationBinding = normalAnnotation.resolveAnnotationBinding(); + IMemberValuePairBinding[] pairs = annotationBinding.getDeclaredMemberValuePairs(); assertEquals("Wrong size", 1, pairs.length); assertNotNull("Should not be null", pairs[0].getValue()); }