當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeKind類代碼示例

本文整理匯總了Java中javax.lang.model.type.TypeKind的典型用法代碼示例。如果您正苦於以下問題:Java TypeKind類的具體用法?Java TypeKind怎麽用?Java TypeKind使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TypeKind類屬於javax.lang.model.type包,在下文中一共展示了TypeKind類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: searchInterfacesAncestry

import javax.lang.model.type.TypeKind; //導入依賴的package包/類
private boolean searchInterfacesAncestry(TypeMirror rootIface, TypeMirror target) {
  TypeElement rootIfaceElement = (TypeElement) typeUtils.asElement(rootIface);
  // check if it implements valid interfaces
  for (TypeMirror iface : rootIfaceElement.getInterfaces()) {
    TypeElement ifaceElement = (TypeElement) typeUtils.asElement(rootIface);
    while (iface.getKind() != TypeKind.NONE) {
      if (typeUtils.isSameType(iface, target)) {
        return true;
      }
      // go up
      if (searchInterfacesAncestry(iface, target)) {
        return true;
      }
      // then move on
      iface = ifaceElement.getSuperclass();
    }
  }
  return false;
}
 
開發者ID:hzsweers,項目名稱:inspector,代碼行數:20,代碼來源:InspectorFactoryProcessor.java

示例2: hint

import javax.lang.model.type.TypeKind; //導入依賴的package包/類
@TriggerPattern("$method($params$);")
public static ErrorDescription hint(HintContext ctx) {
    Element invoked = ctx.getInfo().getTrees().getElement(new TreePath(ctx.getPath(), ((ExpressionStatementTree) ctx.getPath().getLeaf()).getExpression()));

    if (invoked == null || invoked.getKind() != ElementKind.METHOD || ((ExecutableElement) invoked).getReturnType().getKind() == TypeKind.VOID) return null;

    boolean found = false;

    for (AnnotationMirror am : invoked.getAnnotationMirrors()) {
        String simpleName = am.getAnnotationType().asElement().getSimpleName().toString();

        if ("CheckReturnValue".equals(simpleName)) {
            found = true;
            break;
        }
    }

    if (!found && !checkReturnValueForJDKMethods((ExecutableElement) invoked)) return null;

    String displayName = NbBundle.getMessage(CheckReturnValueHint.class, "ERR_org.netbeans.modules.java.hints.bugs.CheckReturnValueHint");
    
    return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), displayName);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:CheckReturnValueHint.java

示例3: readOutResultsFromStub

import javax.lang.model.type.TypeKind; //導入依賴的package包/類
@Override
public void readOutResultsFromStub(VariableElement param, ParamType paramType, String paramName, MethodSpec.Builder methodBuilder) {
    if (param.asType().getKind() == TypeKind.ARRAY) {
        methodBuilder.beginControlFlow("if (" + paramName + " != null)");
        methodBuilder.addStatement("reply.writeInt(" + paramName + ".length)");
        methodBuilder.beginControlFlow("for($T item:" + paramName + " )", ((ArrayType) param.asType()).getComponentType());
        methodBuilder.addStatement("Class pClass = getParcelerClass(item)");
        methodBuilder.addStatement("reply.writeString(pClass.getName())");
        methodBuilder.addStatement("org.parceler.Parcels.wrap(pClass, item).writeToParcel(reply, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE)");
        methodBuilder.endControlFlow();
        methodBuilder.endControlFlow();
        methodBuilder.beginControlFlow("else");
        methodBuilder.addStatement("reply.writeInt(-1)");
        methodBuilder.endControlFlow();
    }
}
 
開發者ID:josesamuel,項目名稱:remoter,代碼行數:17,代碼來源:ParcelerParamBuilder.java

示例4: enumerateFields

import javax.lang.model.type.TypeKind; //導入依賴的package包/類
private static void enumerateFields( @Nonnull final TypeElement scope,
                                     @Nonnull final Types typeUtils,
                                     @Nonnull final TypeElement element,
                                     @Nonnull final Map<String, TypeMirror> fields )
{
  final TypeMirror superclass = element.getSuperclass();
  if ( TypeKind.NONE != superclass.getKind() )
  {
    enumerateFields( scope, typeUtils, (TypeElement) ( (DeclaredType) superclass ).asElement(), fields );
  }
  for ( final Element member : element.getEnclosedElements() )
  {
    if ( member.getKind() == ElementKind.FIELD )
    {
      final TypeMirror fieldType = typeUtils.asMemberOf( (DeclaredType) scope.asType(), member );
      fields.put( member.getSimpleName().toString(), fieldType );
    }
  }
}
 
