List of usage examples for javax.lang.model.element TypeElement getSimpleName
@Override Name getSimpleName();
From source file:Main.java
/** * get package name from class {@code type} * @param type The element of class//from w ww.j ava 2s . co m * @return package name */ public static String getPackageName(TypeElement type) { if (type == null || type.getSimpleName().toString().length() == 0) { return ""; } Element parent = type.getEnclosingElement(); if (parent.getKind() == ElementKind.PACKAGE) { return ((PackageElement) parent).getQualifiedName().toString(); } return getPackageName((TypeElement) parent); }
From source file:org.ez18n.apt.processor.DesktopMessagesProcessor.java
static final String getDesktopMessagesClassName(TypeElement typeElement, boolean fqcn) { final String simpleName = typeElement.getSimpleName().toString(); final int resourceIndex = simpleName.indexOf("Resources"); final String shortName = resourceIndex > 0 ? simpleName.substring(0, resourceIndex) : simpleName; return (fqcn ? typeElement.getEnclosingElement().toString() + "." : "") + shortName + "DesktopMessages"; }
From source file:org.ez18n.apt.processor.MobileMessagesProcessor.java
static final String getMobileMessagesClassName(TypeElement typeElement, boolean fqcn) { final String simpleName = typeElement.getSimpleName().toString(); final int resourceIndex = simpleName.indexOf("Resources"); final String shortName = resourceIndex > 0 ? simpleName.substring(0, resourceIndex) : simpleName; return (fqcn ? typeElement.getEnclosingElement().toString() + "." : "") + shortName + "MobileMessages"; }
From source file:org.ez18n.apt.processor.LabelBundleProcessor.java
protected static String toCamelCase(TypeElement typeElement) { return toCamelCase(typeElement.getSimpleName().toString()); }
From source file:org.leandreck.endpoints.processor.model.EndpointNodeFactory.java
private static String defineName(final TypeElement typeElement, final TypeScriptEndpoint annotation) { final String name; if (annotation.value().isEmpty()) { name = typeElement.getSimpleName().toString(); } else {//from w ww. j a va 2 s .c o m name = annotation.value(); } return name; }
From source file:com.airbnb.deeplinkdispatch.DeepLinkProcessor.java
private static String moduleNameToLoaderName(TypeElement typeElement) { return typeElement.getSimpleName().toString() + "Loader"; }
From source file:com.airbnb.deeplinkdispatch.DeepLinkProcessor.java
private static ClassName moduleElementToLoaderClassName(TypeElement element) { return ClassName.get(getPackage(element).getQualifiedName().toString(), element.getSimpleName().toString() + "Loader"); }
From source file:org.ez18n.apt.processor.BundlePropertiesProcessor.java
@Override protected String getTargetSimpleName(TypeElement typeElement) { return getPrefix() + typeElement.getSimpleName().toString(); }
From source file:info.archinnov.achilles.internals.parser.UDFParser.java
public static List<UDFSignature> parseFunctionRegistryAndValidateTypes(AptUtils aptUtils, TypeElement elm) { final List<ExecutableElement> methods = ElementFilter.methodsIn(elm.getEnclosedElements()); final Optional<String> keyspace = AnnotationTree.findKeyspaceForFunctionRegistry(aptUtils, elm); final TypeName sourceClass = TypeName.get(aptUtils.erasure(elm)); //Not allow to declare function in system keyspaces if (keyspace.isPresent()) { final String keyspaceName = keyspace.get(); aptUtils.validateFalse(/*from w ww . j a v a 2 s . c om*/ FORBIDDEN_KEYSPACES.contains(keyspaceName) || FORBIDDEN_KEYSPACES.contains(keyspaceName.toLowerCase()), "The provided keyspace '%s' on function registry class '%s' is forbidden because it is a system keyspace", keyspaceName, sourceClass); } aptUtils.validateFalse(keyspace.isPresent() && isBlank(keyspace.get()), "The declared keyspace for function registry '%s' should not be blank", elm.getSimpleName().toString()); return methods.stream().map(method -> { final List<TypeName> parametersType = method.getParameters().stream().map(VariableElement::asType) .map(TypeName::get).collect(toList()); final String methodName = method.getSimpleName().toString(); final List<UDFParamSignature> parameterSignatures = method.getParameters().stream() .map(x -> new UDFParamSignature(TypeName.get(x.asType()).box(), x.getSimpleName().toString())) .collect(toList()); //Validate parameter types for (TypeName param : parametersType) { TypeValidator.validateNativeTypesForFunction(aptUtils, method, param, "argument"); } //Validate return type final TypeMirror returnTypeMirror = method.getReturnType(); aptUtils.validateFalse(returnTypeMirror.getKind() == TypeKind.VOID, "The return type for the method '%s' on class '%s' should not be VOID", method.toString(), elm.getSimpleName().toString()); final TypeName returnType = TypeName.get(returnTypeMirror).box(); TypeValidator.validateNativeTypesForFunction(aptUtils, method, returnType, "return type"); // Validate NOT system function comparing only name lowercase aptUtils.validateFalse(SYSTEM_FUNCTIONS_NAME.contains(methodName.toLowerCase()), "The name of the function '%s' in class '%s' is reserved for system functions", method, sourceClass); return new UDFSignature(keyspace, sourceClass, methodName, returnType, parametersType, parameterSignatures); }).collect(toList()); }
From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java
public static String getClassName(JavaSource source) throws IOException { TypeElement te = getTypeElement(source); if (te != null) { return te.getSimpleName().toString(); } else {//from w w w. j ava 2 s . c o m return null; } }