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

The following examples show how to use com.sun.source.tree.Tree.Kind#MODIFIERS . 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: T6472751.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Void scan(Tree node, Void ignored) {
    if (node == null)
        return null;
    Kind k = node.getKind();
    long pos = positions.getStartPosition(null,node);
    System.out.format("%s: %s%n", k, pos);
    if (k != Kind.MODIFIERS && pos < 0)
        throw new Error("unexpected position found");
    return super.scan(node, ignored);
}
 
Example 2
Source File: T6472751.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Void scan(Tree node, Void ignored) {
    if (node == null)
        return null;
    Kind k = node.getKind();
    long pos = positions.getStartPosition(null,node);
    System.out.format("%s: %s%n", k, pos);
    if (k != Kind.MODIFIERS && pos < 0)
        throw new Error("unexpected position found");
    return super.scan(node, ignored);
}
 
Example 3
Source File: T6472751.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Void scan(Tree node, Void ignored) {
    if (node == null)
        return null;
    Kind k = node.getKind();
    long pos = positions.getStartPosition(null,node);
    System.out.format("%s: %s%n", k, pos);
    if (k != Kind.MODIFIERS && pos < 0)
        throw new Error("unexpected position found");
    return super.scan(node, ignored);
}
 
Example 4
Source File: FixFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates a fix, which when invoked changes the existing modifiers
 * @param compilationInfo CompilationInfo to work on
 * @param treePath TreePath to a ModifiersTree.
 * @param toAdd set of Modifiers to add
 * @param toRemove set of Modifiers to remove
 * @param text text displayed as a fix description
 */
public static final Fix changeModifiersFix(CompilationInfo compilationInfo, TreePath treePath, Set<Modifier> toAdd, Set<Modifier> toRemove, String text) {
    Parameters.notNull("compilationInfo", compilationInfo);
    Parameters.notNull("treePath", treePath);
    Parameters.notNull("toAdd", toAdd);
    Parameters.notNull("toRemove", toRemove);
    Parameters.notNull("text", text);

    if (treePath.getLeaf().getKind() != Kind.MODIFIERS) {
        return null;
    }
    return new ChangeModifiersFixImpl(TreePathHandle.create(treePath, compilationInfo), toAdd, toRemove, text).toEditorFix();
}
 
Example 5
Source File: RemoveOverride.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public List<Fix> run(CompilationInfo compilationInfo, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
    treePath = compilationInfo.getTreeUtilities().pathFor(offset + 1);

    //#222582: treePath.getParentPath() may be null under unknown conditions:
    if (treePath.getParentPath() == null) return null;
    
    if (treePath.getParentPath().getLeaf().getKind() == Kind.MODIFIERS)
        return Collections.<Fix>singletonList(new FixImpl(compilationInfo, treePath.getParentPath()).toEditorFix());
    return null;
}
 
Example 6
Source File: GoToImplementation.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static Element resolveTarget(CompilationInfo info, Document doc, int caretPos, AtomicBoolean onDeclaration) {
    Context context = GoToSupport.resolveContext(info, doc, caretPos, false, false);

    TreePath tp = info.getTreeUtilities().pathFor(caretPos);

    if (tp.getLeaf().getKind() == Kind.MODIFIERS) tp = tp.getParentPath();

    int[] elementNameSpan = null;
    switch (tp.getLeaf().getKind()) {
        case ANNOTATION_TYPE:
        case CLASS:
        case ENUM:
        case INTERFACE:
            elementNameSpan = info.getTreeUtilities().findNameSpan((ClassTree) tp.getLeaf());
            onDeclaration.set(true);
            break;
        case METHOD:
            elementNameSpan = info.getTreeUtilities().findNameSpan((MethodTree) tp.getLeaf());
            onDeclaration.set(true);
            break;
    }
    if (context == null) {
        
        if (elementNameSpan != null && caretPos <= elementNameSpan[1]) {
            return info.getTrees().getElement(tp);
        }
        return null;
    } else if (!SUPPORTED_ELEMENTS.contains(context.resolved.getKind())) {
        return null;
    } else {
        return context.resolved;
    }
}
 
Example 7
Source File: T6472751.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Void scan(Tree node, Void ignored) {
    if (node == null)
        return null;
    Kind k = node.getKind();
    long pos = positions.getStartPosition(null,node);
    System.out.format("%s: %s%n", k, pos);
    if (k != Kind.MODIFIERS && pos < 0)
        throw new Error("unexpected position found");
    return super.scan(node, ignored);
}
 
Example 8
Source File: T6472751.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Void scan(Tree node, Void ignored) {
    if (node == null)
        return null;
    Kind k = node.getKind();
    long pos = positions.getStartPosition(null,node);
    System.out.format("%s: %s%n", k, pos);
    if (k != Kind.MODIFIERS && pos < 0)
        throw new Error("unexpected position found");
    return super.scan(node, ignored);
}
 
Example 9
Source File: T6472751.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Void scan(Tree node, Void ignored) {
    if (node == null)
        return null;
    Kind k = node.getKind();
    long pos = positions.getStartPosition(null,node);
    System.out.format("%s: %s%n", k, pos);
    if (k != Kind.MODIFIERS && pos < 0)
        throw new Error("unexpected position found");
    return super.scan(node, ignored);
}
 
Example 10
Source File: T6472751.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Void scan(Tree node, Void ignored) {
    if (node == null)
        return null;
    Kind k = node.getKind();
    long pos = positions.getStartPosition(null,node);
    System.out.format("%s: %s%n", k, pos);
    if (k != Kind.MODIFIERS && pos < 0)
        throw new Error("unexpected position found");
    return super.scan(node, ignored);
}
 
Example 11
Source File: T6472751.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Void scan(Tree node, Void ignored) {
    if (node == null)
        return null;
    Kind k = node.getKind();
    long pos = positions.getStartPosition(null,node);
    System.out.format("%s: %s%n", k, pos);
    if (k != Kind.MODIFIERS && pos < 0)
        throw new Error("unexpected position found");
    return super.scan(node, ignored);
}
 
Example 12
Source File: NFABasedBulkSearch.java    From netbeans with Apache License 2.0 3 votes vote down vote up
private boolean multiModifiers(Tree t) {
    if (t.getKind() != Kind.MODIFIERS) return false;
    
    List<AnnotationTree> annotations = new ArrayList<AnnotationTree>(((ModifiersTree) t).getAnnotations());

    return !annotations.isEmpty() && annotations.get(0).getAnnotationType().getKind() == Kind.IDENTIFIER;
}