javax.lang.model.type.NoType Java Examples

The following examples show how to use javax.lang.model.type.NoType. 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 Project: data-mediator   Author: LightSun   File: BaseGenerator.java    License: Apache License 2.0 6 votes vote down vote up
private TypeElement getSuperInterfaceImpl(TypeMirror tm, GroupPropertyGenerator.TypeElementDelegate delegate) {
    String superName = tm.toString();
    if(tm instanceof NoType){
        //no super.
    }else if(superName.startsWith("java.") || superName.startsWith("android.")){
        // no super too.
    }else {
        TypeElement newTe = new FieldData.TypeCompat(getTypes(), tm).getElementAsType();
        TypeElement ele = delegate.get(superName);
        if(ele == null){
            if(hasAnnotation(newTe)){
                return newTe;
            }
            return getSuperInterface(newTe, delegate);
        }else {
            return newTe;
        }
    }
    return null;
}
 
Example #2
Source Project: manifold   Author: manifold-systems   File: StructuralTypeEraser.java    License: Apache License 2.0 6 votes vote down vote up
private Type eraseBound( Type t, Type bound )
{
  if( bound == null || bound instanceof NoType )
  {
    return bound;
  }

  Type erasedBound;
  if( bound.contains( t ) )
  {
    erasedBound = visit( _types.erasure( bound ) );
  }
  else
  {
    erasedBound = visit( bound );
  }
  return erasedBound;
}
 
Example #3
Source Project: manifold   Author: manifold-systems   File: SrcClassUtil.java    License: Apache License 2.0 6 votes vote down vote up
private SrcType makeNestedType( Type type )
{
  String fqn = type.toString();
  Type enclosingType = type.getEnclosingType();
  SrcType srcType;
  if( enclosingType != null && !(enclosingType instanceof NoType) && fqn.length() > enclosingType.toString().length() )
  {
    String simpleName = fqn.substring( enclosingType.toString().length() + 1 );
    srcType = new SrcType( simpleName );
    srcType.setEnclosingType( makeNestedType( enclosingType ) );
  }
  else
  {
    srcType = new SrcType( fqn );
  }
  return srcType;
}
 
Example #4
Source Project: manifold   Author: manifold-systems   File: SrcClassUtil.java    License: Apache License 2.0 6 votes vote down vote up
private SrcType makeTypeVarType( Symbol.TypeVariableSymbol typeVar )
{
  StringBuilder sb = new StringBuilder( typeVar.type.toString() );
  Type lowerBound = typeVar.type.getLowerBound();
  if( lowerBound != null && !(lowerBound instanceof NullType) )
  {
    sb.append( " super " ).append( lowerBound.toString() );
  }
  else
  {
    Type upperBound = typeVar.type.getUpperBound();
    if( upperBound != null && !(upperBound instanceof NoType) && !upperBound.toString().equals( Object.class.getName() ) )
    {
      sb.append( " extends " ).append( upperBound.toString() );
    }
  }
  return new SrcType( sb.toString() );
}
 
Example #5
Source Project: sundrio   Author: sundrio   File: ElementTo.java    License: Apache License 2.0 6 votes vote down vote up
public TypeRef apply(TypeMirror item) {
    if (item instanceof NoType) {
        return new VoidRef();
    }

    Element element = CodegenContext.getContext().getTypes().asElement(item);
    TypeDef known = element != null ? CodegenContext.getContext().getDefinitionRepository().getDefinition(element.toString()) : null;

    if (known == null && element instanceof TypeElement) {
        known = TYPEDEF.apply((TypeElement) element);
    }
    TypeRef typeRef = item.accept(new TypeRefTypeVisitor(), 0);
    if (typeRef instanceof ClassRef && known != null) {
        return new ClassRefBuilder((ClassRef) typeRef).withDefinition(known).build();
    }
    return typeRef;
}
 