開發者ID:react4j,項目名稱:react4j,代碼行數:20,代碼來源:ProcessorUtil.java

示例5: composeNewTestMethod

import javax.lang.model.type.TypeKind; //導入依賴的package包/類
/**
 */
protected MethodTree composeNewTestMethod(String testMethodName,
                                          BlockTree testMethodBody,
                                          List<ExpressionTree> throwsList,
                                          WorkingCopy workingCopy) {
    TreeMaker maker = workingCopy.getTreeMaker();
    return maker.Method(
            maker.Modifiers(createModifierSet(PUBLIC)),
            testMethodName,
            maker.PrimitiveType(TypeKind.VOID),
            Collections.<TypeParameterTree>emptyList(),
            Collections.<VariableTree>emptyList(),
            throwsList,
            testMethodBody,
            null);          //default value - used by annotations
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:JUnit3TestGenerator.java

示例6: visitClass

import javax.lang.model.type.TypeKind; //導入依賴的package包/類
public Void visitClass(ClassTree node, Boolean p) {
    TypeElement te = (TypeElement)model.getElement(node);
    if (te != null) {
        List<Tree> members = new ArrayList<Tree>();
        for(Tree m : node.getMembers())
            members.add(m);
        members.add(make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "test", make.PrimitiveType(TypeKind.INT), null));
        ClassTree decl = make.Class(node.getModifiers(), node.getSimpleName(), node.getTypeParameters(), node.getExtendsClause(), (List<ExpressionTree>)node.getImplementsClause(), members);
        model.setElement(decl, te);
        model.setType(decl, model.getType(node));
        model.setPos(decl, model.getPos(node));
        copy.rewrite(node, decl);
    }
    
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:MemberAdditionTest.java

示例7: verifyTargetType

import javax.lang.model.type.TypeKind; //導入依賴的package包/類
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);
            }
        }
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:ConvertToLambdaPreconditionChecker.java

示例8: writeParamsToProxy

import javax.lang.model.type.TypeKind; //導入依賴的package包/類
@Override
public void writeParamsToProxy(VariableElement param, ParamType paramType, MethodSpec.Builder methodBuilder) {
    if (param.asType().getKind() == TypeKind.ARRAY) {
        if (paramType == ParamType.OUT) {
            writeArrayOutParamsToProxy(param, methodBuilder);
        } else {
            methodBuilder.addStatement("data.writeTypedArray(" + param.getSimpleName() + ", 0)");
        }
    } else {
        if (paramType != ParamType.OUT) {
            methodBuilder.beginControlFlow("if (" + param.getSimpleName() + " != null)");
            methodBuilder.addStatement("data.writeInt(1)");
            methodBuilder.addStatement(param.getSimpleName() + ".writeToParcel(data, 0)");
            methodBuilder.endControlFlow();
            methodBuilder.beginControlFlow("else");
            methodBuilder.addStatement("data.writeInt(0)");
            methodBuilder.endControlFlow();
        }
    }
}
 
開發者ID:josesamuel,項目名稱:remoter,代碼行數:21,代碼來源:ParcellableParamBuilder.java

示例9: getDummyInner1

