本文整理匯總了Java中javax.lang.model.element.NestingKind.MEMBER屬性的典型用法代碼示例。如果您正苦於以下問題:Java NestingKind.MEMBER屬性的具體用法?Java NestingKind.MEMBER怎麽用?Java NestingKind.MEMBER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類javax.lang.model.element.NestingKind
的用法示例。
在下文中一共展示了NestingKind.MEMBER屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: lookupStaticClass
public TypeElement lookupStaticClass(DeclaredType type, CharSequence className, TypeMirror classType) {
for (TypeElement clazz : ElementFilter.typesIn(type.asElement().getEnclosedElements())) {
final Collection<? extends Modifier> modifiers = clazz.getModifiers();
if (clazz.getNestingKind() != NestingKind.MEMBER
|| !modifiers.contains(Modifier.STATIC)
|| !modifiers.contains(Modifier.PUBLIC)
|| !clazz.getKind().isClass()) {
continue;
}
if (!clazz.getSimpleName().contentEquals(className)) {
continue;
}
if (!types.isAssignable(clazz.asType(), classType)) {
continue;
}
return clazz;
}
return null;
}
示例2: validateBeanType
private static TypeElement validateBeanType(TypeElement beanType) {
if (!hasParameterlessConstructor(beanType)) {
throw new ValidationException(BEAN_NO_DEFAULT_CONSTRUCTOR, beanType);
}
if (beanType.getModifiers().contains(PRIVATE)) {
throw new ValidationException(NESTING_KIND, beanType);
}
if (beanType.getNestingKind() == NestingKind.MEMBER &&
!beanType.getModifiers().contains(STATIC)) {
throw new ValidationException(NESTING_KIND, beanType);
}
if (beanType.getModifiers().contains(ABSTRACT)) {
throw new ValidationException(BEAN_ABSTRACT_CLASS, beanType);
}
if (!beanType.getTypeParameters().isEmpty()) {
throw new ValidationException(TYPE_PARAMS_BEAN, beanType);
}
return beanType;
}
示例3: run
@TriggerTreeKind(Tree.Kind.BLOCK)
public static ErrorDescription run(HintContext ctx) {
TreePath path = ctx.getPath();
if (((BlockTree)path.getLeaf()).isStatic()) {
return null;
}
TreePath parentPath = path.getParentPath();
if (parentPath == null) {
return null;
}
Tree l = parentPath.getLeaf();
if (!(l instanceof ClassTree)) {
return null;
}
Element el = ctx.getInfo().getTrees().getElement(parentPath);
if (el == null || !el.getKind().isClass()) {
return null;
}
TypeElement tel = (TypeElement)el;
// do not suggest for anonymous classes, local classes or members which are not static.
if (tel.getNestingKind() != NestingKind.TOP_LEVEL &&
(tel.getNestingKind() != NestingKind.MEMBER || !tel.getModifiers().contains(Modifier.STATIC))) {
return null;
}
InstanceRefFinder finder = new InstanceRefFinder(ctx.getInfo(), path);
finder.process();
if (finder.containsInstanceReferences() || finder.containsReferencesToSuper()) {
return null;
}
return ErrorDescriptionFactory.forTree(ctx, path, Bundle.TEXT_InitializerCanBeStatic(),
new MakeInitStatic(TreePathHandle.create(path, ctx.getInfo())).toEditorFix());
}
示例4: getFlatName
public static String getFlatName(TypeElement classRepresenter) {
if (classRepresenter.getNestingKind() == NestingKind.MEMBER) {
return classRepresenter.getEnclosingElement() + "" + classRepresenter.getSimpleName().toString();
} else {
return classRepresenter.getQualifiedName().toString();
}
}
示例5: getNestingKind
@DefinedBy(Api.LANGUAGE_MODEL)
public NestingKind getNestingKind() {
complete();
if (owner.kind == PCK)
return NestingKind.TOP_LEVEL;
else if (name.isEmpty())
return NestingKind.ANONYMOUS;
else if (owner.kind == MTH)
return NestingKind.LOCAL;
else
return NestingKind.MEMBER;
}
示例6: getNestingKind
@Override
public NestingKind getNestingKind() {
require(State.FINISHED);
boolean isTopLevel = enclosingTypeDeclaration == null;
return isTopLevel
? NestingKind.TOP_LEVEL
: NestingKind.MEMBER;
}
示例7: doCompile
@Override
protected UnitCache<VariableElement> doCompile(FieldDeclaration unit) {
String unitName = NameUtil.getNodeName(getCompileUnit(), unit);
TypeMirror type = TypeUtil.toMirror(getCompileUnit(), unit.getType());
Name name = new StringName(unitName);
ElementKind kind = ElementKind.FIELD;
Set<Modifier> modifierSet = ModifierUtil.asSet(unit.getModifiers());
List<Element> members = new ArrayList<>();
for(VariableDeclarator var : unit.getVariables()) {
// TODO:
}
VariableElement element = new EmulVariableElement(type, kind, parent, members,
modifierSet, name, name, NestingKind.MEMBER);
// Children
NodeToElementCompiler compiler = new NodeToElementCompiler(getCompileUnit(), element);
for(Node child : unit.getChildrenNodes()) {
Element childElem = compiler.compile(child);
if(childElem != null) {
members.add(childElem);
}
}
return new UnitCache<>(element);
}
示例8: getNestingKind
@Override
public NestingKind getNestingKind() {
ReferenceBinding refBinding = (ReferenceBinding)_binding;
if (refBinding.isAnonymousType()) {
return NestingKind.ANONYMOUS;
} else if (refBinding.isLocalType()) {
return NestingKind.LOCAL;
} else if (refBinding.isMemberType()) {
return NestingKind.MEMBER;
}
return NestingKind.TOP_LEVEL;
}
示例9: matchClass
@Override
public Description matchClass(final ClassTree tree, final VisitorState state) {
final ClassSymbol currentClass = ASTHelpers.getSymbol(tree);
if (currentClass == null || !currentClass.hasOuterInstance()) {
return NO_MATCH;
}
if (currentClass.getNestingKind() != NestingKind.MEMBER) {
// local or anonymous classes can't be static
return NO_MATCH;
}
switch (currentClass.owner.enclClass().getNestingKind()) {
case TOP_LEVEL:
break;
case MEMBER:
// class is nested inside an inner class, so it can't be static
if (currentClass.owner.enclClass().hasOuterInstance()) {
return NO_MATCH;
}
break;
case LOCAL:
case ANONYMOUS:
// members of local and anonymous classes can't be static
return NO_MATCH;
}
if (tree.getExtendsClause() != null
&& ASTHelpers.getType(tree.getExtendsClause()).tsym.hasOuterInstance()) {
return NO_MATCH;
}
if (CanBeStaticAnalyzer.referencesOuter(tree, currentClass, state)) {
return NO_MATCH;
}
return describeMatch(tree, SuggestedFixes.addModifiers(tree, state, Modifier.STATIC));
}
示例10: validateEnclosingElement
protected void validateEnclosingElement(Element element) {
TypeElement typeElement = ElementUtil.toTypeElement(element, env);
if (typeElement == null) {
return;
}
String simpleName = typeElement.getSimpleName().toString();
if (simpleName.contains(Constants.BINARY_NAME_DELIMITER)
|| simpleName.contains(Constants.METATYPE_NAME_DELIMITER)) {
throw new AptException(Message.DOMA4277, env, typeElement,
new Object[] { typeElement.getQualifiedName() });
}
NestingKind nestingKind = typeElement.getNestingKind();
if (nestingKind == NestingKind.TOP_LEVEL) {
return;
} else if (nestingKind == NestingKind.MEMBER) {
Set<Modifier> modifiers = typeElement.getModifiers();
if (modifiers.containsAll(Arrays.asList(Modifier.STATIC,
Modifier.PUBLIC))) {
validateEnclosingElement(typeElement.getEnclosingElement());
} else {
throw new AptException(Message.DOMA4275, env, typeElement,
new Object[] { typeElement.getQualifiedName() });
}
} else {
throw new AptException(Message.DOMA4276, env, typeElement,
new Object[] { typeElement.getQualifiedName() });
}
}
示例11: validateEnclosingElement
protected void validateEnclosingElement(Element element) {
TypeElement typeElement = ElementUtil.toTypeElement(element, env);
if (typeElement == null) {
return;
}
String simpleName = typeElement.getSimpleName().toString();
if (simpleName.contains(Constants.BINARY_NAME_DELIMITER)
|| simpleName.contains(Constants.METATYPE_NAME_DELIMITER)) {
throw new AptException(Message.DOMA4417, env, typeElement,
new Object[] { typeElement.getQualifiedName() });
}
NestingKind nestingKind = typeElement.getNestingKind();
if (nestingKind == NestingKind.TOP_LEVEL) {
return;
} else if (nestingKind == NestingKind.MEMBER) {
Set<Modifier> modifiers = typeElement.getModifiers();
if (modifiers.containsAll(Arrays.asList(Modifier.STATIC,
Modifier.PUBLIC))) {
validateEnclosingElement(typeElement.getEnclosingElement());
} else {
throw new AptException(Message.DOMA4415, env, typeElement,
new Object[] { typeElement.getQualifiedName() });
}
} else {
throw new AptException(Message.DOMA4416, env, typeElement,
new Object[] { typeElement.getQualifiedName() });
}
}
示例12: validateEnclosingElement
protected void validateEnclosingElement(Element element) {
TypeElement typeElement = ElementUtil.toTypeElement(element, env);
if (typeElement == null) {
return;
}
String simpleName = typeElement.getSimpleName().toString();
if (simpleName.contains(Constants.BINARY_NAME_DELIMITER)
|| simpleName.contains(Constants.METATYPE_NAME_DELIMITER)) {
throw new AptException(Message.DOMA4317, env, typeElement,
new Object[] { typeElement.getQualifiedName() });
}
NestingKind nestingKind = typeElement.getNestingKind();
if (nestingKind == NestingKind.TOP_LEVEL) {
return;
} else if (nestingKind == NestingKind.MEMBER) {
Set<Modifier> modifiers = typeElement.getModifiers();
if (modifiers.containsAll(Arrays.asList(Modifier.STATIC,
Modifier.PUBLIC))) {
validateEnclosingElement(typeElement.getEnclosingElement());
} else {
throw new AptException(Message.DOMA4315, env, typeElement,
new Object[] { typeElement.getQualifiedName() });
}
} else {
throw new AptException(Message.DOMA4316, env, typeElement,
new Object[] { typeElement.getQualifiedName() });
}
}
示例13: validateEnclosingElement
protected void validateEnclosingElement(Element element) {
TypeElement typeElement = ElementUtil.toTypeElement(element, env);
if (typeElement == null) {
return;
}
String simpleName = typeElement.getSimpleName().toString();
if (simpleName.contains(Constants.BINARY_NAME_DELIMITER)
|| simpleName.contains(Constants.METATYPE_NAME_DELIMITER)) {
throw new AptException(Message.DOMA4280, env, typeElement,
new Object[] { typeElement.getQualifiedName() });
}
NestingKind nestingKind = typeElement.getNestingKind();
if (nestingKind == NestingKind.TOP_LEVEL) {
return;
} else if (nestingKind == NestingKind.MEMBER) {
Set<Modifier> modifiers = typeElement.getModifiers();
if (modifiers.containsAll(Arrays.asList(Modifier.STATIC,
Modifier.PUBLIC))) {
validateEnclosingElement(typeElement.getEnclosingElement());
} else {
throw new AptException(Message.DOMA4278, env, typeElement,
new Object[] { typeElement.getQualifiedName() });
}
} else {
throw new AptException(Message.DOMA4279, env, typeElement,
new Object[] { typeElement.getQualifiedName() });
}
}
示例14: getNestingKind
@Override
public NestingKind getNestingKind() {
// We'll never need to infer local or anonymous classes, so there are only two options left
// and we can tell the difference:
if (getEnclosingElement() instanceof InferredTypeElement) {
return NestingKind.MEMBER;
}
return NestingKind.TOP_LEVEL;
}
示例15: isAccessibleClass
private static boolean isAccessibleClass(TypeElement te) {
NestingKind nestingKind = te.getNestingKind();
return (nestingKind == NestingKind.TOP_LEVEL) || (nestingKind == NestingKind.MEMBER && te.getModifiers().contains(Modifier.STATIC));
}