Example #6
Source Project: buck   Author: facebook   File: TreeBackedTypeElementTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAsType() throws IOException {
  compile("class Foo { }");

  TypeElement fooElement = elements.getTypeElement("Foo");
  TypeMirror fooTypeMirror = fooElement.asType();

  assertEquals(TypeKind.DECLARED, fooTypeMirror.getKind());
  DeclaredType fooDeclaredType = (DeclaredType) fooTypeMirror;
  assertSame(fooElement, fooDeclaredType.asElement());
  assertEquals(0, fooDeclaredType.getTypeArguments().size());

  TypeMirror enclosingType = fooDeclaredType.getEnclosingType();
  assertEquals(TypeKind.NONE, enclosingType.getKind());
  assertTrue(enclosingType instanceof NoType);
}
 
Example #7
Source Project: buck   Author: facebook   File: TreeBackedTypeElementTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAsTypeGeneric() throws IOException {
  compile("class Foo<T> { }");

  TypeElement fooElement = elements.getTypeElement("Foo");
  TypeMirror fooTypeMirror = fooElement.asType();

  assertEquals(TypeKind.DECLARED, fooTypeMirror.getKind());
  DeclaredType fooDeclaredType = (DeclaredType) fooTypeMirror;
  assertSame(fooElement, fooDeclaredType.asElement());
  List<? extends TypeMirror> typeArguments = fooDeclaredType.getTypeArguments();
  assertEquals("T", ((TypeVariable) typeArguments.get(0)).asElement().getSimpleName().toString());
  assertEquals(1, typeArguments.size());

  TypeMirror enclosingType = fooDeclaredType.getEnclosingType();
  assertEquals(TypeKind.NONE, enclosingType.getKind());
  assertTrue(enclosingType instanceof NoType);
}
 
Example #8
Source Project: buck   Author: facebook   File: TreeBackedTypesTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDeclaredTypeTopLevelNoGenerics() throws IOException {
  compile("class Foo { }");

  TypeElement fooElement = elements.getTypeElement("Foo");
  DeclaredType fooTypeMirror = types.getDeclaredType(fooElement);

  assertEquals(TypeKind.DECLARED, fooTypeMirror.getKind());
  DeclaredType fooDeclaredType = fooTypeMirror;
  assertNotSame(fooElement.asType(), fooDeclaredType);
  assertSame(fooElement, fooDeclaredType.asElement());
  assertEquals(0, fooDeclaredType.getTypeArguments().size());

  TypeMirror enclosingType = fooDeclaredType.getEnclosingType();
  assertEquals(TypeKind.NONE, enclosingType.getKind());
  assertTrue(enclosingType instanceof NoType);
}
 
Example #9
Source Project: buck   Author: facebook   File: TreeBackedTypesTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDeclaredTypeTopLevelRawType() throws IOException {
  compile("class Foo<T> { }");

  TypeElement fooElement = elements.getTypeElement("Foo");
  DeclaredType fooTypeMirror = types.getDeclaredType(fooElement);

  assertEquals(TypeKind.DECLARED, fooTypeMirror.getKind());
  DeclaredType fooDeclaredType = fooTypeMirror;
  assertNotSame(fooElement.asType(), fooDeclaredType);
  assertSame(fooElement, fooDeclaredType.asElement());
  assertEquals(0, fooDeclaredType.getTypeArguments().size());

  TypeMirror enclosingType = fooDeclaredType.getEnclosingType();
  assertEquals(TypeKind.NONE, enclosingType.getKind());
  assertTrue(enclosingType instanceof NoType);
}
 
Example #10
Source Project: data-mediator   Author: LightSun   File: DataBindingAnnotationProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private TypeElement getSuperClassForDataBinding(TypeElement te) {
    TypeMirror superclass = te.getSuperclass();
    String superName = superclass.toString();
    if(superclass instanceof NoType){
        //no super.
    }else if(superName.startsWith("java.") || superName.startsWith("android.")){
        // no super too.
    }else{
        TypeElement newTe = new FieldData.TypeCompat(mContext.getTypes(), superclass).getElementAsType();
        DataBindingInfo info = mInfoMap.get(superName);
        if(info == null){
            //-------------- handle cross modules ------------
            //by class annotation
            if(hasDataBindingClassAnnotation(newTe)){
                return newTe;
            }
            //by field annotation
            List<VariableElement> elements = ElementFilter.fieldsIn(newTe.getEnclosedElements());
            if(elements.size() > 0){
                for(VariableElement ve: elements){
                    if(hasDataBindingFieldAnnotation(ve)){
                        return newTe;
                    }
                }
            }
            //may super's N class is using data-binding
            return getSuperClassForDataBinding(newTe);
        }else{
            //found
            return newTe;
        }
    }
    return null;
}
 
