Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed prefix from suppression strings and added suppression tests #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/**
* @author [email protected] (Steven Goldfeder)
*/
@BugPattern(name = "InjectInvalidTargetingOnScopingAnnotation",
@BugPattern(name = "InvalidTargetingOnScopingAnnotation",
summary = "The target of a scoping annotation must be set to METHOD and/or TYPE.",
explanation = "Scoping annotations are only appropriate for provision and therefore are only " +
"appropriate on @Provides methods and classes that will be provided just-in-time.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/**
* @author [email protected] (Steven Goldfeder)
*/
@BugPattern(name = "InjectMoreThanOneQualifier",
@BugPattern(name = "MoreThanOneQualifier",
summary = "Using more than one qualifier annotation on the same element is not allowed.",
explanation = "An element can be qualified by at most one qualifier.", category = INJECT,
severity = ERROR, maturity = EXPERIMENTAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @author [email protected] (Steven Goldfeder)
*/

@BugPattern(name = "InjectMoreThanOneScopeAnnotationOnClass",
@BugPattern(name = "MoreThanOneScopeAnnotationOnClass",
summary = "A class can be annotated with at most one scope annotation",
explanation = "Annotating a class with more than one scope annotation is "
+ "invalid according to the JSR-330 specification. ", category = INJECT, severity = ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/**
* @author [email protected] (Steven Goldfeder)
*/
@BugPattern(name = "InjectScopeAnnotationOnInterfaceOrAbstractClass",
@BugPattern(name = "ScopeAnnotationOnInterfaceOrAbstractClass",
summary = "Scope annotation on an interface or abstact class is not allowed",
explanation = "Scoping annotations are not allowed on abstract types.", category = INJECT,
severity = ERROR, maturity = EXPERIMENTAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/**
* @author [email protected] (Steven Goldfeder)
*/
@BugPattern(name = "InjectScopeOrQualifierAnnotationRetention",
@BugPattern(name = "ScopeOrQualifierAnnotationRetention",
summary = "Scoping and qualifier annotations must have runtime retention.", explanation =
"The JSR-330 spec allows use of reflection. Not having runtime "
+ "retention on scoping or qualifer annotations will cause unexpected "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ public class TestClass5 {
@Inject
public TestClass5(@Assisted("foo") List<String> x, @Assisted("foo") List<Integer> y, String z) {}
}

/**
* Class has constructor with two @Assisted parameters of the same type.
* Error is suppressed.
*/
public class TestClass6 {
@SuppressWarnings("GuiceAssistedParameters")
@Inject
public TestClass6(int n, @Assisted String x, @Assisted String y, int z) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,15 @@ public class InjectInvalidTargetingOnScopingAnnotationNegativeCases {
@Target(PARAMETER)
public @interface TestAnnotation4 {
}

/**
* A scoping annotation with taeget TYPE, METHOD, and (illegal) PARAMETER.
* Error is suppressed.
*/
@SuppressWarnings("InvalidTargetingOnScopingAnnotation")
@Target({TYPE, METHOD, PARAMETER})
@Scope
public @interface TestAnnotation5 {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import com.google.inject.BindingAnnotation;

import javax.inject.Qualifier;
import java.lang.annotation.Retention;

Expand All @@ -41,39 +42,73 @@ public void setN(int n) {}
* A class in which a single javax.inject.Qualifier annotation is on the class, on a constructor,
* on a field, on a method, and on a method parameter.
*/
@Foo
@Foo1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change all of these to @Foo1?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey sorry for the delay--I forgot to change my email settings to my personal account so didn't get the updates. Before I had the suppression tests, in the negative cases there was only a need to have one qualifier(and one BindingAnnotation) so I called it @Foo. But. when I added the suppression tests, I needed two qualifiers so that I could put two on and suppress the warnings. So I added a second qualifier and instead of having one named @Foo, I used @Foo1 and @Foo2. In the old tests where I only needed one qualifier, I used @Foo1.

public class TestClass2 {
@Foo
@Foo1
private int n;

@Foo
@Foo1
public TestClass2() {}

@Foo
public void setN(@Foo int n) {}
@Foo1
public void setN(@Foo1 int n) {}
}

/**
* A class in which a single com.google.inject.BindingAnnotation annotation is on the class, on a
* constructor, on a field, on a method, and on a method parameter.
*/
@Bar
@Bar1
public class TestClass3 {
@Bar
@Bar1
private int n;

@Bar
@Bar1
public TestClass3() {}

@Bar
public void setN(@Bar int n) {}
@Bar1
public void setN(@Bar1 int n) {}
}

/**
* A suppression test for a class in which the class, a constructor, a field,
* a method, and a method parameter each have two com.google.inject.BindingAnnotation
* annotations
*
* TODO(sgoldfeder) Change so that the error only shows up on elements where qualifiers are
* allowed--i.e. methods and classes.
*/
@SuppressWarnings("MoreThanOneQualifier")
@Foo1
@Foo2
public class TestClass4 {
@Foo1
@Foo2
private int n;

@Foo1
@Foo2
public TestClass4() {}

@Foo1
@Foo2
public void setN(@Foo1 @Foo2 int n) {}
}


@Qualifier
@Retention(RUNTIME)
public @interface Foo1 {}

@Qualifier
@Retention(RUNTIME)
public @interface Foo {}
public @interface Foo2 {}

@BindingAnnotation
@Retention(RUNTIME)
public @interface Bar1 {}

@BindingAnnotation
@Retention(RUNTIME)
public @interface Bar {}
public @interface Bar2 {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
*/
public class InjectMoreThanOneQualifierPositiveCases {


/**
* A class in which the class, a constructor, a field, a method, and a method parameter each have
* two com.google.inject.BindingAnnotation annotations.
* two com.google.inject.BindingAnnotation annotations.
*
* TODO(sgoldfeder) Change so that the error only shows up on elements where qualifiers are
* allowed--i.e. methods and classes.
*/
//BUG: Suggestion includes "remove"
@Foo1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.inject.Singleton;
import com.google.inject.Provides;
import com.google.inject.servlet.SessionScoped;
/**
* @author [email protected](Steven Goldfeder)
*/
Expand Down Expand Up @@ -54,4 +55,12 @@ public class TestClass5 {
@Singleton @Provides
public void foo(){}
}

/**
* Class has two scoping annotations. The error is suppressed.
*/
@SuppressWarnings("MoreThanOneScopeAnnotationOnClass")
@Singleton
@SessionScoped
public class TestClass6 {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,20 @@ public interface TestClass3 {
@Singleton
public class TestClass4 {
}

/**
* An abstract class that has scoping annotation. The error is suppressed.
*/
@SuppressWarnings("ScopeAnnotationOnInterfaceOrAbstractClass")
@Singleton
public abstract class TestClass5 {
}

/**
* An interface interface has scoping annotation. The error is suppressed.
*/
@SuppressWarnings("ScopeAnnotationOnInterfaceOrAbstractClass")
@Singleton
public interface TestClass6 {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,15 @@ public class InjectScopeOrQualifierAnnotationRetentionNegativeCases {
@Retention(SOURCE)
public @interface TestAnnotation5 {
}

/**
* A qualifer(@Qualifier) annotation with SOURCE retention. The error is suppressed.
*/
@SuppressWarnings("ScopeOrQualifierAnnotationRetention")
@Qualifier
@Target({TYPE, METHOD})
@Retention(SOURCE)
public @interface TestAnnotation6 {
}

}