当前位置: 首页>>代码示例>>Java>>正文


Java NoType类代码示例

本文整理汇总了Java中javax.lang.model.type.NoType的典型用法代码示例。如果您正苦于以下问题:Java NoType类的具体用法?Java NoType怎么用?Java NoType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NoType类属于javax.lang.model.type包,在下文中一共展示了NoType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: eraseBound

import javax.lang.model.type.NoType; //导入依赖的package包/类
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;
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:19,代码来源:StructuralTypeEraser.java

示例2: makeNestedType

import javax.lang.model.type.NoType; //导入依赖的package包/类
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;
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:18,代码来源:SrcClassUtil.java

示例3: makeTypeVarType

import javax.lang.model.type.NoType; //导入依赖的package包/类
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() );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:19,代码来源:SrcClassUtil.java

示例4: apply

import javax.lang.model.type.NoType; //导入依赖的package包/类
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;
}
 
开发者ID:sundrio,项目名称:sundrio,代码行数:18,代码来源:ElementTo.java

示例5: isAssignable

import javax.lang.model.type.NoType; //导入依赖的package包/类
/**
 * Checks if the given {@link Element} is, implements or extends the given target type.
 * 
 * @param type the element to analyze
 * @param targetType the type to check
 * @return <code>true</code> if the given {@link Element} corresponds to a type that implements
 *         {@link List}, <code>false</code> otherwise.
 */
public static boolean isAssignable(final DeclaredType type, final Class<?> targetType) {
  if (type instanceof NoType) {
    return false;
  }
  if (type.asElement().toString().equals(targetType.getName())) {
    return true;
  }
  final TypeElement element = (TypeElement) type.asElement();
  final boolean implementation = element.getInterfaces().stream()
      .filter(interfaceMirror -> interfaceMirror.getKind() == TypeKind.DECLARED)
      .map(interfaceMirror -> (DeclaredType) interfaceMirror)
      .map(declaredInterface -> declaredInterface.asElement())
      .anyMatch(declaredElement -> declaredElement.toString().equals(targetType.getName()));
  if (implementation) {
    return true;
  }
  if (element.getSuperclass().getKind() == TypeKind.DECLARED) {
    return isAssignable((DeclaredType)(element.getSuperclass()), targetType);
  } 
  return false;
}
 
开发者ID:lambdamatic,项目名称:lambdamatic-project,代码行数:30,代码来源:ElementUtils.java

示例6: checkIfExtends

import javax.lang.model.type.NoType; //导入依赖的package包/类
/**
 * Check if the given Element extends a given type. A fully qualified name of another type
 * to check for must be given. Throws an IllegalArgumentException if Element is not an instance of
 * TypeElement. The method will recursively climb up the type hierarchy until it reaches either
 * the desired type or a root type.
 *
 * @param element   element to perform the check for
 * @param superType fully qualified name of a type
 * @return true if given element represents a type that extends another type with the given fully
 * qualified name
 * @throws java.lang.IllegalArgumentException if element is not an instance of TypeElement
 */
public static boolean checkIfExtends(Element element, String superType) {
    if (!(element instanceof TypeElement)) {
        throw new IllegalArgumentException("Can only check if TypeElement extends a certain superType");
    }

    TypeElement typeElement = (TypeElement) element;

    if (typeElement.getSuperclass() instanceof NoType) {
        return false;
    } else if (((DeclaredType) typeElement.getSuperclass()).asElement().toString().equals(superType)) {
        return true;
    } else {
        return checkIfExtends(((DeclaredType) typeElement.getSuperclass()).asElement(), superType);
    }
}
 
开发者ID:ikust,项目名称:AbstractViewAdapter,代码行数:28,代码来源:JavaLangUtils.java

示例7: instanceOf

import javax.lang.model.type.NoType; //导入依赖的package包/类
public static boolean instanceOf(Types types, TypeMirror type, String className) {
    //System.out.println("instanceOf : "+type.toString()+":"+className);
    
    String baseType = type.toString();
    if (type instanceof DeclaredType) {
        baseType = ((DeclaredType)type).asElement().toString();
    }
    //System.out.println("BaseType: "+baseType);
    
    if (baseType.equals(className)) {
        return true;
    }
    TypeElement elem = (TypeElement) types.asElement(type);
    for (TypeMirror i : elem.getInterfaces()) {
        if (instanceOf(types,i,className)) {
            return true;
        }
    }
    
    TypeMirror sup =  elem.getSuperclass();
    if (sup instanceof NoType) {
        return false;
    }
    return (instanceOf(types,sup,className));
}
 
开发者ID:rhlabs,项目名称:louie,代码行数:26,代码来源:TypeUtils.java

示例8: testAsType

import javax.lang.model.type.NoType; //导入依赖的package包/类
@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);
}
 
