下面列出了com.sun.source.tree.ClassTree#getKind ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public Type visitClass(ClassTree node, Type type) {
String typeName = fullyQualifiedPath(getCurrentPath()); // null for anon. inner class
Tree.Kind kind = node.getKind();
if ((kind == Tree.Kind.CLASS || kind == Tree.Kind.INTERFACE) && typeName != null) {
List<String> interfaces = SnakeYAMLMojo.treesToStrings(node.getImplementsClause());
final Type newType = new Type(typeName, node.getSimpleName().toString(), kind == Tree.Kind.INTERFACE,
interfaces);
if (interfacesToImpls != null && kind == Tree.Kind.CLASS) {
// Add this class to our map from each interface to all of its implementations.
interfaces.stream()
.map(intf -> interfacesToImpls.computeIfAbsent(intf, key -> new ArrayList<>()))
.forEach(list -> list.add(newType.simpleName()));
}
types.put(typeName, newType);
imports.add(new Import(newType.fullName(), false));
type = newType;
}
return super.visitClass(node, type);
}
@Override
public Void visitClass(ClassTree tree, Void unused) {
switch (tree.getKind()) {
case ANNOTATION_TYPE:
visitAnnotationType(tree);
break;
case CLASS:
case INTERFACE:
visitClassDeclaration(tree);
break;
case ENUM:
visitEnumDeclaration(tree);
break;
default:
throw new AssertionError(tree.getKind());
}
return null;
}
@Override
public Void visitClass(ClassTree tree, Void unused) {
switch (tree.getKind()) {
case ANNOTATION_TYPE:
visitAnnotationType(tree);
break;
case CLASS:
case INTERFACE:
visitClassDeclaration(tree);
break;
case ENUM:
visitEnumDeclaration(tree);
break;
default:
throw new AssertionError(tree.getKind());
}
return null;
}
@Override
public Void visitClass(ClassTree tree, Void unused) {
switch (tree.getKind()) {
case ANNOTATION_TYPE:
visitAnnotationType(tree);
break;
case CLASS:
case INTERFACE:
visitClassDeclaration(tree);
break;
case ENUM:
visitEnumDeclaration(tree);
break;
case RECORD:
visitRecordDeclaration(tree);
break;
default:
throw new AssertionError(tree.getKind());
}
return null;
}
@Override
public Void visitClass(ClassTree tree, Void unused) {
switch (tree.getKind()) {
case ANNOTATION_TYPE:
visitAnnotationType(tree);
break;
case CLASS:
case INTERFACE:
visitClassDeclaration(tree);
break;
case ENUM:
visitEnumDeclaration(tree);
break;
default:
throw new AssertionError(tree.getKind());
}
return null;
}
@Override public Description matchClass(ClassTree tree, VisitorState state) {
if (tree.getKind() != CLASS) {
return NO_MATCH;
}
ModifiersTree modifiers = tree.getModifiers();
Set<Modifier> modifierFlags = modifiers.getFlags();
if (modifierFlags.contains(FINAL) || modifierFlags.contains(ABSTRACT)) {
return NO_MATCH;
}
switch (ASTHelpers.getSymbol(tree).getNestingKind()) {
case LOCAL:
case ANONYMOUS:
return NO_MATCH;
case MEMBER:
if (modifierFlags.contains(PRIVATE)) {
return NO_MATCH;
}
break;
case TOP_LEVEL:
break;
}
for (AnnotationTree annotation : modifiers.getAnnotations()) {
AnnotationMirror annotationMirror = ASTHelpers.getAnnotationMirror(annotation);
if (annotationMirror.getAnnotationType().toString().equals(OPEN_FQCN)) {
return NO_MATCH;
}
}
return describeMatch(tree);
}
@TriggerTreeKind(Tree.Kind.CLASS)
public static Collection<ErrorDescription> run(HintContext hintContext) {
final EJBProblemContext ctx = HintsUtils.getOrCacheContext(hintContext);
if (ctx == null) {
return Collections.emptyList();
}
boolean isEJB = false;
J2eeModuleProvider provider = ctx.getProject().getLookup().lookup(J2eeModuleProvider.class);
if (provider != null) {
J2eeModule module = provider.getJ2eeModule();
isEJB = module != null && J2eeModule.Type.EJB.equals(module.getType());
}
//disable this rule for non ejb project
if (!isEJB) {
return null;
}
AnnotationMirror annWebService = JavaUtils.findAnnotation(ctx.getClazz(),
EJBAPIAnnotations.WEB_SERVICE);
if (annWebService != null) {
ClassTree classTree = hintContext.getInfo().getTrees().getTree(ctx.getClazz());
if (classTree.getKind() == Tree.Kind.INTERFACE) {
return null; // ok, interfaces can have @WebService without ejb annotations
}
if (ctx.getEjb() instanceof Session) {
if (Session.SESSION_TYPE_STATELESS.equals(ctx.getEjbData().getSessionType())
|| Session.SESSION_TYPE_SINGLETON.equals(ctx.getEjbData().getSessionType())) {
return Collections.emptyList(); //OK
}
}
ErrorDescription err = HintsUtils.createProblem(
ctx.getClazz(),
hintContext.getInfo(),
Bundle.WSisSLSB_err());
return Collections.singletonList(err);
}
return Collections.emptyList();
}
@Override
public boolean matches(ClassTree classTree, VisitorState state) {
return classTree.getKind() == Tree.Kind.INTERFACE;
}
private static boolean isInterface(CompilationInfo info, TypeElement clazz) {
ClassTree classTree = info.getTrees().getTree(clazz);
return classTree.getKind() == Tree.Kind.INTERFACE;
}