本文整理匯總了Java中javax.lang.model.type.TypeMirror.getKind方法的典型用法代碼示例。如果您正苦於以下問題:Java TypeMirror.getKind方法的具體用法?Java TypeMirror.getKind怎麽用?Java TypeMirror.getKind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.lang.model.type.TypeMirror
的用法示例。
在下文中一共展示了TypeMirror.getKind方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createCompleter
import javax.lang.model.type.TypeMirror; //導入方法依賴的package包/類
@Override
public Completer createCompleter(CompletionContext ctx) {
FxProperty p = ctx.getEnclosingProperty();
if (p == null || p.getType() == null) {
return null;
}
TypeMirror m = p.getType().resolve(ctx.getCompilationInfo());
if (m.getKind() == TypeKind.BOOLEAN) {
return new EnumValueCompleter(ctx);
}
if (m.getKind() != TypeKind.DECLARED) {
return null;
}
DeclaredType t = (DeclaredType)m;
TypeElement tel = (TypeElement)t.asElement();
if (tel.getQualifiedName().contentEquals("java.lang.Boolean")) {
return new EnumValueCompleter(ctx);
}
if (tel.getKind() == ElementKind.ENUM) {
return new EnumValueCompleter(ctx, tel);
} else {
return null;
}
}
示例2: MethodItem
import javax.lang.model.type.TypeMirror; //導入方法依賴的package包/類
public MethodItem(int substitutionOffset, ExecutableElement element, boolean isInherited, boolean isDeprecated) {
super(substitutionOffset);
this.elementHandle = ElementHandle.create(element);
this.isDeprecated = isDeprecated;
this.isInherited = isInherited;
this.simpleName = element.getSimpleName().toString();
this.modifiers = element.getModifiers();
this.params = new ArrayList<ParamDesc>();
Iterator<? extends VariableElement> it = element.getParameters().iterator();
Iterator<? extends TypeMirror> tIt = ((ExecutableType) element.asType()).getParameterTypes().iterator();
while(it.hasNext() && tIt.hasNext()) {
TypeMirror tm = tIt.next();
this.params.add(new ParamDesc(tm.toString(), getTypeName(tm, false, element.isVarArgs() && !tIt.hasNext()).toString(), it.next().getSimpleName().toString()));
}
TypeMirror retType = element.getReturnType();
this.typeName = getTypeName(retType, false).toString();
this.isPrimitive = retType.getKind().isPrimitive() || retType.getKind() == TypeKind.VOID;
}
示例3: isIterbale
import javax.lang.model.type.TypeMirror; //導入方法依賴的package包/類
private boolean isIterbale(ExpressionTree expression) {
TypeMirror tm = workingCopy.getTrees().getTypeMirror(TreePath.getPath(workingCopy.getCompilationUnit(), expression));
if (!Utilities.isValidType(tm)) {
return false;
}
if (tm.getKind() == TypeKind.ARRAY) {
return false;
} else {
tm = workingCopy.getTypes().erasure(tm);
TypeElement typeEl = workingCopy.getElements().getTypeElement("java.util.Collection");
if (typeEl != null) {
TypeMirror collection = typeEl.asType();
collection = workingCopy.getTypes().erasure(collection);
if (this.workingCopy.getTypes().isSubtype(tm, collection)) {
return true;
}
}
}
return false;
}
示例4: isOfKindAndType
import javax.lang.model.type.TypeMirror; //導入方法依賴的package包/類
private boolean isOfKindAndType(TypeMirror type, Element e, EnumSet<ElementKind> kinds, TypeMirror base, Scope scope, Trees trees, Types types) {
if (type.getKind() != TypeKind.ERROR && kinds.contains(e.getKind())) {
if (base == null)
return true;
if (types.isSubtype(type, base))
return true;
}
if ((e.getKind().isClass() || e.getKind().isInterface()) &&
(kinds.contains(ANNOTATION_TYPE) || kinds.contains(CLASS) || kinds.contains(ENUM) || kinds.contains(INTERFACE))) {
DeclaredType dt = (DeclaredType)e.asType();
for (Element ee : e.getEnclosedElements())
if (trees.isAccessible(scope, ee, dt) && isOfKindAndType(ee.asType(), ee, kinds, base, scope, trees, types))
return true;
}
return false;
}
示例5: CreateEnumConstant
import javax.lang.model.type.TypeMirror; //導入方法依賴的package包/類
public CreateEnumConstant(CompilationInfo info, String name, Set<Modifier> modifiers, TypeElement target, TypeMirror proposedType, FileObject targetFile) {
this.name = name;
this.inFQN = target.getQualifiedName().toString();
this.cpInfo = info.getClasspathInfo();
this.targetFile = targetFile;
this.target = ElementHandle.create(target);
if (proposedType.getKind() == TypeKind.NULL) {
TypeElement tel = info.getElements().getTypeElement("java.lang.Object"); // NOI18N
if (tel != null) {
proposedType = tel.asType();
this.proposedType = TypeMirrorHandle.create(proposedType);
} else {
this.proposedType = null;
}
} else {
this.proposedType = TypeMirrorHandle.create(proposedType);
}
}
示例6: resolveTypeName
import javax.lang.model.type.TypeMirror; //導入方法依賴的package包/類
/**
* uses FQNs where possible since javadoc does not match imports for
* parameter types
*/
private CharSequence resolveTypeName(TypeMirror asType, boolean isVarArgs) {
CharSequence ptype;
if (asType.getKind() == TypeKind.DECLARED) {
// snip generics
Element e = ((DeclaredType) asType).asElement();
ptype = e.getKind().isClass() || e.getKind().isInterface()
? ((TypeElement) e).getQualifiedName()
: e.getSimpleName();
} else if (asType.getKind() == TypeKind.TYPEVAR) {
do {
// Type Erasure JLS 4.6
asType = ((TypeVariable) asType).getUpperBound();
} while (asType.getKind() == TypeKind.TYPEVAR);
ptype = resolveTypeName(asType, isVarArgs);
} else if (isVarArgs && asType.getKind() == TypeKind.ARRAY) {
ptype = resolveTypeName(((ArrayType)asType).getComponentType(), false) + "..."; //NOI18N
} else {
ptype = asType.toString();
}
return ptype;
}
示例7: checkBinaryOp
import javax.lang.model.type.TypeMirror; //導入方法依賴的package包/類
private static boolean checkBinaryOp(CompilationInfo ci, TreePath expr, Tree prev) {
BinaryTree bt = (BinaryTree)expr.getLeaf();
Tree other = prev == bt.getLeftOperand() ? bt.getRightOperand() : bt.getLeftOperand();
Boolean b = checkTwoArguments(ci, expr, other, prev);
if (Boolean.TRUE == b) {
return true;
}
if (b == null) {
return false;
}
TypeMirror tm = ci.getTrees().getTypeMirror(new TreePath(expr, other));
if (tm != null && tm.getKind() == TypeKind.DECLARED) {
Element el = ((DeclaredType)tm).asElement();
if (el != null && el.getKind() == ElementKind.CLASS) {
return ((TypeElement)el).getQualifiedName().contentEquals("java.lang.String"); // NOI18N
}
}
return false;
}
示例8: lambda2Class
import javax.lang.model.type.TypeMirror; //導入方法依賴的package包/類
@Hint(displayName="#DN_lambda2Class", description="#DESC_lambda2Class", category="suggestions", hintKind=Hint.Kind.ACTION,
minSourceVersion = "8")
@Messages({
"DN_lambda2Class=Convert Lambda Expression to Anonymous Innerclass",
"DESC_lambda2Class=Converts lambda expressions to anonymous inner classes",
"ERR_lambda2Class=Anonymous class can be used"
})
@TriggerTreeKind(Kind.LAMBDA_EXPRESSION)
public static ErrorDescription lambda2Class(HintContext ctx) {
TypeMirror samType = ctx.getInfo().getTrees().getTypeMirror(ctx.getPath());
if (samType == null || samType.getKind() != TypeKind.DECLARED) {
return null;
}
return ErrorDescriptionFactory.forTree(ctx, ctx.getPath(), Bundle.ERR_lambda2Class(), new Lambda2Anonymous(ctx.getInfo(), ctx.getPath()).toEditorFix());
}
示例9: toString
import javax.lang.model.type.TypeMirror; //導入方法依賴的package包/類
String toString(TypeMirror bound) {
if (bound.getKind() == TypeKind.TYPEVAR) {
TypeVariable var = (TypeVariable) bound;
return toString(var.asElement());
}
return bound.toString();
}
示例10: getCodeToPopulatePkField
import javax.lang.model.type.TypeMirror; //導入方法依賴的package包/類
public String getCodeToPopulatePkField(TypeElement type, ExecutableElement pkAccessorMethod) {
EmbeddedPkSupportInfo info = getInfo(type);
String code = info.getCodeToPopulatePkField(pkAccessorMethod);
if (code != null) {
return code;
}
code = "";
ExecutableElement relationshipMethod = info.getRelationshipMethod(pkAccessorMethod);
String referencedColumnName = info.getReferencedColumnName(pkAccessorMethod);
if (relationshipMethod == null || referencedColumnName == null) {
info.putCodeToPopulatePkField(pkAccessorMethod, code);
return code;
}
TypeMirror relationshipTypeMirror = relationshipMethod.getReturnType();
if (TypeKind.DECLARED != relationshipTypeMirror.getKind()) {
info.putCodeToPopulatePkField(pkAccessorMethod, code);
return code;
}
DeclaredType declaredType = (DeclaredType) relationshipTypeMirror;
TypeElement relationshipType = (TypeElement) declaredType.asElement();
EmbeddedPkSupportInfo relatedInfo = getInfo(relationshipType);
String accessorString = relatedInfo.getAccessorString(referencedColumnName);
if (accessorString == null) {
info.putCodeToPopulatePkField(pkAccessorMethod, code);
return code;
}
code = relationshipMethod.getSimpleName().toString() + "()." + accessorString;
info.putCodeToPopulatePkField(pkAccessorMethod, code);
return code;
}
示例11: conditions2Constraints
import javax.lang.model.type.TypeMirror; //導入方法依賴的package包/類
private static Map<String, TypeMirror> conditions2Constraints(CompilationInfo info, List<Condition> conditions) {
Map<String, TypeMirror> constraints = new HashMap<String, TypeMirror>();
for (Entry<String, String> e : org.netbeans.modules.java.hints.declarative.Utilities.conditions2Constraints(conditions).entrySet()) {
TypeMirror designedType = Hacks.parseFQNType(info, e.getValue());
if (designedType == null || designedType.getKind() == TypeKind.ERROR) {
continue ;
}
constraints.put(e.getKey(), designedType);
}
return constraints;
}
示例12: asMemberOf
import javax.lang.model.type.TypeMirror; //導入方法依賴的package包/類
private static TypeMirror asMemberOf(Element element, TypeMirror type, Types types) {
TypeMirror ret = element.asType();
TypeMirror enclType = element.getEnclosingElement().asType();
if (enclType.getKind() == TypeKind.DECLARED)
enclType = types.erasure(enclType);
while(type != null && type.getKind() == TypeKind.DECLARED) {
if (types.isSubtype(type, enclType)) {
ret = types.asMemberOf((DeclaredType)type, element);
break;
}
type = ((DeclaredType)type).getEnclosingType();
}
return ret;
}
示例13: canContainArrays
import javax.lang.model.type.TypeMirror; //導入方法依賴的package包/類
/**
* Determines whether the array can contain other arrays. Checks if the component type is an array type.
* Otherwise, checks whether the component type is a declared one, and that it is an Object. Other declared
* types cannot hold array references.
*
* @param ci context
* @param tp path to the array expression
* @return true, if the expression (assuming array type) can hold other arrays as members
*/
static boolean canContainArrays(CompilationInfo ci, TreePath tp) {
TypeMirror tm = ci.getTrees().getTypeMirror(tp);
if (!Utilities.isValidType(tm)) {
return false;
}
tm = ci.getTypes().erasure(tm);
if (tm == null || tm.getKind() != TypeKind.ARRAY) {
return false;
}
ArrayType arrayType = (ArrayType)tm;
TypeMirror ct = arrayType.getComponentType();
boolean enableDeep = false;
if (ct.getKind() == TypeKind.ARRAY) {
// if the component kind is known to be an array, enable deepHash
enableDeep = true;
} else if (ct.getKind() == TypeKind.DECLARED) {
Element obj = ci.getElements().getTypeElement("java.lang.Object"); // NOI18N
if (obj == null) {
return false;
}
// other ref types than Object cannot hold array instances, deepHash is a nonsense
enableDeep = ci.getTypes().isSameType(obj.asType(), ct);
}
return enableDeep;
}
示例14: readResultsFromStub
import javax.lang.model.type.TypeMirror; //導入方法依賴的package包/類
@Override
public void readResultsFromStub(TypeMirror resultType, MethodSpec.Builder methodBuilder) {
if (resultType.getKind() == TypeKind.ARRAY) {
methodBuilder.addStatement("reply.writeDoubleArray(result)");
} else {
methodBuilder.addStatement("reply.writeDouble(result)");
}
}
示例15: assignableToSomeType
import javax.lang.model.type.TypeMirror; //導入方法依賴的package包/類
private static boolean assignableToSomeType(CompilationInfo info, TypeMirror theValue, Collection<? extends TypeMirror> alternatives) {
for (TypeMirror target : alternatives) {
if (target.getKind() == TypeKind.VOID) {
return true;
}
if (info.getTypes().isAssignable(theValue, target)) {
return true;
}
}
return false;
}