当前位置: 首页>>代码示例>>Java>>正文


Java ElementKind.isClass方法代码示例

本文整理汇总了Java中javax.lang.model.element.ElementKind.isClass方法的典型用法代码示例。如果您正苦于以下问题:Java ElementKind.isClass方法的具体用法?Java ElementKind.isClass怎么用?Java ElementKind.isClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.lang.model.element.ElementKind的用法示例。


在下文中一共展示了ElementKind.isClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: paramElementFor

import javax.lang.model.element.ElementKind; //导入方法依赖的package包/类
private static Element paramElementFor(Element methodOrClass, ParamTree ptag) {
    ElementKind kind = methodOrClass.getKind();
    List<? extends Element> params = Collections.emptyList();
    if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
        ExecutableElement ee = (ExecutableElement) methodOrClass;
        params = ptag.isTypeParameter()
                ? ee.getTypeParameters()
                : ee.getParameters();
    } else if (kind.isClass() || kind.isInterface()) {
        TypeElement te = (TypeElement) methodOrClass;
        params = te.getTypeParameters();
    }

    for (Element param : params) {
        if (param.getSimpleName().contentEquals(ptag.getName().getName())) {
            return param;
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:JavadocImports.java

示例2: attributeParamIdentifier

import javax.lang.model.element.ElementKind; //导入方法依赖的package包/类
private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) {
    Symbol javadocSymbol = getElement(path);
    if (javadocSymbol == null)
        return null;
    ElementKind kind = javadocSymbol.getKind();
    List<? extends Symbol> params = List.nil();
    if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
        MethodSymbol ee = (MethodSymbol) javadocSymbol;
        params = ptag.isTypeParameter()
                ? ee.getTypeParameters()
                : ee.getParameters();
    } else if (kind.isClass() || kind.isInterface()) {
        ClassSymbol te = (ClassSymbol) javadocSymbol;
        params = te.getTypeParameters();
    }

    for (Symbol param : params) {
        if (param.getSimpleName() == ptag.getName().getName()) {
            return param;
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:JavacTrees.java

示例3: isInaccessibleOutsideOuterClass

import javax.lang.model.element.ElementKind; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:InstantRenamePerformer.java

示例4: enclosingTypeOf

import javax.lang.model.element.ElementKind; //导入方法依赖的package包/类
private TypeElement enclosingTypeOf(Element element) {
  for (Element e = element; e != null;) {
    ElementKind kind = e.getKind();
    if (kind.isClass() || kind.isInterface()) {
      return (TypeElement) e;
    }
    e = e.getEnclosingElement();
  }
  throw new NoSuchElementException();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:Round.java

示例5: isSameKind

import javax.lang.model.element.ElementKind; //导入方法依赖的package包/类
private static boolean isSameKind (ElementKind k1, ElementKind k2) {
    if ((k1 == k2) ||
       (k1 == ElementKind.OTHER && (k2.isClass() || k2.isInterface())) ||     
       (k2 == ElementKind.OTHER && (k1.isClass() || k1.isInterface()))) {
        return true;
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ElementHandle.java

示例6: signatureEquals

import javax.lang.model.element.ElementKind; //导入方法依赖的package包/类
/**
 * Tests if the handle has this same signature as the parameter.
 * The handles has the same signatures if it is resolved into the same
 * element in the same {@link javax.tools.JavaCompiler} task, but may be resolved into
 * the different {@link Element} in the different {@link javax.tools.JavaCompiler} task.
 * @param element to be checked
 * @return true if this handle resolves into the same {@link Element}
 * in the same {@link javax.tools.JavaCompiler} task.
 */
public boolean signatureEquals (@NonNull final T element) {
    final ElementKind ek = element.getKind();
    final ElementKind thisKind = getKind();
    if ((ek != thisKind) && !(thisKind == ElementKind.OTHER && (ek.isClass() || ek.isInterface()))) {
        return false;
    }
    final ElementHandle<T> handle = create (element);
    return signatureEquals (handle);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ElementHandle.java

示例7: createTypeElementHandle

import javax.lang.model.element.ElementKind; //导入方法依赖的package包/类
/**
 * Creates an {@link ElementHandle} representing a {@link TypeElement}.
 * @param kind the {@link ElementKind} of the {@link TypeElement},
 * allowed values are {@link ElementKind#CLASS}, {@link ElementKind#INTERFACE},
 * {@link ElementKind#ENUM} and {@link ElementKind#ANNOTATION_TYPE}.
 * @param binaryName the class binary name as specified by JLS §13.1
 * @return the created {@link ElementHandle}
 * @throws IllegalArgumentException if kind is neither class nor interface
 * @since 0.98
 */
@NonNull
public static ElementHandle<TypeElement> createTypeElementHandle(
    @NonNull final ElementKind kind,
    @NonNull final String binaryName) throws IllegalArgumentException {
    Parameters.notNull("kind", kind);   //NOI18N
    Parameters.notNull("binaryName", binaryName);   //NOI18N
    if (!kind.isClass() && !kind.isInterface()) {
        throw new IllegalArgumentException(kind.toString());
    }
    return new ElementHandle<TypeElement>(kind, binaryName);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:ElementHandle.java

示例8: getPanel

import javax.lang.model.element.ElementKind; //导入方法依赖的package包/类
@Override
public CustomRefactoringPanel getPanel(ChangeListener parent) {
    if (panel == null) {
        String suffix = "";
        if(handle != null && handle.getKind() == Tree.Kind.LABELED_STATEMENT) {
            suffix = getString("LBL_Label");
        } else if (handle != null && handle.getElementHandle() !=null) {
            ElementKind kind = handle.getElementHandle().getKind();
            if (kind!=null && (kind.isClass() || kind.isInterface())) {
                suffix  = kind.isInterface() ? getString("LBL_Interface") : getString("LBL_Class");
            } else if (kind == ElementKind.METHOD) {
                suffix = getString("LBL_Method");
            } else if (kind == ElementKind.FIELD) {
                suffix = getString("LBL_Field");
            } else if (kind == ElementKind.LOCAL_VARIABLE) {
                suffix = getString("LBL_LocalVar");
            } else if (kind == ElementKind.PACKAGE || (handle == null && fromListener)) {
                suffix = pkgRename ? getString("LBL_Package") : getString("LBL_Folder");
            } else if (kind == ElementKind.PARAMETER) {
                suffix = getString("LBL_Parameter");
            }
        }
        suffix = suffix + " " + this.oldName; // NOI18N
        panel = new RenamePanel(handle, newName, parent, NbBundle.getMessage(RenamePanel.class, "LBL_Rename") + " " + suffix, !fromListener, fromListener && !byPassPakageRename);
    }
    return panel;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:RenameRefactoringUI.java

示例9: checkModifiersIfNested

import javax.lang.model.element.ElementKind; //导入方法依赖的package包/类
private void checkModifiersIfNested(TypeElement type) {
    ElementKind enclosingKind = type.getEnclosingElement().getKind();
    if (enclosingKind.isClass() || enclosingKind.isInterface()) {
        if (type.getModifiers().contains(PRIVATE)) {
            mErrorReporter.abortWithError("@AutoParcel class must not be private", type);
        }
        if (!type.getModifiers().contains(STATIC)) {
            mErrorReporter.abortWithError("Nested @AutoParcel class must be static", type);
        }
    }
    // In principle type.getEnclosingElement() could be an ExecutableElement (for a class
    // declared inside a method), but since RoundEnvironment.getElementsAnnotatedWith doesn't
    // return such classes we won't see them here.
}
 
开发者ID:foodora,项目名称:android-auto-mapper,代码行数:15,代码来源:AutoMappperProcessor.java

示例10: findOwnerType

import javax.lang.model.element.ElementKind; //导入方法依赖的package包/类
protected TypeElement findOwnerType(Element el) {
    Element t;
    if (el instanceof TypeElement) {
        t = ((TypeElement)el);
    } else {
        t = ci.getElementUtilities().enclosingTypeElement(el);
        if (t == null) {
            return null;
        }
    }
    ElementKind k = t.getKind();
    TypeMirror declType = ci.getTypes().erasure(t.asType());
    
    for (TypeElement enclType = enclosingType; enclType != null; enclType = ci.getElementUtilities().enclosingTypeElement(enclType)) {
        if (ci.getTypes().isSubtype(ci.getTypes().erasure(enclType.asType()), declType)) {
            if (k.isClass()) {
                return enclType;
            } else if (k == ElementKind.INTERFACE) {
                if (t.getModifiers().contains(Modifier.DEFAULT)) {
                    return enclType;
                }
            }
            break;
        }
    }
    // PENDING - this is strange, report an error ??
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:InstanceRefFinder.java

示例11: findType

import javax.lang.model.element.ElementKind; //导入方法依赖的package包/类
private TypeElement findType(Tree selector) {
    TypeMirror tm = ci.getTrees().getTypeMirror(new TreePath(getCurrentPath(), selector));
    if (tm != null && tm.getKind() == TypeKind.DECLARED) {
        TypeElement t = (TypeElement)ci.getTypes().asElement(tm);
        ElementKind ek = t.getKind();
        if (!(ek.isClass() || ek.isInterface())) {
            // PENDING: an error, log
            return null;
        }
        // the referenced type must be in the same CU, cannot be a superclass.
        return t;
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:InstanceRefFinder.java

示例12: getEnclosingTypeElement

import javax.lang.model.element.ElementKind; //导入方法依赖的package包/类
public TypeElement getEnclosingTypeElement(Element e) {
    if (e.getKind() == ElementKind.PACKAGE)
        return null;
    Element encl = e.getEnclosingElement();
    ElementKind kind = encl.getKind();
    if (kind == ElementKind.PACKAGE)
        return null;
    while (!(kind.isClass() || kind.isInterface())) {
        encl = encl.getEnclosingElement();
    }
    return (TypeElement)encl;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:Utils.java

示例13: handleNode

import javax.lang.model.element.ElementKind; //导入方法依赖的package包/类
private void handleNode(
        final Tree node,
        final Map<Tree,WhiteListQuery.Result> p) {
    final Element e = trees.getElement(getCurrentPath());
    if (e == null) {
        return;
    }
    final ElementKind k = e.getKind();
    ElementHandle<?> eh = null;
    Tree toReport =  null;
    if (k.isClass() || k.isInterface()) {
        TypeMirror type = e.asType();
        if (type != null) {
            type = findComponentType(type);
            if (type.getKind() == TypeKind.DECLARED) {
                eh = ElementHandle.create(((DeclaredType)type).asElement());
                toReport=node;
            }
        }
    } else if ((k == ElementKind.METHOD || k == ElementKind.CONSTRUCTOR) &&
            !methodInvocation.isEmpty()) {
        toReport=methodInvocation.peekFirst();
        eh = ElementHandle.create(e);
    }
    final WhiteListQuery.Result res;
    if (toReport != null &&
        !(res=whiteList.check(eh,WhiteListQuery.Operation.USAGE)).isAllowed()) {
            p.put(toReport,res);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:WhiteListSupport.java

示例14: getClass

import javax.lang.model.element.ElementKind; //导入方法依赖的package包/类
/**
 * Finds a main top-level class or a nested class element
 * for {@code sourceDataObject} which should be initialized.
 */
private TypeElement getClass(WorkingCopy workingCopy)
                                                    throws IOException {
    workingCopy.toPhase(Phase.ELEMENTS_RESOLVED);

    final String preferredName = sourceDataObject.getName();
    TypeElement firstPublicNestedClass = null;
    
    List<? extends TypeElement> topClasses = workingCopy.getTopLevelElements();
    for (TypeElement topElement : topClasses) {
        ElementKind elementKind = topElement.getKind();
        if (!elementKind.isClass()) {
            continue;
        }

        if (topElement.getSimpleName().contentEquals(preferredName)) {
            return topElement;
        }

        if ((firstPublicNestedClass == null)
                && topElement.getModifiers().contains(Modifier.PUBLIC)) {
            firstPublicNestedClass = topElement;
        }
    }

    return firstPublicNestedClass;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:JavaI18nSupport.java

示例15: isTypeElement

import javax.lang.model.element.ElementKind; //导入方法依赖的package包/类
private static boolean isTypeElement(Element element) {
  ElementKind kind = element.getKind();
  return kind.isClass()
      || kind.isInterface();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:6,代码来源:SourceNames.java


注:本文中的javax.lang.model.element.ElementKind.isClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。