Java Code Examples for com.sun.source.tree.Tree.Kind#INTERFACE

The following examples show how to use com.sun.source.tree.Tree.Kind#INTERFACE . 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: TreeConverter.java    From j2objc with Apache License 2.0 6 votes vote down vote up
private SourcePosition getNamePosition(Tree node) {
  int start = (int) sourcePositions.getStartPosition(unit, node);
  if (start == -1) {
    return SourcePosition.NO_POSITION;
  }
  String src = newUnit.getSource();
  Kind kind = node.getKind();
  if (kind == Kind.ANNOTATION_TYPE
      || kind == Kind.CLASS
      || kind == Kind.ENUM
      || kind == Kind.INTERFACE) {
    // Skip the class/enum/interface token.
    while (src.charAt(start++) != ' ') {}
  } else if (kind != Kind.METHOD && kind != Kind.VARIABLE) {
    return getPosition(node);
  }
  if (!Character.isJavaIdentifierStart(src.charAt(start))) {
    return getPosition(node);
  }
  int endPos = start + 1;
  while (Character.isJavaIdentifierPart(src.charAt(endPos))) {
    endPos++;
  }
  return getSourcePosition(start, endPos);
}
 
Example 2
Source File: JavadocHint.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Hint(id = "error-in-javadoc", category = "JavaDoc", description = "#DESC_ERROR_IN_JAVADOC_HINT", displayName = "#DN_ERROR_IN_JAVADOC_HINT", hintKind = Hint.Kind.INSPECTION, severity = Severity.WARNING, customizerProvider = JavadocHint.CustomizerProviderImplError.class)
@TriggerTreeKind({Kind.METHOD, Kind.ANNOTATION_TYPE, Kind.CLASS, Kind.ENUM, Kind.INTERFACE, Kind.VARIABLE})
public static List<ErrorDescription> errorHint(final HintContext ctx) {
    Preferences pref = ctx.getPreferences();
    boolean correctJavadocForNonPublic = pref.getBoolean(AVAILABILITY_KEY + false, false);

    CompilationInfo javac = ctx.getInfo();
    Boolean publiclyAccessible = AccessibilityQuery.isPubliclyAccessible(javac.getFileObject().getParent());
    boolean isPubliclyA11e = publiclyAccessible == null ? true : publiclyAccessible;

    if (!isPubliclyA11e && !correctJavadocForNonPublic) {
        return null;
    }

    if (javac.getElements().getTypeElement("java.lang.Object") == null) { // NOI18N
        // broken java platform
        return Collections.<ErrorDescription>emptyList();
    }

    TreePath path = ctx.getPath();
    {
        Document doc = null;
        try {
            doc = javac.getDocument();
        } catch (IOException e) {
            Exceptions.printStackTrace(e);
        }
        if (doc != null && isGuarded(path.getLeaf(), javac, doc)) {
            return null;
        }
    }
    
    Access access = Access.resolve(pref.get(SCOPE_KEY, SCOPE_DEFAULT));
    Analyzer a = new Analyzer(javac, path, access, ctx);
    return a.analyze();
}
 
Example 3
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 5 votes vote down vote up
private SourcePosition getNamePosition(String name, JCTree node) {
  int start = node.getPreferredPosition();
  if (start == -1) {
    return null;
  }

  try {
    String src = javacUnit.sourcefile.getCharContent(true).toString();
    Kind kind = node.getKind();
    if (kind == Kind.ANNOTATION_TYPE
        || kind == Kind.CLASS
        || kind == Kind.ENUM
        || kind == Kind.INTERFACE) {
      // Skip the class/enum/interface token.
      while (src.charAt(start++) != ' ') {}
    } else if (kind != Kind.METHOD && kind != Kind.VARIABLE) {
      return getSourcePosition(node);
    }
    if (!Character.isJavaIdentifierStart(src.charAt(start))) {
      return getSourcePosition(node);
    }
    int endPos = start + 1;
    while (Character.isJavaIdentifierPart(src.charAt(endPos))) {
      endPos++;
    }
    return getSourcePosition(name, start, endPos);
  } catch (IOException e) {
    throw internalCompilerError(e, "Error getting name Position for: %s.", node);
  }
}