本文整理匯總了Java中javax.lang.model.element.NestingKind.TOP_LEVEL屬性的典型用法代碼示例。如果您正苦於以下問題:Java NestingKind.TOP_LEVEL屬性的具體用法?Java NestingKind.TOP_LEVEL怎麽用?Java NestingKind.TOP_LEVEL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類javax.lang.model.element.NestingKind
的用法示例。
在下文中一共展示了NestingKind.TOP_LEVEL屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findBuilder
private void findBuilder() {
if (classElement.getNestingKind() != NestingKind.TOP_LEVEL || builder) {
return;
}
Collection<? extends BuilderResolver> resolvers = MimeLookup.getLookup(JavaFXEditorUtils.FXML_MIME_TYPE).lookupAll(BuilderResolver.class);
for (BuilderResolver r : resolvers) {
String builderName = r.findBuilderClass(compilationInfo, null, className);
if (builderName != null) {
FxBean builderBean = provider.getBeanInfo(builderName);
if (builderBean != null) {
resultInfo.setBuilder(builderBean);
builderBean.makeBuilder(resultInfo);
return;
}
}
}
}
示例2: create
public static TargetDescription create(CompilationInfo info, TypeElement type, TreePath path, boolean allowForDuplicates, boolean iface) {
boolean canStatic = true;
if (iface) {
// interface cannot have static methods
canStatic = false;
} else {
if (type.getNestingKind() == NestingKind.ANONYMOUS ||
type.getNestingKind() == NestingKind.LOCAL ||
(type.getNestingKind() != NestingKind.TOP_LEVEL && !type.getModifiers().contains(Modifier.STATIC))) {
canStatic = false;
}
}
return new TargetDescription(Utilities.target2String(type),
ElementHandle.create(type),
TreePathHandle.create(path, info),
allowForDuplicates,
type.getSimpleName().length() == 0, iface, canStatic);
}
示例3: generateComment
public String generateComment(TypeElement clazz, CompilationInfo javac) {
StringBuilder builder = new StringBuilder(
// "/**\n" + // NOI18N
"\n" // NOI18N
);
if (clazz.getNestingKind() == NestingKind.TOP_LEVEL) {
builder.append("@author ").append(author).append("\n"); // NOI18N
}
if (SourceVersion.RELEASE_5.compareTo(srcVersion) <= 0) {
for (TypeParameterElement param : clazz.getTypeParameters()) {
builder.append("@param <").append(param.getSimpleName().toString()).append("> \n"); // NOI18N
}
}
if (SourceVersion.RELEASE_5.compareTo(srcVersion) <= 0 &&
JavadocUtilities.isDeprecated(javac, clazz)) {
builder.append("@deprecated\n"); // NOI18N
}
// builder.append("*/\n"); // NOI18N
return builder.toString();
}
示例4: getParentChain
private static String getParentChain(final TypeElement targetClass) {
// if input is top level class return it
// otherwise return the parent chain plus it
if (targetClass.getNestingKind() == NestingKind.TOP_LEVEL) {
return targetClass.getSimpleName().toString();
} else {
final Element parent = targetClass.getEnclosingElement();
if (parent.getKind() != ElementKind.CLASS) {
throw new RuntimeException("Cannot create parent chain. Non-class parent found.");
}
return (getParentChain((TypeElement) parent)) + "_" + targetClass.getSimpleName().toString();
}
}
示例5: visitClass
@Override
public Void visitClass(ClassTree node, Map<ErrorDescription, Integer> p) {
Element e = ci.getTrees().getElement(getCurrentPath());
if (e != null) {
if (((TypeElement)e).getNestingKind() != NestingKind.TOP_LEVEL) {
addError(node, ERR_ONLY_TOP_LEVEL_CLASS, p);
} else {
btraceClassName = ((TypeElement)e).getQualifiedName().toString();
if (e.getModifiers().contains(Modifier.PRIVATE) ||
e.getModifiers().contains(Modifier.PROTECTED)) {
addError(node, ERR_CLASS_PUBLIC_OR_DEFAULT, p);
} else if (!e.getModifiers().contains(Modifier.PUBLIC)) {
isShortSyntax = true;
}
}
}
return super.visitClass(node, p);
}
示例6: enclosingClassValid
static boolean enclosingClassValid(ProcessorContext context, TypeElement enclosingClass){
// protected, package-private, and public all allow same package
// access
if (enclosingClass.getModifiers().contains(Modifier.PRIVATE)) {
context.messager().printMessage(Kind.ERROR,
"class cannot be private",
enclosingClass);
return false;
}
if (enclosingClass.getNestingKind() != NestingKind.TOP_LEVEL
&& !enclosingClass.getModifiers().contains(Modifier.STATIC)) {
context.messager().printMessage(Kind.ERROR,
"class is nested but not static", enclosingClass);
return false;
}
return true;
}
示例7: getAccessFlagsForClassNode
/**
* Gets the class access flags (see JVMS8 4.1) for the given type element as they should appear in
* the ClassNode of a class file. Inner-class specific flags are not allowed in that node,
* presumably for compatibility reasons.
*/
public int getAccessFlagsForClassNode(TypeElement e) {
// Static never makes it into the file for classes
int accessFlags = getAccessFlags(e) & ~Opcodes.ACC_STATIC;
if (e.getNestingKind() != NestingKind.TOP_LEVEL) {
if (e.getModifiers().contains(Modifier.PROTECTED)) {
// It looks like inner classes with protected visibility get marked as public, and then
// their InnerClasses attributes override that more specifically
accessFlags = (accessFlags & ~Opcodes.ACC_PROTECTED) | Opcodes.ACC_PUBLIC;
} else if (e.getModifiers().contains(Modifier.PRIVATE)) {
// It looks like inner classes with private visibility get marked as package, and then
// their InnerClasses attributes override that more specifically
accessFlags = (accessFlags & ~Opcodes.ACC_PRIVATE);
}
}
return accessFlags;
}
示例8: ReplaceConstructorWithBuilderUI
private ReplaceConstructorWithBuilderUI(TreePathHandle constructor, CompilationInfo info) {
this.refactoring = new ReplaceConstructorWithBuilderRefactoring(constructor);
ExecutableElement contructorElement = (ExecutableElement) constructor.resolveElement(info);
this.name = contructorElement.getSimpleName().toString();
MethodTree constTree = (MethodTree) constructor.resolve(info).getLeaf();
paramaterNames = new ArrayList<String>();
parameterTypes = new ArrayList<String>();
parameterTypeVars = new ArrayList<Boolean>();
boolean varargs = contructorElement.isVarArgs();
List<? extends VariableElement> parameterElements = contructorElement.getParameters();
List<? extends VariableTree> parameters = constTree.getParameters();
for (int i = 0; i < parameters.size(); i++) {
VariableTree var = parameters.get(i);
paramaterNames.add(var.getName().toString());
String type = contructorElement.getParameters().get(i).asType().toString();
if(varargs && i+1 == parameters.size()) {
if(var.getType().getKind() == Tree.Kind.ARRAY_TYPE) {
ArrayTypeTree att = (ArrayTypeTree) var.getType();
type = att.getType().toString();
type += "..."; //NOI18N
}
}
parameterTypes.add(type);
parameterTypeVars.add(parameterElements.get(i).asType().getKind() == TypeKind.TYPEVAR);
}
TypeElement typeEl = (TypeElement) contructorElement.getEnclosingElement();
if(typeEl.getNestingKind() != NestingKind.TOP_LEVEL) {
PackageElement packageOf = info.getElements().getPackageOf(typeEl);
builderFQN = packageOf.toString() + "." + typeEl.getSimpleName().toString();
} else {
builderFQN = typeEl.getQualifiedName().toString();
}
buildMethodName = "create" + typeEl.getSimpleName();
}
示例9: 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());
}
示例10: resolveThrowsName
/**
* computes name of throws clause to work around
* <a href="http://www.netbeans.org/issues/show_bug.cgi?id=160414">issue 160414</a>.
*/
private static String resolveThrowsName(Element el, String fqn, ExpressionTree throwTree) {
boolean nestedClass = ElementKind.CLASS == el.getKind()
&& NestingKind.TOP_LEVEL != ((TypeElement) el).getNestingKind();
String insertName = nestedClass ? fqn : throwTree.toString();
return insertName;
}
示例11: apply
@TriggerPatterns(value = {
@TriggerPattern(value = JPAAnnotations.ENTITY),
@TriggerPattern(value = JPAAnnotations.EMBEDDABLE),
@TriggerPattern(value = JPAAnnotations.MAPPED_SUPERCLASS)})
public static ErrorDescription apply(HintContext hc) {
if (hc.isCanceled() || (hc.getPath().getLeaf().getKind() != Tree.Kind.IDENTIFIER || hc.getPath().getParentPath().getLeaf().getKind() != Tree.Kind.ANNOTATION)) {//NOI18N
return null;//we pass only if it is an annotation
}
final JPAProblemContext ctx = ModelUtils.getOrCreateCachedContext(hc);
if (ctx == null || hc.isCanceled()) {
return null;
}
TypeElement subject = ctx.getJavaClass();
if (subject.getNestingKind() == NestingKind.TOP_LEVEL){
return null;
}
TreePath par = hc.getPath();
while (par != null && par.getParentPath() != null && par.getLeaf().getKind() != Tree.Kind.CLASS) {
par = par.getParentPath();
}
Utilities.TextSpan underlineSpan = Utilities.getUnderlineSpan(
ctx.getCompilationInfo(), par.getLeaf());
return ErrorDescriptionFactory.forSpan(
hc,
underlineSpan.getStartOffset(),
underlineSpan.getEndOffset(),
NbBundle.getMessage(TopLevelClass.class, "MSG_NestedClassAsEntity"));
}
示例12: ComponentDescriptor
ComponentDescriptor( @Nonnull final String name,
@Nonnull final PackageElement packageElement,
@Nonnull final TypeElement element )
{
_name = Objects.requireNonNull( name );
_packageElement = Objects.requireNonNull( packageElement );
_element = Objects.requireNonNull( element );
if ( ElementKind.CLASS != element.getKind() )
{
throw new ReactProcessorException( "@ReactComponent target must be a class", element );
}
else if ( element.getModifiers().contains( Modifier.ABSTRACT ) )
{
throw new ReactProcessorException( "@ReactComponent target must not be abstract", element );
}
else if ( element.getModifiers().contains( Modifier.FINAL ) )
{
throw new ReactProcessorException( "@ReactComponent target must not be final", element );
}
else if ( NestingKind.TOP_LEVEL != element.getNestingKind() &&
!element.getModifiers().contains( Modifier.STATIC ) )
{
throw new ReactProcessorException( "@ReactComponent target must not be a non-static nested class", element );
}
final List<ExecutableElement> constructors = element.getEnclosedElements().stream().
filter( m -> m.getKind() == ElementKind.CONSTRUCTOR ).
map( m -> (ExecutableElement) m ).
collect( Collectors.toList() );
if ( !( 1 == constructors.size() &&
constructors.get( 0 ).getParameters().isEmpty() &&
!constructors.get( 0 ).getModifiers().contains( Modifier.PRIVATE ) ) )
{
throw new ReactProcessorException( "@ReactComponent target must have a single non-private, no-argument " +
"constructor or the default constructor", element );
}
}
示例13: getPackage
private PackageElement getPackage(final TypeElement type) {
if (type.getNestingKind() == NestingKind.TOP_LEVEL) {
return (PackageElement) type.getEnclosingElement();
} else {
return getPackage((TypeElement) type.getEnclosingElement());
}
}
示例14: 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;
}
示例15: getNestingKind
@Override
public NestingKind getNestingKind() {
require(State.FINISHED);
boolean isTopLevel = enclosingTypeDeclaration == null;
return isTopLevel
? NestingKind.TOP_LEVEL
: NestingKind.MEMBER;
}