Example #11
Source Project: qpid-broker-j   Author: apache   File: PluggableProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private Set<String> getPluggableTypes(final TypeElement classElement)
{

    final Set<String> types = new HashSet<>();

    List<? extends TypeMirror> interfaces = classElement.getInterfaces();
    for(TypeMirror typeMirror : interfaces)
    {
        TypeElement interfaceElt = (TypeElement) processingEnv.getTypeUtils().asElement(typeMirror);
        if(interfaceElt.getQualifiedName().toString().equals("org.apache.qpid.server.plugin.Pluggable"))
        {
            types.add(classElement.getQualifiedName().toString());
        }
        else
        {
            types.addAll(getPluggableTypes(interfaceElt));
        }

    }
    TypeMirror superClass = classElement.getSuperclass();
    if(!(superClass instanceof NoType))
    {
        types.addAll(getPluggableTypes((TypeElement) processingEnv.getTypeUtils().asElement(superClass)));
    }

    return types;
}
 
Example #12
Source Project: manifold   Author: manifold-systems   File: StructuralTypeProxyGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private boolean hasPotentialMethod( Symbol.ClassSymbol rootClassSymbol, String name, int paramCount )
{
  if( rootClassSymbol == null || rootClassSymbol instanceof NoType )
  {
    return false;
  }

  for( Symbol member : IDynamicJdk.instance().getMembers( rootClassSymbol, e -> e.flatName().toString().equals( name ) ) )
  {
    Symbol.MethodSymbol methodSym = (Symbol.MethodSymbol)member;
    if( methodSym.getParameters().size() == paramCount )
    {
      return true;
    }
  }
  if( hasPotentialMethod( (Symbol.ClassSymbol)rootClassSymbol.getSuperclass().tsym, name, paramCount ) )
  {
    return true;
  }
  for( Type iface : rootClassSymbol.getInterfaces() )
  {
    if( hasPotentialMethod( (Symbol.ClassSymbol)iface.tsym, name, paramCount ) )
    {
      return true;
    }
  }
  return false;
}
 
Example #13
Source Project: turbine   Author: google   File: TurbineTypes.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public NoType getNoType(TypeKind kind) {
  switch (kind) {
    case VOID:
      return (NoType) factory.asTypeMirror(Type.VOID);
    case NONE:
      return factory.noType();
    default:
      throw new IllegalArgumentException(kind.toString());
  }
}
 
Example #14
Source Project: copybara   Author: google   File: MarkdownGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private List<? extends Element> findStarlarkMethods(TypeElement module) {
  TypeMirror superclass = module.getSuperclass();
  ImmutableList.Builder<Element> result = ImmutableList.builder();
  if (!(superclass instanceof NoType)) {
    Element element = processingEnv.getTypeUtils().asElement(superclass);
    if (element instanceof TypeElement) {
      result.addAll(findStarlarkMethods((TypeElement) element));
    }
  }
  result.addAll(module.getEnclosedElements().stream().filter(member -> {
    AnnotationHelper<StarlarkMethod> ann = annotationHelper(member, StarlarkMethod.class);
    return ann != null && member instanceof ExecutableElement && ann.ann.documented();
  }).collect(Collectors.toList()));
  return result.build();
}
 
Example #15
Source Project: auto-parcel   Author: aitorvs   File: MoreTypes.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link NoType} if the {@link TypeMirror} represents an non-type such
 * as void, or package, etc. or throws an {@link IllegalArgumentException}.
 */
