Skip to content

Commit

Permalink
FilerException problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
msbelaid committed Jul 11, 2020
1 parent 2813f4e commit 11cd614
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@

String where();
// TODO returns? List or One Live or not
boolean liveData = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ TypeSpec generateRepositoryClass() {

for (LivingroomMethod m: this.getMethodsSet()) {
if (!m.hasParams())
repositoryClass.addField(((LiveMethod)m).getLiveDataType(), m.getMethodName()+"List", Modifier.PRIVATE);// TODO test if live or not????
repositoryClass.addField(((SelectMethod)m).getReturnType(), m.getMethodName()+"List", Modifier.PRIVATE);// TODO test if live or not????
repositoryClass.addMethod(m.generateRepositoryMethod(this).build());
if (m instanceof AsyncMethod) {
repositoryClass.addType(
Expand All @@ -149,7 +149,7 @@ TypeSpec generateViewModelClass() {
.addMethod(constructor);
for (LivingroomMethod m: this.getMethodsSet()) {
if (!m.hasParams()) {
viewModelClass.addField(((LiveMethod)m).getLiveDataType(), m.getMethodName()+"List", Modifier.PRIVATE);
viewModelClass.addField(((SelectMethod)m).getReturnType(), m.getMethodName()+"List", Modifier.PRIVATE);
}
viewModelClass.addMethod(m.generateViewModelMethod(this).build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Filer;
import javax.annotation.processing.FilerException;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
Expand Down Expand Up @@ -93,27 +94,18 @@ public boolean process(Set<? extends TypeElement> set, RoundEnvironment env) {
parseSelectableAll(env);
parseSelectableById(env);

for (Map.Entry<TypeElement, EntityClass> e: entitiesList.entrySet()) {
try {
generateCodeForEntity(e.getValue());
entities.add(e.getValue().getTypeName());
} catch (IOException ex) {
ex.printStackTrace();
}
}
try {
generateDatabaseClass();
generateClasses();
} catch (IOException e) {
e.printStackTrace();
}

return false;
}

private void parseAnnotation(Collection<? extends Element> elements, String method) {
for (Element e: elements ) {
checkIfExtendsBasicEntity(e);
checkIfAnnotatedWithEntity(e);
checkIfExtendsBasicEntity(e);
if (entitiesList.containsKey(e)) {
EntityClass entityClass = entitiesList.get(e);
entitiesList.get(e).addMethod(LivingroomMethod.of(entityClass, method));
Expand All @@ -126,6 +118,19 @@ private void parseAnnotation(Collection<? extends Element> elements, String met
}
}

private void generateClasses() throws IOException {
for (Map.Entry<TypeElement, EntityClass> e: entitiesList.entrySet()) {
generateCodeForEntity(e.getValue());
entities.add(e.getValue().getTypeName());
}

try {
generateDatabaseClass();
} catch (FilerException e){

}
}

private void parseCrudable(RoundEnvironment env) {
Collection<? extends Element> elements =
env.getElementsAnnotatedWith(Crudable.class);
Expand Down Expand Up @@ -237,9 +242,14 @@ private void generateCodeForEntity(EntityClass clazz) throws IOException {
packageName = path.substring(0, lastDot);
}
}
generateDaoClass(clazz);
generateRepositoryClass(clazz);
generateViewModelClass(clazz);
try {
generateDaoClass(clazz);
generateRepositoryClass(clazz);
generateViewModelClass(clazz);
} catch (FilerException e) {

}

}

private void checkIfExtendsBasicEntity(Element annotatedElement){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static LivingroomMethod selectByIdMethod(EntityClass entityClass) {
}

static LivingroomMethod selectWhereMethod(EntityClass entityClass, String methodName, String where, String[] params, boolean isList) {
return new LiveMethod(methodName, where, entityClass, params, isList);
return new SelectMethod(methodName, where, entityClass, params, isList);
}

static List<LivingroomMethod> crud(EntityClass entityClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
import java.util.Iterator;
import java.util.Map;

public class LiveMethod extends LivingroomMethod {
public class SelectMethod extends LivingroomMethod {
private static final String LIST = "List";
private final String where;
private boolean isLiveData; // TODO can either be live or not
private boolean isList;

LiveMethod(String methodName, String where, EntityClass entityClass, String[] params, boolean isList) {
SelectMethod(String methodName, String where, EntityClass entityClass, String[] params, boolean isList) {
super(entityClass, methodName);
this.isList = isList;
//this.isLiveData = isLiveData;
this.where = where;
this.setReturnType(getLiveDataType());
this.setReturnType(getReturnType());
this.setAnnotation(Query.class);

if (params != null && params.length>=1) {
Expand Down Expand Up @@ -93,7 +94,7 @@ public MethodSpec.Builder generateViewModelMethod(EntityClass entityClass){
return builder;
}

ParameterizedTypeName getLiveDataType(){
ParameterizedTypeName getReturnType(){
ClassName liveDataClass = ClassName.get("androidx.lifecycle", "LiveData");
ClassName listClass = ClassName.get("java.util", LIST);
return isList?
Expand Down

0 comments on commit 11cd614

Please sign in to comment.