use of com.github.davityle.ngprocessor.source.links.ScopeSourceLink in project ngAndroid by davityle.
the class NgProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
this.roundEnv = roundEnv;
if (annotations.size() == 0)
return false;
try {
this.dependencyComponent = dependencyComponentBuilder.environmentModule(new EnvironmentModule(envModule.getOrElse(new ResolverImpl()))).build();
final MessageUtils messageUtils = dependencyComponent.createMessageUtils();
messageUtils.note(Option.<Element>absent(), ":NgAndroid:processing");
Option<String> manifestPackageName = getPackageNameFromAndroidManifest();
if (manifestPackageName.isAbsent()) {
messageUtils.error(Option.<Element>absent(), ":NgAndroid:Unable to find android manifest.");
return false;
}
Set<Scope> scopes = getScopeSet(annotations);
Map<Layout, Collection<XmlScope>> xmlScopes = getXmlScopes();
if (messageUtils.hasErrors())
return false;
Map<Layout, Collection<Scope>> layoutsWScopes = mapLayoutsToScopes(scopes, xmlScopes);
Collection<LayoutSourceLink> layoutSourceLinks = getLayoutSourceLinks(layoutsWScopes, manifestPackageName.get());
Collection<ScopeSourceLink> scopeSourceLinks = getScopeSourceLinks(scopes, manifestPackageName.get());
List<NgModelSourceLink> modelSourceLinks = getModelSourceLinks(getModels(annotations));
createSourceFiles(modelSourceLinks, layoutSourceLinks, scopeSourceLinks);
messageUtils.note(Option.<Element>absent(), ":NgAndroid:finished");
return true;
} catch (Throwable t) {
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "There was an error compiling your ngAttributes: " + sw.toString().replace('\n', ' '), null);
return false;
}
}
use of com.github.davityle.ngprocessor.source.links.ScopeSourceLink in project ngAndroid by davityle.
the class SourceCreator method createSourceFiles.
public void createSourceFiles() {
Properties props = new Properties();
props.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.SystemLogChute");
props.setProperty("resource.loader", "classpath");
props.setProperty("classpath.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
VelocityEngine ve = new VelocityEngine(props);
ve.init();
Template vtModel = ve.getTemplate("templates/ngmodel.vm");
Template vtScope = ve.getTemplate("templates/scope.vm");
Template vtLayout = ve.getTemplate("templates/layout.vm");
for (NgModelSourceLink ms : modelSourceLinks) {
try {
JavaFileObject jfo = filer.createSourceFile(ms.getSourceFileName(), ms.getElements());
Writer writer = jfo.openWriter();
vtModel.merge(ms.getVelocityContext(), writer);
writer.flush();
writer.close();
} catch (IOException e) {
messageUtils.error(Option.of(ms.getElements()[0]), e.getMessage());
}
}
for (ScopeSourceLink ss : scopeSourceLinks) {
try {
JavaFileObject jfo = filer.createSourceFile(ss.getSourceFileName(), ss.getElements());
Writer writer = jfo.openWriter();
vtScope.merge(ss.getVelocityContext(), writer);
writer.flush();
writer.close();
} catch (IOException e) {
messageUtils.error(Option.of(ss.getElements()[0]), e.getMessage());
}
}
for (LayoutSourceLink lsl : layoutSourceLinks) {
try {
JavaFileObject jfo = filer.createSourceFile(lsl.getSourceFileName(), lsl.getElements());
Writer writer = jfo.openWriter();
vtLayout.merge(lsl.getVelocityContext(), writer);
writer.flush();
writer.close();
} catch (IOException e) {
messageUtils.error(Option.<Element>absent(), e.getMessage());
}
}
}
Aggregations