import javax.lang.model.type.TypeKind; //導入依賴的package包/類
private static PubType getDummyInner1() {
    PubMethod init = new PubMethod(setOf(),
                                   emptyList(),
                                   new PrimitiveTypeDesc(TypeKind.VOID),
                                   "<init>",
                                   emptyList(),
                                   emptyList());

    PubMethod run = new PubMethod(setOf(PUBLIC),
                                  emptyList(),
                                  new PrimitiveTypeDesc(TypeKind.VOID),
                                  "run",
                                  emptyList(),
                                  emptyList());

    PubVar field = new PubVar(setOf(PROTECTED),
                              new PrimitiveTypeDesc(TypeKind.INT),
                              "field",
                              null);

    return new PubType(setOf(STATIC),
                       "TestClass$DummyInner1",
                       new PubApi(emptyList(),
                                  asList(field),
                                  asList(init, run)));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:ApiExtraction.java

示例10: testIsPrimitive

import javax.lang.model.type.TypeKind; //導入依賴的package包/類
static int testIsPrimitive() {
    int failures = 0;
    // The eight primitive types
    Set<TypeKind> primitives = EnumSet.of(BOOLEAN,  // 1
                                          BYTE,     // 2
                                          CHAR,     // 3
                                          DOUBLE,   // 4
                                          FLOAT,    // 5
                                          INT,      // 6
                                          LONG,     // 7
                                          SHORT);   // 8

    for(TypeKind tk : TypeKind.values()) {
        boolean primitiveness;
        if ((primitiveness=tk.isPrimitive()) != primitives.contains(tk) ) {
            failures++;
            System.err.println("Unexpected isPrimitive value " + primitiveness +
                               "for " + tk);
        }
    }
    return failures;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:TestTypeKind.java

示例11: computeConditionalExpression

import javax.lang.model.type.TypeKind; //導入依賴的package包/類
private static List<? extends TypeMirror> computeConditionalExpression(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    ConditionalExpressionTree cet = (ConditionalExpressionTree) parent.getLeaf();
    
    if (cet.getCondition() == error) {
        types.add(ElementKind.PARAMETER);
        types.add(ElementKind.LOCAL_VARIABLE);
        types.add(ElementKind.FIELD);
        
        return Collections.singletonList(info.getTypes().getPrimitiveType(TypeKind.BOOLEAN));
    }
    
    if (cet.getTrueExpression() == error || cet.getFalseExpression() == error) {
        types.add(ElementKind.PARAMETER);
        types.add(ElementKind.LOCAL_VARIABLE);
        types.add(ElementKind.FIELD);
        
        return resolveType(types, info, parent.getParentPath(), cet, offset, null, null);
    }
    
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:CreateElementUtilities.java

示例12: collectInterfacesMirrors

import javax.lang.model.type.TypeKind; //導入依賴的package包/類
private void collectInterfacesMirrors(TypeMirror typeMirror, TypevarContext context) {
  if (typeMirror.getKind() != TypeKind.DECLARED) {
    return;
  }
  DeclaredType declaredType = toDeclaredType(typeMirror);
  TypeElement e = toTypeElement(declaredType);

  if (e.getKind().isInterface()) {
    implementedInterfaces.add(e);
    String stringified = stringify(declaredType, context);
    TypevarContext nestedContext = new TypevarContext(e, stringified);
    implementedInterfaceNames.add(stringified);
    for (TypeMirror m : e.getInterfaces()) {
      collectInterfacesMirrors(m, nestedContext);
    }
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:TypeHierarchyCollector.java

示例13: getTypeMoniker

import javax.lang.model.type.TypeKind; //導入依賴的package包/類
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());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:TypeMonikerFactory.java

示例14: isElementAvail

import javax.lang.model.type.TypeKind; //導入依賴的package包/類
/**
 * Copy from JavaRefactoringPlugin.
 */
private Problem isElementAvail(TreePathHandle e, CompilationInfo info) {
    if (e==null) {
        //element is null or is not valid.
        return new Problem(true, NbBundle.getMessage(FindVisitor.class, "DSC_ElNotAvail")); // NOI18N
    } else {
        Element el = e.resolveElement(info);
        String elName = el != null ? el.getSimpleName().toString() : null;
        if (el == null || el.asType().getKind() == TypeKind.ERROR || "<error>".equals(elName)) { // NOI18N
            return new Problem(true, NbBundle.getMessage(FindVisitor.class, "DSC_ElementNotResolved"));
        }
        
        if ("this".equals(elName) || "super".equals(elName)) { // NOI18N
            return new Problem(true, NbBundle.getMessage(FindVisitor.class, "ERR_CannotRefactorThis", el.getSimpleName()));
        }
        
        // element is still available
        return null;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:InvertBooleanRefactoringPlugin.java

示例15: visitWildcard

import javax.lang.model.type.TypeKind; //導入依賴的package包/類
@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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:SpringXMLConfigCompletionItem.java


注:本文中的javax.lang.model.type.TypeKind類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。