本文整理汇总了Java中javax.lang.model.element.PackageElement类的典型用法代码示例。如果您正苦于以下问题:Java PackageElement类的具体用法?Java PackageElement怎么用?Java PackageElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PackageElement类属于javax.lang.model.element包,在下文中一共展示了PackageElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFlattenedEnclosingElementsTree_withoutRoot_withoutMaxDepth
import javax.lang.model.element.PackageElement; //导入依赖的package包/类
@Test
public void getFlattenedEnclosingElementsTree_withoutRoot_withoutMaxDepth() {
// Prepare
Element parameterElement = Mockito.mock(VariableElement.class);
Element methodElement = Mockito.mock(ExecutableElement.class);
Element typeElement = Mockito.mock(TypeElement.class);
Element packageElement = Mockito.mock(PackageElement.class);
Mockito.when(parameterElement.getEnclosingElement()).thenReturn(methodElement);
Mockito.when(methodElement.getEnclosingElement()).thenReturn(typeElement);
Mockito.when(typeElement.getEnclosingElement()).thenReturn(packageElement);
// execute
List<Element> result = ElementUtils.AccessEnclosingElements.getFlattenedEnclosingElementsTree(parameterElement, false);
// validate
MatcherAssert.assertThat(result, Matchers.containsInAnyOrder(methodElement, typeElement, packageElement));
MatcherAssert.assertThat(result, Matchers.not(Matchers.contains(parameterElement)));
}
开发者ID:toolisticon,项目名称:annotation-processor-toolkit,代码行数:23,代码来源:ElementUtils_AccessEnclosingElementsTest.java
示例2: getFlattenedEnclosingElementsTree_withRoot_withoutMaxDepth
import javax.lang.model.element.PackageElement; //导入依赖的package包/类
@Test
public void getFlattenedEnclosingElementsTree_withRoot_withoutMaxDepth() {
// Prepare
Element parameterElement = Mockito.mock(VariableElement.class);
Element methodElement = Mockito.mock(ExecutableElement.class);
Element typeElement = Mockito.mock(TypeElement.class);
Element packageElement = Mockito.mock(PackageElement.class);
Mockito.when(parameterElement.getEnclosingElement()).thenReturn(methodElement);
Mockito.when(methodElement.getEnclosingElement()).thenReturn(typeElement);
Mockito.when(typeElement.getEnclosingElement()).thenReturn(packageElement);
// execute
List<Element> result = ElementUtils.AccessEnclosingElements.getFlattenedEnclosingElementsTree(parameterElement, true);
// validate
MatcherAssert.assertThat(result, Matchers.containsInAnyOrder(parameterElement, methodElement, typeElement, packageElement));
}
开发者ID:toolisticon,项目名称:annotation-processor-toolkit,代码行数:22,代码来源:ElementUtils_AccessEnclosingElementsTest.java
示例3: getFlattenedEnclosingElementsTree_withoutRoot_withMaxDepth
import javax.lang.model.element.PackageElement; //导入依赖的package包/类
@Test
public void getFlattenedEnclosingElementsTree_withoutRoot_withMaxDepth() {
// Prepare
Element parameterElement = Mockito.mock(VariableElement.class);
Element methodElement = Mockito.mock(ExecutableElement.class);
Element typeElement = Mockito.mock(TypeElement.class);
Element packageElement = Mockito.mock(PackageElement.class);
Mockito.when(parameterElement.getEnclosingElement()).thenReturn(methodElement);
Mockito.when(methodElement.getEnclosingElement()).thenReturn(typeElement);
Mockito.when(typeElement.getEnclosingElement()).thenReturn(packageElement);
// execute
List<Element> result = ElementUtils.AccessEnclosingElements.getFlattenedEnclosingElementsTree(parameterElement, false, 2);
// validate
MatcherAssert.assertThat(result, Matchers.containsInAnyOrder(methodElement, typeElement));
MatcherAssert.assertThat(result, Matchers.not(Matchers.contains(parameterElement, packageElement)));
}
开发者ID:toolisticon,项目名称:annotation-processor-toolkit,代码行数:23,代码来源:ElementUtils_AccessEnclosingElementsTest.java
示例4: addIndexContents
import javax.lang.model.element.PackageElement; //导入依赖的package包/类
/**
* Adds package index contents. Call appropriate methods from
* the sub-classes. Adds it to the body HtmlTree
*
* @param packages a collection of packages to be documented
* @param text string which will be used as the heading
* @param tableSummary summary for the table
* @param body the document tree to which the index contents will be added
*/
protected void addIndexContents(Collection<PackageElement> packages, String text,
String tableSummary, Content body) {
if (!packages.isEmpty()) {
HtmlTree htmlTree = (configuration.allowTag(HtmlTag.NAV))
? HtmlTree.NAV()
: new HtmlTree(HtmlTag.DIV);
htmlTree.addStyle(HtmlStyle.indexNav);
HtmlTree ul = new HtmlTree(HtmlTag.UL);
addAllClassesLink(ul);
if (configuration.showModules && configuration.modules.size() > 1) {
addAllModulesLink(ul);
}
htmlTree.addContent(ul);
body.addContent(htmlTree);
addPackagesList(packages, text, tableSummary, body);
}
}
示例5: addLinkToPackageContent
import javax.lang.model.element.PackageElement; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public void addLinkToPackageContent(PackageElement pkg,
Set<PackageElement> printedPackageHeaders, Content contentListTree) {
//add link to summary
Content link;
if (pkg.isUnnamed()) {
link = getHyperLink(getDocLink(
SectionName.UNNAMED_PACKAGE_ANCHOR),
contents.defaultPackageLabel, "", "");
} else {
String parsedPackageName = utils.parsePackageName(pkg);
Content packageNameContent = getPackageLabel(parsedPackageName);
packageNameContent.addContent(".*");
link = getHyperLink(DocLink.fragment(parsedPackageName),
packageNameContent, "", "");
PackageElement abbrevPkg = configuration.workArounds.getAbbreviatedPackageElement(pkg);
printedPackageHeaders.add(abbrevPkg);
}
contentListTree.addContent(HtmlTree.LI(link));
}
示例6: getPackage
import javax.lang.model.element.PackageElement; //导入依赖的package包/类
/**
* Returns each package name as a separate link.
*
* @param pkg PackageElement
* @param mdle the module being documented
* @return content for the package link
*/
protected Content getPackage(PackageElement pkg, ModuleElement mdle) {
Content packageLinkContent;
Content pkgLabel;
if (!pkg.isUnnamed()) {
pkgLabel = getPackageLabel(utils.getPackageName(pkg));
packageLinkContent = getHyperLink(pathString(pkg,
DocPaths.PACKAGE_FRAME), pkgLabel, "",
"packageFrame");
} else {
pkgLabel = new StringContent("<unnamed package>");
packageLinkContent = getHyperLink(DocPaths.PACKAGE_FRAME,
pkgLabel, "", "packageFrame");
}
Content li = HtmlTree.LI(packageLinkContent);
return li;
}
示例7: getIndexedClassNames
import javax.lang.model.element.PackageElement; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private FoundIndexedClassNames getIndexedClassNames(PackageElement glideGenPackage) {
Set<String> glideModules = new HashSet<>();
Set<String> extensions = new HashSet<>();
List<? extends Element> glideGeneratedElements = glideGenPackage.getEnclosedElements();
for (Element indexer : glideGeneratedElements) {
Index annotation = indexer.getAnnotation(Index.class);
// If the annotation is null, it means we've come across another class in the same package
// that we can safely ignore.
if (annotation != null) {
Collections.addAll(glideModules, annotation.modules());
Collections.addAll(extensions, annotation.extensions());
}
}
processorUtil.debugLog("Found GlideModules: " + glideModules);
return new FoundIndexedClassNames(glideModules, extensions);
}
示例8: addModulePackagesList
import javax.lang.model.element.PackageElement; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
protected void addModulePackagesList(Set<ModuleElement> modules, String text,
String tableSummary, Content body, ModuleElement mdle) {
Content moduleNameContent = new StringContent(mdle.getQualifiedName().toString());
Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true,
getTargetModuleLink("classFrame", moduleNameContent, mdle));
heading.addContent(Contents.SPACE);
heading.addContent(contents.packagesLabel);
HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN))
? HtmlTree.MAIN(HtmlStyle.indexContainer, heading)
: HtmlTree.DIV(HtmlStyle.indexContainer, heading);
HtmlTree ul = new HtmlTree(HtmlTag.UL);
ul.setTitle(contents.packagesLabel);
Set<PackageElement> modulePackages = configuration.modulePackages.get(mdle);
for (PackageElement pkg: modulePackages) {
if ((!(configuration.nodeprecated && utils.isDeprecated(pkg)))) {
ul.addContent(getPackage(pkg, mdle));
}
}
htmlTree.addContent(ul);
body.addContent(htmlTree);
}
示例9: getLocalAndInheritedMethods
import javax.lang.model.element.PackageElement; //导入依赖的package包/类
private static void getLocalAndInheritedMethods(
PackageElement pkg, TypeElement type, SetMultimap<String, ExecutableElement> methods) {
for (TypeMirror superInterface : type.getInterfaces()) {
getLocalAndInheritedMethods(pkg, MoreTypes.asTypeElement(superInterface), methods);
}
if (type.getSuperclass().getKind() != TypeKind.NONE) {
// Visit the superclass after superinterfaces so we will always see the implementation of a
// method after any interfaces that declared it.
getLocalAndInheritedMethods(pkg, MoreTypes.asTypeElement(type.getSuperclass()), methods);
}
for (ExecutableElement method : ElementFilter.methodsIn(type.getEnclosedElements())) {
if (!method.getModifiers().contains(Modifier.STATIC)
&& methodVisibleFromPackage(method, pkg)) {
methods.put(method.getSimpleName().toString(), method);
}
}
}
示例10: validated
import javax.lang.model.element.PackageElement; //导入依赖的package包/类
@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;
}
示例11: collect
import javax.lang.model.element.PackageElement; //导入依赖的package包/类
void collect(Element element) {
switch (element.getKind()) {
case ANNOTATION_TYPE:
case INTERFACE:
case CLASS:
case ENUM:
collectIncludedAndDefinedBy((TypeElement) element);
break;
case METHOD:
case CONSTRUCTOR:
collectDefinedBy((ExecutableElement) element);
break;
case PACKAGE:
collectIncludedBy((PackageElement) element);
break;
default:
Reporter.from(processing())
.withElement(element)
.warning("Unmatched annotation will be skipped for annotation processing");
}
}
示例12: namedParentPackage
import javax.lang.model.element.PackageElement; //导入依赖的package包/类
@Value.Lazy
Optional<DeclaringPackage> namedParentPackage() {
String parentPackageName = SourceNames.parentPackageName(element());
if (!parentPackageName.isEmpty()) {
@Nullable PackageElement parentPackage =
environment().processing()
.getElementUtils()
.getPackageElement(parentPackageName);
if (parentPackage != null) {
return Optional.of(interner().forPackage(
ImmutableProto.DeclaringPackage.builder()
.environment(environment())
.interner(interner())
.element(parentPackage)
.build()));
}
}
return Optional.absent();
}
示例13: findClassElementByBinaryName
import javax.lang.model.element.PackageElement; //导入依赖的package包/类
public static TypeElement findClassElementByBinaryName(final String binaryName, CompilationController cc) {
if (!binaryName.contains("$")) { // NOI18N
// fast search based on fqn
return cc.getElements().getTypeElement(binaryName);
} else {
// get containing package
String packageName = ""; // NOI18N
int dotIndex = binaryName.lastIndexOf("."); // NOI18N
if (dotIndex != -1) {
packageName = binaryName.substring(0, dotIndex);
}
PackageElement packElem = cc.getElements().getPackageElement(packageName);
if (packElem == null) {
return null;
}
// scan for element matching the binaryName
return new BinaryNameTypeScanner().visit(packElem, binaryName);
}
}
示例14: getBundleValue
import javax.lang.model.element.PackageElement; //导入依赖的package包/类
private String getBundleValue(String label, Annotation annotation, String annotationMethod) throws LayerGenerationException {
String javaIdentifier = "(?:\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)";
Matcher m = Pattern.compile("((?:" + javaIdentifier + "\\.)+[^\\s.#]+)?#(\\S*)").matcher(label);
if (m.matches()) {
String bundle = m.group(1);
String key = m.group(2);
if (bundle == null) {
Element referenceElement = originatingElement;
while (referenceElement != null && referenceElement.getKind() != ElementKind.PACKAGE) {
referenceElement = referenceElement.getEnclosingElement();
}
if (referenceElement == null) {
throw new LayerGenerationException("No reference element to determine package in '" + label + "'", originatingElement);
}
bundle = ((PackageElement) referenceElement).getQualifiedName() + ".Bundle";
}
return verifyBundleValue(bundle, key, m.group(1) == null, annotation, annotationMethod);
}
return label;
}
示例15: computeSpecifiedPackages
import javax.lang.model.element.PackageElement; //导入依赖的package包/类
private void computeSpecifiedPackages() throws ToolException {
computeSubpackages();
Set<PackageElement> packlist = new LinkedHashSet<>();
cmdLinePackages.forEach((modpkg) -> {
PackageElement pkg;
if (modpkg.hasModule()) {
ModuleElement mdle = toolEnv.elements.getModuleElement(modpkg.moduleName);
pkg = toolEnv.elements.getPackageElement(mdle, modpkg.packageName);
} else {
pkg = toolEnv.elements.getPackageElement(modpkg.toString());
}
if (pkg != null) {
packlist.add(pkg);
} else {
messager.printWarningUsingKey("main.package_not_found", modpkg.toString());
}
});
specifiedPackageElements = Collections.unmodifiableSet(packlist);
}