javax.lang.model.type.DeclaredType Java Examples

The following examples show how to use javax.lang.model.type.DeclaredType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeserializerGenerator.java    From domino-jackson with Apache License 2.0 6 votes vote down vote up
private void generateSubTypesDeserializers(TypeMirror beanType, String packageName) {
	SubTypesInfo subTypesInfo= Type.getSubTypes(beanType);
    for (Map.Entry<String, TypeMirror> subtypeEntry: subTypesInfo.getSubTypes().entrySet()) {
    	// @JsonTypeInfo and @JsonSubTypes must be used only on non generic types
    	// This limitation is imposed by the the the java.land.model API, which does 
    	// not allow to retrieve interface(s) for given class (i.e. using getSupperClass()). 
    	// That limits the possibilities to inspect interface type parameters. Even
    	// beanType is TypeMirror for base interface (i.e. annotated with @JsonTypeInfo and @JsonSubTypes)
    	// with specified type arguments, we can not match them against the 
    	// type parameters of the subtype retrieved by @JsonSubTypes.
    	if (
    			!((DeclaredType)beanType).getTypeArguments().isEmpty()
    			|| !((DeclaredType)((DeclaredType)subtypeEntry.getValue()).asElement().asType()).getTypeArguments().isEmpty())
    		throw new RuntimeException("@JsonSubTypes and &JsonTypeInfo can be used only on non-generic Java types");

    	new DeserializerGenerator().generate(packageName, subtypeEntry.getValue());
    }
}
 
Example #2
Source File: IntroduceLocalExtensionTransformer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static KindOfType detectKind(CompilationInfo info, TypeMirror tm) {
    if (tm.getKind().isPrimitive()) {
        return KindOfType.valueOf(tm.getKind().name());
    }

    if (tm.getKind() == TypeKind.ARRAY) {
        return ((ArrayType) tm).getComponentType().getKind().isPrimitive() ? KindOfType.ARRAY_PRIMITIVE : KindOfType.ARRAY;
    }

    if (tm.getKind() == TypeKind.DECLARED) {
        Types t = info.getTypes();
        TypeElement en = info.getElements().getTypeElement("java.lang.Enum");

        if (en != null) {
            if (t.isSubtype(tm, t.erasure(en.asType()))) {
                return KindOfType.ENUM;
            }
        }

        if (((DeclaredType) tm).asElement().getKind().isClass() && ((TypeElement) ((DeclaredType) tm).asElement()).getQualifiedName().contentEquals("java.lang.String")) {
            return KindOfType.STRING;
        }
    }

    return KindOfType.OTHER;
}
 
Example #3
Source File: WebServiceVisitor.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected boolean classImplementsSei(TypeElement classElement, TypeElement interfaceElement) {
    for (TypeMirror interfaceType : classElement.getInterfaces()) {
        if (((DeclaredType) interfaceType).asElement().equals(interfaceElement))
            return true;
    }
    List<ExecutableElement> classMethods = getClassMethods(classElement);
    boolean implementsMethod;
    for (ExecutableElement interfaceMethod : ElementFilter.methodsIn(interfaceElement.getEnclosedElements())) {
        implementsMethod = false;
        for (ExecutableElement classMethod : classMethods) {
            if (sameMethod(interfaceMethod, classMethod)) {
                implementsMethod = true;
                classMethods.remove(classMethod);
                break;
            }
        }
        if (!implementsMethod) {
            builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_NOT_IMPLEMENTED(interfaceElement.getSimpleName(), classElement.getSimpleName(), interfaceMethod), interfaceMethod);
            return false;
        }
    }
    return true;
}
 
Example #4
Source File: ConvertToLambdaPreconditionChecker.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void verifyTargetType() {

        TypeMirror expectedType = findExpectedType(pathToNewClassTree);
        if (!Utilities.isValidType(expectedType)) {
            foundErroneousTargetType = true;
            return;
        }

        TypeMirror erasedExpectedType = info.getTypes().erasure(expectedType);

        TreePath pathForClassIdentifier = new TreePath(pathToNewClassTree, newClassTree.getIdentifier());
        TypeMirror lambdaType = info.getTrees().getTypeMirror(pathForClassIdentifier);
        lambdaType = info.getTypes().erasure(lambdaType);

        foundAssignmentToSupertype = !info.getTypes().isSameType(erasedExpectedType, lambdaType);
        
        if (erasedExpectedType.getKind() == TypeKind.DECLARED) {
            TypeElement te = (TypeElement)((DeclaredType)erasedExpectedType).asElement();
            TypeMirror tt = (DeclaredType)te.asType();
            if (tt.getKind() == TypeKind.DECLARED && !((DeclaredType)tt).getTypeArguments().isEmpty()) {
                foundAssignmentToRawType =  info.getTypes().isSameType(erasedExpectedType, expectedType);
            }
        }
    }
 
