use of com.yahoo.aptutils.model.DeclaredTypeName in project squidb by yahoo.
the class AndroidModelPlugin method emitConstructors.
@Override
public void emitConstructors(JavaFileWriter writer) throws IOException {
if (generateConstructors) {
String valuesName = "contentValues";
DeclaredTypeName valuesType = TypeConstants.CONTENT_VALUES;
MethodDeclarationParameters params = new MethodDeclarationParameters().setModifiers(Modifier.PUBLIC).setConstructorName(modelSpec.getGeneratedClassName());
params.setArgumentTypes(Collections.singletonList(valuesType)).setArgumentNames(valuesName);
writer.beginConstructorDeclaration(params).writeStatement(Expressions.callMethod("this", valuesName, ModelFileWriter.PROPERTIES_ARRAY_NAME)).finishMethodDefinition();
String methodName = "readPropertiesFromContentValues";
params.setArgumentTypes(Arrays.asList(valuesType, TypeConstants.PROPERTY_VARARGS)).setArgumentNames(valuesName, "withProperties");
writer.beginConstructorDeclaration(params).writeStringStatement("this()").writeStringStatement(methodName + "(" + valuesName + ", withProperties)").finishMethodDefinition();
}
}
use of com.yahoo.aptutils.model.DeclaredTypeName in project squidb by yahoo.
the class ConstantCopyingPlugin method afterProcessVariableElements.
@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);
}
}
}
}
}
}
use of com.yahoo.aptutils.model.DeclaredTypeName in project squidb by yahoo.
the class ConstantCopyingPlugin method afterEmitSchema.
@Override
public void afterEmitSchema(JavaFileWriter writer) throws IOException {
writer.writeComment("--- constants");
for (VariableElement constant : constantElements) {
writeConstantField(writer, modelSpec.getModelSpecName(), constant);
}
for (Map.Entry<String, List<VariableElement>> innerClassConstant : innerClassConstants.entrySet()) {
String classNameString = innerClassConstant.getKey();
DeclaredTypeName constClassName = new DeclaredTypeName(null, modelSpec.getModelSpecName().getSimpleName() + "." + classNameString);
for (VariableElement element : innerClassConstant.getValue()) {
writeConstantField(writer, constClassName, element);
}
}
writer.writeNewline();
}
use of com.yahoo.aptutils.model.DeclaredTypeName in project squidb by yahoo.
the class ConstructorPlugin method emitConstructors.
@Override
public void emitConstructors(JavaFileWriter writer) throws IOException {
writer.writeComment("--- default constructors");
MethodDeclarationParameters params = new MethodDeclarationParameters().setModifiers(Modifier.PUBLIC).setConstructorName(modelSpec.getGeneratedClassName());
writer.beginConstructorDeclaration(params).writeStringStatement("super()").finishMethodDefinition();
DeclaredTypeName squidCursorType = TypeConstants.SQUID_CURSOR.clone();
squidCursorType.setTypeArgs(Collections.singletonList(modelSpec.getGeneratedClassName()));
params.setArgumentTypes(squidCursorType).setArgumentNames("cursor");
writer.beginConstructorDeclaration(params).writeStringStatement("this()").writeStringStatement("readPropertiesFromCursor(cursor)").finishMethodDefinition();
String valuesName = "values";
DeclaredTypeName valuesType = TypeConstants.MAP_VALUES;
params.setArgumentTypes(Collections.singletonList(valuesType)).setArgumentNames(valuesName);
writer.beginConstructorDeclaration(params).writeStatement(Expressions.callMethod("this", valuesName, ModelFileWriter.PROPERTIES_ARRAY_NAME)).finishMethodDefinition();
String methodName = "readPropertiesFromMap";
params.setArgumentTypes(Arrays.asList(valuesType, TypeConstants.PROPERTY_VARARGS)).setArgumentNames(valuesName, "withProperties");
writer.beginConstructorDeclaration(params).writeStringStatement("this()").writeStringStatement(methodName + "(" + valuesName + ", withProperties)").finishMethodDefinition();
MethodDeclarationParameters cloneParams = new MethodDeclarationParameters().setModifiers(Modifier.PUBLIC).setMethodName("clone").setReturnType(modelSpec.getGeneratedClassName());
Expression cloneBody = Expressions.callMethodOn("super", "clone").cast(modelSpec.getGeneratedClassName()).returnExpr();
writer.writeAnnotation(CoreTypes.OVERRIDE);
writer.beginMethodDefinition(cloneParams).writeStatement(cloneBody).finishMethodDefinition();
}
use of com.yahoo.aptutils.model.DeclaredTypeName in project squidb by yahoo.
the class ImplementsPlugin method parseInterfaces.
private void parseInterfaces() {
TypeElement modelSpecElement = modelSpec.getModelSpecElement();
if (modelSpecElement.getAnnotation(Implements.class) != null) {
List<DeclaredTypeName> typeNames = utils.getTypeNamesFromAnnotationValue(utils.getAnnotationValue(modelSpecElement, Implements.class, "interfaceClasses"));
if (!AptUtils.isEmpty(typeNames)) {
interfaces.addAll(typeNames);
}
AnnotationValue value = utils.getAnnotationValue(modelSpecElement, Implements.class, "interfaceDefinitions");
List<AnnotationMirror> interfaceSpecs = utils.getValuesFromAnnotationValue(value, AnnotationMirror.class);
for (AnnotationMirror spec : interfaceSpecs) {
AnnotationValue interfaceClassValue = utils.getAnnotationValueFromMirror(spec, "interfaceClass");
List<DeclaredTypeName> interfaceClassList = utils.getTypeNamesFromAnnotationValue(interfaceClassValue);
if (!AptUtils.isEmpty(interfaceClassList)) {
DeclaredTypeName interfaceClass = interfaceClassList.get(0);
AnnotationValue interfaceTypeArgsValue = utils.getAnnotationValueFromMirror(spec, "interfaceTypeArgs");
List<DeclaredTypeName> typeArgs = utils.getTypeNamesFromAnnotationValue(interfaceTypeArgsValue);
if (AptUtils.isEmpty(typeArgs)) {
List<String> typeArgNames = utils.getValuesFromAnnotationValue(utils.getAnnotationValueFromMirror(spec, "interfaceTypeArgNames"), String.class);
for (String typeArgName : typeArgNames) {
typeArgs.add(new DeclaredTypeName(typeArgName));
}
}
interfaceClass.setTypeArgs(typeArgs);
interfaces.add(interfaceClass);
}
}
}
}
Aggregations