KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > apt > core > internal > declaration > SourceParameterDeclarationImpl


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 BEA Systems, Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * tyeung@bea.com - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.apt.core.internal.declaration;
12
13 import org.eclipse.core.resources.IFile;
14 import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv;
15 import org.eclipse.jdt.apt.core.internal.util.Factory;
16 import org.eclipse.jdt.core.dom.ITypeBinding;
17 import org.eclipse.jdt.core.dom.IVariableBinding;
18 import org.eclipse.jdt.core.dom.Name;
19 import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
20 import org.eclipse.jdt.core.dom.Type;
21
22 import com.sun.mirror.declaration.ParameterDeclaration;
23 import com.sun.mirror.type.TypeMirror;
24 import com.sun.mirror.util.DeclarationVisitor;
25
26 /**
27  * Represents a formal parameter that came from source
28  */

29 public class SourceParameterDeclarationImpl
30     extends ASTBasedDeclarationImpl implements ParameterDeclaration{
31    
32     /**
33      * Parameter declaration from source files
34      * @param astNode the ast node that defines this parameter
35      * @param file the file where the ast node originates
36      * @param env
37      */

38     public SourceParameterDeclarationImpl(SingleVariableDeclaration astNode,
39                                           IFile file,
40                                           BaseProcessorEnv env)
41     {
42         super( astNode, file, env);
43     }
44     
45     public void accept(DeclarationVisitor visitor)
46     {
47         visitor.visitParameterDeclaration(this);
48     }
49     
50     public TypeMirror getType()
51     {
52         final SingleVariableDeclaration astNode = getAstNode();
53         final Type type = astNode.getType();
54         if( type == null )
55             return Factory.createErrorClassType(EMPTY_STRING);
56         final IVariableBinding varBinding = astNode.resolveBinding();
57         if( varBinding == null ){
58             String JavaDoc typeName = type.toString();
59              if( astNode.isVarargs() )
60                  return Factory.createErrorArrayType(typeName, 1);
61              else
62                  return Factory.createErrorClassType(typeName);
63         }
64         else{
65              final ITypeBinding typeBinding = varBinding.getType();
66              if( typeBinding == null ){
67                  String JavaDoc typeName = type.toString();
68                  if( astNode.isVarargs() )
69                      return Factory.createErrorArrayType(typeName, 1);
70                  else
71                      return Factory.createErrorClassType(typeName);
72              }
73              else{
74                 final TypeMirror mirrorType = Factory.createTypeMirror(typeBinding, _env);
75                 if(mirrorType == null )
76                     return Factory.createErrorClassType(type.toString());
77                 return mirrorType;
78              }
79         }
80     }
81     
82     public String JavaDoc getSimpleName()
83     {
84         final Name nameNode = getAstNode().getName();
85         return nameNode == null ? EMPTY_STRING : nameNode.toString();
86     }
87     
88     public String JavaDoc getDocComment()
89     {
90         return EMPTY_STRING;
91     }
92     
93     SingleVariableDeclaration getAstNode()
94     {
95         return (SingleVariableDeclaration)_astNode;
96     }
97     
98     public MirrorKind kind(){ return MirrorKind.FORMAL_PARAMETER; }
99     
100     public String JavaDoc toString(){
101         return _astNode.toString();
102     }
103     
104     public boolean equals(Object JavaDoc obj){
105         if( obj instanceof SourceParameterDeclarationImpl ){
106             final SourceParameterDeclarationImpl otherParam = (SourceParameterDeclarationImpl)obj;
107             return _astNode == otherParam._astNode;
108         }
109         return false;
110     }
111     
112     public int hashCode(){
113         return _astNode.hashCode();
114     }
115 }
116
117
118
Popular Tags