@Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); note("LensKit Shareable linting active"); typeUtils = processingEnv.getTypeUtils(); elementUtils = processingEnv.getElementUtils(); }
@Override public void writeFieldReadStatement( VariableElement field, Collection<ExecutableElement> postCreateChildMethods, JavaWriter writer) throws IOException { DeclaredType type = (DeclaredType) field.asType(); TypeMirror itemType = type.getTypeArguments().get(0); TypeMirror itemTypeErasure = processingEnv.getTypeUtils().erasure(itemType); String collectionInitializer; try { collectionInitializer = initializers.findCollectionInitializer(type); } catch (InvalidTypeException e) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage(), field); collectionInitializer = "null"; } writer.beginControlFlow("if (bundle.containsKey(\"%s\"))", field.getSimpleName()); writer.emitStatement("object.%s = %s", field.getSimpleName(), collectionInitializer); writer.emitStatement( "%1$s.readCollectionFromBundle(object.%2$s, bundle, %3$s.class, \"%2$s\")", CollectionBundler.class.getCanonicalName(), field.getSimpleName(), itemTypeErasure); writePostCreateChildMethodCalls(field, itemType, postCreateChildMethods, writer); writer.endControlFlow(); }
@Override public synchronized void init(ProcessingEnvironment env) { super.init(env); elementUtils = env.getElementUtils(); typeUtils = env.getTypeUtils(); filer = env.getFiler(); }
@Override public synchronized void init(ProcessingEnvironment env) { super.init(env); mLogger = new Logger(env); mElements = env.getElementUtils(); mTypes = env.getTypeUtils(); mFiler = env.getFiler(); }
@Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); Elements elementUtils = processingEnv.getElementUtils(); Types typeUtils = processingEnv.getTypeUtils(); Filer filer = processingEnv.getFiler(); Messager messager = processingEnv.getMessager(); }
@Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); elements = processingEnv.getElementUtils(); types = processingEnv.getTypeUtils(); messager = processingEnv.getMessager(); factoryWriter = new FactoryWriter(processingEnv.getFiler()); providedChecker = new ProvidedChecker(messager); declarationFactory = new AutoFactoryDeclaration.Factory(elements, messager); factoryDescriptorGenerator = new FactoryDescriptorGenerator(messager, elements, declarationFactory); }
@Override public void writeFieldWriteStatement(VariableElement field, JavaWriter writer) throws IOException { DeclaredType type = (DeclaredType) field.asType(); TypeMirror itemType = type.getTypeArguments().get(0); TypeMirror itemTypeErasure = processingEnv.getTypeUtils().erasure(itemType); writer.beginControlFlow("if (object.%s != null)", field.getSimpleName()); writer.emitStatement( "%1$s.writeCollectionToBundle(object.%2$s, bundle, %3$s.class, \"%2$s\")", CollectionBundler.class.getCanonicalName(), field.getSimpleName(), itemTypeErasure); writer.endControlFlow(); }
private void assembleAttributeDeclaration(Writer w, AttributeInfo ai) throws IOException { // TODO: default value w.append( "<xsd:attribute name=\"" + ai.getXMLName() + "\" type=\"" + ai.getXSDType(processingEnv.getTypeUtils()) + "\" " + (ai.isRequired() ? "use=\"required\"" : "") + ">\r\n"); assembleDocumentation(w, ai); w.append("</xsd:attribute>\r\n"); }
/** * Whether the specified element is assignable to the fqTn parameter * * @param processingEnvironment The environment this runs in * @param fqTn THe fully qualified type name of the element we want to check * @param element The element to check that implements * @return true if element implements the fqTn */ public static boolean implementsClass( ProcessingEnvironment processingEnvironment, String fqTn, TypeElement element) { TypeElement typeElement = processingEnvironment.getElementUtils().getTypeElement(fqTn); if (typeElement == null) { processingEnvironment .getMessager() .printMessage( Diagnostic.Kind.ERROR, "Type Element was null for: " + fqTn + "" + "ensure that the visibility of the class is not private."); return false; } else { TypeMirror classMirror = typeElement.asType(); if (classMirror != null) { classMirror = processingEnvironment.getTypeUtils().erasure(classMirror); } return classMirror != null && element != null && element.asType() != null && processingEnvironment.getTypeUtils().isAssignable(element.asType(), classMirror); } }
private boolean hasLocalSignatureField(Element field) { assert field.getKind() == ElementKind.FIELD; if (isAnnotatedBy(procEnv, field, "org.paninij.lang.Local")) { TypeMirror type = getScalarType(field.asType()); if (type.getKind() == TypeKind.DECLARED) { TypeElement typeElem = (TypeElement) procEnv.getTypeUtils().asElement(type); if (typeElem == null) { throw new IllegalArgumentException("Failed to lookup type element: " + type); } if (isAnnotatedBy(procEnv, typeElem, "org.paninij.lang.SignatureInterface")) { return true; } } } return false; }
/** * @param env the environment * @param annUtil utils * @param d the method */ public MethodHandler( final ProcessingEnvironment env, final AnnUtil annUtil, final ExecutableElement d) { this.env = env; this.annUtil = annUtil; msg = env.getMessager(); staticMethod = d.getModifiers().contains(Modifier.STATIC); methName = d.getSimpleName().toString(); getter = methName.startsWith("get"); setter = methName.startsWith("set"); immutable = d.getAnnotation(Immutable.class) != null; CloneForOverride cfo = d.getAnnotation(CloneForOverride.class); cloneForOverride = cfo != null; if (cloneForOverride) { cloneCollectionType = cfo.cloneCollectionType(); cloneElementType = cfo.cloneElementType(); } returnType = d.getReturnType(); returnsVoid = env.getTypeUtils().getNoType(TypeKind.VOID).equals(returnType); pars = d.getParameters(); thrownTypes = d.getThrownTypes(); if ((setter) && (pars != null) && (pars.size() == 1)) { fieldType = pars.iterator().next().asType(); basicType = fieldType.getKind().isPrimitive(); } if (getter) { fieldType = returnType; basicType = returnType.getKind().isPrimitive(); } if (setter || getter) { ucFieldName = methName.substring(3); fieldName = ucFieldName.substring(0, 1).toLowerCase() + ucFieldName.substring(1); } }
public ValidateDescriptor(ModelDescriptor modelDescriptor, Element field) { super(modelDescriptor, field); this.validateIf = field.getAnnotation(ValidateIf.class); this.validateIfValue = field.getAnnotation(ValidateIfValue.class); ProcessingEnvironment processingEnv = modelDescriptor.getProcessingEnvironment(); Types typeUtils = processingEnv.getTypeUtils(); this.isMethodValidation = getField().getKind().equals(ElementKind.METHOD); if (this.isMethodValidation) { // Make sure our method validation returns a boolean value if (!((ExecutableElement) this.field).getReturnType().getKind().equals(TypeKind.BOOLEAN)) { modelDescriptor .getMessager() .printMessage( Diagnostic.Kind.ERROR, "Methods annotated with @Validate must return a boolean value!", field); } methodAnnotation = getField().getAnnotation(Validate.class); if (this.methodAnnotation == null) { modelDescriptor .getMessager() .printMessage(Diagnostic.Kind.ERROR, "Could not retrieve method validation annotation"); } } else { this.isList = typeUtils.isAssignable( field.asType(), typeUtils.getDeclaredType( processingEnv .getElementUtils() .getTypeElement(ListContainer.class.getCanonicalName()), typeUtils.getWildcardType(null, null))); } }
public Types getTypeUtils() { return processingEnvironment.getTypeUtils(); }
private static void printMethodWithMultiType( ProcessingEnvironment env, TypeMap type_map, PrintWriter writer, TypeElement interface_decl, ExecutableElement method, Map<VariableElement, TypeInfo> typeinfos_instance, Mode mode, boolean generate_error_checks, boolean context_specific) { Utils.printDocComment(writer, method, env); if (method.getAnnotation(Deprecated.class) != null) { writer.println("\t@Deprecated"); } if (interface_decl.getAnnotation(Private.class) == null && method.getAnnotation(Private.class) == null) { writer.print("\tpublic static "); } else { writer.print("\tstatic "); } writer.print(getResultType(method, false)); StripPostfix strip_annotation = method.getAnnotation(StripPostfix.class); String method_name; Alternate alt_annotation = method.getAnnotation(Alternate.class); method_name = alt_annotation == null || alt_annotation.javaAlt() ? method.getSimpleName().toString() : alt_annotation.value(); if (strip_annotation != null && mode == Mode.NORMAL) { method_name = getPostfixStrippedName(type_map, interface_decl, method); } writer.print(" " + method_name + "("); generateParametersJava(writer, method, typeinfos_instance, false, true, mode); writer.println(") {"); final TypeMirror result_type = Utils.getMethodReturnType(method); boolean has_result = !result_type.equals(env.getTypeUtils().getNoType(TypeKind.VOID)); final Reuse reuse_annotation = method.getAnnotation(Reuse.class); if (reuse_annotation != null) { writer.print("\t\t"); if (has_result || method.getAnnotation(GLreturn.class) != null) { writer.print("return "); } writer.print( reuse_annotation.value() + "." + (reuse_annotation.method().length() > 0 ? reuse_annotation.method() : method_name) + "("); generateParametersJava(writer, method, typeinfos_instance, false, false, mode); writer.println(");\n\t}"); return; } if (context_specific) { type_map.printCapabilitiesInit(writer); writer.print( "\t\tlong " + Utils.FUNCTION_POINTER_VAR_NAME + " = " + type_map.getCapabilities() + "."); writer.println(Utils.getFunctionAddressName(interface_decl, method, true) + ";"); writer.print("\t\tBufferChecks.checkFunctionAddress("); writer.println(Utils.FUNCTION_POINTER_VAR_NAME + ");"); } final Code code_annotation = method.getAnnotation(Code.class); if (code_annotation != null && code_annotation.value().length() > 0) { writer.println(code_annotation.value()); } printBufferObjectChecks(writer, method, mode, context_specific); printParameterChecks(writer, method, typeinfos_instance, mode, generate_error_checks); printParameterCaching(writer, interface_decl, method, mode, context_specific); if (code_annotation != null && code_annotation.javaBeforeNative().length() > 0) { writer.println(code_annotation.javaBeforeNative()); } writer.print("\t\t"); final PointerWrapper pointer_wrapper_annotation = method.getAnnotation(PointerWrapper.class); if (has_result) { writer.print(getResultType(method, false) + " " + Utils.RESULT_VAR_NAME); if (code_annotation != null && code_annotation.tryBlock()) { writer.print(" = " + getDefaultResultValue(method)); writer.println(";\n\t\ttry {"); writer.print("\t\t\t" + Utils.RESULT_VAR_NAME); } writer.print(" = "); if (pointer_wrapper_annotation != null) { if (pointer_wrapper_annotation.factory().length() > 0) { writer.print(pointer_wrapper_annotation.factory() + "("); } else { writer.print("new " + getResultType(method, false) + "("); } } } else if (method.getAnnotation(GLreturn.class) != null) { has_result = true; Utils.printGLReturnPre(writer, method, method.getAnnotation(GLreturn.class), type_map); } writer.print(Utils.getSimpleNativeMethodName(method, generate_error_checks, context_specific)); if (mode == Mode.BUFFEROBJECT) { writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX); } writer.print("("); boolean first_parameter = printMethodCallArguments(writer, method, typeinfos_instance, mode, type_map); if (context_specific) { if (!first_parameter) { writer.print(", "); } writer.print(Utils.FUNCTION_POINTER_VAR_NAME); } if (has_result && pointer_wrapper_annotation != null) { writer.print(")"); if (pointer_wrapper_annotation.params().length() > 0) { writer.print(", " + pointer_wrapper_annotation.params()); } } writer.println(");"); if (code_annotation != null && code_annotation.javaAfterNative().length() > 0) { writer.println(code_annotation.javaAfterNative()); } final String tabs = code_annotation != null && code_annotation.tryBlock() ? "\t\t\t" : "\t\t"; if (generate_error_checks && method.getAnnotation(NoErrorCheck.class) == null) { type_map.printErrorCheckMethod(writer, method, tabs); } // DISABLED: indirect buffer support // printNondirectParameterCopies(writer, method, mode); if (has_result) { if (method.getAnnotation(GLreturn.class) == null) { if (ByteBuffer.class.equals(Utils.getJavaType(result_type))) { writer.println( tabs + "return LWJGLUtil.CHECKS && " + Utils.RESULT_VAR_NAME + " == null ? null : " + Utils.RESULT_VAR_NAME + ".order(ByteOrder.nativeOrder());"); // safeNewBuffer returns a direct // ByteBuffer with BIG_ENDIAN order. } else { writer.println(tabs + "return " + Utils.RESULT_VAR_NAME + ";"); } } else { Utils.printGLReturnPost(writer, method, method.getAnnotation(GLreturn.class), type_map); } } if (code_annotation != null && code_annotation.tryBlock()) { writer.println("\t\t} finally {"); writer.println(code_annotation.javaFinally()); writer.println("\t\t}"); } writer.println("\t}"); }
/** * Returns an implementation of some utility methods for operating on types. * * @return type utilities */ public Types getTypeUtils() { return processingEnv.getTypeUtils(); }
@Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); this.utils = new Utils(processingEnv.getElementUtils(), processingEnv.getTypeUtils()); }