本文整理匯總了Java中javax.lang.model.element.ElementKind.ENUM_CONSTANT屬性的典型用法代碼示例。如果您正苦於以下問題:Java ElementKind.ENUM_CONSTANT屬性的具體用法?Java ElementKind.ENUM_CONSTANT怎麽用?Java ElementKind.ENUM_CONSTANT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類javax.lang.model.element.ElementKind
的用法示例。
在下文中一共展示了ElementKind.ENUM_CONSTANT屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: EnumDefinition
EnumDefinition(TypeElement element, String qualified, String simple) {
this.qualified = qualified;
this.simple = simple;
for (Element e : element.getEnclosedElements()) {
if (e.getKind() == ElementKind.ENUM_CONSTANT) {
Optional<OkNamedMirror> nameAnnotation = OkNamedMirror.find(e);
String name = e.getSimpleName().toString();
String jsonName = name;
if (nameAnnotation.isPresent()) {
String s = nameAnnotation.get().name();
// just ignore annotation with empty name
if (!s.isEmpty()) {
jsonName = s;
}
}
byFirstLetter.put(
jsonName.charAt(0),
new EnumConstant(name, jsonName));
}
}
}
示例2: visitIdentifier
public Void visitIdentifier(IdentifierTree node, Void p) {
TreePath path = getCurrentPath();
Element element = info.getTrees().getElement(path);
if (element != null && element.asType().getKind() != TypeKind.ERROR) {
// solve the imports only when declared type!!!
if (element.getKind().isClass() || element.getKind().isInterface()
|| (element.getKind().isField() && ((Symbol) element).isStatic())) {
Tree parent = path.getParentPath() != null ? path.getParentPath().getLeaf() : null;
if ( (parent != null && parent.getKind() == Kind.CASE && ((CaseTree) parent).getExpression() == node && element.getKind() == ElementKind.ENUM_CONSTANT)
|| (path.getCompilationUnit() != null && ((Symbol) element).enclClass() != null && path.getCompilationUnit().getSourceFile() == ((Symbol) element).enclClass().sourcefile)) {
translateMap.put(node, make.Identifier(element.getSimpleName()));
} else {
translateMap.put(node, make.QualIdent(element));
}
}
}
return null;
}
示例3: createHtmlHeader
private String createHtmlHeader(CompilationInfo info, VariableElement e, boolean isDeprecated,boolean isInherited, boolean fqn) {
StringBuilder sb = new StringBuilder();
if ( isDeprecated ) {
sb.append("<s>"); // NOI18N
}
if( isInherited ) {
sb.append( "<font color=" + ui.getInheritedColor() + ">" ); // NOI18N
}
sb.append(Utils.escape(e.getSimpleName().toString()));
if ( isDeprecated ) {
sb.append("</s>"); // NOI18N
}
if ( e.getKind() != ElementKind.ENUM_CONSTANT ) {
sb.append( " : " ); // NOI18N
sb.append( "<font color=" + ui.getTypeColor() + ">" ); // NOI18N
sb.append(print(info, e.asType(), fqn));
sb.append("</font>"); // NOI18N
}
return sb.toString();
}
示例4: visitMemberSelect
@Override
public State visitMemberSelect(MemberSelectTree node, Void p) {
State expr = scan(node.getExpression(), p);
boolean wasNPE = false;
if (expr == State.NULL || expr == State.NULL_HYPOTHETICAL || expr == State.POSSIBLE_NULL || expr == State.POSSIBLE_NULL_REPORT) {
wasNPE = true;
}
Element site = info.getTrees().getElement(new TreePath(getCurrentPath(), node.getExpression()));
if (isVariableElement(site) && wasNPE && (variable2State.get((VariableElement) site) == null || !variable2State.get((VariableElement) site).isNotNull())) {
variable2State.put((VariableElement) site, NOT_NULL_BE_NPE);
}
// special case: if the memberSelect selects enum field = constant, it is never null.
if (site != null && site.getKind() == ElementKind.ENUM) {
Element enumConst = info.getTrees().getElement(getCurrentPath());
if (enumConst != null && enumConst.getKind() == ElementKind.ENUM_CONSTANT) {
return State.NOT_NULL;
}
}
return getStateFromAnnotations(info, info.getTrees().getElement(getCurrentPath()));
}
示例5: visitIdentifier
@Override
public State visitIdentifier(IdentifierTree node, Void p) {
super.visitIdentifier(node, p);
Element e = info.getTrees().getElement(getCurrentPath());
if (e == null || !isVariableElement(e)) {
return State.POSSIBLE_NULL;
}
if (e.getKind() == ElementKind.ENUM_CONSTANT) {
// enum constants are never null
return State.NOT_NULL;
}
State s = variable2State.get((VariableElement) e);
if (s != null) {
return s;
}
return getStateFromAnnotations(info, e);
}
示例6: generateClassBody
protected boolean generateClassBody(TreePath p) throws Exception {
Element e = copy.getTrees().getElement(p);
boolean isUsableElement = e != null && (e.getKind().isClass() || e.getKind().isInterface());
if (isUsableElement) {
return true;
}
if (e.getKind() == ElementKind.ENUM_CONSTANT) {
VariableTree var = (VariableTree) p.getLeaf();
if (var.getInitializer() != null && var.getInitializer().getKind() == Kind.NEW_CLASS) {
NewClassTree nct = (NewClassTree) var.getInitializer();
if (nct.getClassBody() != null) {
return true;
}
}
}
return !generateClassBody2(copy, p);
}
示例7: getKind
@DefinedBy(Api.LANGUAGE_MODEL)
public ElementKind getKind() {
long flags = flags();
if ((flags & PARAMETER) != 0) {
if (isExceptionParameter())
return ElementKind.EXCEPTION_PARAMETER;
else
return ElementKind.PARAMETER;
} else if ((flags & ENUM) != 0) {
return ElementKind.ENUM_CONSTANT;
} else if (owner.kind == TYP || owner.kind == ERR) {
return ElementKind.FIELD;
} else if (isResourceVariable()) {
return ElementKind.RESOURCE_VARIABLE;
} else {
return ElementKind.LOCAL_VARIABLE;
}
}
示例8: checkElementVisibility
/**
* Checks that {@code target} is visible from {@code fromPkg}.
* If {@code fromPkg} is {@code null}, we take that to mean that {@code target} should be visible everywhere.
* Throws an {@link EasyPluginException} with a proper error message if the target element does not match
* the visibility constraint.
* @param eles Elements
* @param target The target element to check for visibility
* @param fromPkg The package to check for visibility from.
* Null indicates it needs to be globally visible.
* @throws EasyPluginException if it's not visible
*/
static void checkElementVisibility(Elements eles, Element target, String fromPkg) {
// I would have used a switch, but that messed up compilation somehow.
// I guess it generated another class file?
// Anyways, this works.
if (target.getKind().isClass() || target.getKind().isInterface()) {
checkClassVisibility(eles, (TypeElement) target, fromPkg);
} else if (target.getKind().isField()
|| target.getKind() == ElementKind.METHOD
|| target.getKind() == ElementKind.CONSTRUCTOR) {
checkMemberVisibility(eles, target, fromPkg);
} else if (target.getKind() == ElementKind.ENUM_CONSTANT) {
checkClassVisibility(eles, (TypeElement) target.getEnclosingElement(), fromPkg);
} else {
// This isn't an EasyPluginException because our code shouldn't be dumb
// enough to check the visibility of any other kind of element.
throw new IllegalArgumentException("Bad kind for element visibility check: " + target.getKind());
}
}
示例9: constructOptions
private ImmutableList<SwitchOption> constructOptions() {
ImmutableList.Builder<SwitchOption> builder = ImmutableList.builder();
for (Element v : containedTypeElement.getEnclosedElements()) {
if (v.getKind() == ElementKind.ENUM_CONSTANT) {
String name = v.getSimpleName().toString();
builder.add(new SwitchOption(name, defaultName.equals(name)));
}
}
return builder.build();
}
示例10: getEnumConstants
@Override
public String[] getEnumConstants() {
if(enumConstants == null){
Element elt = po != null ? getTypeElement(po) : element;
if(elt != null){
ArrayList<String> constants = new ArrayList<String>();
for( Element el:elt.getEnclosedElements() ){
if(el.getKind() == ElementKind.ENUM_CONSTANT){
constants.add(el.getSimpleName().toString());
}
}
enumConstants = constants.toArray(new String[]{});
} else if (type != null) {
if (!type.isEnum()) {
enumConstants = new String[]{};
} else {
Object[] enumC = type.getEnumConstants();
enumConstants = new String[enumC.length];
for (int index = enumC.length; --index >= 0;) {
enumConstants[index] = ((Enum<?>) enumC[index]).name();
}
}
} else {
enumConstants = new String[]{};
}
}
return enumConstants;
}
示例11: complete
@Override
public List<CompletionItem> complete() {
List<String> valueStrings = new ArrayList<String>();
if (isBooleanType()) {
valueStrings.add(Boolean.FALSE.toString());
valueStrings.add(Boolean.TRUE.toString());
} else {
for (Element e : enumType.getEnclosedElements()) {
if (e.getKind() == ElementKind.ENUM_CONSTANT) {
valueStrings.add(e.getSimpleName().toString());
}
}
}
String prefix = ctx.getPrefix();
if (!prefix.isEmpty()) {
if (prefix.charAt(0) == '"' || prefix.charAt(0) == '\'') {
prefix = prefix.substring(1);
}
for (Iterator<String> it = valueStrings.iterator(); it.hasNext(); ) {
String s = it.next();
if (!CompletionUtils.startsWith(s, prefix)) {
it.remove();
}
}
}
List<CompletionItem> items = new ArrayList<CompletionItem>();
for (String v : valueStrings) {
ValueItem vi = new ValueItem(ctx, v, ICON_ENUM_VALUE);
items.add(vi);
}
return items;
}
示例12: tryResolveIdentifier
private static boolean tryResolveIdentifier(CompilationInfo info, TreePath place,
TypeMirror expectedType, Set<Element> resolved, String ident) {
SourcePositions[] positions = new SourcePositions[1];
ExpressionTree et = info.getTreeUtilities().parseExpression(ident, positions);
TypeMirror unqType = info.getTreeUtilities().attributeTree(et, info.getTrees().getScope(place));
Element e = info.getTrees().getElement(new TreePath(place, et));
if (!Utilities.isValidType(unqType) || e == null ||
(e.getKind() != ElementKind.FIELD && e.getKind() != ElementKind.ENUM_CONSTANT)) {
return false;
}
if (!resolved.add(e)) {
return false;
}
return info.getTypes().isAssignable(unqType, expectedType);
}
示例13: executeRound
@Override
protected boolean executeRound(Element el, int round) throws Exception {
if (el.getKind() != ElementKind.ENUM) {
return false;
}
ClassTree ct = (ClassTree)path.getLeaf();
for (ListIterator<? extends Tree> it = ct.getMembers().listIterator(ct.getMembers().size()); it.hasPrevious(); ) {
Tree t = it.previous();
if (t.getKind() != Tree.Kind.VARIABLE) {
continue;
}
TreePath p = new TreePath(path, t);
Element e = copy.getTrees().getElement(p);
if (e == null || e.getKind() != ElementKind.ENUM_CONSTANT) {
continue;
}
switch (round) {
case 0:
if (!generateClassBody(p)) {
return false;
}
break;
case 1:
if (!generateImplementation(el, p)) {
return false;
}
break;
default:
throw new IllegalStateException();
}
}
return true;
}
示例14: visitSwitch
@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;
}
示例15: evalConstant
/**
* Evaluates the constant. The method should return a constant value, possibly wrapped
* if the value is primitive. It may return an encapsulated constant, with well-defned
* equals/hashcode. The value is just compared and {@link #convert}ed. <p/>
* Returns {@code null} if the path is not a compile-time constant.
* @param path
* @return constant value.
*/
protected Object evalConstant(TreePath path) {
TypeMirror m = ci.getTrees().getTypeMirror(path);
if (m != null && m.getKind() != TypeKind.DECLARED) {
return ArithmeticUtilities.compute(ci, path, true, true);
}
Element e = ci.getTrees().getElement(path);
if (e != null && e.getKind() == ElementKind.ENUM_CONSTANT) {
return new EnumConst(e);
}
return null;
}