Skip to content

Commit

Permalink
quick patch
Browse files Browse the repository at this point in the history
fixes an NPE related to instantiating a translator, as it was being instantiated before the treemaker was
  • Loading branch information
Maowcraft authored and Maowcraft committed Mar 29, 2021
1 parent 2b9b6e9 commit c39ca0e
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 27 deletions.
2 changes: 1 addition & 1 deletion example-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ archivesBaseName = 'lucent-example-test'
version = '1.0.0'

dependencies {
compileOnly project(':example')
compile project(':example')
annotationProcessor project(':example')
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package org.transparent.lucent.example.test;

import org.transparent.lucent.example.Example;

@Example
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.transparent.lucent.example;

import com.sun.tools.javac.tree.JCTree;
import org.transparent.lucent.processor.LucentProcessor;
import org.transparent.lucent.transform.LucentTranslator;

import javax.lang.model.element.Element;
import java.lang.annotation.Annotation;

public final class ExampleProcessor extends LucentProcessor {
Expand All @@ -13,26 +11,6 @@ public LucentTranslator getTranslator() {
return translator(ExampleTranslator::new);
}

@Override
protected void process() {
System.out.println("Process");
}

@Override
protected void preTranslate(JCTree tree, Element element, LucentTranslator translator) {
System.out.println("Pre-Translate");
}

@Override
protected void postTranslate(JCTree tree, Element element, LucentTranslator translator) {
System.out.println("Post-Translate");
}

@Override
protected void notSupported(Element element) {
System.out.println("Not Supported");
}

@Override
public Class<? extends Annotation> getSupportedAnnotation() {
return Example.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ public void translate(JCTree tree, Element element) {
final JCClassDecl clazz = (JCClassDecl) tree;
clazz.defs = clazz.defs
.append(field());
result = clazz;
}
}

private JCVariableDecl field() {
final JCModifiers mods = factory.Modifiers(
Flags.PRIVATE & Flags.FINAL);
Flags.PRIVATE | Flags.FINAL);
final Name name = names.fromString("generated");
final JCExpression type = factory.Ident(
names.fromString("String"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.transparent.lucent.example.ExampleProcessor
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
rootProject.name = 'lucent'
include 'example'
include 'lucent-example-test'
include 'example-test'

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
public abstract class LucentProcessor extends AbstractProcessor {
private final Set<TypeKind> kinds;
private final LucentTranslator translator;
private LucentTranslator translator;

protected Trees trees;
protected Context context;
Expand All @@ -56,7 +56,6 @@ public abstract class LucentProcessor extends AbstractProcessor {
*/
public LucentProcessor() {
kinds = getSupportedTypeKinds();
translator = getTranslator();
}

@Override
Expand All @@ -67,6 +66,7 @@ public synchronized void init(ProcessingEnvironment env) {
.getContext();
factory = TreeMaker.instance(context);
names = Names.instance(context);
translator = getTranslator();
}

/**
Expand Down Expand Up @@ -102,6 +102,7 @@ protected boolean process(RoundEnvironment env) {
if (translator != null)
translator.translate(tree, element);
postTranslate(tree, element, translator);
continue;
}
notSupported(element);
}
Expand Down

0 comments on commit c39ca0e

Please sign in to comment.