1 12 13 package org.eclipse.jdt.internal.compiler.apt.model; 14 15 import java.util.ArrayList ; 16 import java.util.Collections ; 17 import java.util.HashSet ; 18 import java.util.List ; 19 20 import javax.lang.model.element.Element; 21 import javax.lang.model.element.ElementKind; 22 import javax.lang.model.element.ElementVisitor; 23 import javax.lang.model.element.Name; 24 import javax.lang.model.element.PackageElement; 25 26 import org.eclipse.jdt.core.compiler.CharOperation; 27 import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseProcessingEnvImpl; 28 import org.eclipse.jdt.internal.compiler.batch.FileSystem; 29 import org.eclipse.jdt.internal.compiler.env.INameEnvironment; 30 import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; 31 import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; 32 import org.eclipse.jdt.internal.compiler.lookup.PackageBinding; 33 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; 34 import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; 35 36 39 public class PackageElementImpl extends ElementImpl implements PackageElement { 40 41 PackageElementImpl(BaseProcessingEnvImpl env, PackageBinding binding) { 42 super(env, binding); 43 } 44 45 @Override 46 public <R, P> R accept(ElementVisitor<R, P> v, P p) 47 { 48 return v.visitPackage(this, p); 49 } 50 51 @Override 52 protected AnnotationBinding[] getAnnotationBindings() 53 { 54 PackageBinding packageBinding = (PackageBinding) this._binding; 55 char[][] compoundName = CharOperation.arrayConcat(packageBinding.compoundName, TypeConstants.PACKAGE_INFO_NAME); 56 ReferenceBinding type = this._env.getLookupEnvironment().getType(compoundName); 57 AnnotationBinding[] annotations = null; 58 if (type != null && type.isValidBinding()) { 59 annotations = type.getAnnotations(); 60 } 61 return annotations; 62 } 63 64 @Override 65 public List <? extends Element> getEnclosedElements() { 66 PackageBinding binding = (PackageBinding)_binding; 67 LookupEnvironment environment = binding.environment; 68 char[][][] typeNames = null; 69 INameEnvironment nameEnvironment = binding.environment.nameEnvironment; 70 if (nameEnvironment instanceof FileSystem) { 71 typeNames = ((FileSystem) nameEnvironment).findTypeNames(binding.compoundName); 72 } 73 HashSet <Element> set = new HashSet <Element>(); 74 if (typeNames != null) { 75 for (char[][] typeName : typeNames) { 76 ReferenceBinding type = environment.getType(typeName); 77 if (type != null && type.isValidBinding()) { 78 set.add(_env.getFactory().newElement(type)); 79 } 80 } 81 } 82 ArrayList <Element> list = new ArrayList <Element>(set.size()); 83 list.addAll(set); 84 return Collections.unmodifiableList(list); 85 } 86 87 @Override 88 public Element getEnclosingElement() { 89 return null; 91 } 92 93 @Override 94 public ElementKind getKind() { 95 return ElementKind.PACKAGE; 96 } 97 98 @Override 99 PackageElement getPackage() 100 { 101 return this; 102 } 103 104 @Override 105 public Name getSimpleName() { 106 char[][] compoundName = ((PackageBinding)_binding).compoundName; 107 int length = compoundName.length; 108 if (length == 0) { 109 return new NameImpl(CharOperation.NO_CHAR); 110 } 111 return new NameImpl(compoundName[length - 1]); 112 } 113 114 @Override 115 public Name getQualifiedName() { 116 return new NameImpl(CharOperation.concatWith(((PackageBinding)_binding).compoundName, '.')); 117 } 118 119 @Override 120 public boolean isUnnamed() { 121 PackageBinding binding = (PackageBinding)_binding; 122 return binding.compoundName == CharOperation.NO_CHAR_CHAR; 123 } 124 125 } 126 | Popular Tags |