private void writeConstantField(JavaFileWriter writer, DeclaredTypeName containingClassName, VariableElement constant) throws IOException { JavadocPlugin.writeJavadocFromElement(pluginEnv, writer, constant); writer.writeFieldDeclaration( utils.getTypeNameFromTypeMirror(constant.asType()), constant.getSimpleName().toString(), Expressions.staticReference(containingClassName, constant.getSimpleName().toString()), TypeConstants.PUBLIC_STATIC_FINAL); } }
private void processVariableElements() { for (Element e : modelSpecElement.getEnclosedElements()) { if (e instanceof VariableElement && e.getAnnotation(Ignore.class) == null) { TypeName typeName = utils.getTypeNameFromTypeMirror(e.asType()); if (!(typeName instanceof DeclaredTypeName)) { utils.getMessager().printMessage(Diagnostic.Kind.WARNING, "Element type " + typeName + " is not a concrete type, will be ignored", e); } else if (!pluginBundle.processVariableElement((VariableElement) e, (DeclaredTypeName) typeName)) { // Deprecated things are generally ignored by plugins, so don't warn about them // private static final fields are generally internal model spec constants, so don't warn about them if (e.getAnnotation(Deprecated.class) == null && !e.getModifiers().containsAll(TypeConstants.PRIVATE_STATIC_FINAL)) { utils.getMessager().printMessage(Diagnostic.Kind.WARNING, "No plugin found to handle field", e); } } } } }
private boolean checkFirstArgType(TypeMirror type, DeclaredTypeName generatedClassName) { if (type instanceof ErrorType) { return true; } if (!(type instanceof DeclaredType)) { return false; } DeclaredTypeName typeName = (DeclaredTypeName) utils.getTypeNameFromTypeMirror(type); return typeName.equals(generatedClassName) || typeName.equals(TypeConstants.ABSTRACT_MODEL); } }
@Override public void afterProcessVariableElements() { // Look for additional constants in @Constant annotated inner classes List<? extends Element> elements = modelSpec.getModelSpecElement().getEnclosedElements(); for (Element element : elements) { if (element instanceof TypeElement && element.getAnnotation(Constants.class) != null) { if (!element.getModifiers().containsAll(Arrays.asList(Modifier.PUBLIC, Modifier.STATIC))) { utils.getMessager().printMessage(Diagnostic.Kind.WARNING, "@Constants annotated class is not " + "public static, will be ignored", element); continue; } TypeElement constantClass = (TypeElement) element; List<VariableElement> constantList = new ArrayList<>(); innerClassConstants.put(constantClass.getSimpleName().toString(), constantList); for (Element e : constantClass.getEnclosedElements()) { if (e instanceof VariableElement && e.getAnnotation(Ignore.class) == null) { TypeName typeName = utils.getTypeNameFromTypeMirror(e.asType()); if (!(typeName instanceof DeclaredTypeName)) { utils.getMessager().printMessage(Diagnostic.Kind.WARNING, "Element type " + typeName + " is not a concrete type, will be ignored", e); } else { processVariableElement((VariableElement) e, constantList); } } } } } }
private void writeConstantField(JavaFileWriter writer, DeclaredTypeName containingClassName, VariableElement constant) throws IOException { JavadocPlugin.writeJavadocFromElement(pluginEnv, writer, constant); writer.writeFieldDeclaration( utils.getTypeNameFromTypeMirror(constant.asType()), constant.getSimpleName().toString(), Expressions.staticReference(containingClassName, constant.getSimpleName().toString()), TypeConstants.PUBLIC_STATIC_FINAL); } }
private void processVariableElements() { for (Element e : modelSpecElement.getEnclosedElements()) { if (e instanceof VariableElement && e.getAnnotation(Ignore.class) == null) { TypeName typeName = utils.getTypeNameFromTypeMirror(e.asType()); if (!(typeName instanceof DeclaredTypeName)) { utils.getMessager().printMessage(Diagnostic.Kind.WARNING, "Element type " + typeName + " is not a concrete type, will be ignored", e); } else if (!pluginBundle.processVariableElement((VariableElement) e, (DeclaredTypeName) typeName)) { // Deprecated things are generally ignored by plugins, so don't warn about them // private static final fields are generally internal model spec constants, so don't warn about them if (e.getAnnotation(Deprecated.class) == null && !e.getModifiers().containsAll(TypeConstants.PRIVATE_STATIC_FINAL)) { utils.getMessager().printMessage(Diagnostic.Kind.WARNING, "No plugin found to handle field", e); } } } } }
private boolean checkFirstArgType(TypeMirror type, DeclaredTypeName generatedClassName) { if (type instanceof ErrorType) { return true; } if (!(type instanceof DeclaredType)) { return false; } DeclaredTypeName typeName = (DeclaredTypeName) utils.getTypeNameFromTypeMirror(type); return typeName.equals(generatedClassName) || typeName.equals(TypeConstants.ABSTRACT_MODEL); } }
@Override public void afterProcessVariableElements() { // Look for additional constants in @Constant annotated inner classes List<? extends Element> elements = modelSpec.getModelSpecElement().getEnclosedElements(); for (Element element : elements) { if (element instanceof TypeElement && element.getAnnotation(Constants.class) != null) { if (!element.getModifiers().containsAll(Arrays.asList(Modifier.PUBLIC, Modifier.STATIC))) { utils.getMessager().printMessage(Diagnostic.Kind.WARNING, "@Constants annotated class is not " + "public static, will be ignored", element); continue; } TypeElement constantClass = (TypeElement) element; List<VariableElement> constantList = new ArrayList<>(); innerClassConstants.put(constantClass.getSimpleName().toString(), constantList); for (Element e : constantClass.getEnclosedElements()) { if (e instanceof VariableElement && e.getAnnotation(Ignore.class) == null) { TypeName typeName = utils.getTypeNameFromTypeMirror(e.asType()); if (!(typeName instanceof DeclaredTypeName)) { utils.getMessager().printMessage(Diagnostic.Kind.WARNING, "Element type " + typeName + " is not a concrete type, will be ignored", e); } else { processVariableElement((VariableElement) e, constantList); } } } } } }