Example #5
Source File: BaseProcessor.java    From pocketknife with Apache License 2.0 6 votes vote down vote up
protected void validateSerializer(Element element, Class<? extends Annotation> annotation, TypeMirror serializer, Class abstractSerializer) {
    if (serializer == null) {
        return;
    }
    Element absSerializerElement = elements.getTypeElement(abstractSerializer.getName());
    if (absSerializerElement == null) {
        throw new IllegalStateException(String.format("Unable to find %s type", abstractSerializer.getName()));
    }
    TypeMirror absSerializerMirror = absSerializerElement.asType();
    if (!types.isAssignable(serializer, types.erasure(absSerializerMirror))) {
        throw new IllegalStateException(String.format("@%s value must extend %s", annotation.getName(), abstractSerializer.getName()));
    }
    TypeMirror elementType = element.asType();
    for (TypeMirror superType : types.directSupertypes(serializer)) {
        if (types.isAssignable(superType, types.erasure(absSerializerMirror)) &&  superType instanceof DeclaredType) {
            if (types.isSameType(((DeclaredType) superType).getTypeArguments().get(0), elementType)) {
                return;
            } else {
                throw new IllegalStateException(String.format("Serializer T must be of type %s", elementType.toString()));
            }
        }
    }
    throw new IllegalStateException(String.format("%s must extend %s", serializer.toString(), absSerializerMirror.toString()));
}
 
Example #6
Source File: CriteriaModel.java    From immutables with Apache License 2.0 6 votes vote down vote up
/**
 * Criteria templates are always generated as top-level class (separate file).
 * Construct criteria name from {@linkplain TypeMirror}
 *
 * @return fully qualified criteria (template) class name
 */
private static String topLevelCriteriaClassName(TypeMirror type) {
  DeclaredType declaredType = MoreTypes.asDeclared(type);
  Element element = declaredType.asElement();
  do {
    element = element.getEnclosingElement();
  } while (element.getKind() != ElementKind.PACKAGE);

  String packagePrefix = "";
  if (!element.getSimpleName().contentEquals("")) {
    packagePrefix = MoreElements.asPackage(element).getQualifiedName() + ".";
  }

  // package name + type name + "CriteriaTemplate"
  return packagePrefix + declaredType.asElement().getSimpleName().toString() + "CriteriaTemplate";
}
 
Example #7
Source File: SpringXMLConfigCompletionItem.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public StringBuilder visitWildcard(WildcardType t, Boolean p) {
    DEFAULT_VALUE.append("?"); //NOI18N
    TypeMirror bound = t.getSuperBound();
    if (bound == null) {
        bound = t.getExtendsBound();
        if (bound != null) {
            DEFAULT_VALUE.append(" extends "); //NOI18N
            if (bound.getKind() == TypeKind.WILDCARD)
                bound = ((WildcardType)bound).getSuperBound();
            visit(bound, p);
        } else {
            bound = SourceUtils.getBound(t);
            if (bound != null && (bound.getKind() != TypeKind.DECLARED || !((TypeElement)((DeclaredType)bound).asElement()).getQualifiedName().contentEquals("java.lang.Object"))) { //NOI18N
                DEFAULT_VALUE.append(" extends "); //NOI18N
                visit(bound, p);
            }
        }
    } else {
        DEFAULT_VALUE.append(" super "); //NOI18N
        visit(bound, p);
    }
    return DEFAULT_VALUE;
}
 
Example #8
Source File: TypeModeler.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static TypeMirror getHolderValueType(TypeMirror type, TypeElement defHolder, ProcessingEnvironment env) {
    TypeElement typeElement = getDeclaration(type);
    if (typeElement == null)
        return null;

    if (isSubElement(typeElement, defHolder)) {
        if (type.getKind().equals(TypeKind.DECLARED)) {
            Collection<? extends TypeMirror> argTypes = ((DeclaredType) type).getTypeArguments();
            if (argTypes.size() == 1) {
                return argTypes.iterator().next();
            } else if (argTypes.isEmpty()) {
                VariableElement member = getValueMember(typeElement);
                if (member != null) {
                    return member.asType();
                }
            }
        }
    }
    return null;
}
 
