Java Code Examples for javax.lang.model.element.ElementKind.isField()

The following are Jave code examples for showing how to use isField() of the javax.lang.model.element.ElementKind class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: InstantRenamePerformer.java   View Source Code Vote up 6 votes
/**
 * computes accessibility of members of nested classes
 * @param e member
 * @return {@code true} if the member cannot be accessed outside the outer class
 * @see <a href="http://www.netbeans.org/issues/show_bug.cgi?id=169377">169377</a>
 */
private static boolean isInaccessibleOutsideOuterClass(Element e, ElementUtilities eu) {
    Element enclosing = e.getEnclosingElement();
    boolean isStatic = e.getModifiers().contains(Modifier.STATIC);
    ElementKind kind = e.getKind();
    if (isStatic || kind.isClass() || kind.isInterface() || kind.isField()) {
        // static declaration of nested class, interface, enum, ann type, method, field
        // or inner class
        return isAnyEncloserPrivate(e);
    } else if (enclosing != null && kind == ElementKind.METHOD) {
        // final is enum, ann type and some classes
        ElementKind enclosingKind = enclosing.getKind();
        boolean isEnclosingFinal = enclosing.getModifiers().contains(Modifier.FINAL)
                // ann type is not final even if it cannot be subclassed
                || enclosingKind == ElementKind.ANNOTATION_TYPE;
        return isAnyEncloserPrivate(e) && !eu.overridesMethod((ExecutableElement) e) && !eu.implementsMethod((ExecutableElement)e) &&
                (isEnclosingFinal || !isOverriddenInsideOutermostEnclosingClass((ExecutableElement)e, eu));
    }
    return false;
}
 
Example 2
Project: incubator-netbeans   File: RenameRefactoringUI.java   View Source Code Vote up 5 votes
@Override
public HelpCtx getHelpCtx() {
    String postfix;
    if (handle==null) {
        postfix = ".JavaPackage";//NOI18N
    } else {
        ElementHandle elHandle = handle.getElementHandle();
        if (elHandle == null) {
            postfix = "";
        } else {
            ElementKind k = elHandle.getKind();

            if (k == null) {
                postfix = "";
            } else if (k.isClass() || k.isInterface()) {
                postfix = ".JavaClass";//NOI18N
            } else if (k == ElementKind.METHOD) {
                postfix = ".Method";//NOI18N
            } else if (k.isField()) {
                postfix = ".Field";//NOI18N
            } else {
                postfix = "";
            }
        }
    }
    
    return new HelpCtx(RenameRefactoringUI.class.getName() + postfix);
}
 
Example 3
Project: incubator-netbeans   File: JavaI18nSupport.java   View Source Code Vote up 5 votes
/**
 * Finds the target position within the source class element.
 * In the current implementation, the target position is just below
 * the last static field of the class; if there is no static field
 * in the class, the target position is the top of the class.
 * 
 * @param  classMembers  list of all members of the class
 * @param  fields  list of the fields in the class
 * @return  target position ({@code 0}-based) of the field,
 *          or {@code -1} if the field should be added to the end
 *          of the class
 */
private int findTargetPosition(
        List<? extends javax.lang.model.element.Element> classMembers,
        List<? extends VariableElement> fields) {
    if (fields.isEmpty()) {
        return 0;
    }

    int target = 0;
    boolean skippingStaticFields = false;
    Iterator<? extends javax.lang.model.element.Element> membersIt
            = classMembers.iterator();
    for (int index = 0; membersIt.hasNext(); index++) {
        javax.lang.model.element.Element member = membersIt.next();
        ElementKind kind = member.getKind();
        if (kind.isField()
                && (kind != ElementKind.ENUM_CONSTANT)
                && member.getModifiers().contains(Modifier.STATIC)) {
            /* it is a static field - skip it! */
            skippingStaticFields = true;
        } else if (skippingStaticFields) {
            /* we were skipping all static fields - until now */
            skippingStaticFields = false;
            target = index;
        }
    }

    return !skippingStaticFields ? target : -1;
}