1 11 package org.eclipse.jdt.apt.core.internal.declaration; 12 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.List ; 16 17 import org.eclipse.core.resources.IFile; 18 import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv; 19 import org.eclipse.jdt.core.dom.ASTNode; 20 import org.eclipse.jdt.core.dom.CompilationUnit; 21 import org.eclipse.jdt.core.dom.IBinding; 22 23 import com.sun.mirror.declaration.Modifier; 24 25 public abstract class DeclarationImpl extends EclipseDeclarationImpl { 26 27 28 protected final IBinding _binding; 29 DeclarationImpl(final IBinding binding, final BaseProcessorEnv env ) 30 { 31 super(env); 32 assert binding != null : "binding cannot be null"; _binding = binding; 34 } 35 36 public boolean equals(Object obj) 37 { 38 if(obj instanceof DeclarationImpl) 39 return _binding.isEqualTo( ((DeclarationImpl)obj)._binding ); 40 41 return false; 42 } 43 44 public int hashCode(){ 45 final String key = getDeclarationBinding().getKey(); 46 return key == null ? 0 : key.hashCode(); 47 } 48 49 56 public abstract IBinding getDeclarationBinding(); 57 58 public Collection <Modifier> getModifiers() 59 { 60 final int modBits = getDeclarationBinding().getModifiers(); 61 final List <Modifier> mods = new ArrayList <Modifier>(4); 62 if( org.eclipse.jdt.core.dom.Modifier.isAbstract(modBits) ) 63 mods.add(Modifier.ABSTRACT); 64 if( org.eclipse.jdt.core.dom.Modifier.isFinal(modBits) ) 65 mods.add(Modifier.FINAL); 66 if( org.eclipse.jdt.core.dom.Modifier.isNative(modBits) ) 67 mods.add(Modifier.NATIVE); 68 if( org.eclipse.jdt.core.dom.Modifier.isPrivate(modBits) ) 69 mods.add(Modifier.PRIVATE); 70 if( org.eclipse.jdt.core.dom.Modifier.isProtected(modBits) ) 71 mods.add(Modifier.PROTECTED); 72 if( org.eclipse.jdt.core.dom.Modifier.isPublic(modBits) ) 73 mods.add(Modifier.PUBLIC); 74 if( org.eclipse.jdt.core.dom.Modifier.isStatic(modBits) ) 75 mods.add(Modifier.STATIC); 76 if( org.eclipse.jdt.core.dom.Modifier.isStrictfp(modBits) ) 77 mods.add(Modifier.STRICTFP); 78 if( org.eclipse.jdt.core.dom.Modifier.isSynchronized(modBits) ) 79 mods.add(Modifier.SYNCHRONIZED); 80 if( org.eclipse.jdt.core.dom.Modifier.isTransient(modBits) ) 81 mods.add(Modifier.TRANSIENT); 82 if( org.eclipse.jdt.core.dom.Modifier.isVolatile(modBits) ) 83 mods.add(Modifier.VOLATILE); 84 return mods; 85 } 86 87 public boolean isBindingBased(){ return true; } 88 89 ASTNode getAstNode(){ 90 if( !isFromSource() ) return null; 91 return _env.getASTNodeForBinding(getDeclarationBinding()); 92 } 93 94 CompilationUnit getCompilationUnit(){ 95 if( !isFromSource() ) return null; 96 return _env.getCompilationUnitForBinding(getDeclarationBinding()); 97 } 98 99 public IFile getResource(){ 100 if( isFromSource() ){ 101 final IBinding binding = getDeclarationBinding(); 102 return _env.getDeclaringFileForBinding(binding); 103 } 104 return null; 105 } 106 107 } 108 | Popular Tags |