Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 19927 Details for
Bug 90344
Building JSR 175 annotation into binding and exposing them through DOM
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch to o.e.jdt.core/dom (APT branch) with improvements
jdt-core-apt-patch-200504014b.txt (text/plain), 30.83 KB, created by
Jim des Rivieres
on 2005-04-15 01:34:26 EDT
(
hide
)
Description:
patch to o.e.jdt.core/dom (APT branch) with improvements
Filename:
MIME Type:
Creator:
Jim des Rivieres
Created:
2005-04-15 01:34:26 EDT
Size:
30.83 KB
patch
obsolete
>Index: ASTConverter.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java,v >retrieving revision 1.202 >diff -u -r1.202 ASTConverter.java >--- ASTConverter.java 26 Mar 2005 23:39:49 -0000 1.202 >+++ ASTConverter.java 15 Apr 2005 05:26:22 -0000 >@@ -1892,6 +1892,7 @@ > markerAnnotation.setSourceRange(start, end - start + 1); > if (this.resolveBindings) { > recordNodes(markerAnnotation, annotation); >+ markerAnnotation.resolveAnnotation(); > } > return markerAnnotation; > } >@@ -1953,6 +1954,7 @@ > normalAnnotation.setSourceRange(start, end - start + 1); > if (this.resolveBindings) { > recordNodes(normalAnnotation, annotation); >+ normalAnnotation.resolveAnnotation(); > } > return normalAnnotation; > } >@@ -2129,6 +2131,7 @@ > singleMemberAnnotation.setSourceRange(start, end - start + 1); > if (this.resolveBindings) { > recordNodes(singleMemberAnnotation, annotation); >+ singleMemberAnnotation.resolveAnnotation(); > } > return singleMemberAnnotation; > } >Index: Annotation.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/Annotation.java,v >retrieving revision 1.11 >diff -u -r1.11 Annotation.java >--- Annotation.java 15 Mar 2005 04:30:05 -0000 1.11 >+++ Annotation.java 15 Apr 2005 05:26:22 -0000 >@@ -164,5 +164,20 @@ > int memSize() { > return BASE_NODE_SIZE + 1 * 4; > } >+ >+ /** >+ * Resolves and returns the resolved annotation for this annotation. >+ * <p> >+ * Note that bindings (which includes resolved annotations) are generally unavailable unless >+ * requested when the AST is being built. >+ * </p> >+ * >+ * @return the resolved annotation, or >+ * <code>null</code> if the annotation cannot be resolved >+ * @since 3.2 >+ */ >+ public IResolvedAnnotation resolveAnnotation() { >+ return this.ast.getBindingResolver().resolveAnnotation(this); >+ } > } > >Index: BindingResolver.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/BindingResolver.java,v >retrieving revision 1.39 >diff -u -r1.39 BindingResolver.java >--- BindingResolver.java 23 Mar 2005 21:45:18 -0000 1.39 >+++ BindingResolver.java 15 Apr 2005 05:26:22 -0000 >@@ -17,7 +17,8 @@ > > /** > * A binding resolver is an internal mechanism for figuring out the binding >- * for a major declaration, type, or name reference. >+ * for a major declaration, type, or name reference. This also handles >+ * the creation and mapping between annotations and the ast nodes that defines them > * <p> > * The default implementation serves as the default binding resolver > * that does no resolving whatsoever. Internal subclasses do all the real work. >@@ -91,6 +92,21 @@ > ASTNode findDeclaringNode(String bindingKey) { > return null; > } >+ >+ /** >+ * Finds the corresponding AST node from which the given annotation instance originated. >+ * >+ * The default implementation of this method returns <code>null</code>. >+ * Subclasses may reimplement. >+ * </p> >+ * >+ * @param instance the dom annotation >+ * @return the corresponding node where the bindings is declared, >+ * or <code>null</code> if none >+ */ >+ ASTNode findDeclaringNode(IResolvedAnnotation instance){ >+ return null; >+ } > > /** > * Allows the user to get information about the given old/new pair of >@@ -164,6 +180,20 @@ > } > > /** >+ * Return the new annotation corresponding to the given old annotation >+ * <p> >+ * The default implementation of this method returns <code>null</code> >+ * Subclasses may reimplement. >+ * </p> >+ * >+ * @param instance the old annotation >+ * @return the new DOM annotation >+ */ >+ IResolvedAnnotation getAnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance instance){ >+ return null; >+ } >+ >+ /** > * Returns the compiler lookup environment used by this binding resolver. > * Returns <code>null</code> if none. > * >@@ -785,6 +815,25 @@ > } > > /** >+ * Resolves the given annotation instance and returns the DOM representation for it. >+ * <p> >+ * The implementation of {@link Annotation#resolveAnnotation()} >+ * forwards to this method. >+ * </p> >+ * <p> >+ * The default implementation of this method returns <code>null</code>. >+ * Subclasses may reimplement. >+ * </p> >+ * >+ * @param annotation the annotation ast node of interest >+ * @return the DOM annotation representation for the given ast node, or >+ * <code>null</code> if none is available >+ */ >+ IResolvedAnnotation resolveAnnotation(Annotation annotation){ >+ return null; >+ } >+ >+ /** > * Returns the compilation unit scope used by this binding resolver. > * Returns <code>null</code> if none. > * >Index: CompilationUnit.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnit.java,v >retrieving revision 1.65 >diff -u -r1.65 CompilationUnit.java >--- CompilationUnit.java 15 Mar 2005 04:30:05 -0000 1.65 >+++ CompilationUnit.java 15 Apr 2005 05:26:23 -0000 >@@ -406,6 +406,24 @@ > public ASTNode findDeclaringNode(IBinding binding) { > return this.ast.getBindingResolver().findDeclaringNode(binding); > } >+ >+ /** >+ * Finds the corresponding AST node in the given compilation unit from >+ * which the given resolved annotation originated. Returns <code>null</code> >+ * if the resolved annotation does not correspond to any node in this compilation unit. >+ * >+ * This method always returns <code>null</code> 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 <code>null</code> 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 >Index: DefaultBindingResolver.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java,v >retrieving revision 1.132 >diff -u -r1.132 DefaultBindingResolver.java >--- DefaultBindingResolver.java 23 Mar 2005 21:45:18 -0000 1.132 >+++ DefaultBindingResolver.java 15 Apr 2005 05:26:23 -0000 >@@ -90,8 +90,11 @@ > Map bindingKeysToBindings; > /** > * This map is used to keep the correspondance between new bindings and the >- * compiler bindings. This is an identity map. We should only create one object >- * for one binding. >+ * compiler bindings as well as new annotation instances to their >+ * internal counterpart. >+ * This is an identity map. We should only create one object >+ * for one binding or annotation. >+ * > */ > Map compilerBindingsToASTBindings; > >@@ -107,7 +110,7 @@ > Map astNodesToBlockScope; > > /** >- * This map is used to get an ast node from its binding (new binding) >+ * This map is used to get an ast node from its binding (new binding) or DOM > */ > Map bindingsToAstNodes; > >@@ -183,6 +186,13 @@ > return (ASTNode) this.bindingsToAstNodes.get(binding); > } > >+ synchronized ASTNode findDeclaringNode(IResolvedAnnotation instance) >+ { >+ if( instance == null ) >+ return null; >+ return (ASTNode)this.bindingsToAstNodes.get(instance); >+ } >+ > IBinding getBinding(org.eclipse.jdt.internal.compiler.lookup.Binding binding) { > switch (binding.kind()) { > case Binding.PACKAGE: >@@ -351,6 +361,17 @@ > return null; > } > >+ synchronized IResolvedAnnotation getAnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance internalInstance){ >+ IResolvedAnnotation domInstance = >+ (IResolvedAnnotation) this.bindingTables.compilerBindingsToASTBindings.get(internalInstance); >+ if (domInstance != null) { >+ return domInstance; >+ } >+ domInstance = new ResolvedAnnotation(internalInstance, this); >+ this.bindingTables.compilerBindingsToASTBindings.put(internalInstance, domInstance); >+ return domInstance; >+ } >+ > /* > * Method declared on BindingResolver. > */ >@@ -1398,6 +1419,23 @@ > return null; > } > >+ synchronized IResolvedAnnotation 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.compilerAnnotation); >+ if (domAnnotation == null) { >+ return null; >+ } >+ this.bindingsToAstNodes.put(domAnnotation, domASTNode); >+ return domAnnotation; >+ } >+ return null; >+ } >+ > /* > * Method declared on BindingResolver. > */ >Index: IBinding.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/IBinding.java,v >retrieving revision 1.21 >diff -u -r1.21 IBinding.java >--- IBinding.java 15 Mar 2005 04:30:05 -0000 1.21 >+++ IBinding.java 15 Apr 2005 05:26:24 -0000 >@@ -136,6 +136,27 @@ > public IJavaElement getJavaElement(); > > /** >+ * Return the resolved annotations associated with this binding. >+ * <ul> >+ * <li>Package bindings - these are annotations on a package declaration. >+ * </li> >+ * <li>Type bindings - these are annotations on a class, interface, enum, >+ * or annotation type declaration. The result is the same regardless of >+ * whether the type is parameterized.</li> >+ * <li>Method bindings - these are annotations on a method or constructor >+ * declaration. The result is the same regardless of whether the method is >+ * parameterized.</li> >+ * <li>Variable bindings - these are annotations on a field, enum constant, >+ * or formal parameter declaration.</li> >+ * </ul> >+ * >+ * @return the list of resolved annotations, or the empty list if there are no >+ * annotations associated with the object for which this is the binding >+ * @since 3.2 >+ */ >+ public IResolvedAnnotation[] getAnnotations(); >+ >+ /** > * Returns the key for this binding. > * <p> > * Within a connected cluster of bindings (for example, all bindings >Index: IMethodBinding.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/IMethodBinding.java,v >retrieving revision 1.24 >diff -u -r1.24 IMethodBinding.java >--- IMethodBinding.java 24 Mar 2005 13:12:31 -0000 1.24 >+++ IMethodBinding.java 15 Apr 2005 05:26:24 -0000 >@@ -42,8 +42,8 @@ > * @return <code>true</code> if this is the binding for a constructor, > * and <code>false</code> if this is the binding for a method > */ >- public boolean isConstructor(); >- >+ public boolean isConstructor(); >+ > /** > * Returns whether this binding is known to be a compiler-generated > * default constructor. >@@ -237,7 +237,7 @@ > * > * @return <code>true</code> if this method binding represents a > * an instance of a generic method corresponding to a raw >- * method reference, and <code>false</code> otherwise >+ * method reference, ad <code>false</code> otherwise > * @see #getMethodDeclaration() > * @see #getTypeArguments() > * @since 3.1 >@@ -266,6 +266,38 @@ > public boolean isVarargs(); > > /** >+ * Return whether this is the binding for an annotation type member. >+ * >+ * @return <code>true</code> iff this is the binding for an annotation type member >+ * and <code>false</code> otherwise >+ * @since 3.2 >+ */ >+ public boolean isAnnotationMember(); >+ >+ /** >+ * Return the resolved default value of an annotation type member, >+ * or <code>null</code> if the member has no default value, or if this >+ * is not the binding for an annotation type member. >+ * <p> >+ * Resolved values are represented as follows (same as for >+ * {@link IResolvedMemberValuePair#getValue()}): >+ * <ul> >+ * <li>Primitive type - the equivalent boxed object</li> >+ * <li>java.lang.Class - the <code>ITypeBinding</code> for the class object</li> >+ * <li>java.lang.String - the string value itself</li> >+ * <li>enum type - the <code>IVariableBinding</code> for the enum constant</li> >+ * <li>annotation type - an <code>IResolvedAnnotation</code></li> >+ * <li>array type - an <code>Object[]</code> whose elements are as per above >+ * (the language only allows single dimensional arrays in annotations)</li> >+ * </ul> >+ * >+ * @return the default value of this annotation type member, or <code>null</code> >+ * if none or not applicable >+ * @since 3.2 >+ */ >+ public Object getDefaultValue(); >+ >+ /** > * Returns whether this method overrides the given method, > * as specified in section 6.4.2 of <em>The Java Language > * Specification, Second Edition</em> (JLS2). >@@ -276,4 +308,18 @@ > * @since 3.1 > */ > public boolean overrides(IMethodBinding method); >+ >+ /** >+ * Return the resolved annotations of a parameter of this method. >+ * The result returned is the same regardless of whether >+ * this is a parameterized method. >+ * >+ * @param paramIndex the index of the parameter of interest >+ * @return the resolved annotations of the <code>paramIndex</code>th parameter, >+ * or an empty list if there are none >+ * @throws ArrayIndexOutOfBoundsException if <code>paramIndex</code> is >+ * not a valid index >+ * @since 3.2 >+ */ >+ public IResolvedAnnotation[] getParameterAnnotations(int paramIndex); > } >Index: MethodBinding.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodBinding.java,v >retrieving revision 1.56 >diff -u -r1.56 MethodBinding.java >--- MethodBinding.java 15 Mar 2005 19:28:59 -0000 1.56 >+++ MethodBinding.java 15 Apr 2005 05:26:24 -0000 >@@ -383,7 +383,49 @@ > MethodVerifier methodVerifier = lookupEnvironment.methodVerifier(); > return methodVerifier.doesMethodOverride(this.binding, otherCompilerBinding); > } >+ >+ public IResolvedAnnotation[] getAnnotations(){ >+ final org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance[] internalAnnotations = >+ this.binding.getAnnotations(); >+ final int len = internalAnnotations == null ? 0 : internalAnnotations.length; >+ IResolvedAnnotation[] domInstances = ResolvedAnnotation.NoAnnotations; >+ if( len > 0 ){ >+ domInstances = new ResolvedAnnotation[len]; >+ for( int i=0; i<len; i++ ){ >+ domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]); >+ } >+ } >+ return domInstances; >+ } >+ >+ public IResolvedAnnotation[] getParameterAnnotations(int index){ >+ // this line may through <code>ArrayIndexOutOfBoundException()</code> if >+ // <code>index</code> is invalid >+ final org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance[] internalAnnotations = >+ this.binding.getParameterAnnotations(index); >+ final int len = internalAnnotations == null ? 0 : internalAnnotations.length; >+ IResolvedAnnotation[] domInstances = ResolvedAnnotation.NoAnnotations; >+ if( len > 0 ){ >+ domInstances = new ResolvedAnnotation[len]; >+ for( int i=0; i<len; i++ ){ >+ domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]); >+ } >+ } >+ return domInstances; >+ } >+ >+ public boolean isAnnotationMember() >+ { return this.binding instanceof org.eclipse.jdt.internal.compiler.lookup.AnnotationMethodBinding; } > >+ public Object getDefaultValue() >+ { >+ if( isAnnotationMember() ){ >+ final Object internalObject = >+ ((org.eclipse.jdt.internal.compiler.lookup.AnnotationMethodBinding)this.binding).getDefaultValue(); >+ return ResolvedMemberValuePair.buildDOMValue(internalObject, this.binding.returnType, this.resolver); >+ } >+ return null; >+ } > /* > * For debugging purpose only. > * @see java.lang.Object#toString() >Index: PackageBinding.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/PackageBinding.java,v >retrieving revision 1.28 >diff -u -r1.28 PackageBinding.java >--- PackageBinding.java 23 Feb 2005 02:47:27 -0000 1.28 >+++ PackageBinding.java 15 Apr 2005 05:26:24 -0000 >@@ -148,6 +148,11 @@ > } > } > >+ public IResolvedAnnotation[] getAnnotations() { >+ // TODO Auto-generated method stub >+ throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$ >+ } >+ > /* > * For debugging purpose only. > * @see java.lang.Object#toString() >Index: TypeBinding.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java,v >retrieving revision 1.93 >diff -u -r1.93 TypeBinding.java >--- TypeBinding.java 26 Mar 2005 23:39:49 -0000 1.93 >+++ TypeBinding.java 15 Apr 2005 05:26:24 -0000 >@@ -1029,6 +1029,27 @@ > return methodBinding.isDefaultAbstract() || methodBinding.isSynthetic() || (methodBinding.isConstructor() && isInterface()); > } > >+ public IResolvedAnnotation[] getAnnotations(){ >+ if( this.binding.isAnnotationType() || this.binding.isClass() || >+ this.binding.isEnum() || this.binding.isInterface() ){ >+ final org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding refType = >+ (org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding)this.binding; >+ final org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance[] >+ internalAnnotations = refType.getAnnotations(); >+ >+ final int len = internalAnnotations == null ? 0 : internalAnnotations.length; >+ IResolvedAnnotation[] domInstances = ResolvedAnnotation.NoAnnotations; >+ if( len > 0 ){ >+ domInstances = new ResolvedAnnotation[len]; >+ for( int i=0; i<len; i++ ){ >+ domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]); >+ } >+ } >+ return domInstances; >+ } >+ return null; >+ } >+ > /* > * For debugging purpose only. > * @see java.lang.Object#toString() >Index: VariableBinding.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableBinding.java,v >retrieving revision 1.41 >diff -u -r1.41 VariableBinding.java >--- VariableBinding.java 25 Feb 2005 17:33:37 -0000 1.41 >+++ VariableBinding.java 15 Apr 2005 05:26:25 -0000 >@@ -289,6 +289,23 @@ > } > return false; > } >+ >+ public IResolvedAnnotation[] getAnnotations() >+ { >+ final org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance[] internalAnnotations = >+ this.binding.getAnnotations(); >+ // the variable is not an enum constant nor a field nor an argument. >+ if( internalAnnotations == null ) return null; >+ final int len = internalAnnotations.length; >+ IResolvedAnnotation[] domInstances = ResolvedAnnotation.NoAnnotations; >+ if( len > 0 ){ >+ domInstances = new ResolvedAnnotation[len]; >+ for( int i=0; i<len; i++ ){ >+ domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]); >+ } >+ } >+ return domInstances; >+ } > > /* > * For debugging purpose only. >Index: IResolvedAnnotation.java >=================================================================== >RCS file: IResolvedAnnotation.java >diff -N IResolvedAnnotation.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ IResolvedAnnotation.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,53 @@ >+/******************************************************************************* >+ * 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 <code>true</code> to <code>ITypeBinding.isAnnotation()</code>. >+ * >+ * @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 <code>MarkerAnnotation</code>, a one element >+ * list for a <code>SingleMemberAnnotation</code>, and one entry for each >+ * of the explicitly listed values in a <code>NormalAnnotation</code>. >+ * <p> >+ * 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. >+ * </p> >+ * >+ * @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: IResolvedMemberValuePair.java >=================================================================== >RCS file: IResolvedMemberValuePair.java >diff -N IResolvedMemberValuePair.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ IResolvedMemberValuePair.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,51 @@ >+/******************************************************************************* >+ * 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 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 getMemberBinding(); >+ >+ /** >+ * Returns the resolved value. Resolved values are represented as follows: >+ * <ul> >+ * <li>Primitive type - the equivalent boxed object</li> >+ * <li>java.lang.Class - the <code>ITypeBinding</code> for the class object</li> >+ * <li>java.lang.String - the string value itself</li> >+ * <li>enum type - the <code>IVariableBinding</code> for the enum constant</li> >+ * <li>annotation type - an <code>IResolvedAnnotation</code></li> >+ * <li>array type - an <code>Object[]</code> whose elements are as per above >+ * (the language only allows single dimensional arrays in annotations)</li> >+ * </ul> >+ * >+ * @return the resolved value, or <code>null</code> if none exists >+ */ >+ public Object getValue(); >+} >Index: ResolvedAnnotation.java >=================================================================== >RCS file: ResolvedAnnotation.java >diff -N ResolvedAnnotation.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ResolvedAnnotation.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,51 @@ >+/******************************************************************************* >+ * 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; >+ >+/** >+ * Internal class >+ */ >+class ResolvedAnnotation implements IResolvedAnnotation >+{ >+ static final ResolvedAnnotation[] NoAnnotations = new ResolvedAnnotation[0]; >+ private final org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance internalAnnotation; >+ private final BindingResolver bindingResolver; >+ >+ ResolvedAnnotation(org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance anno, >+ BindingResolver resolver ) >+ { >+ internalAnnotation = anno; >+ bindingResolver = resolver; >+ } >+ >+ public ITypeBinding getAnnotationType() { >+ final ITypeBinding binding = >+ this.bindingResolver.getTypeBinding(this.internalAnnotation.getAnnotationType()); >+ return binding.isAnnotation() ? binding : null; >+ } >+ >+ public IResolvedMemberValuePair[] getDeclaredMemberValuePairs() { >+ final org.eclipse.jdt.internal.compiler.lookup.IElementValuePair[] internalPair = >+ this.internalAnnotation.getElementValuePairs(); >+ final int len = internalPair.length; >+ IResolvedMemberValuePair[] pairs = ResolvedMemberValuePair.NoPair; >+ for( int i=0; i<len; i++ ){ >+ pairs[i] = new ResolvedMemberValuePair(internalPair[i],this.bindingResolver); >+ } >+ return pairs; >+ } >+ >+ public IResolvedMemberValuePair[] getAllMemberValuePairs() { >+ // TODO missing implementation >+ throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$ >+ } >+ >+} >Index: ResolvedMemberValuePair.java >=================================================================== >RCS file: ResolvedMemberValuePair.java >diff -N ResolvedMemberValuePair.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ResolvedMemberValuePair.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,109 @@ >+/******************************************************************************* >+ * 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.TypeIds; >+ >+/** >+ * Internal class. >+ */ >+class ResolvedMemberValuePair implements IResolvedMemberValuePair >+{ >+ static final ResolvedMemberValuePair[] NoPair = new ResolvedMemberValuePair[0]; >+ private static final Object NoValue = new Object(); >+ private final org.eclipse.jdt.internal.compiler.lookup.IElementValuePair internalPair; >+ private Object value = null; >+ private final BindingResolver bindingResolver; >+ >+ ResolvedMemberValuePair(final org.eclipse.jdt.internal.compiler.lookup.IElementValuePair pair, >+ BindingResolver resolver) >+ { >+ this.internalPair = pair; >+ this.bindingResolver = resolver; >+ } >+ >+ private void init() >+ { >+ final org.eclipse.jdt.internal.compiler.lookup.TypeBinding type = this.internalPair.getType(); >+ this.value = buildDOMValue(this.internalPair.getValue(), type, this.bindingResolver); >+ if( this.value == null ) >+ this.value = NoValue; >+ } >+ >+ static Object buildDOMValue(final Object internalObject, >+ org.eclipse.jdt.internal.compiler.lookup.TypeBinding type, >+ BindingResolver resolver) >+ { >+ if( internalObject == null || type == null ) return null; >+ switch(type.id) >+ { >+ case TypeIds.T_boolean: >+ return new Boolean( ((Constant)internalObject).booleanValue() ); >+ case TypeIds.T_byte: >+ return new Byte( ((Constant)internalObject).byteValue() ); >+ case TypeIds.T_char: >+ return new Character( ((Constant)internalObject).charValue() ); >+ case TypeIds.T_double: >+ return new Double( ((Constant)internalObject).doubleValue() ); >+ case TypeIds.T_float: >+ return new Float( ((Constant)internalObject).floatValue() ); >+ case TypeIds.T_int: >+ return new Integer( ((Constant)internalObject).intValue() ); >+ case TypeIds.T_long: >+ return new Long( ((Constant)internalObject).longValue() ); >+ case TypeIds.T_short: >+ return new Short( ((Constant)internalObject).shortValue() ); >+ case TypeIds.T_JavaLangString: >+ return internalObject; >+ case TypeIds.T_JavaLangClass: >+ return resolver.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)internalObject); >+ } >+ >+ if( type.isAnnotationType() ){ >+ return new ResolvedAnnotation( >+ (org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance)internalObject, >+ resolver); >+ } >+ else if( type.isEnum() ){ >+ return resolver.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.FieldBinding)internalObject); >+ } >+ else if( type.isArrayType() ){ >+ final Object[] iElements = (Object[])internalObject; >+ final int len = iElements.length; >+ Object[] values = null; >+ if( len > 0){ >+ final org.eclipse.jdt.internal.compiler.lookup.TypeBinding elementType = >+ ((org.eclipse.jdt.internal.compiler.lookup.ArrayBinding)type).leafComponentType; >+ values = new Object[len]; >+ for( int i=0; i<len; i++ ){ >+ values[i] = buildDOMValue(iElements[i], elementType, resolver); >+ } >+ } >+ } >+ throw new IllegalStateException(); // should never get here. >+ } >+ >+ public String getName() { >+ final char[] membername = this.internalPair.getMemberName(); >+ return membername == null ? null : new String(membername); >+ } >+ >+ public IMethodBinding getMemberBinding() { >+ return this.bindingResolver.getMethodBinding(this.internalPair.getMethodBinding()); >+ } >+ >+ public Object getValue() { >+ if( value == null ) >+ init(); >+ return value == NoValue ? null : this.value; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 90344
:
19892
|
19893
|
19925
| 19927