Created
July 20, 2016 16:27
-
-
Save kikuchy/ed15b080e14c26984899d22e6ba2a964 to your computer and use it in GitHub Desktop.
Generate Kotlin extension code and not working... X(
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import com.google.auto.service.AutoService; | |
import com.google.common.collect.Sets; | |
import java.io.IOException; | |
import java.io.OutputStream; | |
import java.io.Writer; | |
import java.util.Set; | |
import javax.annotation.processing.AbstractProcessor; | |
import javax.annotation.processing.ProcessingEnvironment; | |
import javax.annotation.processing.Processor; | |
import javax.annotation.processing.RoundEnvironment; | |
import javax.lang.model.element.Element; | |
import javax.lang.model.element.TypeElement; | |
import javax.annotation.processing.Filer; | |
import javax.tools.FileObject; | |
import javax.tools.JavaFileObject; | |
import javax.tools.StandardLocation; | |
@AutoService(Processor.class) | |
public class MyProcessor extends AbstractProcessor { | |
private Filer filer; | |
@Override | |
public Set<String> getSupportedAnnotationTypes() { | |
return Sets.newHashSet(MyAnnotation.class.getCanonicalName()); | |
} | |
@Override | |
public synchronized void init(ProcessingEnvironment processingEnv) { | |
super.init(processingEnv); | |
filer = processingEnv.getFiler(); | |
} | |
@Override | |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { | |
try { | |
FileObject file = filer.createResource(StandardLocation.SOURCE_OUTPUT, "net.kikuchy.kaptapttest", "MainActivityExtension.kt", new Element[0]); | |
Writer writer = file.openWriter(); | |
writer.append("package net.kikuchy.kaptapttest\n\nfun MainActivity.doSomething() = intent"); | |
writer.flush(); | |
writer.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment