本文整理汇总了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;
}
示例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);
}
示例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();
}
}
示例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 );
}
}
}
示例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
}
示例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;
}
示例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);
}
}
}
示例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();
}
}
}
示例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)));
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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());
}
示例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;
}
}
示例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;
}