Skip to content

Commit

Permalink
Additional changes in generators, processors, rx sources from EP project
Browse files Browse the repository at this point in the history
  • Loading branch information
gurappa committed Jun 23, 2020
1 parent aa2162b commit e5dc180
Show file tree
Hide file tree
Showing 10 changed files with 389 additions and 294 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.olku.generators;
package net.easypark.generators;

import androidx.annotation.*;

import com.olku.annotations.RetBool;
import com.squareup.javapoet.MethodSpec;
import com.sun.tools.javac.code.Type;

import androidx.annotation.NonNull;
import net.easypark.annotations.RetBool;

/** Compose return types for boolean. */
public class RetBoolGenerator implements ReturnsPoet {
Expand All @@ -28,6 +29,6 @@ public boolean compose(@NonNull final Type returnType,
}

private static final class Singleton {
/* package */ static final RetBoolGenerator INSTANCE = new RetBoolGenerator();
static final RetBoolGenerator INSTANCE = new RetBoolGenerator();
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.olku.generators;
package net.easypark.generators;

import androidx.annotation.*;

import com.olku.annotations.RetNumber;
import com.squareup.javapoet.MethodSpec;
import com.sun.tools.javac.code.Type;

import net.easypark.annotations.RetNumber;

import java.util.Map;
import java.util.TreeMap;

import androidx.annotation.NonNull;

/** Compose return types for boolean. */
public class RetNumberGenerator implements ReturnsPoet {
private static final Map<String, Class<?>> PRIMITIVES = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
Expand Down Expand Up @@ -55,6 +56,6 @@ public boolean compose(@NonNull final Type returnType,
}

private static final class Singleton {
/* package */ static final RetNumberGenerator INSTANCE = new RetNumberGenerator();
static final RetNumberGenerator INSTANCE = new RetNumberGenerator();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.olku.generators;
package net.easypark.generators;

import androidx.annotation.NonNull;

import com.olku.annotations.Returns;
import com.squareup.javapoet.MethodSpec;
import com.sun.tools.javac.code.Type;

import androidx.annotation.NonNull;
import net.easypark.annotations.Returns;

/** Compose return types for boolean. */
public class ReturnsGenerator implements ReturnsPoet {
Expand Down Expand Up @@ -40,10 +41,17 @@ public boolean compose(@NonNull final Type returnType,
return true;
}

// Builders support, return instance for chained calls
if (Returns.THIS.equals(type)) {
builder.addComment("return current instance");
builder.addStatement("return ($T)this", returnType);
return true;
}

return false;
}

private static final class Singleton {
/* package */ static final ReturnsGenerator INSTANCE = new ReturnsGenerator();
static final ReturnsGenerator INSTANCE = new ReturnsGenerator();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.olku.generators;
package net.easypark.generators;

import androidx.annotation.*;

import com.squareup.javapoet.MethodSpec;
import com.sun.tools.javac.code.Type;

import androidx.annotation.NonNull;

/** Code generator interface. */
public interface ReturnsPoet {
/** Compose return statement for provided method based on return type and modifier. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.olku.processors;
package net.easypark.processors;

import com.google.auto.service.AutoService;
import com.olku.annotations.AutoProxy;
import com.olku.annotations.AutoProxyClassGenerator;

import net.easypark.annotations.AutoProxy;
import net.easypark.annotations.AutoProxyClassGenerator;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

Expand All @@ -26,7 +29,11 @@
import static javax.tools.Diagnostic.Kind.ERROR;
import static javax.tools.Diagnostic.Kind.NOTE;

/** Annotation processor. Generate proxy class for interface. */
/**
* Annotation processor. Generate proxy class for interface.
*
* @see <a href="https://docs.gradle.org/nightly/userguide/java_plugin.html#sec:incremental_annotation_processing">Incremental Annotation Processing</a>
*/
@AutoService(Processor.class)
@SuppressWarnings("unused")
public class AutoProxyProcessor extends AbstractProcessor {
Expand All @@ -36,6 +43,8 @@ public class AutoProxyProcessor extends AbstractProcessor {
private Types typesUtil;
private Elements elementsUtil;
private Filer filer;
/** @see <a href="https://github.com/evernote/android-state/commit/0072478291e2735223d6c14cb79a6b26524ec075#diff-6">Support incremental annotation processing</a> */
private HashMap<String, List<Element>> mMapGeneratedFileToOriginatingElements = new LinkedHashMap<>();

@Override
public synchronized void init(final ProcessingEnvironment pe) {
Expand All @@ -56,11 +65,6 @@ public Set<String> getSupportedAnnotationTypes() {
return annotations;
}

@Override
public Set<String> getSupportedOptions() {
return Collections.singleton("org.gradle.annotation.processing.aggregating");
}

@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
Expand All @@ -85,9 +89,14 @@ public boolean process(final Set<? extends TypeElement> annotations, final Round

final AutoProxyClassGenerator generator = tp.generator();

if (!generator.compose(filer)) {
// logger.printMessage(ERROR, generator.getErrors());
logger.printMessage(NOTE, generator.getErrors());
if (generator.compose(filer)) {
if (IS_DEBUG) logger.printMessage(NOTE, "--- file: " + generator.getName());
if (IS_DEBUG) logger.printMessage(NOTE, "--- elements: " + generator.getOriginating().size());
if (IS_DEBUG) logger.printMessage(NOTE, "--- elements: " + generator.getOriginating().get(0).getSimpleName());

mMapGeneratedFileToOriginatingElements.put(generator.getName(), generator.getOriginating());
} else {
logger.printMessage(IS_DEBUG ? ERROR : NOTE, generator.getErrors());
}
} catch (Throwable e) {
e.printStackTrace(new PrintWriter(errors));
Expand All @@ -100,10 +109,13 @@ public boolean process(final Set<? extends TypeElement> annotations, final Round
}

if (failed > 0) {
// logger.printMessage(NOTE, errors.toString());
logger.printMessage(ERROR, errors.toString());
}

return true;
}

public HashMap<String, List<Element>> getMapGeneratedFileToOriginatingElements() {
return mMapGeneratedFileToOriginatingElements;
}
}
Loading

0 comments on commit e5dc180

Please sign in to comment.