本文整理汇总了Java中javax.lang.model.element.ElementKind.PACKAGE属性的典型用法代码示例。如果您正苦于以下问题:Java ElementKind.PACKAGE属性的具体用法?Java ElementKind.PACKAGE怎么用?Java ElementKind.PACKAGE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.lang.model.element.ElementKind
的用法示例。
在下文中一共展示了ElementKind.PACKAGE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validated
@Nullable
private TypeElement validated(Element element) {
Element enclosingElement = element.getEnclosingElement();
if (element.getKind() == ElementKind.ANNOTATION_TYPE
&& element.getModifiers().contains(Modifier.PUBLIC)
&& enclosingElement != null
&& (enclosingElement.getKind() != ElementKind.PACKAGE
|| !((PackageElement) enclosingElement).isUnnamed())) {
return (TypeElement) element;
}
processing().getMessager().printMessage(
Diagnostic.Kind.ERROR,
"Element annotated with @Mirror.Annotation annotation should public annotation type in a package",
element);
return null;
}
示例2: getPanel
@Override
public CustomRefactoringPanel getPanel(ChangeListener parent) {
if (panel == null) {
String suffix = "";
if(handle != null && handle.getKind() == Tree.Kind.LABELED_STATEMENT) {
suffix = getString("LBL_Label");
} else if (handle != null && handle.getElementHandle() !=null) {
ElementKind kind = handle.getElementHandle().getKind();
if (kind!=null && (kind.isClass() || kind.isInterface())) {
suffix = kind.isInterface() ? getString("LBL_Interface") : getString("LBL_Class");
} else if (kind == ElementKind.METHOD) {
suffix = getString("LBL_Method");
} else if (kind == ElementKind.FIELD) {
suffix = getString("LBL_Field");
} else if (kind == ElementKind.LOCAL_VARIABLE) {
suffix = getString("LBL_LocalVar");
} else if (kind == ElementKind.PACKAGE || (handle == null && fromListener)) {
suffix = pkgRename ? getString("LBL_Package") : getString("LBL_Folder");
} else if (kind == ElementKind.PARAMETER) {
suffix = getString("LBL_Parameter");
}
}
suffix = suffix + " " + this.oldName; // NOI18N
panel = new RenamePanel(handle, newName, parent, NbBundle.getMessage(RenamePanel.class, "LBL_Rename") + " " + suffix, !fromListener, fromListener && !byPassPakageRename);
}
return panel;
}
示例3: packageOf
@Override
@Value.Derived
@Value.Auxiliary
public DeclaringPackage packageOf() {
Element e = element();
for (; e.getKind() != ElementKind.PACKAGE; e = e.getEnclosingElement()) {
}
return interner().forPackage(
ImmutableProto.DeclaringPackage.builder()
.environment(environment())
.interner(interner())
.element((PackageElement) e)
.build());
}
示例4: getRelativeName
private String getRelativeName(TypeElement elem) {
StringBuilder sb = new StringBuilder();
sb.append(elem.getSimpleName().toString());
Element parent = elem.getEnclosingElement();
while(parent.getKind() != ElementKind.PACKAGE) {
sb.insert(0, parent.getSimpleName().toString() + "$"); // NOI18N
parent = parent.getEnclosingElement();
}
return sb.toString();
}
示例5: getFile
/**
* Returns a source file in which the passed element
* is declared in. This tuned up version of {@code SourceUtils.getFile}
* is necessary as sequential invocations of {@code SourceUtils.getFile} are
* excessively slow.
*
* @param element an element to find {@link FileObject} for
* @param cpInfo scope where the file will be searched
* @param cache a cache
* @return the source file
* @see SourceUtils#getFile(org.netbeans.api.java.source.ElementHandle, org.netbeans.api.java.source.ClasspathInfo) SourceUtils.getFile
*/
public static FileObject getFile(final Element element, final ClasspathInfo cpInfo, final Cache cache) {
Parameters.notNull("element", element); //NOI18N
Parameters.notNull("cpInfo", cpInfo); //NOI18N
Parameters.notNull("cache", cache); //NOI18N
Element current = element;
Element prev = current.getKind() == ElementKind.PACKAGE ? current : null;
while (current.getKind() != ElementKind.PACKAGE) {
prev = current;
current = current.getEnclosingElement();
}
if (prev == null) {
return null;
}
final ElementKind kind = prev.getKind();
String fqn;
if (kind.isClass() || kind.isInterface()) {
fqn = ((TypeElement) prev).getQualifiedName().toString();
} else if (kind == ElementKind.PACKAGE) {
fqn = ((PackageElement) prev).getQualifiedName().toString();
} else {
return null;
}
Object cached = cache.cacheOfSrcFiles.get(fqn);
if (cached == null) {
final ElementHandle<? extends Element> handle = ElementHandle.create(prev);
cached = SourceUtils.getFile(handle, cpInfo);
cache.cacheOfSrcFiles.put(fqn, cached != null ? cached : Cache.NULL);
} else if (cached == Cache.NULL) {
cached = null;
}
return (FileObject) cached;
}
示例6: createPackageElementHandle
/**
* Creates an {@link ElementHandle} representing a {@link PackageElement}.
* @param packageName the name of the package
* @return the created {@link ElementHandle}
* @since 0.98
*/
@NonNull
public static ElementHandle<PackageElement> createPackageElementHandle (
@NonNull final String packageName) {
Parameters.notNull("packageName", packageName); //NOI18N
return new ElementHandle<PackageElement>(ElementKind.PACKAGE, packageName);
}
示例7: enclosingTypeElement
private TypeElement enclosingTypeElement(Element element) {
if (element.getKind() == ElementKind.PACKAGE) {
throw new IllegalArgumentException();
}
while (element != null && !isType(element)) {
element = element.getEnclosingElement();
}
return (TypeElement) element;
}
示例8: findPackage
private PackageElement findPackage(Element e) {
if (e.getKind() == ElementKind.PACKAGE) {
return ((PackageElement) e);
}
Element parent = e.getEnclosingElement();
if (parent == null) {
return null;
}
return findPackage(parent);
}
示例9: getName
private String getName(Element e) {
if (e.getKind().isClass() || e.getKind().isInterface()) {
return processingEnv.getElementUtils().getBinaryName((TypeElement)e).toString();
} else if (e.getKind() == ElementKind.PACKAGE) {
return e.getSimpleName().toString();
} else {
return getName(e.getEnclosingElement()) + '.' + e.getSimpleName();
}
}
示例10: doCreateFromTemplate
FileObject doCreateFromTemplate(CompilationUnitTree cut) throws IOException {
ElementKind kind;
if ("package-info.java".equals(cut.getSourceFile().getName())) {
kind = ElementKind.PACKAGE;
} else if (cut.getTypeDecls().isEmpty()) {
kind = null;
} else {
switch (cut.getTypeDecls().get(0).getKind()) {
case CLASS:
kind = ElementKind.CLASS;
break;
case INTERFACE:
kind = ElementKind.INTERFACE;
break;
case ANNOTATION_TYPE:
kind = ElementKind.ANNOTATION_TYPE;
break;
case ENUM:
kind = ElementKind.ENUM;
break;
default:
Logger.getLogger(WorkingCopy.class.getName()).log(Level.SEVERE, "Cannot resolve template for {0}", cut.getTypeDecls().get(0).getKind());
kind = null;
}
}
FileObject template = FileUtil.getConfigFile(template(kind));
return doCreateFromTemplate(template, cut.getSourceFile());
}
示例11: isPackage
public boolean isPackage(Element e) {
return e.getKind() == ElementKind.PACKAGE;
}
示例12: create
@Override
public RefactoringUI create(CompilationInfo info, TreePathHandle[] handles, FileObject[] files, NonRecursiveFolder[] packages) {
final boolean b = lookup.lookup(ExplorerContext.class)!=null;
if (packages != null && packages.length == 1) {
return new SafeDeleteUI(packages[0], b);
}
if (handles != null && handles.length == 0 || (files!=null && files.length > 1)) {
return new SafeDeleteUI(files, Arrays.asList(handles), b);
}
if (b && files!=null && files.length == 1) {
return new SafeDeleteUI(files, Arrays.asList(handles), b);
}
if (info == null) {
return new SafeDeleteUI(handles);
}
TreePathHandle selectedElement = handles[0];
Element selected = selectedElement.resolveElement(info);
TreePath selectedTree = selectedElement.resolve(info);
if (selected == null || selectedTree == null) {
return null;
}
if (selected.getKind() == ElementKind.PACKAGE || selected.getEnclosingElement().getKind() == ElementKind.PACKAGE) {
ElementHandle<Element> handle = ElementHandle.create(selected);
FileObject file = SourceUtils.getFile(handle, info.getClasspathInfo());
if (file == null) {
return null;
}
if (file.getName().equals(selected.getSimpleName().toString())) {
return new SafeDeleteUI(new FileObject[]{file}, Collections.singleton(selectedElement), b);
}
}
if(!TreeUtilities.CLASS_TREE_KINDS.contains(selectedTree.getParentPath().getLeaf().getKind())
&& selectedTree.getParentPath().getLeaf().getKind() != Tree.Kind.COMPILATION_UNIT
&& selectedTree.getLeaf().getKind() == Tree.Kind.VARIABLE) {
switch (selectedTree.getParentPath().getLeaf().getKind()) {
case BLOCK:
case METHOD:
break;
default:
return null;
}
}
return new SafeDeleteUI(new TreePathHandle[]{selectedElement});
}
示例13: getPackage
public static PackageElement getPackage(TypeElement type) {
Element owner = type;
while (owner.getKind() != ElementKind.PACKAGE)
owner = owner.getEnclosingElement();
return (PackageElement)owner;
}
示例14: run
public List<ErrorDescription> run(CompilationInfo compilationInfo,
TreePath treePath) {
stop = false;
Element e = compilationInfo.getTrees().getElement(treePath);
if (e == null) {
return null;
}
Boolean b = e.accept(this, null);
if (b) {
Element parent = e;
for (;;) {
if (stop) {
return null;
}
if (parent == null || parent.getKind() == ElementKind.PACKAGE) {
break;
}
if (!parent.getModifiers().contains(Modifier.PUBLIC) && !parent.getModifiers().contains(Modifier.PROTECTED)) {
return null;
}
parent = parent.getEnclosingElement();
}
//#124456: disabling the fix:
// List<Fix> fixes = Collections.<Fix>singletonList(new FixImpl(
// "MSG_ExportNonAccessibleElementMakeNonVisible", // NOI18N
// TreePathHandle.create(e, compilationInfo),
// compilationInfo.getFileObject()
// ));
int[] span = null;
switch (treePath.getLeaf().getKind()) {
case METHOD: span = compilationInfo.getTreeUtilities().findNameSpan((MethodTree) treePath.getLeaf()); break;
case ANNOTATION_TYPE:
case CLASS:
case ENUM:
case INTERFACE:
span = compilationInfo.getTreeUtilities().findNameSpan((ClassTree) treePath.getLeaf()); break;
case VARIABLE: span = compilationInfo.getTreeUtilities().findNameSpan((VariableTree) treePath.getLeaf()); break;
}
if (span != null) {
ErrorDescription ed = ErrorDescriptionFactory.createErrorDescription(
getSeverity().toEditorSeverity(),
NbBundle.getMessage(ExportNonAccessibleElement.class, "MSG_ExportNonAccessibleElement"),
// fixes,
compilationInfo.getFileObject(),
span[0],
span[1]
);
return Collections.singletonList(ed);
}
}
return null;
}
示例15: check
@TriggerTreeKind({Tree.Kind.CLASS, Tree.Kind.INTERFACE})
public static ErrorDescription check(HintContext context) {
TreePath tp = context.getPath();
ClassTree cls = (ClassTree) tp.getLeaf();
CompilationInfo info = context.getInfo();
SourcePositions sourcePositions = info.getTrees().getSourcePositions();
long startPos = sourcePositions.getStartPosition(tp.getCompilationUnit(), cls);
if (startPos > Integer.MAX_VALUE) {
return null;
}
int[] bodySpan = info.getTreeUtilities().findBodySpan(cls);
if (bodySpan == null || bodySpan[0] <= startPos) {
return null;
}
int caret = context.getCaretLocation();
if (startPos < 0 || caret < 0 || caret < startPos || caret >= bodySpan[0]) {
return null;
}
// #222487
// If there is a compile-time error on the class, then don't offer to
// create a subclass.
List<Diagnostic> errors = info.getDiagnostics();
if (!errors.isEmpty()) {
for (Diagnostic d : errors) {
if (d.getKind() != Diagnostic.Kind.ERROR) {
continue;
}
// Check that the error's start position is within the class header
// Note: d.getEndPosition() is not used because, for example,
// a "compiler.err.does.not.override.abstract" error ends at
// the end of the class tree.
if (startPos <= d.getStartPosition() && d.getStartPosition() <= bodySpan[0]) {
return null;
}
}
}
TypeElement typeElement = (TypeElement) info.getTrees().getElement(tp);
if (typeElement == null || typeElement.getModifiers().contains(Modifier.FINAL)) return null;
Element outer = typeElement.getEnclosingElement();
// do not offer the hint for non-static inner classes. Permit for classes nested into itnerface - no enclosing instance
if (outer != null && outer.getKind() != ElementKind.PACKAGE && outer.getKind() != ElementKind.INTERFACE) {
if (outer.getKind() != ElementKind.CLASS && outer.getKind() != ElementKind.ENUM) {
return null;
}
if (!typeElement.getModifiers().contains(Modifier.STATIC)) {
return null;
}
}
ClassPath cp = info.getClasspathInfo().getClassPath(PathKind.SOURCE);
FileObject root = cp.findOwnerRoot(info.getFileObject());
if (root == null) { //File not part of any project
return null;
}
PackageElement packageElement = (PackageElement) info.getElementUtilities().outermostTypeElement(typeElement).getEnclosingElement();
CreateSubclassFix fix = new CreateSubclassFix(info, root, packageElement.getQualifiedName().toString(), typeElement.getSimpleName().toString() + "Impl", typeElement); //NOI18N
return ErrorDescriptionFactory.forTree(context, context.getPath(), NbBundle.getMessage(CreateSubclass.class, typeElement.getKind() == ElementKind.CLASS
? typeElement.getModifiers().contains(Modifier.ABSTRACT) ? "ERR_ImplementAbstractClass" : "ERR_CreateSubclass" : "ERR_ImplementInterface"), fix); //NOI18N
}