當前位置: 首頁>>代碼示例>>Java>>正文


Java Element.getKind方法代碼示例

本文整理匯總了Java中javax.lang.model.element.Element.getKind方法的典型用法代碼示例。如果您正苦於以下問題:Java Element.getKind方法的具體用法?Java Element.getKind怎麽用?Java Element.getKind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.lang.model.element.Element的用法示例。


在下文中一共展示了Element.getKind方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: enclosingTypeElementImpl

import javax.lang.model.element.Element; //導入方法依賴的package包/類
static TypeElement enclosingTypeElementImpl( Element element ) throws IllegalArgumentException {

if( element.getKind() == ElementKind.PACKAGE ) {
    throw new IllegalArgumentException();
}

       element = element.getEnclosingElement();

       if (element.getKind() == ElementKind.PACKAGE) {
           //element is a top level class, returning null according to the contract:
           return null;
       }
       
while(element != null && !(element.getKind().isClass() || element.getKind().isInterface())) {
    element = element.getEnclosingElement();
}

return (TypeElement)element;
   }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:ElementUtilities.java

示例2: initialize

import javax.lang.model.element.Element; //導入方法依賴的package包/類
@Override
void initialize(final Element element, CompilationController info) {
    final String labelText;
    if(element.getKind() == ElementKind.TYPE_PARAMETER) {
        labelText = UIUtilities.createHeader((TypeParameterElement) element, info.getElements().isDeprecated(element), false, false, true);
    } else {
        labelText = UIUtilities.createHeader((VariableElement) element, info.getElements().isDeprecated(element), false, false, true);
    }
    final Icon labelIcon = ElementIcons.getElementIcon(element.getKind(), element.getModifiers());
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            Dimension preferredSize = label.getPreferredSize();
            label.setText(labelText);
            label.setIcon(labelIcon);
            label.setPreferredSize(preferredSize);
            label.setMinimumSize(preferredSize);
        }
    });
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:WhereUsedPanelVariable.java

示例3: isElegibleAccessorMethod

import javax.lang.model.element.Element; //導入方法依賴的package包/類
private static boolean isElegibleAccessorMethod(Element element) {
  if (element.getKind() != ElementKind.METHOD) {
    return false;
  }
  if (element.getModifiers().contains(Modifier.STATIC)) {
    return false;
  }
  switch (element.getSimpleName().toString()) {
  case HASH_CODE_METHOD:
  case TO_STRING_METHOD:
    return false;
  default:
  }
  String definitionType = element.getEnclosingElement().toString();
  if (definitionType.equals(Object.class.getName())
      || definitionType.equals(Proto.ORDINAL_VALUE_INTERFACE_TYPE)
      || definitionType.equals(Proto.PARCELABLE_INTERFACE_TYPE)) {
    return false;
  }
  return true;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:AccessorAttributesCollector.java

示例4: visitSwitch

import javax.lang.model.element.Element; //導入方法依賴的package包/類
@Override
public Boolean visitSwitch(SwitchTree node, Void p) {
    boolean lastCaseExit = false;
    boolean defaultSeen = false;
    Set<Element> enumValues = null;
    
    if (node.getExpression() != null) {
        TypeMirror exprType = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getExpression()));
        if (isValidType(exprType) && exprType.getKind() == TypeKind.DECLARED) {
            Element el = ((DeclaredType)exprType).asElement();
            enumValues = new HashSet<>();
            for (Element f : el.getEnclosedElements()) {
                if (f.getKind() == ElementKind.ENUM_CONSTANT) {
                    enumValues.add(f);
                }
            }
        }
    }
    for (CaseTree ct : node.getCases()) {
        Boolean res = scan(ct, null);
        if (res == Boolean.FALSE) {
            return res;
        }
        lastCaseExit = res == Boolean.TRUE;
        if (ct.getExpression() == null) {
            defaultSeen = true;
        } else if (enumValues != null ) {
            TreePath casePath = new TreePath(getCurrentPath(), ct);
            Element v = info.getTrees().getElement(new TreePath(
                    casePath, ct.getExpression()));
            if (v != null) {
                enumValues.remove(v);
            }
        }
    }
    if (enumValues != null && enumValues.isEmpty()) {
        defaultSeen = true;
    }
    return lastCaseExit == Boolean.TRUE && defaultSeen;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:41,代碼來源:Utilities.java

示例5: accept

