Java Code Examples for com.sun.source.tree.ClassTree#getKind()

The following examples show how to use com.sun.source.tree.ClassTree#getKind() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SnakeYAMLMojo.java    From helidon-build-tools with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: JavaInputAstVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: JavaInputAstVisitor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example 4
Source File: Java14InputAstVisitor.java    From google-java-format with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 5
Source File: JavaInputAstVisitor.java    From google-java-format with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 6
Source File: NopenChecker.java    From nopen with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 7
Source File: WSisSLSB.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 8
Source File: NoStaticOrDefaultMethodsInInterfaces.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
@Override
public boolean matches(ClassTree classTree, VisitorState state) {
  return classTree.getKind() == Tree.Kind.INTERFACE;
}
 
Example 9
Source File: LegalModifiers.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static boolean isInterface(CompilationInfo info, TypeElement clazz) {
    ClassTree classTree = info.getTrees().getTree(clazz);
    return classTree.getKind() == Tree.Kind.INTERFACE;
}