當前位置: 首頁>>代碼示例>>Java>>正文


Java ElementKind.PACKAGE屬性代碼示例

本文整理匯總了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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:Mirrors.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:RenameRefactoringUI.java

示例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());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:Proto.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:SpringXMLConfigCompletionItem.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:47,代碼來源:SourceUtilsEx.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:ElementHandle.java

示例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;
  }
 
開發者ID:gradle,項目名稱:incap,代碼行數:12,代碼來源:InputTypeFinder.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:Hinter.java

示例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();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:MIMEResolverProcessor.java

示例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());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:28,代碼來源:WorkingCopy.java

示例11: isPackage

public boolean isPackage(Element e) {
    return e.getKind() == ElementKind.PACKAGE;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:3,代碼來源:Utils.java

示例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});
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:47,代碼來源:SafeDeleteUI.java

示例13: getPackage

public static PackageElement getPackage(TypeElement type) {
    Element owner = type;
    while (owner.getKind() != ElementKind.PACKAGE)
        owner = owner.getEnclosingElement();
    return (PackageElement)owner;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:Main.java

示例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;
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:60,代碼來源:ExportNonAccessibleElement.java

示例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
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:65,代碼來源:CreateSubclass.java


注:本文中的javax.lang.model.element.ElementKind.PACKAGE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。