Automated merge with main-silver
authorffjre@netbeans.org
Mon, 17 Aug 2009 02:50:05 +0400
changeset 936630115800cc9
parent 935 90a6c54a9bf6
parent 820 a73ba534c6c8
child 937 da971c243f7f
Automated merge with main-silver
     1.1 --- a/openide.util/src/org/netbeans/modules/openide/util/ServiceProviderProcessor.java	Fri Aug 14 03:04:53 2009 +0400
     1.2 +++ b/openide.util/src/org/netbeans/modules/openide/util/ServiceProviderProcessor.java	Mon Aug 17 02:50:05 2009 +0400
     1.3 @@ -49,11 +49,15 @@
     1.4  import java.io.PrintWriter;
     1.5  import java.lang.annotation.Annotation;
     1.6  import java.util.ArrayList;
     1.7 +import java.util.Collection;
     1.8 +import java.util.Collections;
     1.9  import java.util.HashMap;
    1.10 +import java.util.LinkedList;
    1.11  import java.util.List;
    1.12  import java.util.Map;
    1.13  import java.util.Set;
    1.14  import javax.annotation.processing.AbstractProcessor;
    1.15 +import javax.annotation.processing.Completion;
    1.16  import javax.annotation.processing.RoundEnvironment;
    1.17  import javax.annotation.processing.SupportedAnnotationTypes;
    1.18  import javax.annotation.processing.SupportedSourceVersion;
    1.19 @@ -65,6 +69,7 @@
    1.20  import javax.lang.model.element.Modifier;
    1.21  import javax.lang.model.element.TypeElement;
    1.22  import javax.lang.model.type.MirroredTypeException;
    1.23 +import javax.lang.model.type.TypeKind;
    1.24  import javax.lang.model.type.TypeMirror;
    1.25  import javax.lang.model.util.ElementFilter;
    1.26  import javax.tools.Diagnostic.Kind;
    1.27 @@ -270,4 +275,74 @@
    1.28          return null;
    1.29      }
    1.30  
    1.31 +    @Override
    1.32 +    public Iterable<? extends Completion> getCompletions(Element annotated, AnnotationMirror annotation, ExecutableElement attr, String userText) {
    1.33 +        if (processingEnv == null || annotated == null || !annotated.getKind().isClass()) {
    1.34 +            return Collections.emptyList();
    1.35 +        }
    1.36 +
    1.37 +        if (   annotation == null
    1.38 +            || !"org.openide.util.lookup.ServiceProvider".contentEquals(((TypeElement) annotation.getAnnotationType().asElement()).getQualifiedName())) {
    1.39 +            return Collections.emptyList();
    1.40 +        }
    1.41 +
    1.42 +        if (!"service".contentEquals(attr.getSimpleName())) {
    1.43 +            return Collections.emptyList();
    1.44 +        }
    1.45 +
    1.46 +        TypeElement jlObject = processingEnv.getElementUtils().getTypeElement("java.lang.Object");
    1.47 +
    1.48 +        if (jlObject == null) {
    1.49 +            return Collections.emptyList();
    1.50 +        }
    1.51 +        
    1.52 +        Collection<Completion> result = new LinkedList<Completion>();
    1.53 +        List<TypeElement> toProcess = new LinkedList<TypeElement>();
    1.54 +
    1.55 +        toProcess.add((TypeElement) annotated);
    1.56 +
    1.57 +        while (!toProcess.isEmpty()) {
    1.58 +            TypeElement c = toProcess.remove(0);
    1.59 +
    1.60 +            result.add(new TypeCompletion(c.getQualifiedName().toString() + ".class"));
    1.61 +
    1.62 +            List<TypeMirror> parents = new LinkedList<TypeMirror>();
    1.63 +
    1.64 +            parents.add(c.getSuperclass());
    1.65 +            parents.addAll(c.getInterfaces());
    1.66 +
    1.67 +            for (TypeMirror tm : parents) {
    1.68 +                if (tm == null || tm.getKind() != TypeKind.DECLARED) {
    1.69 +                    continue;
    1.70 +                }
    1.71 +
    1.72 +                TypeElement type = (TypeElement) processingEnv.getTypeUtils().asElement(tm);
    1.73 +
    1.74 +                if (!jlObject.equals(type)) {
    1.75 +                    toProcess.add(type);
    1.76 +                }
    1.77 +            }
    1.78 +        }
    1.79 +
    1.80 +        return result;
    1.81 +    }
    1.82 +
    1.83 +    private static final class TypeCompletion implements Completion {
    1.84 +
    1.85 +        private final String type;
    1.86 +
    1.87 +        public TypeCompletion(String type) {
    1.88 +            this.type = type;
    1.89 +        }
    1.90 +
    1.91 +        public String getValue() {
    1.92 +            return type;
    1.93 +        }
    1.94 +
    1.95 +        public String getMessage() {
    1.96 +            return null;
    1.97 +        }
    1.98 +        
    1.99 +    }
   1.100 +
   1.101  }