import javax.lang.model.element.Element; //導入方法依賴的package包/類
public boolean accept(Element e, TypeMirror type) {
    
    if (e.getKind() != ElementKind.FIELD) {
        return false;
    } else {
        if( e.getSimpleName().toString().equals(fieldName) ) {
             return true;
        }
    }
    
    return false;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:HibernateEditorUtil.java

示例6: isInvalidAutoJacksonInterface

import javax.lang.model.element.Element; //導入方法依賴的package包/類
/**
 * Check if an element is invalid or not. Any errors must be reported by this method
 *
 * @param element The element to check
 * @return true if the element is invalid, false if valid
 */
private boolean isInvalidAutoJacksonInterface(Element element) {
    boolean invalid = false;
    // Check if an interface  has been annotated with @Factory
    if (element.getKind() != ElementKind.INTERFACE) {
        this.processorUtil.error(element, "Only interfaces can be annotated with @%s", AutoJackson.class.getSimpleName());
        invalid = true;
    }
    return invalid;
}
 
開發者ID:peckb1,項目名稱:autojackson,代碼行數:16,代碼來源:AutoJacksonProcessor.java

示例7: getPackage

import javax.lang.model.element.Element; //導入方法依賴的package包/類
/**
 * An alternate implementation of {@link Elements#getPackageOf} that does not require an
 * {@link Elements} instance.
 *
 * @throws NullPointerException if {@code element} is {@code null}
 */
public static PackageElement getPackage(Element element) {
    while (element.getKind() != PACKAGE) {
        element = element.getEnclosingElement();
    }
    return (PackageElement) element;
}
 
開發者ID:foodora,項目名稱:android-auto-mapper,代碼行數:13,代碼來源:MoreElements.java

示例8: findEnclosingMethod

import javax.lang.model.element.Element; //導入方法依賴的package包/類
private static ExecutableElement findEnclosingMethod(CompilationInfo info, TreePath path) {
    while (path != null && path.getLeaf().getKind() != Kind.CLASS && path.getLeaf().getKind() != Kind.METHOD) {
        path = path.getParentPath();
    }

    if (path != null && path.getLeaf().getKind() == Kind.METHOD) {
        Element el = info.getTrees().getElement(path);

        if (el != null && el.getKind() == ElementKind.METHOD) {
            return (ExecutableElement) el;
        }
    }

    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:CollectionRemove.java

示例9: getElementOwnerElement

import javax.lang.model.element.Element; //導入方法依賴的package包/類
protected Element getElementOwnerElement(Element element) {
    Element resultEle;

    // todo: Get the Class which element's owner.
    ElementKind elementKind = element.getKind();
    if (ElementKind.FIELD == elementKind) {
        resultEle = MoreElements.asVariable(element).getEnclosingElement();
    } else if (ElementKind.METHOD == elementKind) {
        resultEle = MoreElements.asExecutable(element).getEnclosingElement();
    } else {
        resultEle = element;
    }
    return resultEle;
}
 
開發者ID:wangjiegulu,項目名稱:RapidRouter,代碼行數:15,代碼來源:BaseAbstractProcessor.java

示例10: getElementHeader

import javax.lang.model.element.Element; //導入方法依賴的package包/類
private StringBuilder getElementHeader(final Element element, final CompilationInfo info) {
    final StringBuilder sb = new StringBuilder();
    if (element != null) {
        sb.append(getContainingClassOrPackageHeader(element, info.getElements(), info.getElementUtilities()));
        switch(element.getKind()) {
            case METHOD:
            case CONSTRUCTOR:
                sb.append(getMethodHeader((ExecutableElement)element));
                break;
            case FIELD:
            case ENUM_CONSTANT:
                sb.append(getFieldHeader((VariableElement)element));
                break;
            case CLASS:
            case INTERFACE:
            case ENUM:
            case ANNOTATION_TYPE:
                sb.append(getClassHeader((TypeElement)element));
                break;
            case PACKAGE:
                sb.append(getPackageHeader((PackageElement)element));
                break;
            case MODULE:
                sb.append(getModuleHeader((ModuleElement)element));
                break;
        }
    }
    return sb;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:30,代碼來源:ElementJavadoc.java

示例11: checkElementForMembers

import javax.lang.model.element.Element; //導入方法依賴的package包/類
private void checkElementForMembers(Element rootElement) {
    for (Element element : rootElement.getEnclosedElements()) {
        if (element.getKind() == ElementKind.METHOD) {
            methods.add((ExecutableElement) element);
        } else if (element.getKind() == ElementKind.FIELD) {
            fields.add((VariableElement) element);
        }
    }
}
 
開發者ID:rsulkowski,項目名稱:jdoocsoup,代碼行數:10,代碼來源:DataClassBuilderDescriptor.java

示例12: isPossibleBuilderClass

import javax.lang.model.element.Element; //導入方法依賴的package包/類
/**
 * Determine if inner class could be a builder.
 *
 * @param possibleBuilderClass nested value element that could be builder class.
 * @return true if it's a static inner class.
 */
private static boolean isPossibleBuilderClass(Element possibleBuilderClass, ValueAttribute valueAttribute) {
  if (possibleBuilderClass.getKind() == ElementKind.CLASS) {

    if (valueAttribute.containingType.names().newTokenInAttributeBuilder()) {
      return possibleBuilderClass.getModifiers().contains(Modifier.STATIC)
          && possibleBuilderClass.getKind() == ElementKind.CLASS;
    }
  }

  return false;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:AttributeBuilderReflection.java

示例13: ChangeParametersUI

import javax.lang.model.element.Element; //導入方法依賴的package包/類
/** Creates a new instance of ChangeMethodSignatureRefactoring */
private ChangeParametersUI(TreePathHandle refactoredObj, CompilationInfo info, ParameterInfo[] preConfiguration, CodeStyle cs) {
    this.refactoring = new ChangeParametersRefactoring(refactoredObj);
    this.method = refactoredObj;
    this.preConfiguration = preConfiguration;
    Element element = method.resolveElement(info);
    this.name = element.getSimpleName().toString();
    this.isMethod = element.getKind() == ElementKind.METHOD;
    this.cs = cs;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:ChangeParametersUI.java

示例14: createTypeNames

import javax.lang.model.element.Element; //導入方法依賴的package包/類
TypeNames createTypeNames() {
  Element sourceElement = sourceElement();
  if (sourceElement.getKind() == ElementKind.CONSTRUCTOR) {
    sourceElement = sourceElement.getEnclosingElement();
  }
  return styles().forType(sourceElement.getSimpleName().toString());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:Proto.java

示例15: process

import javax.lang.model.element.Element; //導入方法依賴的package包/類
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver()) {
        return false;
    }

    GraphNodeVerifier verifier = new GraphNodeVerifier(this);

    for (Element element : roundEnv.getElementsAnnotatedWith(NodeInfo.class)) {
        scope = element;
        try {
            if (!isNodeType(element)) {
                errorMessage(element, "%s can only be applied to Node subclasses", NodeInfo.class.getSimpleName());
                continue;
            }

            NodeInfo nodeInfo = element.getAnnotation(NodeInfo.class);
            if (nodeInfo == null) {
                errorMessage(element, "Cannot get %s annotation from annotated element", NodeInfo.class.getSimpleName());
                continue;
            }

            TypeElement typeElement = (TypeElement) element;

            Set<Modifier> modifiers = typeElement.getModifiers();
            if (!modifiers.contains(Modifier.FINAL) && !modifiers.contains(Modifier.ABSTRACT)) {
                // TODO(thomaswue): Reenable this check.
                // errorMessage(element, "%s annotated class must be either final or abstract",
                // NodeInfo.class.getSimpleName());
                // continue;
            }
            boolean found = false;
            for (Element e : typeElement.getEnclosedElements()) {
                if (e.getKind() == ElementKind.FIELD) {
                    if (e.getSimpleName().toString().equals("TYPE")) {
                        found = true;
                        break;
                    }
                }
            }
            if (!found) {
                errorMessage(element, "%s annotated class must have a field named TYPE", NodeInfo.class.getSimpleName());
            }

            if (!typeElement.equals(verifier.Node) && !modifiers.contains(Modifier.ABSTRACT)) {
                verifier.verify(typeElement);
            }
        } catch (ElementException ee) {
            errorMessage(ee.element, ee.getMessage());
        } catch (Throwable t) {
            reportException(isBug367599(t) ? Kind.NOTE : Kind.ERROR, element, t);
        } finally {
            scope = null;
        }
    }
    return false;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:58,代碼來源:GraphNodeProcessor.java


注:本文中的javax.lang.model.element.Element.getKind方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。