本文整理汇总了Java中javax.lang.model.type.TypeKind.DECLARED属性的典型用法代码示例。如果您正苦于以下问题:Java TypeKind.DECLARED属性的具体用法?Java TypeKind.DECLARED怎么用?Java TypeKind.DECLARED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.lang.model.type.TypeKind
的用法示例。
在下文中一共展示了TypeKind.DECLARED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseBeanMethod
private boolean parseBeanMethod(ExecutableElement beanMethod, String[] beanNames, Messager messager) {
boolean valid = true;
if (beanNames.length == 0) {
valid = false;
messager.printMessage(Kind.ERROR, "All @Bean annotations must define at least one name for a bean.", beanMethod);
}
if (beanMethod.getReturnType().getKind() != TypeKind.DECLARED) {
valid = false;
messager.printMessage(Kind.ERROR, "@Bean methods must return an Object", beanMethod);
}
if (!beanMethod.getModifiers().contains(Modifier.PUBLIC)) {
valid = false;
messager.printMessage(Kind.ERROR, "@Bean methods must be marked public", beanMethod);
}
List<Modifier> illegalModifiers = getIllegalModifiers(beanMethod.getModifiers(), DISALLOWED_ON_METHOD);
if (illegalModifiers.size() != 0) {
valid = false;
messager.printMessage(Kind.ERROR, "Illegal modifiers found on spring @Bean method: "
+ illegalModifiers.stream().map(m -> m.name()).collect(Collectors.joining(", ")),
beanMethod);
}
return valid;
}
示例2: findTypeElement
/**
* Returns the Element which is incomplete, or, for anonymous classes,
* returns the extended TypeElement (which is also incomplete). This is because
* an Element is not available for the incomplete class.
*/
private static TypeElement findTypeElement(CompilationInfo info, TreePath path) {
Element e = info.getTrees().getElement(path);
if (e == null) {
return null;
} else if (e.getKind().isClass() || e.getKind().isInterface()) {
return (TypeElement)e;
}
TypeMirror tm = info.getTrees().getTypeMirror(path);
if (tm == null || tm.getKind() != TypeKind.DECLARED) {
if (path.getLeaf().getKind() == Tree.Kind.NEW_CLASS) {
tm = info.getTrees().getTypeMirror(new TreePath(path, ((NewClassTree)path.getLeaf()).getIdentifier()));
}
}
if (tm != null && tm.getKind() == TypeKind.DECLARED) {
return (TypeElement)((DeclaredType)tm).asElement();
} else {
return null;
}
}
示例3: visitNewClass
@Override
public List<? extends TypeMirror> visitNewClass(NewClassTree node, Object p) {
TypeMirror tm = info.getTrees().getTypeMirror(getCurrentPath());
if (tm == null || tm.getKind() != TypeKind.DECLARED) {
return null;
}
Element el = info.getTrees().getElement(getCurrentPath());
if (el == null) {
return null;
}
if (theExpression.getLeaf() != node.getEnclosingExpression()) {
ExecutableType execType = (ExecutableType)info.getTypes().asMemberOf((DeclaredType)tm, el);
return visitMethodOrNew(node, p, node.getArguments(), execType);
} else {
DeclaredType dt = (DeclaredType)tm;
if (dt.getEnclosingType() == null) {
return null;
}
return Collections.singletonList(dt.getEnclosingType());
}
}
示例4: checkBinaryOp
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;
}
示例5: testElement
private static VariableElement testElement(HintContext ctx) {
TreePath tp = ctx.getPath();
Element el = ctx.getInfo().getTrees().getElement(tp);
if (!isAcceptable(el)) return null;
TypeMirror actualType = ctx.getInfo().getTrees().getTypeMirror(tp);
if (actualType == null || actualType.getKind() != TypeKind.DECLARED) return null;
if (testType(ctx.getInfo(), actualType, "java.util.Collection") || testType(ctx.getInfo(), actualType, "java.util.Map")) {
return (VariableElement) el;
} else {
return null;
}
}
示例6: collectConstructors
private void collectConstructors(Collection<IConstructor> constructors, Element element){
if(element == null || element.getKind()!=ElementKind.CLASS) {
return;
}
TypeElement el = (TypeElement) element;
for(Element sub: el.getEnclosedElements()){
if(sub.getKind() == ElementKind.CONSTRUCTOR){
constructors.add(new Constructor(this, (ExecutableElement)sub));
} else if ((sub.getKind() == ElementKind.CLASS) && (((TypeElement) sub).getSuperclass() != null)){
TypeMirror supMirror = ((TypeElement) sub).getSuperclass();
if (supMirror.getKind() == TypeKind.DECLARED) {
DeclaredType superclassDeclaredType = (DeclaredType)supMirror;
Element superclassElement = superclassDeclaredType.asElement();
collectConstructors(constructors, superclassElement);
}
}
}
}
示例7: visitNewClass
@Override
public Boolean visitNewClass(NewClassTree node, Void p) {
TypeMirror tm = ci.getTrees().getTypeMirror(getCurrentPath());
if (tm == null || tm.getKind() != TypeKind.DECLARED) {
return false;
}
TypeElement el = (TypeElement)((DeclaredType)tm).asElement();
if (el == null) {
return false;
}
Name n = el.getQualifiedName();
boolean res = n.contentEquals("java.lang.StringBuilder") || n.contentEquals("java.lang.StringBuffer"); // NOI18N
// check if there is some initial contents
if (node.getArguments().size() == 1 &&
Utilities.isJavaString(ci, ci.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getArguments().get(0))))) {
hasContents = true;
}
return res;
}
示例8: encodeAsString
public static String encodeAsString(TypeDesc td) {
if (td.typeKind.isPrimitive() || td.typeKind == TypeKind.VOID)
return StringUtils.toLowerCase(td.typeKind.toString());
if (td.typeKind == TypeKind.ARRAY)
return encodeAsString(((ArrayTypeDesc) td).compTypeDesc) + "[]";
if (td.typeKind == TypeKind.TYPEVAR)
return "#" + ((TypeVarTypeDesc) td).identifier;
if (td.typeKind == TypeKind.DECLARED)
return ((ReferenceTypeDesc) td).javaType.toString();
throw new AssertionError("Unhandled type: " + td.typeKind);
}
示例9: getTypeName
private static String getTypeName(TypeMirror type) {
if (type.getKind() == TypeKind.ARRAY) {
return getTypeName(((javax.lang.model.type.ArrayType) type).getComponentType())+"[]";
}
if (type.getKind() == TypeKind.TYPEVAR) {
TypeVariable tv = (TypeVariable) type;
return getTypeName(tv.getUpperBound());
}
if (type.getKind() == TypeKind.DECLARED) {
return ElementUtilities.getBinaryName((TypeElement) ((DeclaredType) type).asElement());
}
return type.toString();
}
示例10: processGetBundleCall
private void processGetBundleCall(MethodInvocationTree node) {
TypeMirror tm = info.getTrees().getTypeMirror(getCurrentPath());
if (resourceBundleType == null ||tm == null || tm.getKind() != TypeKind.DECLARED) {
return;
}
if (!info.getTypes().isAssignable(tm, resourceBundleType)) {
return;
}
// OK, get the parameter said to describe the bundle name
exprBundleName = getBundleName(node, messageMethod.getBundleParam(), messageMethod.getBundleFile());
}
示例11: from
/**
* Gets {@link ElementHandle} from {@link TypeMirrorHandle} representing {@link DeclaredType}.
* @param typeMirrorHandle from which the {@link ElementHandle} should be retrieved. Permitted
* {@link TypeKind} is {@link TypeKind#DECLARED}.
* @return an {@link ElementHandle}
* @since 0.29.0
*/
public static @NonNull ElementHandle<? extends TypeElement> from (@NonNull final TypeMirrorHandle<? extends DeclaredType> typeMirrorHandle) {
Parameters.notNull("typeMirrorHandle", typeMirrorHandle);
if (typeMirrorHandle.getKind() != TypeKind.DECLARED) {
throw new IllegalStateException("Incorrect kind: " + typeMirrorHandle.getKind());
}
return (ElementHandle<TypeElement>)typeMirrorHandle.getElementHandle();
}
示例12: handleNode
private void handleNode(
final Tree node,
final Map<Tree,WhiteListQuery.Result> p) {
final Element e = trees.getElement(getCurrentPath());
if (e == null) {
return;
}
final ElementKind k = e.getKind();
ElementHandle<?> eh = null;
Tree toReport = null;
if (k.isClass() || k.isInterface()) {
TypeMirror type = e.asType();
if (type != null) {
type = findComponentType(type);
if (type.getKind() == TypeKind.DECLARED) {
eh = ElementHandle.create(((DeclaredType)type).asElement());
toReport=node;
}
}
} else if ((k == ElementKind.METHOD || k == ElementKind.CONSTRUCTOR) &&
!methodInvocation.isEmpty()) {
toReport=methodInvocation.peekFirst();
eh = ElementHandle.create(e);
}
final WhiteListQuery.Result res;
if (toReport != null &&
!(res=whiteList.check(eh,WhiteListQuery.Operation.USAGE)).isAllowed()) {
p.put(toReport,res);
}
}
示例13: performRewrite
@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
final WorkingCopy copy = ctx.getWorkingCopy();
TypeMirror samType = copy.getTrees().getTypeMirror(ctx.getPath());
if (samType == null || samType.getKind() != TypeKind.DECLARED) {
// FIXME: report
return ;
}
LambdaExpressionTree lambda = (LambdaExpressionTree) ctx.getPath().getLeaf();
Tree tree = lambda.getBody();
if (tree.getKind() == Tree.Kind.BLOCK) {
if (((BlockTree)tree).getStatements().size() == 1) {
tree = ((BlockTree)tree).getStatements().get(0);
if (tree.getKind() == Tree.Kind.EXPRESSION_STATEMENT) {
tree = ((ExpressionStatementTree)tree).getExpression();
} else if (tree.getKind() == Tree.Kind.RETURN) {
tree = ((ReturnTree)tree).getExpression();
} else {
return;
}
} else {
return;
}
}
Tree changed = null;
if (tree.getKind() == Tree.Kind.METHOD_INVOCATION) {
changed = ConvertToLambdaConverter.methodInvocationToMemberReference(copy, tree, ctx.getPath(), lambda.getParameters(), false);
} else if (tree.getKind() == Tree.Kind.NEW_CLASS) {
changed = ConvertToLambdaConverter.newClassToConstructorReference(copy, tree, ctx.getPath(), lambda.getParameters(), false);
}
if (changed != null) {
copy.rewrite(lambda, changed);
}
}
示例14: visitThrow
public Void visitThrow(ThrowTree node, Set<TypeMirror> p) {
super.visitThrow(node, p);
TypeMirror tm = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getExpression()));
if (tm != null) {
if (tm.getKind() == TypeKind.DECLARED)
p.add(tm);
else if (tm.getKind() == TypeKind.UNION)
p.addAll(((UnionType)tm).getAlternatives());
}
return null;
}
示例15: checkNoLoggers
@TriggerTreeKind({Tree.Kind.ANNOTATION_TYPE, Tree.Kind.CLASS, Tree.Kind.ENUM, Tree.Kind.INTERFACE})
public static Iterable<ErrorDescription> checkNoLoggers(HintContext ctx) {
Element cls = ctx.getInfo().getTrees().getElement(ctx.getPath());
if (cls == null || cls.getKind() != ElementKind.CLASS || cls.getModifiers().contains(Modifier.ABSTRACT) ||
(cls.getEnclosingElement() != null && cls.getEnclosingElement().getKind() != ElementKind.PACKAGE)
) {
return null;
}
TypeElement loggerTypeElement = ctx.getInfo().getElements().getTypeElement("java.util.logging.Logger"); // NOI18N
if (loggerTypeElement == null) {
return null;
}
TypeMirror loggerTypeElementAsType = loggerTypeElement.asType();
if (loggerTypeElementAsType == null || loggerTypeElementAsType.getKind() != TypeKind.DECLARED) {
return null;
}
List<TypeMirror> customLoggersList = new ArrayList<>();
if (isCustomEnabled(ctx.getPreferences())) {
List<String> customLoggerClasses = getCustomLoggers(ctx.getPreferences());
if (customLoggerClasses != null) {
for (String className : customLoggerClasses) {
TypeElement customTypeElement = ctx.getInfo().getElements().getTypeElement(className);
if (customTypeElement == null) {
continue;
}
TypeMirror customTypeMirror = customTypeElement.asType();
if (customTypeMirror == null || customTypeMirror.getKind() != TypeKind.DECLARED) {
continue;
}
customLoggersList.add(customTypeMirror);
}
}
}
List<VariableElement> loggerFields = new LinkedList<VariableElement>();
List<VariableElement> fields = ElementFilter.fieldsIn(cls.getEnclosedElements());
for(VariableElement f : fields) {
if (f.getKind() != ElementKind.FIELD) {
continue;
}
if (f.asType().equals(loggerTypeElementAsType)) {
loggerFields.add(f);
} else if (customLoggersList.contains(f.asType())) {
loggerFields.add(f);
}
}
if (loggerFields.size() == 0) {
return Collections.singleton(ErrorDescriptionFactory.forName(
ctx,
ctx.getPath(),
NbBundle.getMessage(NoLoggers.class, "MSG_NoLoggers_checkNoLoggers", cls), //NOI18N
new NoLoggersFix(NbBundle.getMessage(NoLoggers.class, "MSG_NoLoggers_checkNoLoggers_Fix", cls), TreePathHandle.create(cls, ctx.getInfo())).toEditorFix() //NOI18N
));
} else {
return null;
}
}