Refine search
/** * Returns a method name from the {@code android.content.res.Resources} class for array resource * binding, null if the element type is not supported. */ private static @Nullable FieldResourceBinding.Type getArrayResourceMethodName(Element element) { TypeMirror typeMirror = element.asType(); if (TYPED_ARRAY_TYPE.equals(typeMirror.toString())) { return FieldResourceBinding.Type.TYPED_ARRAY; } if (TypeKind.ARRAY.equals(typeMirror.getKind())) { ArrayType arrayType = (ArrayType) typeMirror; String componentType = arrayType.getComponentType().toString(); if (STRING_TYPE.equals(componentType)) { return FieldResourceBinding.Type.STRING_ARRAY; } else if ("int".equals(componentType)) { return FieldResourceBinding.Type.INT_ARRAY; } else if ("java.lang.CharSequence".equals(componentType)) { return FieldResourceBinding.Type.TEXT_ARRAY; } } return null; }
private String getFullyQualifiedClassNameOfTargetEntity(AnnotationMirror mirror, String parameterName) { assert mirror != null; assert parameterName != null; String targetEntityName = null; Object parameterValue = TypeUtils.getAnnotationValue( mirror, parameterName ); if ( parameterValue != null ) { TypeMirror parameterType = (TypeMirror) parameterValue; if ( !parameterType.getKind().equals( TypeKind.VOID ) ) { targetEntityName = parameterType.toString(); } } return targetEntityName; } }
private void addSuperInterfaceMethods(List<? extends TypeMirror> superInterfaces, TypeSpec.Builder classBuilder) { if (superInterfaces != null && !superInterfaces.isEmpty()) { for (TypeMirror tm : superInterfaces) { try { if (tm.getKind().equals(TypeKind.DECLARED)) { TypeElement de = (TypeElement) ((DeclaredType) tm).asElement(); addMethods(de, classBuilder); addSuperInterfaceMethods(de.getInterfaces(), classBuilder); } } catch (Exception e) { processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "MotanAsyncProcessor process superinterface " + tm.toString() + " fail. exception:" + e.getMessage()); e.printStackTrace(); } } } }
public RInnerClass(TypeElement rInnerTypeElement) { if (rInnerTypeElement != null) { rInnerQualifiedName = rInnerTypeElement.getQualifiedName().toString(); List<? extends Element> idEnclosedElements = rInnerTypeElement.getEnclosedElements(); List<VariableElement> idFields = ElementFilter.fieldsIn(idEnclosedElements); for (VariableElement idField : idFields) { TypeKind fieldType = idField.asType().getKind(); if (fieldType.isPrimitive() && fieldType.equals(TypeKind.INT)) { String idQualifiedName = rInnerQualifiedName + "." + idField.getSimpleName(); idQualifiedNames.add(idQualifiedName); Integer idFieldId = (Integer) idField.getConstantValue(); if (idFieldId != null) { idQualifiedNamesByIdValues.put(idFieldId, idQualifiedName); } } } } else { rInnerQualifiedName = ""; } }
public static String extractClosestRealTypeAsString(TypeMirror type, Context context) { if ( type instanceof TypeVariable ) { final TypeMirror compositeUpperBound = ( (TypeVariable) type ).getUpperBound(); return extractClosestRealTypeAsString( compositeUpperBound, context ); } else { final TypeMirror erasureType = context.getTypeUtils().erasure( type ); if ( TypeKind.ARRAY.equals( erasureType.getKind() ) ) { // keep old behavior here for arrays since #asElement returns null for them. return erasureType.toString(); } else { return ( (TypeElement) context.getTypeUtils().asElement( erasureType ) ).getQualifiedName().toString(); } } }
@Override public void process(Element element, HasOnActivityResult holder) throws Exception { String methodName = element.getSimpleName().toString(); ExecutableElement executableElement = (ExecutableElement) element; List<? extends VariableElement> parameters = executableElement.getParameters(); int requestCode = executableElement.getAnnotation(OnActivityResult.class).value(); JBlock onResultBlock = holder.getOnActivityResultCaseBlock(requestCode).blockSimple(); IJExpression activityRef = holder.getGeneratedClass().staticRef("this"); JInvocation onResultInvocation = JExpr.invoke(activityRef, methodName); JVar intent = holder.getOnActivityResultDataParam(); JVar extras = null; for (VariableElement parameter : parameters) { TypeMirror parameterType = parameter.asType(); if (parameter.getAnnotation(OnActivityResult.Extra.class) != null) { if (extras == null) { extras = onResultBlock.decl(getClasses().BUNDLE, "extras_", JOp.cond(intent.ne(_null()).cand(intent.invoke("getExtras").ne(_null())), intent.invoke("getExtras"), _new(getClasses().BUNDLE))); } IJExpression extraParameter = extraHandler.getExtraValue(parameter, extras, onResultBlock, holder); onResultInvocation.arg(extraParameter); } else if (CanonicalNameConstants.INTENT.equals(parameterType.toString())) { onResultInvocation.arg(intent); } else if (parameterType.getKind().equals(TypeKind.INT) // || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) { onResultInvocation.arg(holder.getOnActivityResultResultCodeParam()); } } onResultBlock.add(onResultInvocation); }
TypeMirror returnMirror = execute.getReturnType(); handleCode.add("\n").addStatement("Object o = null", type, executeName).beginControlFlow("try"); if (!TypeKind.VOID.equals(returnMirror.getKind())) { handleCode.addStatement("o = (($T)mHost).$L($L)", type, executeName, paramBuild.toString()); } else {
private String toString(AnnotationValue value) { if (value.getValue() instanceof TypeMirror) { TypeMirror tm = (TypeMirror) value.getValue(); if (tm.getKind().equals(TypeKind.DECLARED)) { DeclaredType dt = (DeclaredType) tm; return getClassName((TypeElement) dt.asElement()); } } return value.toString(); }
/** * Name starts with set, has one parameter, returns either null or something * assignable from the element's enclosing type. */ protected boolean isSetter(ExecutableElement x, State state) { String name = x.getSimpleName().toString(); TypeMirror returnType = x.getReturnType(); if (x.getParameters().size() != 1) { return false; } if (!name.startsWith("set")) { return false; } if (returnType.getKind().equals(TypeKind.VOID)) { return true; } if (x.getEnclosingElement() != null && state.types.isAssignable(x.getEnclosingElement().asType(), returnType)) { return true; } return false; }
/** * Find a {@code javax.validation.GroupSequence} annotation if one is present on given type ({@link TypeMirror}). */ private AnnotationMirror getGroupSequence(TypeMirror typeMirror) { // the annotation can be present only on TypeKind.DECLARED elements if ( TypeKind.DECLARED.equals( typeMirror.getKind() ) ) { for ( AnnotationMirror annotationMirror : typeUtils.asElement( typeMirror ).getAnnotationMirrors() ) { if ( ConstraintHelper.AnnotationType.GROUP_SEQUENCE_ANNOTATION.equals( constraintHelper.getAnnotationType( annotationMirror ) ) ) { return annotationMirror; } } } return null; }
@Override public TypeMirror visitDeclared(DeclaredType t, TypeElement sup) { TypeMirror r = onDeclaredType(t, sup); if (r != null) return r; Element e = t.asElement(); switch (e.getKind()) { case CLASS: { // otherwise recursively apply super class and base types TypeMirror sc = ((TypeElement) e).getSuperclass(); if (!TypeKind.NONE.equals(sc.getKind())) r = visitDeclared((DeclaredType) sc, sup); if (r != null) return r; } } return null; }
/** * Check a type and all of its supertypes for the annotation. */ protected void checkForAnnotation(TypeElement x, State state) { // Check type's declaration checkForAnnotation((Element) x, state); // Look at superclass, if it exists if (!x.getSuperclass().getKind().equals(TypeKind.NONE)) { checkForAnnotation((TypeElement) state.types.asElement(x.getSuperclass()), state); } // Check super-interfaces for (TypeMirror intf : x.getInterfaces()) { checkForAnnotation((TypeElement) state.types.asElement(intf), state); } }