Example #9
Source File: EventsModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void update( List<VariableElement> vars , 
        CompilationController controller) 
{
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    
    for (VariableElement var : vars) {
        FileObject fileObject = SourceUtils.getFile(ElementHandle
                .create(var), controller.getClasspathInfo());
        InjectableTreeNode<Element> node = 
            new InjectableTreeNode<Element>(fileObject, var,  
                    (DeclaredType)controller.getElementUtilities().
                    enclosingTypeElement(var).asType(), false,controller);
        root.add( node );
    }
    setRoot(root);
}
 
Example #10
Source File: ElementJavadoc.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void appendAnnotation(StringBuilder sb, AnnotationMirror annotationDesc, boolean topLevel) {
    DeclaredType annotationType = annotationDesc.getAnnotationType();
    if (annotationType != null && (!topLevel || isDocumented(annotationType))) {
        appendType(sb, annotationType, false, false, true);
        Map<? extends ExecutableElement, ? extends AnnotationValue> values = annotationDesc.getElementValues();
        if (!values.isEmpty()) {
            sb.append('('); //NOI18N
            for (Iterator<? extends Map.Entry<? extends ExecutableElement, ? extends AnnotationValue>> it = values.entrySet().iterator(); it.hasNext();) {
                Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> value = it.next();
                createLink(sb, value.getKey(), value.getKey().getSimpleName());
                sb.append('='); //NOI18N
                appendAnnotationValue(sb, value.getValue());
                if (it.hasNext())
                    sb.append(","); //NOI18N
            }
            sb.append(')'); //NOI18N
        }
        if (topLevel)
            sb.append("<br>"); //NOI18N
    }
}
 
Example #11
Source File: PrimitiveTypeAnalyzer.java    From Akatsuki with Apache License 2.0 6 votes vote down vote up
@Override
public DefaultAnalysis createAnalysis(InvocationContext<TypeMirror> context)
		throws UnknownTypeException {
	// boxed primitives have different names (at least for int)
	CharSequence typeName;
	final TypeMirror refinedMirror = context.field.refinedMirror();
	if (refinedMirror instanceof DeclaredType) {
		// we are boxed
		typeName = this.type == Type.UNBOXED
				? toCapitalCase(types().unboxedType(refinedMirror).getKind().name())
				: ((DeclaredType) refinedMirror).asElement().getSimpleName();
	} else {
		// we are unboxed
		typeName = this.type == Type.BOXED
				? types().boxedClass((PrimitiveType) refinedMirror).getSimpleName()
				: toCapitalCase(refinedMirror.getKind().name());
	}
	String methodName = (suffix != null) ? (typeName.toString() + suffix) : typeName.toString();
	return DefaultAnalysis.of(this, methodName, context);
}
 
Example #12
Source File: AnnotationObjectProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static void findQualifiers(Element element , 
        AnnotationModelHelper helper , boolean event , 
        AnnotationHandleStrategy strategy )
{
    List<? extends AnnotationMirror> allAnnotationMirrors = 
        helper.getCompilationController().getElements().
        getAllAnnotationMirrors( element );
    for (AnnotationMirror annotationMirror : allAnnotationMirrors) {
        DeclaredType annotationType = annotationMirror
                .getAnnotationType();
        if ( annotationType == null || annotationType.getKind() == TypeKind.ERROR){
            continue;
        }
        TypeElement annotationElement = (TypeElement) annotationType
                .asElement();
        if (annotationElement!= null && isQualifier(annotationElement, 
                helper , event )) 
        {
            strategy.handleAnnotation(annotationMirror , annotationElement );
        }
    }
}
 
Example #13
Source File: TypeModeler.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static TypeMirror getHolderValueType(TypeMirror type, TypeElement defHolder, ProcessingEnvironment env) {
    TypeElement typeElement = getDeclaration(type);
    if (typeElement == null)
        return null;

    if (isSubElement(typeElement, defHolder)) {
        if (type.getKind().equals(TypeKind.DECLARED)) {
            Collection<? extends TypeMirror> argTypes = ((DeclaredType) type).getTypeArguments();
            if (argTypes.size() == 1) {
                return argTypes.iterator().next();
            } else if (argTypes.isEmpty()) {
                VariableElement member = getValueMember(typeElement);
                if (member != null) {
                    return member.asType();
                }
            }
        }
    }
    return null;
}
 
