本文整理汇总了Java中javax.lang.model.element.Element.getSimpleName方法的典型用法代码示例。如果您正苦于以下问题:Java Element.getSimpleName方法的具体用法?Java Element.getSimpleName怎么用?Java Element.getSimpleName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.Element
的用法示例。
在下文中一共展示了Element.getSimpleName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toString
import javax.lang.model.element.Element; //导入方法依赖的package包/类
@Override
public String toString(List<? extends DocTree> tags, Element element) {
// The content lines below are primarily to help verify the element
// and the values passed to init.
return "<dt>"
+"<span class=\"simpleTagLabel\">Info:</span>\n"
+ "</dt>"
+ "<dd>"
+ "<ul>\n"
+ "<li>Element: " + element.getKind() + " " + element.getSimpleName() + "\n"
+ "<li>Element supertypes: " +
env.getTypeUtils().directSupertypes(element.asType()) + "\n"
+ "<li>Doclet: " + doclet.getClass() + "\n"
+ "</ul>\n"
+ "</dd>";
}
示例2: categories
import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
* Categories field, find his papa.
*
* @param elements Field need autowired
*/
private void categories(Set<? extends Element> elements) throws IllegalAccessException {
if (CollectionUtils.isNotEmpty(elements)) {
for (Element element : elements) {
TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
if (element.getModifiers().contains(Modifier.PRIVATE)) {
throw new IllegalAccessException("The autowired fields CAN NOT BE 'private'!!! please check field ["
+ element.getSimpleName() + "] in class [" + enclosingElement.getQualifiedName() + "]");
}
if (parentAndChild.containsKey(enclosingElement)) { // Has categries
parentAndChild.get(enclosingElement).add(element);
} else {
List<Element> childs = new ArrayList<>();
childs.add(element);
parentAndChild.put(enclosingElement, childs);
}
}
logger.info("categories finished.");
}
}
示例3: resolveTypeName
import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
* uses FQNs where possible since javadoc does not match imports for
* parameter types
*/
private CharSequence resolveTypeName(TypeMirror asType, boolean isVarArgs) {
CharSequence ptype;
if (asType.getKind() == TypeKind.DECLARED) {
// snip generics
Element e = ((DeclaredType) asType).asElement();
ptype = e.getKind().isClass() || e.getKind().isInterface()
? ((TypeElement) e).getQualifiedName()
: e.getSimpleName();
} else if (asType.getKind() == TypeKind.TYPEVAR) {
do {
// Type Erasure JLS 4.6
asType = ((TypeVariable) asType).getUpperBound();
} while (asType.getKind() == TypeKind.TYPEVAR);
ptype = resolveTypeName(asType, isVarArgs);
} else if (isVarArgs && asType.getKind() == TypeKind.ARRAY) {
ptype = resolveTypeName(((ArrayType)asType).getComponentType(), false) + "..."; //NOI18N
} else {
ptype = asType.toString();
}
return ptype;
}
示例4: checkParamsDocumented
import javax.lang.model.element.Element; //导入方法依赖的package包/类
private void checkParamsDocumented(List<? extends Element> list, List<? extends Tree> trees, DocTreePath docTreePath, Set<String> inheritedParams, List<ErrorDescription> errors) {
if(foundInheritDoc) return;
for (int i = 0; i < list.size() && i < trees.size(); i++) {
if(ctx.isCanceled()) { return; }
Element e = list.get(i);
Tree t = trees.get(i);
if (!foundParams.contains(e) && !inheritedParams.contains(e.getSimpleName().toString())) {
boolean isTypeParam = e.getKind() == ElementKind.TYPE_PARAMETER;
CharSequence paramName = (isTypeParam)
? "<" + e.getSimpleName() + ">"
: e.getSimpleName();
DocTreePathHandle dtph = DocTreePathHandle.create(docTreePath, javac);
if (dtph != null) {
errors.add(ErrorDescriptionFactory.forTree(ctx, t, MISSING_PARAM_DESC(paramName), AddTagFix.createAddParamTagFix(dtph, e.getSimpleName().toString(), isTypeParam, i).toEditorFix()));
}
}
}
}
示例5: ExposedMethod
import javax.lang.model.element.Element; //导入方法依赖的package包/类
public ExposedMethod(Element element) {
ExecutableType method = (ExecutableType) element.asType();
TypeElement declaringClass = (TypeElement) element.getEnclosingElement();
this.name = element.getSimpleName().toString();
this.originalMethod = declaringClass.getQualifiedName().toString() + "." + element.getSimpleName();
this.returnType = method.getReturnType().toString();
this.params = new ArrayList<>();
int count = 0;
for (TypeMirror param : method.getParameterTypes()) {
this.params.add(param.toString());
String[] components = param.toString().toLowerCase().split("\\.");
String paramName = components[components.length - 1];
if (paramName.endsWith(">")) {
paramName = paramName.substring(0, paramName.length() - 1);
}
this.params.add(paramName + count);
count++;
}
this.thrown = Stream.of(method.getThrownTypes()).map(new Function<TypeMirror, String>() {
@Override
public String apply(TypeMirror typeMirror) {
return typeMirror.toString();
}
}).toList();
}
示例6: getName
import javax.lang.model.element.Element; //导入方法依赖的package包/类
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();
}
}
示例7: toString
import javax.lang.model.element.Element; //导入方法依赖的package包/类
String toString(Element el) {
switch (el.getKind()) {
case METHOD:
return toString(el.getEnclosingElement()) + "." + el.getSimpleName();
case CLASS:
return processingEnv.getElementUtils().getBinaryName((TypeElement) el).toString();
case TYPE_PARAMETER:
return toString(((TypeParameterElement) el).getGenericElement()) + "." + el.getSimpleName();
default:
throw new IllegalStateException("Unexpected element: " + el + "(" + el.getKind() + ")");
}
}
示例8: getClassName
import javax.lang.model.element.Element; //导入方法依赖的package包/类
String getClassName(String suffix) {
String name = type.getSimpleName() + suffix;
for (Element enclosing : getEnclosingElements()) {
name = enclosing.getSimpleName() + CLASS_SEPARATOR + name;
}
return name;
}
示例9: builderField
import javax.lang.model.element.Element; //导入方法依赖的package包/类
public static FieldSpec builderField(Element element) {
Name name = element.getSimpleName();
return FieldSpec
.builder(TypeName.get(element.asType()), name.toString())
.addModifiers(Modifier.PRIVATE)
.build();
}
示例10: elementSignature
import javax.lang.model.element.Element; //导入方法依赖的package包/类
private String elementSignature(Element el) {
switch (el.getKind()) {
case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE:
return ((TypeElement) el).getQualifiedName().toString();
case FIELD:
return elementSignature(el.getEnclosingElement()) + "." + el.getSimpleName() + ":" + el.asType();
case ENUM_CONSTANT:
return elementSignature(el.getEnclosingElement()) + "." + el.getSimpleName();
case EXCEPTION_PARAMETER: case LOCAL_VARIABLE: case PARAMETER: case RESOURCE_VARIABLE:
return el.getSimpleName() + ":" + el.asType();
case CONSTRUCTOR: case METHOD:
StringBuilder header = new StringBuilder();
header.append(elementSignature(el.getEnclosingElement()));
if (el.getKind() == ElementKind.METHOD) {
header.append(".");
header.append(el.getSimpleName());
}
header.append("(");
String sep = "";
ExecutableElement method = (ExecutableElement) el;
for (Iterator<? extends VariableElement> i = method.getParameters().iterator(); i.hasNext();) {
VariableElement p = i.next();
header.append(sep);
header.append(p.asType());
sep = ", ";
}
header.append(")");
return header.toString();
default:
return el.toString();
}
}
示例11: createPluginFactory
import javax.lang.model.element.Element; //导入方法依赖的package包/类
private static void createPluginFactory(ProcessingEnvironment env, Element topLevelClass, List<GeneratedPlugin> plugins) {
PackageElement pkg = (PackageElement) topLevelClass.getEnclosingElement();
String genClassName = "PluginFactory_" + topLevelClass.getSimpleName();
try {
JavaFileObject factory = env.getFiler().createSourceFile(pkg.getQualifiedName() + "." + genClassName, topLevelClass);
try (PrintWriter out = new PrintWriter(factory.openWriter())) {
out.printf("// CheckStyle: stop header check\n");
out.printf("// CheckStyle: stop line length check\n");
out.printf("// GENERATED CONTENT - DO NOT EDIT\n");
out.printf("// GENERATORS: %s, %s\n", VerifierAnnotationProcessor.class.getName(), PluginGenerator.class.getName());
out.printf("package %s;\n", pkg.getQualifiedName());
out.printf("\n");
createImports(out, plugins);
out.printf("\n");
out.printf("@ServiceProvider(NodeIntrinsicPluginFactory.class)\n");
out.printf("public class %s implements NodeIntrinsicPluginFactory {\n", genClassName);
for (GeneratedPlugin plugin : plugins) {
out.printf("\n");
plugin.generate(env, out);
}
out.printf("\n");
createPluginFactoryMethod(out, plugins);
out.printf("}\n");
}
} catch (IOException e) {
env.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage());
}
}
示例12: parseBindView
import javax.lang.model.element.Element; //导入方法依赖的package包/类
private void parseBindView(Element element, Map<TypeElement, BindingSet.Builder> builderMap,
Set<TypeElement> erasedTargetNames) {
TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
// Start by verifying common generated code restrictions.
boolean hasError = isInaccessibleViaGeneratedCode(BindView.class, "fields", element)
|| isBindingInWrongPackage(BindView.class, element);
// Verify that the target type extends from View.
TypeMirror elementType = element.asType();
if (elementType.getKind() == TypeKind.TYPEVAR) {
TypeVariable typeVariable = (TypeVariable) elementType;
elementType = typeVariable.getUpperBound();
}
Name qualifiedName = enclosingElement.getQualifiedName();
Name simpleName = element.getSimpleName();
if (!isSubtypeOfType(elementType, VIEW_TYPE) && !isInterface(elementType)) {
if (elementType.getKind() == TypeKind.ERROR) {
note(element, "@%s field with unresolved type (%s) "
+ "must elsewhere be generated as a View or interface. (%s.%s)",
BindView.class.getSimpleName(), elementType, qualifiedName, simpleName);
} else {
error(element, "@%s fields must extend from View or be an interface. (%s.%s)",
BindView.class.getSimpleName(), qualifiedName, simpleName);
hasError = true;
}
}
if (hasError) {
return;
}
// Assemble information on the field.
int id = element.getAnnotation(BindView.class).value();
BindingSet.Builder builder = builderMap.get(enclosingElement);
QualifiedId qualifiedId = elementToQualifiedId(element, id);
if (builder != null) {
String existingBindingName = builder.findExistingBindingName(getId(qualifiedId));
if (existingBindingName != null) {
error(element, "Attempt to use @%s for an already bound ID %d on '%s'. (%s.%s)",
BindView.class.getSimpleName(), id, existingBindingName,
enclosingElement.getQualifiedName(), element.getSimpleName());
return;
}
} else {
builder = getOrCreateBindingBuilder(builderMap, enclosingElement);
}
String name = simpleName.toString();
TypeName type = TypeName.get(elementType);
boolean required = isFieldRequired(element);
builder.addField(getId(qualifiedId), new FieldViewBinding(name, type, required));
// Add the type-erased version to the valid binding targets set.
erasedTargetNames.add(enclosingElement);
}
示例13: CachingElement
import javax.lang.model.element.Element; //导入方法依赖的package包/类
CachingElement(Element delegate) {
this.delegate = delegate;
this.kind = delegate.getKind();
this.simpleName = delegate.getSimpleName();
this.modifiers = delegate.getModifiers();
}
示例14: getDeprecatedLink
import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected Content getDeprecatedLink(Element member) {
String name = utils.getFullyQualifiedName(member) + "." + member.getSimpleName();
return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, member, name);
}
示例15: process
import javax.lang.model.element.Element; //导入方法依赖的package包/类
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment environment) {
for(final Element element : environment.getElementsAnnotatedWith(GetMany.class)) {
final GetMany annotation = element.getAnnotation(GetMany.class);
if(ElementKind.METHOD != element.getKind()) {
throw new DataSourceDefinitionException(
"Must use @GetMany with methods only! Tried to use with " + element.getSimpleName()
+ ", which is not a method.");
}
final Set<Modifier> modifiers = element.getModifiers();
if(!modifiers.contains(Modifier.PUBLIC)) {
throw new DataSourceDefinitionException(
"Must use @GetMany with public methods only! Tried to use with " + element.getSimpleName()
+ ", which is not public.");
}
if(modifiers.contains(Modifier.STATIC)) {
throw new DataSourceDefinitionException(
"Must use @GetMany with non-static methods only! Tried to use with " + element.getSimpleName()
+ ", which is static.");
}
final ExecutableType method = (ExecutableType)element.asType();
final Types types = processingEnv.getTypeUtils();
final Elements elements = processingEnv.getElementUtils();
// annotation.value() will throw the exception because it doesn't have compiled class information yet, and is of type Class<?>.
TypeMirror annotatedType = null;
try {
annotation.value();
} catch(final MirroredTypeException e) {
annotatedType = e.getTypeMirror();
}
final TypeElement closeableIteratorType = elements.getTypeElement(CloseableIterator.class.getName());
final DeclaredType returnType = types.getDeclaredType(closeableIteratorType, annotatedType);
if(!types.isAssignable(method.getReturnType(), returnType)) {
throw new DataSourceDefinitionException(
"@GetMany methods must return a CloseableIterator over a type which is assignable from the annotation value. Tried to use with "
+ element.getSimpleName() + ", which returns " + method.getReturnType() + ".");
}
if(method.getParameterTypes().size() != 2) {
throw new DataSourceDefinitionException(
"@GetMany methods must take 2 arguments: Map<String, Object> query, PipelineContext context. Tried to use with "
+ element.getSimpleName() + ", which has a different signature.");
}
final TypeMirror stringType = elements.getTypeElement(String.class.getName()).asType();
final TypeMirror objectType = elements.getTypeElement(Object.class.getName()).asType();
final TypeElement mapType = elements.getTypeElement(Map.class.getName());
final TypeMirror[] genericTypes = new TypeMirror[] {stringType, objectType};
final DeclaredType queryType = types.getDeclaredType(mapType, genericTypes);
final TypeMirror contextType = elements.getTypeElement(PipelineContext.class.getName()).asType();
if(!types.isAssignable(method.getParameterTypes().get(0), queryType)) {
throw new DataSourceDefinitionException("@GetMany method first argument must be assignable from " + queryType + ". Tried to use with "
+ element.getSimpleName() + ", which takes " + method.getParameterTypes().get(0) + ".");
}
if(!types.isAssignable(method.getParameterTypes().get(1), contextType)) {
throw new DataSourceDefinitionException("@GetMany method second argument must be assignable from " + contextType + ". Tried to use with "
+ element.getSimpleName() + ", which takes " + method.getParameterTypes().get(1) + ".");
}
}
return true;
}