public static NoType asNoType(TypeMirror maybeNoType) {
    return maybeNoType.accept(new CastingTypeVisitor<NoType>() {
        @Override
        public NoType visitNoType(NoType noType, String p) {
            return noType;
        }
    }, "non-type");
}
 
Example #16
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: Factory.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public NoType getNoType(TypeKind kind)
{
	switch (kind) {
	case NONE:
		return NoTypeImpl.NO_TYPE_NONE;
	case VOID:
		return NoTypeImpl.NO_TYPE_VOID;
	case PACKAGE:
		return NoTypeImpl.NO_TYPE_PACKAGE;
	default:
		throw new IllegalArgumentException();
	}
}
 
Example #17
Source Project: AnnotatedAdapter   Author: sockeqwe   File: AdapterInfo.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Checks if this AnnotatedAdapter has another AnnotatedAdapter as super class. Therfore the
 * binder interface must extends from this one.
 */
public AdapterInfo getAnnotatedAdapterSuperClass(Map<String, AdapterInfo> adaptersMap) {

  if (searchedForSuperAnnotatedAdapterClass) {
    return superAnnotatedAdapterClass;
  }

  searchedForSuperAnnotatedAdapterClass = true;

  // Search from bottom up along inheritance three for the fist Annotated adapter class we find
  TypeElement currentClass = adapterClass;

  while (currentClass != null) {
    TypeMirror currentMirror = currentClass.getSuperclass();

    if (currentMirror instanceof NoType || currentMirror.getKind() == TypeKind.NONE) {
      // java.lang.Object has been found, there is no other super class
      return null;
    }

    AdapterInfo superAdapter = adaptersMap.get(currentMirror.toString());
    if (superAdapter != null) {
      // "Cache" the found super class for performance reasons
      superAnnotatedAdapterClass = superAdapter;
      return superAnnotatedAdapterClass;
    }

    // Continue with the super class
    currentClass = elementUtils.getTypeElement(currentMirror.toString());
  }

  return null;
}
 
Example #18
Source Project: revapi   Author: revapi   File: Util.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final T visitNoType(NoType t, StringBuilderAndState<S> st) {
    try {
        st.depth++;
        return doVisitNoType(t, st);
    } finally {
        st.depth--;
    }
}
 
Example #19
Source Project: revapi   Author: revapi   File: Util.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Void visitNoType(NoType t, StringBuilderAndState<TypeMirror> state) {
    switch (t.getKind()) {
    case VOID:
        state.bld.append("void");
        break;
    case PACKAGE:
        state.bld.append("package");
        break;
    default:
        break;
    }

    return null;
}
 
Example #20
Source Project: revapi   Author: revapi   File: Util.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Void doVisitNoType(NoType t, StringBuilderAndState<TypeMirror> state) {
    switch (t.getKind()) {
    case VOID:
        state.bld.append("void");
        break;
    case PACKAGE:
        state.bld.append("package");
        break;
    default:
        break;
    }

    return null;
}
 
Example #21
Source Project: cathode   Author: SimonVT   File: JobProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private boolean isJob(Element element) {
  TypeMirror superType = ((TypeElement) element).getSuperclass();
  while (!(superType instanceof NoType)) {
    Element superTypeElement = ((DeclaredType) superType).asElement();
    if (JOB.equals(ClassName.get(superTypeElement.asType()))) {
      return true;
    }

    superType = ((TypeElement) superTypeElement).getSuperclass();
  }

  return false;
}
 