开发者ID:facebook,项目名称:buck,代码行数:17,代码来源:TreeBackedTypeElementTest.java

示例9: testAsTypeGeneric

import javax.lang.model.type.NoType; //导入依赖的package包/类
@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);
}
 
开发者ID:facebook,项目名称:buck,代码行数:19,代码来源:TreeBackedTypeElementTest.java

示例10: testGetDeclaredTypeTopLevelNoGenerics

import javax.lang.model.type.NoType; //导入依赖的package包/类
@Test
public void testGetDeclaredTypeTopLevelNoGenerics() throws IOException {
  compile("class Foo { }");

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

  assertEquals(TypeKind.DECLARED, fooTypeMirror.getKind());
  DeclaredType fooDeclaredType = (DeclaredType) 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);
}
 
开发者ID:facebook,项目名称:buck,代码行数:18,代码来源:TreeBackedTypesTest.java

示例11: testGetDeclaredTypeTopLevelRawType

import javax.lang.model.type.NoType; //导入依赖的package包/类
@Test
public void testGetDeclaredTypeTopLevelRawType() throws IOException {
  compile("class Foo<T> { }");

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

  assertEquals(TypeKind.DECLARED, fooTypeMirror.getKind());
  DeclaredType fooDeclaredType = (DeclaredType) 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);
}
 
开发者ID:facebook,项目名称:buck,代码行数:18,代码来源:TreeBackedTypesTest.java

示例12: getMethods

import javax.lang.model.type.NoType; //导入依赖的package包/类
private Set<MethodSpec> getMethods(Types typeUtils) {
    Set<MethodSpec> methods = new HashSet<>();

    MethodSpec constructor = MethodSpec.constructorBuilder()
            .addModifiers(Modifier.PUBLIC)
            .addParameter(classTypeName, MEMBER_FIELD_NAME)
            .addStatement("this.$N = $N", MEMBER_FIELD_NAME, MEMBER_FIELD_NAME)
            .build();

    methods.add(constructor);

    Set<Element> allElements = new HashSet<>();
    allElements.addAll(element.getEnclosedElements());
    for (TypeMirror typeMirror : element.getInterfaces()) {
        allElements.addAll(typeUtils.asElement(typeMirror).getEnclosedElements());
    }

    for (Element e : allElements) {
        if (!(e instanceof ExecutableElement)) {
            continue;
        }
        ExecutableElement method = (ExecutableElement) e;
        String methodName = method.getSimpleName().toString();
        if ("<init>".equals(methodName)) { // skip constructors
            continue;
        }
        Set<Modifier> modifiers = new HashSet<>(method.getModifiers());
        if (modifiers.contains(Modifier.PRIVATE)
                || modifiers.contains(Modifier.STATIC)
                || modifiers.contains(Modifier.FINAL)) {
            continue;
        }
        modifiers.remove(Modifier.ABSTRACT);
        modifiers.add(Modifier.SYNCHRONIZED);

        MethodSpec.Builder spec = MethodSpec.methodBuilder(methodName)
                .addModifiers(modifiers);

        List<? extends TypeMirror> thrownTypes = method.getThrownTypes();
        for (TypeMirror throwable : thrownTypes) {
            spec = spec.addException(TypeName.get(throwable));
        }

        String arguments = "";
        List<? extends VariableElement> parameters = method.getParameters();
        for (VariableElement parameter : parameters) {
            arguments += parameter.getSimpleName().toString();
            if (parameters.indexOf(parameter) != parameters.size() - 1) {
                arguments += ", ";
            }
            spec.addParameter(ParameterSpec.get(parameter));
        }

        if (method.getReturnType() instanceof NoType) {
            spec = spec.addStatement("$N.$N($L)", MEMBER_FIELD_NAME, methodName, arguments);
        } else {
            spec = spec.addStatement("return $N.$N($L)", MEMBER_FIELD_NAME, methodName, arguments)
                    .returns(TypeName.get(method.getReturnType()));
        }

        methods.add(spec.build());
    }
    return methods;
}
 
开发者ID:egor-n,项目名称:SyncGenerator,代码行数:65,代码来源:AnnotatedType.java

示例13: getSuperClassForDataBinding

import javax.lang.model.type.NoType; //导入依赖的package包/类
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;
}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:35,代码来源:DataBindingAnnotationProcessor.java

示例14: asNoType

import javax.lang.model.type.NoType; //导入依赖的package包/类
/**
 * 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");
}
 
开发者ID:foodora,项目名称:android-auto-mapper,代码行数:13,代码来源:MoreTypes.java

示例15: hasPotentialMethod

import javax.lang.model.type.NoType; //导入依赖的package包/类
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;
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:29,代码来源:StructuralTypeProxyGenerator.java


注:本文中的javax.lang.model.type.NoType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。