Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
cgruber committed Jun 27, 2013
2 parents 66e14ce + cb95092 commit 50665b0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 32 deletions.
8 changes: 4 additions & 4 deletions compiler/src/it/provide-provider-or-lazy/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import java.io.File;

File buildLog = new File(basedir, "build.log");
new BuildLogValidator().assertHasText(buildLog, new String[]{
"@Provides method must not return Provider directly: test.TestModule.provideProvider"});
"@Provides method must not return javax.inject.Provider directly: test.TestModule.provideProvider"});
new BuildLogValidator().assertHasText(buildLog, new String[]{
"@Provides method must not return Provider directly: test.TestModule.provideRawProvider"});
"@Provides method must not return javax.inject.Provider directly: test.TestModule.provideRawProvider"});
new BuildLogValidator().assertHasText(buildLog, new String[]{
"@Provides method must not return Lazy directly: test.TestModule.provideLazy"});
"@Provides method must not return dagger.Lazy directly: test.TestModule.provideLazy"});
new BuildLogValidator().assertHasText(buildLog, new String[]{
"@Provides method must not return Lazy directly: test.TestModule.provideRawLazy"});
"@Provides method must not return dagger.Lazy directly: test.TestModule.provideRawLazy"});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package dagger.internal.codegen;

import com.squareup.java.JavaWriter;
import com.squareup.javawriter.JavaWriter;
import java.io.Closeable;
import java.io.IOException;
import java.io.Writer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package dagger.internal.codegen;

import com.squareup.java.JavaWriter;
import com.squareup.javawriter.JavaWriter;
import dagger.MembersInjector;
import dagger.internal.Binding;
import dagger.internal.Linker;
Expand Down Expand Up @@ -239,7 +239,7 @@ private void writeInjectAdapter(TypeElement type, ExecutableElement constructor,
boolean dependent = injectMembers
|| ((constructor != null) && !constructor.getParameters().isEmpty());

writer.emitEndOfLineComment(AdapterJavadocs.GENERATED_BY_DAGGER);
writer.emitSingleLineComment(AdapterJavadocs.GENERATED_BY_DAGGER);
writer.emitPackage(packageName);
writer.emitEmptyLine();
writer.emitImports(getImports(dependent, injectMembers, constructor != null));
Expand Down Expand Up @@ -411,7 +411,7 @@ private void writeStaticInjection(TypeElement type, List<Element> fields) throws
.createSourceFile(adapterName, type);
JavaWriter writer = new JavaWriter(sourceFile.openWriter());

writer.emitEndOfLineComment(AdapterJavadocs.GENERATED_BY_DAGGER);
writer.emitSingleLineComment(AdapterJavadocs.GENERATED_BY_DAGGER);
writer.emitPackage(getPackage(type).getQualifiedName().toString());

writer.emitEmptyLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package dagger.internal.codegen;

import com.squareup.java.JavaWriter;
import com.squareup.javawriter.JavaWriter;
import dagger.Module;
import dagger.Provides;
import dagger.internal.Binding;
Expand All @@ -24,6 +24,7 @@
import dagger.internal.SetBinding;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -68,7 +69,7 @@
* Generates an implementation of {@link ModuleAdapter} that includes a binding
* for each {@code @Provides} method of a target class.
*/
@SupportedAnnotationTypes({ "dagger.Provides", "dagger.Module" })
@SupportedAnnotationTypes({ "*" })
public final class ModuleAdapterProcessor extends AbstractProcessor {
private final LinkedHashMap<String, List<ExecutableElement>> remainingTypes =
new LinkedHashMap<String, List<ExecutableElement>>();
Expand Down Expand Up @@ -117,11 +118,6 @@ private Map<String, List<ExecutableElement>> providerMethodsByClass(RoundEnviron
Elements elementUtils = processingEnv.getElementUtils();
Types types = processingEnv.getTypeUtils();

TypeElement providerElement = elementUtils.getTypeElement("javax.inject.Provider");
TypeMirror providerType = types.erasure(providerElement.asType());
TypeElement lazyElement = elementUtils.getTypeElement("dagger.Lazy");
TypeMirror lazyType = types.erasure(lazyElement.asType());

Map<String, List<ExecutableElement>> result = new HashMap<String, List<ExecutableElement>>();
for (Element providerMethod : providesMethods(env)) {
switch (providerMethod.getEnclosingElement().getKind()) {
Expand Down Expand Up @@ -157,20 +153,17 @@ private Map<String, List<ExecutableElement>> providerMethodsByClass(RoundEnviron
continue;
}

// Invalidate return types.
TypeMirror returnType = types.erasure(providerMethodAsExecutable.getReturnType());
if (types.isSameType(returnType, providerType)) {
error("@Provides method must not return Provider directly: "
+ type.getQualifiedName()
+ "."
+ providerMethod, providerMethod);
continue;
}
if (types.isSameType(returnType, lazyType)) {
error("@Provides method must not return Lazy directly: "
+ type.getQualifiedName()
+ "."
+ providerMethod, providerMethod);
continue;
for (String invalidTypeName : Arrays.asList("javax.inject.Provider", "dagger.Lazy")) {
TypeElement invalidTypeElement = elementUtils.getTypeElement(invalidTypeName);
if (invalidTypeElement != null) {
if (types.isSameType(returnType, types.erasure(invalidTypeElement.asType()))) {
error(String.format("@Provides method must not return %s directly: %s.%s",
invalidTypeElement, type.getQualifiedName(), providerMethod), providerMethod);
continue; // skip to next provides method.
}
}
}

List<ExecutableElement> methods = result.get(type.getQualifiedName().toString());
Expand Down Expand Up @@ -238,7 +231,7 @@ private void writeModuleAdapter(TypeElement type, Map<String, Object> module,
boolean multibindings = checkForMultibindings(providerMethods);
boolean providerMethodDependencies = checkForDependencies(providerMethods);

writer.emitEndOfLineComment(AdapterJavadocs.GENERATED_BY_DAGGER);
writer.emitSingleLineComment(AdapterJavadocs.GENERATED_BY_DAGGER);
writer.emitPackage(getPackage(type).getQualifiedName().toString());
writer.emitEmptyLine();
writer.emitImports(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public class DemoApplication extends Application {
}

protected List<Object> getModules() {
return Arrays.<Object>asList(
new AndroidModule(this)
return Arrays.asList(
new AndroidModule(this),
new DemoModule()
);
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<!-- Compilation -->
<java.version>1.6</java.version>
<javax.inject.version>1</javax.inject.version>
<javawriter.version>1.0.5</javawriter.version>
<javawriter.version>2.0.1</javawriter.version>

<!-- Test Dependencies -->
<junit.version>4.10</junit.version>
Expand Down

0 comments on commit 50665b0

Please sign in to comment.