Example #22
Source Project: buck   Author: facebook   File: StandaloneTypeMirror.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
  switch (kind) {
    case BOOLEAN:
    case BYTE:
    case SHORT:
    case INT:
    case LONG:
    case CHAR:
    case FLOAT:
    case DOUBLE:
      return v.visitPrimitive((PrimitiveType) this, p);
    case PACKAGE:
    case VOID:
    case NONE:
      return v.visitNoType((NoType) this, p);
    case NULL:
      return v.visitNull((NullType) this, p);
    case ARRAY:
      return v.visitArray((ArrayType) this, p);
    case DECLARED:
      return v.visitDeclared((DeclaredType) this, p);
    case ERROR:
      return v.visitError((ErrorType) this, p);
    case TYPEVAR:
      return v.visitTypeVariable((TypeVariable) this, p);
    case WILDCARD:
      return v.visitWildcard((WildcardType) this, p);
    case EXECUTABLE:
      return v.visitExecutable((ExecutableType) this, p);
    case OTHER:
      return v.visit(this, p);
    case UNION:
      return v.visitUnion((UnionType) this, p);
    case INTERSECTION:
      return v.visitIntersection((IntersectionType) this, p);
    default:
      throw new AssertionError(String.format("Unknown TypeKind: %s", kind));
  }
}
 
Example #23
Source Project: buck   Author: facebook   File: SignatureFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Void visitNoType(NoType t, SignatureVisitor visitor) {
  if (t.getKind() == TypeKind.VOID) {
    visitor.visitBaseType(descriptorFactory.getDescriptor(t).charAt(0));
    return null;
  }

  return defaultAction(t, visitor);
}
 
Example #24
Source Project: auto   Author: google   File: MoreTypes.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Boolean visitNoType(NoType noType, Void p) {
  if (noType.getKind().equals(TypeKind.VOID)) {
    return clazz.equals(Void.TYPE);
  }
  throw new IllegalArgumentException(noType + " cannot be represented as a Class<?>.");
}
 
Example #25
Source Project: java   Author: tensorflow   File: OperatorProcessor.java    License: Apache License 2.0 4 votes vote down vote up
private MethodSpec buildOpMethod(
    String methodName, TypeElement opClass, ExecutableElement endpointMethod,
    boolean describeByClass, boolean deprecated) {
  MethodSpec.Builder builder =
      MethodSpec.methodBuilder(methodName)
          .addModifiers(Modifier.PUBLIC)
          .returns(TypeName.get(endpointMethod.getReturnType()))
          .varargs(endpointMethod.isVarArgs())
          .addJavadoc("$L", buildOpMethodJavadoc(opClass, endpointMethod, describeByClass));

  if (deprecated) {
    builder.addAnnotation(Deprecated.class);
  }
  for (TypeParameterElement tp : endpointMethod.getTypeParameters()) {
    TypeVariableName tvn = TypeVariableName.get((TypeVariable) tp.asType());
    builder.addTypeVariable(tvn);
  }
  for (TypeMirror thrownType : endpointMethod.getThrownTypes()) {
    builder.addException(TypeName.get(thrownType));
  }
  StringBuilder call = new StringBuilder();
  if (!NoType.class.isAssignableFrom(endpointMethod.getReturnType().getClass())) {
    call.append("return ");
  }
  call.append("$T.")
    .append(endpointMethod.getSimpleName())
    .append("(scope");
  boolean first = true;
  for (VariableElement param : endpointMethod.getParameters()) {
    ParameterSpec p = ParameterSpec.get(param);
    if (first) {
      first = false;
      continue;
    }
    call.append(", ");
    call.append(p.name);
    builder.addParameter(p);
  }
  call.append(")");
  builder.addStatement(call.toString(), ClassName.get(opClass));
  return builder.build();
}
 
Example #26
Source Project: TencentKona-8   Author: Tencent   File: WebServiceVisitor.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Boolean visitNoType(NoType t, Void o) {
    return true;
}
 
Example #27
Source Project: TencentKona-8   Author: Tencent   File: MakeSafeTypeVisitor.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public TypeMirror visitNoType(NoType type, Types types) {
    return type;
}
 
Example #28
Source Project: jdk8u60   Author: chenghanpeng   File: WebServiceVisitor.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Boolean visitNoType(NoType t, Void o) {
    return true;
}
 
Example #29
Source Project: jdk8u60   Author: chenghanpeng   File: MakeSafeTypeVisitor.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public TypeMirror visitNoType(NoType type, Types types) {
    return type;
}
 
Example #30
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: WebServiceVisitor.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Boolean visitNoType(NoType t, Void o) {
    return true;
}