Java Code Examples for javax.lang.model.type.TypeMirror#toString()
The following examples show how to use
javax.lang.model.type.TypeMirror#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LLNI.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
protected final String jniMethodName(ExecutableElement method, String cname, boolean longName) throws TypeSignature.SignatureException { String res = "Java_" + cname + "_" + method.getSimpleName(); if (longName) { TypeMirror mType = types.erasure(method.getReturnType()); List<? extends VariableElement> params = method.getParameters(); List<TypeMirror> argTypes = new ArrayList<TypeMirror>(); for (VariableElement param: params) { argTypes.add(types.erasure(param.asType())); } res = res + "__"; for (TypeMirror t: argTypes) { String tname = t.toString(); TypeSignature newTypeSig = new TypeSignature(elems); String sig = newTypeSig.getTypeSignature(tname); res = res + nameToIdentifier(sig); } } return res; }
Example 2
Source File: ConfigDoItemFinder.java From quarkus with Apache License 2.0 | 6 votes |
private String simpleTypeToString(TypeMirror typeMirror) { if (typeMirror.getKind().isPrimitive()) { return typeMirror.toString(); } else if (typeMirror.getKind() == TypeKind.ARRAY) { return simpleTypeToString(((ArrayType) typeMirror).getComponentType()); } final String knownGenericType = getKnownGenericType((DeclaredType) typeMirror); if (knownGenericType != null) { return knownGenericType; } List<? extends TypeMirror> typeArguments = ((DeclaredType) typeMirror).getTypeArguments(); if (!typeArguments.isEmpty()) { return simpleTypeToString(typeArguments.get(0)); } return typeMirror.toString(); }
Example 3
Source File: AutoServiceProcessor.java From mica-auto with GNU Lesser General Public License v3.0 | 5 votes |
public String getType(TypeMirror type) { if (type == null) { return null; } if (type instanceof DeclaredType) { DeclaredType declaredType = (DeclaredType) type; Element enclosingElement = declaredType.asElement().getEnclosingElement(); if (enclosingElement != null && enclosingElement instanceof TypeElement) { return getQualifiedName(enclosingElement) + "$" + declaredType.asElement().getSimpleName().toString(); } else { return getQualifiedName(declaredType.asElement()); } } return type.toString(); }
Example 4
Source File: ElementCompletionItem.java From netbeans with Apache License 2.0 | 5 votes |
private static String getTypeSimpleName(TypeMirror tm) { String name = tm.toString(); int i = name.lastIndexOf('.'); if (i > 0) { name = name.substring(i+1); } return name; }
Example 5
Source File: ParamTypeUtils.java From EasyRouter with Apache License 2.0 | 5 votes |
/** * Diagnostics out the true java type * * @param element Raw type * @return Type class of java */ public int typeExchange(Element element) { TypeMirror typeMirror = element.asType(); // Primitive if (typeMirror.getKind().isPrimitive()) { return element.asType().getKind().ordinal(); } switch (typeMirror.toString()) { case BYTE: return ParamTypeKinds.BYTE.ordinal(); case SHORT: return ParamTypeKinds.SHORT.ordinal(); case INTEGER: return ParamTypeKinds.INT.ordinal(); case LONG: return ParamTypeKinds.LONG.ordinal(); case FLOAT: return ParamTypeKinds.FLOAT.ordinal(); case DOUBEL: return ParamTypeKinds.DOUBLE.ordinal(); case BOOLEAN: return ParamTypeKinds.BOOLEAN.ordinal(); case STRING: return ParamTypeKinds.STRING.ordinal(); default: return ParamTypeKinds.OBJECT.ordinal(); } }
Example 6
Source File: PreferenceInjector.java From saber with Apache License 2.0 | 5 votes |
static String getType(TypeMirror type) { if (type.getKind().isPrimitive()) { // Get wrapper for primitive types switch (type.getKind()) { case BOOLEAN: return "java.lang.Boolean"; case BYTE: return "java.lang.Byte"; case SHORT: return "java.lang.Short"; case INT: return "java.lang.Integer"; case LONG: return "java.lang.Long"; case CHAR: return "java.lang.Character"; case FLOAT: return "java.lang.Float"; case DOUBLE: return "java.lang.Double"; default: // Shouldn't happen throw new RuntimeException(); } } else { return type.toString(); } }
Example 7
Source File: Analysis.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean isCompatibileCollection(TypeMirror left, TypeMirror rawCollection) { final String leftStr = left.toString(); final String rightStr = rawCollection.toString(); if (leftStr.equals(rightStr)) return true; if (left.getKind() != rawCollection.getKind()) return false; TypeMirror leftRaw = types.erasure(left); return types.isAssignable(rawCollection, leftRaw); }
Example 8
Source File: TypeHelper.java From magic-starter with GNU Lesser General Public License v3.0 | 5 votes |
public String getType(TypeMirror type) { if (type == null) { return null; } if (type instanceof DeclaredType) { DeclaredType declaredType = (DeclaredType) type; Element enclosingElement = declaredType.asElement().getEnclosingElement(); if (enclosingElement != null && enclosingElement instanceof TypeElement) { return getQualifiedName(enclosingElement) + "$" + declaredType.asElement().getSimpleName().toString(); } else { return getQualifiedName(declaredType.asElement()); } } return type.toString(); }
Example 9
Source File: ElementUtilities.java From netbeans with Apache License 2.0 | 5 votes |
/**Find all methods in given type and its supertypes, which are overridable. * * @param type to inspect * @return list of all overridable methods * * @since 0.136 */ public List<? extends ExecutableElement> findOverridableMethods(TypeElement type) { List<ExecutableElement> overridable = new ArrayList<>(); final Set<Modifier> notOverridable = EnumSet.copyOf(NOT_OVERRIDABLE); if (!type.getModifiers().contains(Modifier.ABSTRACT)) { notOverridable.add(Modifier.ABSTRACT); } DeclaredType dt = (DeclaredType)type.asType(); Types types = JavacTypes.instance(ctx); Set<String> typeStrings = new HashSet<>(); for (ExecutableElement ee : ElementFilter.methodsIn(info.getElements().getAllMembers(type))) { TypeMirror methodType = types.erasure(types.asMemberOf(dt, ee)); String methodTypeString = ee.getSimpleName().toString() + methodType.toString(); if (typeStrings.contains(methodTypeString)) { continue; } Set<Modifier> set = EnumSet.copyOf(notOverridable); set.removeAll(ee.getModifiers()); if (set.size() == notOverridable.size() && !overridesPackagePrivateOutsidePackage(ee, type) //do not offer package private methods in case they're from different package && !isOverridden(ee, type)) { overridable.add(ee); if (ee.getModifiers().contains(Modifier.ABSTRACT)) { typeStrings.add(methodTypeString); } } } Collections.reverse(overridable); return overridable; }
Example 10
Source File: GwtSerialization.java From auto with Apache License 2.0 | 5 votes |
/** * Returns the suffix in serializer method names for values of the given type. For example, if * the type is "int" then the returned value will be "Int" because the serializer methods are * called readInt and writeInt. There are methods for all primitive types and String; every * other type uses readObject and writeObject. */ public String getGwtType() { TypeMirror typeMirror = property.getTypeMirror(); String type = typeMirror.toString(); if (property.getKind().isPrimitive()) { return Character.toUpperCase(type.charAt(0)) + type.substring(1); } else if (type.equals("java.lang.String")) { return "String"; } else { return "Object"; } }
Example 11
Source File: AnnotationProxyMaker.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
MirroredTypeExceptionProxy(TypeMirror t) { type = t; typeString = t.toString(); }
Example 12
Source File: LLNI.java From hottub with GNU General Public License v2.0 | 4 votes |
protected final String jniType(TypeMirror t) throws Util.Exit { TypeElement throwable = elems.getTypeElement("java.lang.Throwable"); TypeElement jClass = elems.getTypeElement("java.lang.Class"); TypeElement jString = elems.getTypeElement("java.lang.String"); Element tclassDoc = types.asElement(t); switch (t.getKind()) { case ARRAY: { TypeMirror ct = ((ArrayType) t).getComponentType(); switch (ct.getKind()) { case BOOLEAN: return "jbooleanArray"; case BYTE: return "jbyteArray"; case CHAR: return "jcharArray"; case SHORT: return "jshortArray"; case INT: return "jintArray"; case LONG: return "jlongArray"; case FLOAT: return "jfloatArray"; case DOUBLE: return "jdoubleArray"; case ARRAY: case DECLARED: return "jobjectArray"; default: throw new Error(ct.toString()); } } case VOID: return "void"; case BOOLEAN: return "jboolean"; case BYTE: return "jbyte"; case CHAR: return "jchar"; case SHORT: return "jshort"; case INT: return "jint"; case LONG: return "jlong"; case FLOAT: return "jfloat"; case DOUBLE: return "jdouble"; case DECLARED: { if (tclassDoc.equals(jString)) return "jstring"; else if (types.isAssignable(t, throwable.asType())) return "jthrowable"; else if (types.isAssignable(t, jClass.asType())) return "jclass"; else return "jobject"; } } util.bug("jni.unknown.type"); return null; /* dead code. */ }
Example 13
Source File: JNI.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
protected final String jniType(TypeMirror t) throws Util.Exit { TypeElement throwable = elems.getTypeElement("java.lang.Throwable"); TypeElement jClass = elems.getTypeElement("java.lang.Class"); TypeElement jString = elems.getTypeElement("java.lang.String"); Element tclassDoc = types.asElement(t); switch (t.getKind()) { case ARRAY: { TypeMirror ct = ((ArrayType) t).getComponentType(); switch (ct.getKind()) { case BOOLEAN: return "jbooleanArray"; case BYTE: return "jbyteArray"; case CHAR: return "jcharArray"; case SHORT: return "jshortArray"; case INT: return "jintArray"; case LONG: return "jlongArray"; case FLOAT: return "jfloatArray"; case DOUBLE: return "jdoubleArray"; case ARRAY: case DECLARED: return "jobjectArray"; default: throw new Error(ct.toString()); } } case VOID: return "void"; case BOOLEAN: return "jboolean"; case BYTE: return "jbyte"; case CHAR: return "jchar"; case SHORT: return "jshort"; case INT: return "jint"; case LONG: return "jlong"; case FLOAT: return "jfloat"; case DOUBLE: return "jdouble"; case DECLARED: { if (tclassDoc.equals(jString)) return "jstring"; else if (types.isAssignable(t, throwable.asType())) return "jthrowable"; else if (types.isAssignable(t, jClass.asType())) return "jclass"; else return "jobject"; } } util.bug("jni.unknown.type"); return null; /* dead code. */ }
Example 14
Source File: LLNI.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
protected final String jniType(TypeMirror t) throws Util.Exit { TypeElement throwable = elems.getTypeElement("java.lang.Throwable"); TypeElement jClass = elems.getTypeElement("java.lang.Class"); TypeElement jString = elems.getTypeElement("java.lang.String"); Element tclassDoc = types.asElement(t); switch (t.getKind()) { case ARRAY: { TypeMirror ct = ((ArrayType) t).getComponentType(); switch (ct.getKind()) { case BOOLEAN: return "jbooleanArray"; case BYTE: return "jbyteArray"; case CHAR: return "jcharArray"; case SHORT: return "jshortArray"; case INT: return "jintArray"; case LONG: return "jlongArray"; case FLOAT: return "jfloatArray"; case DOUBLE: return "jdoubleArray"; case ARRAY: case DECLARED: return "jobjectArray"; default: throw new Error(ct.toString()); } } case VOID: return "void"; case BOOLEAN: return "jboolean"; case BYTE: return "jbyte"; case CHAR: return "jchar"; case SHORT: return "jshort"; case INT: return "jint"; case LONG: return "jlong"; case FLOAT: return "jfloat"; case DOUBLE: return "jdouble"; case DECLARED: { if (tclassDoc.equals(jString)) return "jstring"; else if (types.isAssignable(t, throwable.asType())) return "jthrowable"; else if (types.isAssignable(t, jClass.asType())) return "jclass"; else return "jobject"; } } util.bug("jni.unknown.type"); return null; /* dead code. */ }
Example 15
Source File: ComponentProcessor.java From appinventor-extensions with Apache License 2.0 | 4 votes |
private Property executableElementToProperty(Element element, String componentInfoName) { String propertyName = element.getSimpleName().toString(); SimpleProperty simpleProperty = element.getAnnotation(SimpleProperty.class); if (!(element.asType() instanceof ExecutableType)) { throw new RuntimeException("element.asType() is not an ExecutableType for " + propertyName); } // Use Javadoc for property unless description is set to a non-empty string. String description = elementUtils.getDocComment(element); String longDescription = description; if (!simpleProperty.description().isEmpty()) { description = simpleProperty.description(); } if (description == null) { description = ""; } // Read only until the first javadoc parameter description = description.split("[^\\\\][@{]")[0].trim(); Property property = new Property(propertyName, description, longDescription, simpleProperty.category(), simpleProperty.userVisible(), elementUtils.isDeprecated(element)); // Get parameters to tell if this is a getter or setter. ExecutableType executableType = (ExecutableType) element.asType(); List<? extends TypeMirror> parameters = executableType.getParameterTypes(); // Check if it is a setter or getter, and set the property's readable, writable, // and type fields appropriately. TypeMirror typeMirror; if (parameters.size() == 0) { // It is a getter. property.readable = true; typeMirror = executableType.getReturnType(); if (typeMirror.getKind().equals(TypeKind.VOID)) { throw new RuntimeException("Property method is void and has no parameters: " + propertyName); } if (element.getAnnotation(IsColor.class) != null) { property.color = true; } } else { // It is a setter. property.writable = true; if (parameters.size() != 1) { throw new RuntimeException("Too many parameters for setter for " + propertyName); } typeMirror = parameters.get(0); for (VariableElement ve : ((ExecutableElement) element).getParameters()) { if (ve.getAnnotation(IsColor.class) != null) { property.color = true; } } } // Use typeMirror to set the property's type. if (!typeMirror.getKind().equals(TypeKind.VOID)) { property.type = typeMirror.toString(); updateComponentTypes(typeMirror); } property.componentInfoName = componentInfoName; return property; }
Example 16
Source File: BasicAnnoTests.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** Get the annoType value from an @Test annotation mirror. */ static String getAnnoType(AnnotationMirror test) { AnnotationValue v = getValue(test, "annoType"); TypeMirror m = (TypeMirror) v.getValue(); return m.toString(); }
Example 17
Source File: BasicAnnoTests.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** Get the annoType value from an @Test annotation mirror. */ static String getAnnoType(AnnotationMirror test) { AnnotationValue v = getValue(test, "annoType"); TypeMirror m = (TypeMirror) v.getValue(); return m.toString(); }
Example 18
Source File: JNI.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
protected final String jniType(TypeMirror t) throws Util.Exit { TypeElement throwable = elems.getTypeElement("java.lang.Throwable"); TypeElement jClass = elems.getTypeElement("java.lang.Class"); TypeElement jString = elems.getTypeElement("java.lang.String"); Element tclassDoc = types.asElement(t); switch (t.getKind()) { case ARRAY: { TypeMirror ct = ((ArrayType) t).getComponentType(); switch (ct.getKind()) { case BOOLEAN: return "jbooleanArray"; case BYTE: return "jbyteArray"; case CHAR: return "jcharArray"; case SHORT: return "jshortArray"; case INT: return "jintArray"; case LONG: return "jlongArray"; case FLOAT: return "jfloatArray"; case DOUBLE: return "jdoubleArray"; case ARRAY: case DECLARED: return "jobjectArray"; default: throw new Error(ct.toString()); } } case VOID: return "void"; case BOOLEAN: return "jboolean"; case BYTE: return "jbyte"; case CHAR: return "jchar"; case SHORT: return "jshort"; case INT: return "jint"; case LONG: return "jlong"; case FLOAT: return "jfloat"; case DOUBLE: return "jdouble"; case DECLARED: { if (tclassDoc.equals(jString)) return "jstring"; else if (types.isAssignable(t, throwable.asType())) return "jthrowable"; else if (types.isAssignable(t, jClass.asType())) return "jclass"; else return "jobject"; } } util.bug("jni.unknown.type"); return null; /* dead code. */ }
Example 19
Source File: AnnotationProxyMaker.java From hottub with GNU General Public License v2.0 | 4 votes |
MirroredTypeExceptionProxy(TypeMirror t) { type = t; typeString = t.toString(); }
Example 20
Source File: AnnotationProxyMaker.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
MirroredTypeExceptionProxy(TypeMirror t) { type = t; typeString = t.toString(); }