Example #14
Source File: SpringXMLConfigCompletionItem.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public StringBuilder visitDeclared(DeclaredType t, Boolean p) {
    Element e = t.asElement();
    if (e instanceof TypeElement) {
        TypeElement te = (TypeElement)e;
        DEFAULT_VALUE.append((p ? te.getQualifiedName() : te.getSimpleName()).toString());
        Iterator<? extends TypeMirror> it = t.getTypeArguments().iterator();
        if (it.hasNext()) {
            DEFAULT_VALUE.append("<"); //NOI18N
            while(it.hasNext()) {
                visit(it.next(), p);
                if (it.hasNext())
                    DEFAULT_VALUE.append(", "); //NOI18N
            }
            DEFAULT_VALUE.append(">"); //NOI18N
        }
        return DEFAULT_VALUE;
    } else {
        return DEFAULT_VALUE.append(UNKNOWN); //NOI18N
    }
}
 
Example #15
Source File: TypeUtil.java    From pocketknife with Apache License 2.0 5 votes vote down vote up
public String getBundleType(TypeMirror type) throws InvalidTypeException {
    // Primitive
    if (isPrimitive(type)) {
        return getPrimitiveType(type);
    }

    // Array
    if (isArrayType(type)) {
        return getArrayType((ArrayType) type);
    }

    // ArrayList
    if (isArrayListType(type)) {
        return getArrayListType((DeclaredType) type);
    }

    // Sparse ParcelableArray
    if (isSparseParcelableArray(type)) {
        return "SparseParcelableArray";
    }

    // Other types
    if (types.isAssignable(type, bundleType)) {
        return "Bundle";
    }

    if (isAggregateType(type)) {
        return getAggregateType(type);
    }

    if (types.isAssignable(type, serializableType)) {
        return "Serializable";
    }
    throw new InvalidTypeException(InvalidTypeException.Container.BUNDLE, type);
}
 
Example #16
Source File: InferredTypeElementTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetQualifiedNameInferredFromIdentifier() throws IOException {
  compile(
      Joiner.on('\n').join("package com.example.buck;", "public class Foo extends Bar {", "}"));

  DeclaredType superclass =
      (DeclaredType) elements.getTypeElement("com.example.buck.Foo").getSuperclass();
  TypeElement element = (TypeElement) superclass.asElement();
  assertNameEquals("com.example.buck.Bar", element.getQualifiedName());
}
 
Example #17
Source File: JavacRoundEnvironment.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<Element> scan(Element e, DeclaredType p) {
    List<? extends AnnotationMirror> annotationMirrors =
        processingEnv.getElementUtils().getAllAnnotationMirrors(e);
    for (AnnotationMirror annotationMirror : annotationMirrors) {
        if (typeUtil.isSameType(annotationMirror.getAnnotationType(), p))
            annotatedElements.add(e);
    }
    e.accept(this, p);
    return annotatedElements;
}
 
Example #18
Source File: NullablePropertyFactoryTest.java    From FreeBuilder with Apache License 2.0 5 votes vote down vote up
@Test
public void nullable() {
  TypeElement dataType = model.newType(
      "package com.example;",
      "public class DataType {",
      "  public abstract @" + Nullable.class.getName() + " String getName();",
      "  public static class Builder extends DataType_Builder {}",
      "}");
  DeclaredType builderType = (DeclaredType)
      getOnlyElement(typesIn(dataType.getEnclosedElements())).asType();
  ExecutableElement getterMethod = getOnlyElement(methodsIn(dataType.getEnclosedElements()));
  Property property = new Property.Builder()
      .setType(getterMethod.getReturnType())
      .setCapitalizedName("Name")
      .buildPartial();
  when(config.getBuilder()).thenReturn(builderType);
  when(config.getProperty()).thenReturn(property);
  when(config.getElements()).thenReturn(model.elementUtils());
  doReturn(getterMethod.getAnnotationMirrors()).when(config).getAnnotations();

  Optional<NullableProperty> codeGenerator = factory.create(config);

  assertThat(codeGenerator.get()).isEqualTo(new NullableProperty(
      datatype,
      property,
      ImmutableSet.of(model.typeElement(Nullable.class)),
      unaryOperator(model.typeMirror(String.class))));
}
 
