本文整理汇总了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;
}
示例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);
}
});
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}