Skip to content

Commit

Permalink
Add a check for Singleton on constructors.
Browse files Browse the repository at this point in the history
  • Loading branch information
cgruber committed Jun 12, 2013
1 parent 2477211 commit 980e72a
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ static GraphAnalysisInjectBinding create(TypeElement type, boolean mustHaveInjec
ExecutableElement constructor = (ExecutableElement) enclosed;
List<? extends VariableElement> parameters = constructor.getParameters();
if (hasAtInject(enclosed)) {
if (hasAtSingleton(enclosed)) {
throw new IllegalArgumentException("Singleton annotations have no effect on " +
"constructors. Did you mean to annotate the class? " +
type.getQualifiedName().toString());
}
if (hasInjectConstructor) {
throw new IllegalArgumentException("Too many injectable constructors on "
+ type.getQualifiedName().toString());
Expand Down Expand Up @@ -111,6 +116,10 @@ private static boolean hasAtInject(Element enclosed) {
return enclosed.getAnnotation(Inject.class) != null;
}

private static boolean hasAtSingleton(Element enclosed) {
return enclosed.getAnnotation(Singleton.class) != null;
}

@Override public void attach(Linker linker) {
String requiredBy = type.getQualifiedName().toString();
for (int i = 0; i < keys.size(); i++) {
Expand Down

0 comments on commit 980e72a

Please sign in to comment.