Example #19
Source File: JavacTrees.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean isAccessible(Scope scope, Element member, DeclaredType type) {
    if (scope instanceof JavacScope
            && member instanceof Symbol
            && type instanceof com.sun.tools.javac.code.Type) {
        Env<AttrContext> env = ((JavacScope) scope).env;
        return resolve.isAccessible(env, (com.sun.tools.javac.code.Type)type, (Symbol)member, true);
    } else
        return false;
}
 
Example #20
Source File: ApNavigator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public boolean isParameterizedType(TypeMirror typeMirror) {
    if (typeMirror != null && typeMirror.getKind().equals(TypeKind.DECLARED)) {
        DeclaredType d = (DeclaredType) typeMirror;
        return !d.getTypeArguments().isEmpty();
    }
    return false;
}
 
Example #21
Source File: JavahTask.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Void visitDeclared(DeclaredType t, Types types) {
    t.asElement().getKind(); // ensure class exists
    for (TypeMirror st: types.directSupertypes(t))
        visit(st, types);
    return null;
}
 
Example #22
Source File: TypeMonikerFactory.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static TypeMoniker getTypeMoniker(TypeMirror typeMirror) {
    if (typeMirror == null)
        throw new NullPointerException();

    if (typeMirror.getKind().isPrimitive())
        return new PrimitiveTypeMoniker((PrimitiveType) typeMirror);
    else if (typeMirror.getKind().equals(TypeKind.ARRAY))
        return new ArrayTypeMoniker((ArrayType) typeMirror);
    else if (typeMirror.getKind().equals(TypeKind.DECLARED))
        return new DeclaredTypeMoniker((DeclaredType) typeMirror);
    return getTypeMoniker(typeMirror.toString());
}
 
Example #23
Source File: MissingTypeAwareDelegatingTypes.java    From revapi with Apache License 2.0 5 votes vote down vote up
@Override
public DeclaredType getDeclaredType(TypeElement typeElem, TypeMirror... typeArgs) {
    if (typeElem instanceof MissingTypeElement) {
        throw new IllegalArgumentException("Invalid type element.");
    }
    for (TypeMirror t : typeArgs) {
        if (isMissing(t)) {
            throw new IllegalArgumentException("Invalid type arguments.");
        }
    }
    return IgnoreCompletionFailures.in(types::getDeclaredType, typeElem, typeArgs);
}
 
Example #24
Source File: EnclosedElementsProcessor.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  for (Element element : roundEnv.getElementsAnnotatedWith(Annotation.class)) {
    TypeElement cls = (TypeElement) element;

    // Explore enclosed field types of this class.
    for (Element enclosedElement : cls.getEnclosedElements()) {
        if (enclosedElement.asType() instanceof DeclaredType) {
          ((DeclaredType)enclosedElement.asType()).asElement().getEnclosedElements();
        }
    }
  }

  return super.process(annotations, roundEnv);
}
 
Example #25
Source File: WebServiceVisitor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected boolean isValidOneWayMethod(ExecutableElement method, TypeElement typeElement) {
    boolean valid = true;
    if (!(method.getReturnType().accept(NO_TYPE_VISITOR, null))) {
        // this is an error, cannot be OneWay and have a return type
        builder.processError(WebserviceapMessages.WEBSERVICEAP_ONEWAY_OPERATION_CANNOT_HAVE_RETURN_TYPE(typeElement.getQualifiedName(), method.toString()), method);
        valid = false;
    }
    VariableElement outParam = getOutParameter(method);
    if (outParam != null) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_ONEWAY_AND_OUT(typeElement.getQualifiedName(), method.toString()), outParam);
        valid = false;
    }
    if (!isDocLitWrapped() && soapStyle.equals(SOAPStyle.DOCUMENT)) {
        int inCnt = getModeParameterCount(method, WebParam.Mode.IN);
        if (inCnt != 1) {
            builder.processError(WebserviceapMessages.WEBSERVICEAP_ONEWAY_AND_NOT_ONE_IN(typeElement.getQualifiedName(), method.toString()), method);
            valid = false;
        }
    }
    for (TypeMirror thrownType : method.getThrownTypes()) {
        TypeElement thrownElement = (TypeElement) ((DeclaredType) thrownType).asElement();
        if (builder.isServiceException(thrownType)) {
            builder.processError(WebserviceapMessages.WEBSERVICEAP_ONEWAY_OPERATION_CANNOT_DECLARE_EXCEPTIONS(
                    typeElement.getQualifiedName(), method.toString(), thrownElement.getQualifiedName()), method);
            valid = false;
        }
    }
    return valid;
}
 
Example #26
Source File: TestContainTypes.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.getRootElements().size() == 0) {
        return true;
    }
    if (annotations.isEmpty() || annotations.size() > 1) {
        error("no anno found/wrong number of annotations found: " + annotations.size());
    }
    TypeElement anno = (TypeElement)annotations.toArray()[0];
    Set<? extends Element> annoElems = roundEnv.getElementsAnnotatedWith(anno);
    if (annoElems.isEmpty() || annoElems.size() > 1) {
        error("no annotated element found/wrong number of annotated elements found: " + annoElems.size());
    }
    Element annoElement = (Element)annoElems.toArray()[0];
    if (!(annoElement instanceof ExecutableElement)) {
        error("annotated element must be a method");
    }
    ExecutableElement method = (ExecutableElement)annoElement;
    if (method.getParameters().size() != 2) {
        error("annotated method must have 2 arguments");
    }
    DeclaredType d1 = (DeclaredType)method.getParameters().get(0).asType();
    DeclaredType d2 = (DeclaredType)method.getParameters().get(1).asType();
    if (d1.getTypeArguments().size() != 1 ||
            d1.getTypeArguments().size() != 1) {
        error("parameter type must be generic in one type-variable");
    }
    TypeMirror t1 = d1.getTypeArguments().get(0);
    TypeMirror t2 = d2.getTypeArguments().get(0);

    if (processingEnv.getTypeUtils().contains(t1, t2) != expected) {
        error("bad type containment result\n" +
                "t1 : " + t1 +"\n" +
                "t2 : " + t2 +"\n" +
                "expected answer : " + expected +"\n");
    }
    return true;
}
 
Example #27
Source File: BeanModelBuilder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void addListProperty(ExecutableElement m, String propName) {
    FxProperty pi = new FxProperty(propName, FxDefinitionKind.LIST);
    pi.setSimple(false);
    pi.setAccessor(ElementHandle.create(m));
    
    // must extract type arguments; assume there's a DeclaredType
    DeclaredType t = ((DeclaredType)m.getReturnType());
    ExecutableType getterType = findListGetMethod(t);
    
    pi.setType(TypeMirrorHandle.create(getterType.getReturnType()));
    pi.setObservableAccessors(pi.getAccessor());
    
    registerProperty(pi);
}
 
Example #28
Source File: WebServiceVisitor.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected boolean isLegalType(TypeMirror type) {
    if (!(type != null && type.getKind().equals(TypeKind.DECLARED)))
        return true;
    TypeElement tE = (TypeElement) ((DeclaredType) type).asElement();
    if (tE == null) {
        // can be null, if this type's declaration is unknown. This may be the result of a processing error, such as a missing class file.
        builder.processError(WebserviceapMessages.WEBSERVICEAP_COULD_NOT_FIND_TYPEDECL(type.toString(), context.getRound()));
    }
    return !builder.isRemote(tE);
}
 
Example #29
Source File: HashCodeValidator.java    From epoxy with Apache License 2.0 5 votes vote down vote up
private void validateIterableType(DeclaredType declaredType) throws EpoxyProcessorException {
  for (TypeMirror typeParameter : declaredType.getTypeArguments()) {
    // check that the type implements hashCode
    try {
      validateImplementsHashCode(typeParameter);
    } catch (EpoxyProcessorException e) {
      throwError("Type in Iterable does not implement hashCode. Type: %s",
          typeParameter.toString());
    }
  }

  // Assume that the iterable class implements hashCode and just return
}
 
Example #30
Source File: InterceptorBindingsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void checkInterceptorBindings( WebBeansModel model , 
        String typeElement, String... annotationFqns) 
{
    TypeMirror mirror = model.resolveType( typeElement );
    Element clazz = ((DeclaredType)mirror).asElement();
    
    checkInterceptorBindings(model, clazz, annotationFqns);
}