repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/dagger/testdata/AndroidInjectionBeforeSuperPositiveCases.java
/* * Copyright 2017 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.dagger.testdata; import android.app.Activity; import android.app.Fragment; import android.app.Service; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.IBinder; import dagger.android.AndroidInjection; final class AndroidInjectionBeforeSuperPositiveCases { public class WrongOrder extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // BUG: Diagnostic contains: AndroidInjectionBeforeSuper AndroidInjection.inject(this); } } public class StatementsInBetween extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); System.out.println("hello, world"); // BUG: Diagnostic contains: AndroidInjectionBeforeSuper AndroidInjection.inject(this); } } public static class BaseActivity extends Activity {} public class ExtendsBase extends BaseActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // BUG: Diagnostic contains: AndroidInjectionBeforeSuper AndroidInjection.inject(this); } } public class WrongOrderFragmentPreApi23 extends Fragment { @Override public void onAttach(Activity activity) { super.onAttach(activity); // BUG: Diagnostic contains: AndroidInjectionBeforeSuper AndroidInjection.inject(this); } } public class WrongOrderFragment extends Fragment { @Override public void onAttach(Context context) { super.onAttach(context); // BUG: Diagnostic contains: AndroidInjectionBeforeSuper AndroidInjection.inject(this); } } public class WrongOrderService extends Service { @Override public void onCreate() { super.onCreate(); // BUG: Diagnostic contains: AndroidInjectionBeforeSuper AndroidInjection.inject(this); } @Override public IBinder onBind(Intent intent) { return null; } } }
2,714
28.835165
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/dagger/testdata/stubs/android/content/Context.java
/* * Copyright 2017 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.content; public class Context {}
659
32
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/dagger/testdata/stubs/android/content/Intent.java
/* * Copyright 2017 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.content; public class Intent {}
658
31.95
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/dagger/testdata/stubs/android/app/Service.java
/* * Copyright 2017 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.app; public class Service { public void onCreate() {} public android.os.IBinder onBind(android.content.Intent intent) { return null; } }
774
28.807692
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/dagger/testdata/stubs/android/app/Activity.java
/* * Copyright 2017 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.app; public class Activity { public void onCreate(android.os.Bundle bundle) {} }
709
31.272727
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/dagger/testdata/stubs/android/app/Fragment.java
/* * Copyright 2017 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.app; public class Fragment { public void onAttach(android.app.Activity activity) {} public void onAttach(android.content.Context context) {} }
773
32.652174
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/dagger/testdata/stubs/android/os/Bundle.java
/* * Copyright 2017 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.os; public class Bundle {}
653
31.7
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/dagger/testdata/stubs/android/os/IBinder.java
/* * Copyright 2017 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.os; public interface IBinder {}
658
31.95
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/AssistedParametersTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice; import com.google.errorprone.CompilationTestHelper; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ @RunWith(JUnit4.class) public class AssistedParametersTest { private final CompilationTestHelper compilationHelper = CompilationTestHelper.newInstance(AssistedParameters.class, getClass()); @Test public void positiveCase() { compilationHelper.addSourceFile("AssistedParametersPositiveCases.java").doTest(); } @Test public void negativeCase() { compilationHelper.addSourceFile("AssistedParametersNegativeCases.java").doTest(); } }
1,329
29.930233
85
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/BindingToUnqualifiedCommonTypeTest.java
/* * Copyright 2016 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice; import com.google.errorprone.CompilationTestHelper; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * @author glorioso@google.com (Nick Glorioso) */ @RunWith(JUnit4.class) public class BindingToUnqualifiedCommonTypeTest { private final CompilationTestHelper compilationHelper = CompilationTestHelper.newInstance(BindingToUnqualifiedCommonType.class, getClass()); @Test public void positiveCase() { compilationHelper.addSourceFile("BindingToUnqualifiedCommonTypePositiveCases.java").doTest(); } @Test public void negativeCase() { compilationHelper.addSourceFile("BindingToUnqualifiedCommonTypeNegativeCases.java").doTest(); } }
1,371
31.666667
97
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/OverridesJavaxInjectableMethodTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice; import com.google.errorprone.CompilationTestHelper; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ @RunWith(JUnit4.class) public class OverridesJavaxInjectableMethodTest { private final CompilationTestHelper compilationHelper = CompilationTestHelper.newInstance(OverridesJavaxInjectableMethod.class, getClass()); @Test public void positiveCase() { compilationHelper.addSourceFile("OverridesJavaxInjectableMethodPositiveCases.java").doTest(); } @Test public void negativeCase() { compilationHelper.addSourceFile("OverridesJavaxInjectableMethodNegativeCases.java").doTest(); } }
1,376
31.785714
97
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/OverridesGuiceInjectableMethodTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice; import com.google.errorprone.CompilationTestHelper; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ @RunWith(JUnit4.class) public class OverridesGuiceInjectableMethodTest { private final CompilationTestHelper compilationHelper = CompilationTestHelper.newInstance(OverridesGuiceInjectableMethod.class, getClass()); @Test public void positiveCase() { compilationHelper.addSourceFile("OverridesGuiceInjectableMethodPositiveCases.java").doTest(); } @Test public void negativeCase() { compilationHelper.addSourceFile("OverridesGuiceInjectableMethodNegativeCases.java").doTest(); } }
1,376
31.785714
97
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/ProvidesMethodOutsideOfModuleTest.java
/* * Copyright 2016 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice; import com.google.errorprone.CompilationTestHelper; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * @author glorioso@google.com (Nick Glorioso) */ @RunWith(JUnit4.class) public class ProvidesMethodOutsideOfModuleTest { private final CompilationTestHelper compilationHelper = CompilationTestHelper.newInstance(ProvidesMethodOutsideOfModule.class, getClass()); @Test public void positiveCase() { compilationHelper.addSourceFile("ProvidesMethodOutsideOfModulePositiveCases.java").doTest(); } @Test public void negativeCase() { compilationHelper.addSourceFile("ProvidesMethodOutsideOfModuleNegativeCases.java").doTest(); } }
1,367
31.571429
96
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/InjectOnFinalFieldTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice; import com.google.errorprone.CompilationTestHelper; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ @RunWith(JUnit4.class) public class InjectOnFinalFieldTest { private final CompilationTestHelper compilationHelper = CompilationTestHelper.newInstance(InjectOnFinalField.class, getClass()); @Test public void positiveCase() { compilationHelper.addSourceFile("InjectOnFinalFieldPositiveCases.java").doTest(); } @Test public void negativeCase() { compilationHelper.addSourceFile("InjectOnFinalFieldNegativeCases.java").doTest(); } }
1,328
30.642857
85
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/AssistedInjectScopingTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice; import com.google.errorprone.CompilationTestHelper; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * @author eaftan@google.com (Eddie Aftandilian) */ @RunWith(JUnit4.class) public class AssistedInjectScopingTest { private final CompilationTestHelper compilationHelper = CompilationTestHelper.newInstance(AssistedInjectScoping.class, getClass()); @Test public void positiveCase() { compilationHelper.addSourceFile("AssistedInjectScopingPositiveCases.java").doTest(); } @Test public void negativeCase() { compilationHelper.addSourceFile("AssistedInjectScopingNegativeCases.java").doTest(); } }
1,338
30.139535
88
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/testdata/AssistedParametersPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice.testdata; import com.google.inject.assistedinject.Assisted; import java.util.List; import javax.inject.Inject; /** * @author sgoldfeder@google.com(Steven Goldfeder) */ public class AssistedParametersPositiveCases { /** Class has constructor with two @Assisted parameters of the same type. */ public class TestClass1 { @Inject // BUG: Diagnostic contains: java.lang.String: x, y public TestClass1(int n, @Assisted String x, @Assisted String y, int z) {} @Inject // BUG: Diagnostic contains: java.lang.String, @Assisted("baz"): x, z public TestClass1( @Assisted("foo") int a, @Assisted("foo") int b, @Assisted("baz") String x, @Assisted("baz") String z) {} } /** Class has constructor with two @Assisted parameters of the same type and same value. */ public class TestClass2 { @Inject // BUG: Diagnostic contains: int, @Assisted("foo"): x, y public TestClass2(int n, @Assisted("foo") int x, @Assisted("foo") int y, String z) {} } /** Class has constructor with two @Assisted parameters of the same parameterized type. */ public class TestClass3 { private static final String FOO = "foo"; @Inject // BUG: Diagnostic contains: java.util.List<java.lang.String>, @Assisted("foo"): x, y public TestClass3( int n, @Assisted("foo") List<String> x, @Assisted(FOO) List<String> y, String z) {} @Inject // BUG: Diagnostic contains: int, @Assisted("bar"): x, y public TestClass3( @Assisted() int n, @Assisted("bar") int x, @Assisted("bar") int y, String z) {} } class GenericClass<T> { @Inject // BUG: Diagnostic contains: T: a, b GenericClass(@Assisted T a, @Assisted T b) {} @Inject // BUG: Diagnostic contains: int: a, b GenericClass(@Assisted Integer a, @Assisted int b) {} } }
2,503
32.386667
93
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/testdata/OverridesJavaxInjectableMethodPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice.testdata; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class OverridesJavaxInjectableMethodPositiveCases { /** Class with foo() */ public class TestClass0 { public void foo() {} } /** * Class with a method foo() that is annotated with {@code javax.inject.Inject}. Other test * classes will extend this class. */ public class TestClass1 extends TestClass0 { @javax.inject.Inject public void foo() {} } /** * Class with a method foo() that is not annotated, but overrides a method annotated with * {@code @}javax.inject.Inject. */ public class TestClass2 extends TestClass1 { // BUG: Diagnostic contains: @Inject public void foo() {} } /** * Class with a method foo() that is not annotated, but overrides a method that in turn overrides * a method that is annotated with @javax.inject.Inject. */ public class TestClass3 extends TestClass2 { // BUG: Diagnostic contains: @Inject public void foo() {} } }
1,671
28.857143
99
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/testdata/AssistedInjectScopingNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice.testdata; import com.google.inject.Inject; import com.google.inject.Singleton; import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.AssistedInject; /** * @author eaftan@google.com (Eddie Aftandilian) */ public class AssistedInjectScopingNegativeCases { /** Class is not assisted and has no scoping annotation. */ public class TestClass1 { public TestClass1(String unassisted1, String unassisted2) {} } /** Class is not assisted and has no scoping annotation, but has an unrelated annotation. */ @SuppressWarnings("foo") public class TestClass2 { public TestClass2(String unassisted, @Assisted String assisted) {} } /** Class is not assisted but has scoping annotation. */ @Singleton public class TestClass3 { public TestClass3(String unassisted1, String unassisted2) {} } /** Class is assisted via @Assisted param but has no scoping annotation. */ public class TestClass4 { @Inject public TestClass4(@Assisted String assisted) {} } /** Class is assisted via @AssistedInject constructor but has no scoping annotation. */ public class TestClass5 { @AssistedInject public TestClass5(String unassisted) {} } /** Class is not assisted -- constructor with @Assisted param does not have @Inject. */ @Singleton public class TestClass6 { public TestClass6(@Assisted String assisted) {} } /** Multiple constructors but not assisted. */ @Singleton public class TestClass7 { public TestClass7(String unassisted1, String unassisted2) {} public TestClass7(String unassisted, int i) {} public TestClass7(int i, String unassisted) {} } /** Multiple constructors, one with @Inject, non-@Inject ones match. */ @Singleton public class TestClass8 { @Inject public TestClass8(String unassisted1, String unassisted2) {} @AssistedInject public TestClass8(String param, int i) {} @AssistedInject public TestClass8(int i, String param) {} } /** Multiple constructors, one with @Inject, non-@Inject ones match. */ @Singleton public class TestClass9 { @Inject public TestClass9(String unassisted1, String unassisted2) {} @AssistedInject public TestClass9(String param, int i) {} @AssistedInject public TestClass9(int i, String param) {} } @Singleton public class TestClass10 { public TestClass10(@Assisted String assisted, String unassisted) {} public TestClass10(@Assisted String assisted, int i) {} public TestClass10(int i, @Assisted String assisted) {} } }
3,232
28.935185
94
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/testdata/OverridesGuiceInjectableMethodNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice.testdata; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class OverridesGuiceInjectableMethodNegativeCases { /** Class with a method foo() annotated with @com.google.inject.Inject. */ public class TestClass1 { @com.google.inject.Inject public void foo() {} } /** Class with a method foo() annotated with @javax.inject.Inject. */ public class TestClass2 { @javax.inject.Inject public void foo() {} } /** * Class with a method foo() annotated with @javax.inject.Inject that overrides a method annotated * with @com.google.inject.Inject. */ public class TestClass3 extends TestClass1 { @javax.inject.Inject public void foo() {} } /** * Class with a method foo() annotated with @com.google.inject.Inject that overrides a method * annoted with @javax.inject.Inject. */ public class TestClass4 extends TestClass2 { @com.google.inject.Inject public void foo() {} } /** * Class with a method foo() annotated with @javax.inject.Inject that overrides a method annotated * with @com.google.inject.Inject */ public class TestClass5 extends TestClass1 { @javax.inject.Inject public void foo() {} } /** * Class with a method foo() that is not annotated with @Inject, but overrides a method that is * annotated with @com.google.inject.Inject. Warning is suppressed. */ public class TestClass6 extends TestClass1 { @SuppressWarnings("OverridesGuiceInjectableMethod") @Override public void foo() {} } /** Class that extends a class with an injected method, but doesn't override it. */ public class TestClass7 extends TestClass1 {} }
2,336
29.75
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/testdata/ProvidesMethodOutsideOfModuleNegativeCases.java
/* * Copyright 2016 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice.testdata; import com.google.gwt.inject.client.AbstractGinModule; import com.google.gwt.inject.client.GinModule; import com.google.gwt.inject.client.binder.GinBinder; import com.google.inject.AbstractModule; import com.google.inject.Binder; import com.google.inject.Module; import com.google.inject.Provides; /** Tests for {@code ProvidesMethodOutsideOfModule} */ public class ProvidesMethodOutsideOfModuleNegativeCases { /** Regular module */ class Module1 extends AbstractModule { @Override protected void configure() {} @Provides int providesFoo() { return 42; } } /** implements the Module interface directly */ class Module2 implements Module { @Override public void configure(Binder binder) {} @Provides int providesFoo() { return 42; } } /** Regular GinModule */ class GinModule1 extends AbstractGinModule { @Override protected void configure() {} @Provides int providesFoo() { return 42; } } /** Implements the GinModule interface directly */ class GinModule2 implements GinModule { @Override public void configure(GinBinder binder) {} @Provides int providesFoo() { return 42; } } }
1,893
24.253333
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/testdata/InjectOnFinalFieldPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice.testdata; import com.google.inject.Inject; import javax.annotation.Nullable; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class InjectOnFinalFieldPositiveCases { /** Class has a final injectable(com.google.inject.Inject) field. */ public class TestClass1 { // BUG: Diagnostic contains: @Inject int a @Inject final int a = 0; @Inject // BUG: Diagnostic contains: public int b public final int b = 0; @Inject @Nullable // BUG: Diagnostic contains: Object c final Object c = null; } }
1,210
29.275
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/testdata/BindingToUnqualifiedCommonTypeNegativeCases.java
/* * Copyright 2016 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice.testdata; import com.google.common.collect.ImmutableList; import com.google.inject.AbstractModule; import com.google.inject.Binder; import com.google.inject.BindingAnnotation; import com.google.inject.Module; import com.google.inject.Provides; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.List; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** Tests for {@code BindingToUnqualifiedCommonType} */ public class BindingToUnqualifiedCommonTypeNegativeCases { // All of the tagged instances would normally be flagged, but aren't because it's in a JUnit4 // class @RunWith(JUnit4.class) static class MyTestClass { /** Regular module */ class Module1 extends AbstractModule { @Override protected void configure() { bind(Integer.class).toInstance(2); bind(String.class).toInstance("Hello"); bind(Double.class).toProvider(() -> 42.0); binder().bind(Long.class).toInstance(42L); } @Provides int providesFoo() { return 42; } @Provides Integer provideBoxedFoo() { return 42; } @Provides String providesGreeting() { return "hi"; } } } /** Regular module */ class Module1 extends AbstractModule { @Override protected void configure() { // Bindings to unannotated complex instances bind(A.class).toInstance(new A()); // Binding to literals, but with a binding annotation bind(Integer.class).annotatedWith(MyBindingAnnotation.class).toInstance(42); } @Provides List<Integer> providesFoo() { return ImmutableList.of(42); } } /** implements the Module interface directly */ class Module2 implements Module { @Override public void configure(Binder binder) {} @Provides @MyBindingAnnotation int providesFoo() { return 42; } } class A {} @BindingAnnotation @Retention(RetentionPolicy.RUNTIME) @interface MyBindingAnnotation {} }
2,716
26.17
95
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/testdata/OverridesGuiceInjectableMethodPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice.testdata; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class OverridesGuiceInjectableMethodPositiveCases { /** Class with a method foo() annotated with @com.google.inject.Inject. */ public class TestClass1 { @com.google.inject.Inject public void foo() {} } /** * Class with a method foo() that is not annotated with @Inject, but overrides a method that is * annotated with @com.google.inject.Inject */ public class TestClass2 extends TestClass1 { // BUG: Diagnostic contains: @Inject public void foo() {} } /** * Class with a method foo() that is not annotated with @Inject, but overrides a method that in * turn is overrides a method that is annotated with @com.google.inject.Inject */ public class TestClass3 extends TestClass2 { // BUG: Diagnostic contains: @Inject public void foo() {} } /** * Class with a method foo() that is not annotated with @javax.inject.Inject and overrides a * method that is annotated with @com.google.inject.Inject. This class does not contain an error, * but it is extended in the next test class. */ public class TestClass4 extends TestClass1 { @javax.inject.Inject public void foo() {} } /** * Class with a method foo() that is not annotated with @Inject and overrides a method that is is * annotated with @javax.inject.Inject. This super method in turn overrides a method that is * annoatated with @com.google.inject.Inject. */ public class TestClass5 extends TestClass4 { // BUG: Diagnostic contains: @Inject public void foo() {} } /** Class that extends a class with an injected method, but doesn't override it. */ public class TestClass6 extends TestClass1 {} /** * Class that extends a class with an injected method, but it was declared in a supertype that * isn't a direct supertype. */ public class TestClass7 extends TestClass1 { // BUG: Diagnostic contains: @Inject public void foo() {} } }
2,667
32.35
99
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/testdata/ProvidesMethodOutsideOfModulePositiveCases.java
/* * Copyright 2016 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice.testdata; import com.google.inject.AbstractModule; import com.google.inject.Provides; /** Tests for {@code ProvidesMethodOutsideOfModule} */ public class ProvidesMethodOutsideOfModulePositiveCases { /** Random class contains a provides method. */ public class TestClass1 { // BUG: Diagnostic contains: remove @Provides void providesBlah() {} } /** Module contains an anonymous inner with a Provides method. */ public class TestModule extends AbstractModule { @Override protected void configure() { Object x = new Object() { // BUG: Diagnostic contains: remove @Provides void providesBlah() {} }; } } /** Class has inner module class */ public class TestClass2 { class NestedModule extends AbstractModule { @Override protected void configure() {} @Provides int thisIsOk() { return 42; } } // BUG: Diagnostic contains: remove @Provides int thisIsNotOk() { return 42; } } }
1,714
25.796875
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/testdata/AssistedInjectScopingPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice.testdata; import com.google.inject.Inject; import com.google.inject.Singleton; import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.AssistedInject; import com.google.inject.servlet.RequestScoped; /** * @author eaftan@google.com (Eddie Aftandilian) */ public class AssistedInjectScopingPositiveCases { // BUG: Diagnostic contains: remove this line @Singleton public class TestClass { @Inject public TestClass(String unassisted, @Assisted String assisted) {} } // BUG: Diagnostic contains: remove this line @RequestScoped public class TestClass2 { @Inject public TestClass2(String unassisted, @Assisted String assisted) {} } // BUG: Diagnostic contains: remove this line @Singleton public class TestClass3 { @AssistedInject public TestClass3(String param) {} } /** Multiple constructors, but only one with @Inject, and that one matches. */ // BUG: Diagnostic contains: remove this line @Singleton public class TestClass4 { @Inject public TestClass4(String unassisted, @Assisted String assisted) {} public TestClass4(String unassisted, int i) {} public TestClass4(int i, String unassisted) {} } /** Multiple constructors, none with @Inject, one matches. */ // BUG: Diagnostic contains: remove this line @Singleton public class TestClass5 { public TestClass5(String unassisted1, String unassisted2) {} public TestClass5(String unassisted, int i) {} @AssistedInject public TestClass5(int i, String unassisted) {} } /** JSR330 annotations. */ // BUG: Diagnostic contains: remove this line @javax.inject.Singleton public class TestClass6 { @javax.inject.Inject public TestClass6(String unassisted, @Assisted String assisted) {} } }
2,457
28.97561
80
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/testdata/BindingToUnqualifiedCommonTypePositiveCases.java
/* * Copyright 2016 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice.testdata; import com.google.inject.AbstractModule; import com.google.inject.Provides; /** Tests for {@code BindingToUnqualifiedCommonType} */ public class BindingToUnqualifiedCommonTypePositiveCases { /** Regular module */ class Module1 extends AbstractModule { @Override protected void configure() { // BUG: Diagnostic contains: BindingToUnqualifiedCommonType bind(Integer.class).toInstance(2); // BUG: Diagnostic contains: BindingToUnqualifiedCommonType bind(String.class).toInstance("Hello"); // BUG: Diagnostic contains: BindingToUnqualifiedCommonType bind(Double.class).toProvider(() -> 42.0); // BUG: Diagnostic contains: BindingToUnqualifiedCommonType binder().bind(Long.class).toInstance(42L); } @Provides // BUG: Diagnostic contains: BindingToUnqualifiedCommonType int providesFoo() { return 42; } @Provides // BUG: Diagnostic contains: BindingToUnqualifiedCommonType Integer provideBoxedFoo() { return 42; } @Provides // BUG: Diagnostic contains: BindingToUnqualifiedCommonType String providesGreeting() { return "hi"; } } }
1,840
29.180328
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/testdata/OverridesJavaxInjectableMethodNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice.testdata; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class OverridesJavaxInjectableMethodNegativeCases { /** Class with a method foo() with no annotations. */ public class TestClass1 { public void foo() {} } /** Class with a method foo() annotated with @com.google.inject.Inject. */ public class TestClass2 { @com.google.inject.Inject public void foo() {} } /** Class with a method foo() annotated with @javax.inject.Inject. */ public class TestClass3 { @javax.inject.Inject public void foo() {} } /** OK, as it overrides a Guice-Inject method */ public class TestClass4 extends TestClass2 { @Override public void foo() {} } /** gInject <- jInject */ public class TestClass5 extends TestClass3 { @com.google.inject.Inject public void foo() {} } /** jInject <- gInject */ public class TestClass6 extends TestClass2 { @javax.inject.Inject public void foo() {} } /** OK, as 7 <- jInject <- gInject */ public class TestClass7 extends TestClass6 { public void foo() {} } /** OK, as 8 <- gInject */ public class TestClass8 extends TestClass5 { public void foo() {} } /** Explicitly suppressed warning */ public class TestClass9 extends TestClass3 { @Override @SuppressWarnings("OverridesJavaxInjectableMethod") public void foo() {} } }
2,045
26.28
76
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/testdata/InjectOnFinalFieldNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.guice.testdata; import com.google.inject.Inject; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class InjectOnFinalFieldNegativeCases { /** Class has no final fields or @Inject annotations. */ public class TestClass1 {} /** Class has a final field that is not injectable. */ public class TestClass2 { public final int n = 0; } /** Class has an injectable(com.google.inject.Inject) field that is not final. */ public class TestClass3 { @Inject public int n; } /** Class has an injectable(com.google.inject.Inject), final method. */ public class TestClass4 { @Inject final void method() {} } }
1,314
28.222222
83
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/testdata/AssistedParametersNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package com.google.errorprone.bugpatterns.inject.guice.testdata; import com.google.inject.assistedinject.Assisted; import java.util.List; import javax.inject.Inject; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class AssistedParametersNegativeCases { /** Class has constructor with two @Assisted parameters of different types. */ public class TestClass1 { @Inject public TestClass1(@Assisted int x, @Assisted String y, long z) {} } /** * Class has constructor with two @Assisted parameters, but the @Assisted annotations have * different values. */ public class TestClass2 { @Inject public TestClass2(@Assisted("foo") int x, @Assisted("bar") int y, String z) {} } /** * Class has constructor with one @Assisted parameter with no value specified and another * parameter of the same type. */ public class TestClass3 { @Inject public TestClass3(@Assisted int x, int y, String z) {} } /** * Class has constructor with one @Assisted parameters with a value specified and another * parameter of the same type. */ public class TestClass4 { @Inject public TestClass4(@Assisted("foo") int x, int y, String z) {} } /** * Class has constructor with two @Assisted parameters with the same value and generic type and * different type parameters. */ public class TestClass5 { @Inject public TestClass5( @Assisted("foo") List<String> x, @Assisted("foo") List<Integer> y, String z) {} } }
2,115
29.666667
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/AutoFactoryAtInjectNegativeCases.java
/* * Copyright 2016 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.auto.factory.AutoFactory; import javax.inject.Inject; class AutoFactoryAtInjectNegativeCases { @AutoFactory static class AtInjectOnInnerType { static class InnerType { @Inject InnerType() {} } } static class AutoFactoryOnInnerType { @Inject AutoFactoryOnInnerType() {} @AutoFactory static class InnerType {} } static class OnDifferentConstructors { @Inject OnDifferentConstructors(String string) {} @AutoFactory OnDifferentConstructors(Object object) {} } }
1,217
24.375
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/QualifierWithTypeUseNegativeCases.java
/* * Copyright 2016 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import java.lang.annotation.ElementType; import java.lang.annotation.Target; import javax.inject.Qualifier; /** Tests for {@code QualifierWithTypeUse} */ public class QualifierWithTypeUseNegativeCases { @Qualifier @Target({ElementType.CONSTRUCTOR}) @interface Qualifier1 {} @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface NotAQualifier {} }
1,046
30.727273
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/CloseableProvidesNegativeCases.java
/* * Copyright 2018 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.inject.Provides; import javax.inject.Singleton; /** * @author bhagwani@google.com (Sumit Bhagwani) */ public class CloseableProvidesNegativeCases { static class DoesNotImplementsClosable { public void close() { // no op } } @Provides DoesNotImplementsClosable providesDoesNotImplementsClosable() { return new DoesNotImplementsClosable(); } @Provides @Singleton Object providesObject() { return new Object(); } }
1,145
25.045455
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/OverlappingQualifierAndScopeAnnotationNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class OverlappingQualifierAndScopeAnnotationNegativeCases { @javax.inject.Scope @interface MyJavaxScope {} @com.google.inject.ScopeAnnotation @interface MyGuiceScope {} @javax.inject.Qualifier @interface MyJavaxQualifier {} @com.google.inject.BindingAnnotation @interface MyGuiceBindingAnnotation {} // suppression tests @SuppressWarnings("OverlappingQualifierAndScopeAnnotation") @javax.inject.Scope @javax.inject.Qualifier @interface JavaxScopeAndJavaxQualifier {} @SuppressWarnings("OverlappingQualifierAndScopeAnnotation") @com.google.inject.ScopeAnnotation @javax.inject.Qualifier @interface GuiceScopeAndJavaxQualifier {} @SuppressWarnings("OverlappingQualifierAndScopeAnnotation") @com.google.inject.ScopeAnnotation @com.google.inject.BindingAnnotation @interface GuiceScopeAndGuiceBindingAnnotation {} @SuppressWarnings("OverlappingQualifierAndScopeAnnotation") @javax.inject.Scope @com.google.inject.BindingAnnotation @interface JavaxScopeAndGuiceBindingAnnotation {} }
1,773
30.122807
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/ScopeAnnotationOnInterfaceOrAbstractClassNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.inject.Singleton; import dagger.Component; import dagger.Subcomponent; import javax.inject.Scope; /** * Negative test cases in which scoping annotations are used correctly. * * @author sgoldfeder@google.com (Steven Goldfeder) */ public class ScopeAnnotationOnInterfaceOrAbstractClassNegativeCases { /** A concrete class that has no scoping annotation. */ public class TestClass1 {} /** An abstract class that has no scoping annotation. */ public abstract class TestClass2 {} /** An interface that has no scoping annotation. */ public interface TestClass3 {} /** A concrete class that has scoping annotation. */ @Singleton public class TestClass4 {} @Scope @interface CustomScope {} /** A concrete class that has a custom annotation. */ @CustomScope public class ClassWithCustomScope {} @Component @Singleton interface DaggerInterfaceComponent { @Subcomponent @CustomScope abstract class DaggerAbstractClassSubcomponent {} } }
1,673
27.372881
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/CloseableProvidesPositiveCases.java
/* * Copyright 2018 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.inject.Provides; import java.io.Closeable; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; import javax.inject.Singleton; /** * @author bhagwani@google.com (Sumit Bhagwani) */ public class CloseableProvidesPositiveCases { static class ImplementsClosable implements Closeable { public void close() { // no op } } @Provides // BUG: Diagnostic contains: CloseableProvides ImplementsClosable providesImplementsClosable() { return new ImplementsClosable(); } @Provides @Singleton // BUG: Diagnostic contains: CloseableProvides PrintWriter providesPrintWriter() throws Exception { return new PrintWriter("some_file_path", StandardCharsets.UTF_8.name()); } }
1,411
27.816327
76
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/JavaxInjectOnAbstractMethodPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class JavaxInjectOnAbstractMethodPositiveCases { /** Abstract class has an injectable(javax.inject.Inject) abstract method. */ public abstract class TestClass1 { // BUG: Diagnostic contains: remove @javax.inject.Inject abstract void abstractMethod(); } /** * Abstract class has an injectable(javax.inject.Inject) abstract method and an unrelated concrete * method. */ public abstract class TestClass2 { // BUG: Diagnostic contains: remove @javax.inject.Inject abstract void abstractMethod(); public void foo() {} } /** * Abstract class has an injectable(javax.inject.Inject) abstract method and an unrelated abstract * method. */ public abstract class TestClass3 { // BUG: Diagnostic contains: remove @javax.inject.Inject abstract void abstractMethod1(); abstract void abstractMethod2(); } /** Interface with Inject method, should also fail. */ public interface TestInterface { // BUG: Diagnostic contains: remove @javax.inject.Inject void abstractMethod(); } /** Concrete Implementer of interface. */ public class Implementing implements TestInterface { // No error here public void abstractMethod() {} } /** Abstract implementer of interface. */ public abstract class AbstractImplementing implements TestInterface { // BUG: Diagnostic contains: remove @javax.inject.Inject public abstract void abstractMethod(); } interface HasDefault { // BUG: Diagnostic contains: remove @javax.inject.Inject default void foo() {} } }
2,313
27.567901
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/JavaxInjectOnFinalFieldNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import javax.inject.Inject; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class JavaxInjectOnFinalFieldNegativeCases { /** Class has no final fields or @Inject annotations. */ public class TestClass1 {} /** Class has a final field that is not injectable. */ public class TestClass2 { public final int n = 0; } /** Class has an injectable(javax.inject.Inject) field that is not final. */ public class TestClass3 { @Inject public int n; } /** Class has an injectable(javax.inject.Inject), final method. */ public class TestClass4 { @Inject final void method() {} } }
1,298
27.866667
78
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/MoreThanOneQualifierNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import static java.lang.annotation.RetentionPolicy.RUNTIME; import com.google.inject.BindingAnnotation; import java.lang.annotation.Retention; import javax.inject.Qualifier; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class MoreThanOneQualifierNegativeCases { /** A class in with no annotations on any of its members. */ public class TestClass1 { private int n; public TestClass1() {} 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 public class TestClass2 { @Foo private int n; @Foo public TestClass2() {} @Foo public void setN(@Foo 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 public class TestClass3 { @Bar private int n; @Bar public TestClass3() {} @Bar public void setN(@Bar int n) {} } @Qualifier @Retention(RUNTIME) public @interface Foo {} @BindingAnnotation @Retention(RUNTIME) public @interface Bar {} }
1,909
24.131579
99
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/ScopeOrQualifierAnnotationRetentionPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.SOURCE; import com.google.inject.BindingAnnotation; import com.google.inject.ScopeAnnotation; import java.lang.annotation.Retention; import java.lang.annotation.Target; import javax.inject.Qualifier; import javax.inject.Scope; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class ScopeOrQualifierAnnotationRetentionPositiveCases { /** A scoping (@Scope) annotation with SOURCE retention */ @Scope @Target({TYPE, METHOD}) // BUG: Diagnostic contains: @Retention(RUNTIME) @Retention(SOURCE) public @interface TestAnnotation1 {} /** A scoping (@ScopingAnnotation) annotation with SOURCE retention. */ @ScopeAnnotation @Target({TYPE, METHOD}) // BUG: Diagnostic contains: @Retention(RUNTIME) @Retention(SOURCE) public @interface TestAnnotation2 {} /** A qualifer(@Qualifier) annotation with SOURCE retention. */ @Qualifier @Target({TYPE, METHOD}) // BUG: Diagnostic contains: @Retention(RUNTIME) @Retention(SOURCE) public @interface TestAnnotation3 {} /** A qualifer(@BindingAnnotation) annotation with SOURCE retention. */ @BindingAnnotation @Target({TYPE, METHOD}) // BUG: Diagnostic contains: @Retention(RUNTIME) @Retention(SOURCE) public @interface TestAnnotation4 {} /** A qualifer annotation with default retention. */ @BindingAnnotation @Target({TYPE, METHOD}) // BUG: Diagnostic contains: @Retention(RUNTIME) public @interface TestAnnotation5 {} /** A dagger map key annotation with default retention. */ @dagger.MapKey @Target({TYPE, METHOD}) // BUG: Diagnostic contains: @Retention(RUNTIME) public @interface TestAnnotation6 {} /** A Guice map key annotation with default retention. */ @com.google.inject.multibindings.MapKey @Target({TYPE, METHOD}) // BUG: Diagnostic contains: @Retention(RUNTIME) public @interface TestAnnotation7 {} }
2,678
32.4875
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/MoreThanOneScopeAnnotationOnClassNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.inject.Provides; import com.google.inject.Singleton; import com.google.inject.servlet.SessionScoped; import dagger.Component; import dagger.Subcomponent; import dagger.producers.ProductionComponent; import dagger.producers.ProductionSubcomponent; /** * @author sgoldfeder@google.com(Steven Goldfeder) */ public class MoreThanOneScopeAnnotationOnClassNegativeCases { /** Class has no annotation. */ public class TestClass1 {} /** Class has a single non scoping annotation. */ @SuppressWarnings("foo") public class TestClass2 {} /** Class hasa single scoping annotation. */ @Singleton public class TestClass3 {} /** Class has two annotations, one of which is a scoping annotation. */ @Singleton @SuppressWarnings("foo") public class TestClass4 {} /** * Class has two annotations, one of which is a scoping annotation. Class also has a method with a * scoping annotation. */ @SuppressWarnings("foo") public class TestClass5 { @Singleton @Provides public void foo() {} } /** Class has two scoped annotations, but is a Dagger component */ @Singleton @SessionScoped @Component public class DaggerComponent {} /** Class has two scoped annotations, but is a Dagger subcomponent */ @Singleton @SessionScoped @Subcomponent public class DaggerSubcomponent {} /** Class has two scoped annotations, but is a Dagger component */ @Singleton @SessionScoped @ProductionComponent public class DaggerProductionComponent {} /** Class has two scoped annotations, but is a Dagger subcomponent */ @Singleton @SessionScoped @ProductionSubcomponent public class DaggerProductionSubcomponent {} /** Suppression through secondary name */ @SuppressWarnings("MoreThanOneScopeAnnotationOnClass") public class TestClass6 {} }
2,493
28
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/QualifierWithTypeUsePositiveCases.java
/* * Copyright 2016 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.inject.BindingAnnotation; import java.lang.annotation.ElementType; import java.lang.annotation.Target; import javax.inject.Qualifier; /** Tests for {@code QualifierWithTypeUse} */ public class QualifierWithTypeUsePositiveCases { @Qualifier // BUG: Diagnostic contains: @Target({CONSTRUCTOR}) @Target({ElementType.TYPE_USE, ElementType.CONSTRUCTOR}) @interface Qualifier1 {} @Qualifier // BUG: Diagnostic contains: remove @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface Qualifier2 {} @BindingAnnotation // BUG: Diagnostic contains: @Target({FIELD}) @Target({ElementType.FIELD, ElementType.TYPE_USE}) @interface BindingAnnotation1 {} @BindingAnnotation // BUG: Diagnostic contains: remove @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface BindingAnnotation2 {} @BindingAnnotation // BUG: Diagnostic contains: remove @Target(ElementType.TYPE_USE) @interface BindingAnnotation3 {} }
1,656
30.865385
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/InjectedConstructorAnnotationsPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.inject.BindingAnnotation; import com.google.inject.Inject; /** A positive test case for InjectedConstructorAnnotation. */ public class InjectedConstructorAnnotationsPositiveCases { /** A binding annotation. */ @BindingAnnotation public @interface TestBindingAnnotation { } /** A class with an optionally injected constructor. */ public class TestClass1 { // BUG: Diagnostic contains: @Inject public TestClass1 @Inject(optional = true) public TestClass1() {} } /** A class with an injected constructor that has a binding annotation. */ public class TestClass2 { // BUG: Diagnostic contains: @Inject public TestClass2 @TestBindingAnnotation @Inject public TestClass2() {} } /** A class whose constructor is optionally injected and has a binding annotation. */ public class TestClass3 { // BUG: Diagnostic contains: @Inject public TestClass3 @TestBindingAnnotation @Inject(optional = true) public TestClass3() {} } }
1,657
32.836735
87
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/InvalidTargetingOnScopingAnnotationPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import static java.lang.annotation.ElementType.CONSTRUCTOR; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.PARAMETER; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import com.google.inject.ScopeAnnotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.Target; import javax.inject.Scope; /** * @author sgoldfeder@google.com(Steven Goldfeder) */ public class InvalidTargetingOnScopingAnnotationPositiveCases { /** Scoping excludes METHOD */ // BUG: Diagnostic contains: @Target({TYPE, METHOD}) @Target(TYPE) @Scope @Retention(RUNTIME) public @interface TestAnnotation1 {} /** Scoping excludes TYPE */ // BUG: Diagnostic contains: @Target({TYPE, METHOD}) @Target(METHOD) @Scope @Retention(RUNTIME) public @interface TestAnnotation2 {} /** Scoping excludes both, but has other elements to preserve */ // BUG: Diagnostic contains: @Target({TYPE, METHOD, PARAMETER}) @Target(PARAMETER) @Scope @Retention(RUNTIME) public @interface TestAnnotation4 {} /** Scoping includes one of the required ones. */ // BUG: Diagnostic contains: @Target({TYPE, METHOD, PARAMETER, CONSTRUCTOR}) @Target({PARAMETER, METHOD, CONSTRUCTOR}) @Scope @Retention(RUNTIME) public @interface TestAnnotation5 {} /** Same as above, but with a different physical manifestation */ // BUG: Diagnostic contains: @Target({TYPE, METHOD, PARAMETER, CONSTRUCTOR}) @Target(value = {ElementType.PARAMETER, METHOD, CONSTRUCTOR}) @Scope @Retention(RUNTIME) public @interface TestAnnotation6 {} /** Target annotation is empty, nonsensical since it can't be applied to anything */ // BUG: Diagnostic contains: @Target({TYPE, METHOD}) @Target({}) @ScopeAnnotation @Retention(RUNTIME) public @interface TestAnnotation7 {} }
2,607
32.435897
86
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/JavaxInjectOnFinalFieldPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import javax.inject.Inject; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class JavaxInjectOnFinalFieldPositiveCases { /** * Class has a final injectable(javax.inject.Inject) field. */ public class TestClass1 { // BUG: Diagnostic contains: remove @Inject public final int n = 0; } }
1,002
27.657143
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/InvalidTargetingOnScopingAnnotationNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.PARAMETER; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import javax.inject.Scope; /** * @author sgoldfeder@google.com(Steven Goldfeder) */ public class InvalidTargetingOnScopingAnnotationNegativeCases { /** A scoping annotation with no specified target. */ @Scope @Retention(RUNTIME) public @interface TestAnnotation1 {} /** A scoping annotation that contains more than the required */ @Target({TYPE, METHOD, PARAMETER}) @Scope @Retention(RUNTIME) public @interface TestAnnotation2 {} /** A scoping annotation with legal targeting. */ @Target({TYPE, METHOD}) @Scope @Retention(RUNTIME) public @interface TestAnnotation3 {} /** * A non-scoping annotation with targeting that would be illegal if it were a scoping annotation. */ @Target(PARAMETER) @Retention(RUNTIME) public @interface TestAnnotation4 {} }
1,770
30.070175
99
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/AssistedInjectAndInjectOnConstructorsPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.inject.assistedinject.AssistedInject; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class AssistedInjectAndInjectOnConstructorsPositiveCases { /** * Class has a constructor annotated with @javax.inject.Inject and another constructor annotated * with @AssistedInject. */ // BUG: Diagnostic contains: AssistedInjectAndInjectOnConstructors public class TestClass1 { @javax.inject.Inject public TestClass1() {} @AssistedInject public TestClass1(int n) {} } /** * Class has a constructor annotated with @com.google.inject.Inject and another constructor * annotated with @AssistedInject. */ // BUG: Diagnostic contains: AssistedInjectAndInjectOnConstructors public class TestClass2 { @com.google.inject.Inject public TestClass2() {} @AssistedInject public TestClass2(int n) {} } /** * Class has a constructor annotated with @com.google.inject.Inject, another constructor annotated * with @AssistedInject, and a third constructor with no annotation. */ // BUG: Diagnostic contains: AssistedInjectAndInjectOnConstructors public class TestClass3 { @com.google.inject.Inject public TestClass3() {} @AssistedInject public TestClass3(int n) {} public TestClass3(String s) {} } }
1,985
29.090909
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/AutoFactoryAtInjectPositiveCases.java
/* * Copyright 2016 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.auto.factory.AutoFactory; import javax.inject.Inject; class AssistedInjectAndInjectOnSameConstructorPositiveCases { @AutoFactory static class HasAutoFactoryOnClass { // BUG: Diagnostic contains: remove @Inject HasAutoFactoryOnClass() {} } @AutoFactory static class UsesGuiceInject { // BUG: Diagnostic contains: remove @com.google.inject.Inject UsesGuiceInject() {} } static class HasAutoFactoryOnConstructor { // BUG: Diagnostic contains: remove @Inject @AutoFactory HasAutoFactoryOnConstructor() {} } }
1,252
26.844444
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/OverlappingQualifierAndScopeAnnotationPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class OverlappingQualifierAndScopeAnnotationPositiveCases { @javax.inject.Scope @javax.inject.Qualifier // BUG: Diagnostic contains: OverlappingQualifierAndScopeAnnotation @interface JavaxScopeAndJavaxQualifier {} @com.google.inject.ScopeAnnotation @javax.inject.Qualifier // BUG: Diagnostic contains: OverlappingQualifierAndScopeAnnotation @interface GuiceScopeAndJavaxQualifier {} @com.google.inject.ScopeAnnotation @com.google.inject.BindingAnnotation // BUG: Diagnostic contains: OverlappingQualifierAndScopeAnnotation @interface GuiceScopeAndGuiceBindingAnnotation {} @javax.inject.Scope @com.google.inject.BindingAnnotation // BUG: Diagnostic contains: OverlappingQualifierAndScopeAnnotation @interface JavaxScopeAndGuiceBindingAnnotation {} }
1,522
33.613636
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/ScopeOrQualifierAnnotationRetentionNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import static java.lang.annotation.RetentionPolicy.SOURCE; import com.google.inject.BindingAnnotation; import com.google.inject.ScopeAnnotation; import java.lang.annotation.Retention; import java.lang.annotation.Target; import javax.inject.Qualifier; import javax.inject.Scope; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class ScopeOrQualifierAnnotationRetentionNegativeCases { /** A scoping (@Scope) annotation with runtime retention */ @Scope @Target({TYPE, METHOD}) @Retention(RUNTIME) public @interface TestAnnotation1 {} /** A scoping (@ScopingAnnotation) annotation with runtime retention. */ @ScopeAnnotation @Target({TYPE, METHOD}) @Retention(RUNTIME) public @interface TestAnnotation2 {} /** A qualifer(@Qualifier) annotation with runtime retention. */ @Qualifier @Target({TYPE, METHOD}) @Retention(RUNTIME) public @interface TestAnnotation3 {} /** A qualifer(@BindingAnnotation) annotation with runtime retention. */ @BindingAnnotation @Target({TYPE, METHOD}) @Retention(RUNTIME) public @interface TestAnnotation4 {} /** A non-qualifer, non-scoping annotation without runtime retention. */ @Retention(SOURCE) public @interface TestAnnotation5 {} /** A dagger map key annotation. */ @dagger.MapKey @Retention(RUNTIME) public @interface TestAnnotation6 {} /** A Guice map key annotation. */ @com.google.inject.multibindings.MapKey @Retention(RUNTIME) public @interface TestAnnotation7 {} }
2,329
30.917808
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/ScopeAnnotationOnInterfaceOrAbstractClassPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.inject.Singleton; /** * Positive test cases in which a scoping annotation is put on an interface or anabstract class. The * suggested fix is to remove the scoping annotation. * * @author sgoldfeder@google.com (Steven Goldfeder) */ public class ScopeAnnotationOnInterfaceOrAbstractClassPositiveCases { /** An abstract class that has scoping annotation. */ // BUG: Diagnostic contains: remove @Singleton public abstract class TestClass1 {} /** An interface interface has scoping annotation. */ // BUG: Diagnostic contains: remove @Singleton public interface TestClass2 {} }
1,283
31.923077
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/InjectOnMemberAndConstructorNegativeCases.java
/* * Copyright 2018 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import javax.inject.Inject; /** * Negative test cases for {@link InjectOnMemberAndConstructor} check. * * @author bhagwani@google.com (Sumit Bhagwani) */ public class InjectOnMemberAndConstructorNegativeCases { public class InjectOnConstructorOnly { private final String stringFieldWithoutInject; @Inject public InjectOnConstructorOnly(String stringFieldWithoutInject) { this.stringFieldWithoutInject = stringFieldWithoutInject; } } public class InjectOnFieldOnly { @Inject private String stringFieldWithInject; } public class MixedInject { @Inject private String stringFieldWithInject; @Inject public MixedInject() {} } }
1,352
27.1875
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/MoreThanOneQualifierPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import static java.lang.annotation.RetentionPolicy.RUNTIME; import com.google.inject.BindingAnnotation; import java.lang.annotation.Retention; import javax.inject.Qualifier; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class MoreThanOneQualifierPositiveCases { /** * A class in which the class, a constructor, a field, a method, and a method parameter each have * two com.google.inject.BindingAnnotation annotations. */ // BUG: Diagnostic contains: remove @Foo1 // BUG: Diagnostic contains: remove @Foo2 public class TestClass1 { // BUG: Diagnostic contains: remove @Foo1 // BUG: Diagnostic contains: remove @Foo2 private int n; // BUG: Diagnostic contains: remove @Foo1 // BUG: Diagnostic contains: remove @Foo2 public TestClass1() {} // BUG: Diagnostic contains: remove @Foo1 // BUG: Diagnostic contains: remove @Foo2 public void setN( // BUG: Diagnostic contains: remove @Foo1 // BUG: Diagnostic contains: remove @Foo2 int n) {} } /** * A class in which the class, a constructor, a field, a method, and a method parameter each have * two javax.inject.Qualifier annotations. */ // BUG: Diagnostic contains: remove @Bar1 // BUG: Diagnostic contains: remove @Bar2 public class TestClass2 { // BUG: Diagnostic contains: remove @Bar1 // BUG: Diagnostic contains: remove @Bar2 private int n; // BUG: Diagnostic contains: remove @Bar1 // BUG: Diagnostic contains: remove @Bar2 public TestClass2() {} // BUG: Diagnostic contains: remove @Bar1 // BUG: Diagnostic contains: remove @Bar2 public void setN( // BUG: Diagnostic contains: remove @Bar1 // BUG: Diagnostic contains: remove @Bar2 int n) {} } /** * A class in which the class, a constructor, a field, a method, and a method parameter each have * one javax.inject.Qualifier annotation and one com.google.inject.BindingAnnotation annotation. */ // BUG: Diagnostic contains: remove @Foo1 // BUG: Diagnostic contains: remove @Bar1 public class TestClass3 { // BUG: Diagnostic contains: remove @Foo1 // BUG: Diagnostic contains: remove @Bar1 private int n; // BUG: Diagnostic contains: remove @Foo1 // BUG: Diagnostic contains: remove @Bar1 public TestClass3() {} // BUG: Diagnostic contains: remove @Foo1 // BUG: Diagnostic contains: remove @Bar1 public void setN( // BUG: Diagnostic contains: remove @Foo1 // BUG: Diagnostic contains: remove @Bar1 int n) {} } @Qualifier @Retention(RUNTIME) public @interface Foo1 {} @Qualifier @Retention(RUNTIME) public @interface Foo2 {} @BindingAnnotation @Retention(RUNTIME) public @interface Bar1 {} @BindingAnnotation @Retention(RUNTIME) public @interface Bar2 {} }
3,691
24.115646
99
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/JavaxInjectOnAbstractMethodNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import javax.inject.Inject; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class JavaxInjectOnAbstractMethodNegativeCases { /** Concrete class has no methods or annotations. */ public class TestClass1 {} /** Abstract class has a single abstract method with no annotation. */ public abstract class TestClass2 { abstract void abstractMethod(); } /** Concrete class has an injectable method. */ public class TestClass3 { @Inject public void foo() {} } /** Abstract class has an injectable concrete method. */ public abstract class TestClass4 { abstract void abstractMethod(); @Inject public void concreteMethod() {} } /** * Abstract class has an com.google.inject.Inject abstract method (This is allowed; Injecting * abstract methods is only forbidden with javax.inject.Inject). */ public abstract class TestClass5 { @com.google.inject.Inject abstract void abstractMethod(); } /** Abstract class has an injectable(javax.inject.Inject) abstract method. Error is suppressed. */ public abstract class TestClass6 { @SuppressWarnings("JavaxInjectOnAbstractMethod") @javax.inject.Inject abstract void abstractMethod(); } }
1,898
28.671875
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/MoreThanOneInjectableConstructorNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.inject.Inject; /** * @author sgoldfeder@google.com(Steven Goldfeder) */ public class MoreThanOneInjectableConstructorNegativeCases { /** Class has a single non-injectable constructor. */ public class TestClass1 { public TestClass1() {} } /** Class has a single injectable constructor. */ public class TestClass2 { @Inject public TestClass2() {} } /** Class has two constructors, one of which is injectable. */ public class TestClass3 { @Inject public TestClass3() {} public TestClass3(int n) {} } /** Class has two constructors, one of which is injectable. Class also has an injectable field. */ public class TestClass4 { @Inject String x; @Inject public TestClass4() {} public TestClass4(int n) {} } /** Class has 2 constructors, both are injectable. Error is suppressed. */ @SuppressWarnings("MoreThanOneInjectableConstructor") public class TestClass5 { @Inject public TestClass5() {} @Inject public TestClass5(int n) {} } /** Suppressed class */ @SuppressWarnings("inject-constructors") public class TestClass6 { @Inject public TestClass6() {} @Inject public TestClass6(int n) {} } /** Suppressed class */ @SuppressWarnings("InjectMultipleAtInjectConstructors") public class TestClass7 { @Inject public TestClass7() {} @Inject public TestClass7(int n) {} } }
2,102
23.453488
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/AssistedInjectAndInjectOnSameConstructorPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.inject.assistedinject.AssistedInject; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class AssistedInjectAndInjectOnSameConstructorPositiveCases { /** Class has a constructor annotated with @javax.inject.Inject and @AssistedInject. */ public class TestClass1 { // BUG: Diagnostic contains: remove @javax.inject.Inject // BUG: Diagnostic contains: remove @AssistedInject public TestClass1() {} } /** Class has a constructor annotated with @com.google.inject.Inject and @AssistedInject. */ public class TestClass2 { // BUG: Diagnostic contains: remove @com.google.inject.Inject // BUG: Diagnostic contains: remove @AssistedInject public TestClass2() {} } }
1,416
31.953488
94
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/MoreThanOneScopeAnnotationOnClassPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.inject.Singleton; import com.google.inject.servlet.SessionScoped; import javax.inject.Scope; /** * @author sgoldfeder@google.com(Steven Goldfeder) */ public class MoreThanOneScopeAnnotationOnClassPositiveCases { /** Class has two scope annotations */ @Singleton @SessionScoped // BUG: Diagnostic contains: class TestClass1 {} /** Class has three annotations, two of which are scope annotations. */ @Singleton @SuppressWarnings("foo") @SessionScoped // BUG: Diagnostic contains: class TestClass2 {} @Scope @interface CustomScope {} @Singleton @CustomScope @SessionScoped // BUG: Diagnostic contains: class TestClass3 {} }
1,351
26.04
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/InjectedConstructorAnnotationsNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.inject.BindingAnnotation; import com.google.inject.Inject; /** A negative test case for InjectedConstructorAnnotation. */ public class InjectedConstructorAnnotationsNegativeCases { private @interface TestAnnotation {} @BindingAnnotation private @interface TestBindingAnnotation {} /** A class with a constructor that has no annotations. */ public class TestClass1 { public TestClass1() {} } /** A class with a constructor that has a binding Annotation. */ public class TestClass2 { @TestBindingAnnotation public TestClass2() {} } /** A class with an injected constructor. */ public class TestClass3 { @Inject public TestClass3() {} } /** A class with an injected constructor that has a non-binding annotation. */ public class TestClass4 { @Inject @TestAnnotation public TestClass4() {} } }
1,546
27.648148
80
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/AssistedInjectAndInjectOnSameConstructorNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.inject.assistedinject.AssistedInject; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class AssistedInjectAndInjectOnSameConstructorNegativeCases { /** Class has a single constructor with no annotation. */ public class TestClass1 { TestClass1() {} } /** Class has a constructor with a @javax.inject.Inject annotation. */ public class TestClass2 { @javax.inject.Inject public TestClass2() {} } /** Class has a constructor with a @com.google.injectInject annotation. */ public class TestClass3 { @com.google.inject.Inject public TestClass3() {} } /** Class has a constructor annotated with @AssistedInject */ public class TestClass4 { @AssistedInject public TestClass4() {} } /** Class has one constructor with a @AssistedInject and one with @javax.inject.inject . */ public class TestClass5 { @javax.inject.Inject public TestClass5(int n) {} @AssistedInject public TestClass5() {} } /** Class has one constructor with a @AssistedInject and one with @javax.inject.inject . */ public class TestClass6 { @com.google.inject.Inject public TestClass6(int n) {} @AssistedInject public TestClass6() {} } /** * Class has a constructor annotated with @javax.inject.Inject and @AssistedInject. Error is * suppressed. */ @SuppressWarnings("AssistedInjectAndInjectOnSameConstructor") public class TestClass7 { @javax.inject.Inject @AssistedInject public TestClass7() {} } /** * Class has a constructor annotated with @com.google.inject.Inject and @AssistedInject. Error is * suppressed. */ @SuppressWarnings("AssistedInjectAndInjectOnSameConstructor") public class TestClass8 { @com.google.inject.Inject @AssistedInject public TestClass8() {} } }
2,503
27.454545
99
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/MoreThanOneInjectableConstructorPositiveCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.inject.Inject; import java.beans.ConstructorProperties; /** * @author sgoldfeder@google.com(Steven Goldfeder) */ public class MoreThanOneInjectableConstructorPositiveCases { /** Class has 2 constructors, both are injectable */ // BUG: Diagnostic contains: MoreThanOneInjectableConstructor public class TestClass1 { @Inject public TestClass1() {} @Inject public TestClass1(int n) {} } /** Class has 3 constructors, two of which are injectable. */ // BUG: Diagnostic contains: MoreThanOneInjectableConstructor public class TestClass2 { @Inject public TestClass2() {} public TestClass2(int n) {} @Inject public TestClass2(String s) {} } /** * testing that the error appears on the @Inject annotation even in the presence of other * annotations */ // BUG: Diagnostic contains: MoreThanOneInjectableConstructor public class TestClass3 { @Inject public TestClass3() {} @Inject @ConstructorProperties({"m", "n"}) public TestClass3(int m, int n) {} } /** Fails on 3 constructors w/ @Inject */ // BUG: Diagnostic contains: MoreThanOneInjectableConstructor public class TestClass4 { @Inject public TestClass4() {} @Inject public TestClass4(int m, int n) {} @Inject public TestClass4(int m, int n, boolean x) {} } }
2,026
25.671053
91
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/bugpatterns/inject/testdata/AssistedInjectAndInjectOnConstructorsNegativeCases.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.bugpatterns.inject.testdata; import com.google.inject.assistedinject.AssistedInject; /** * @author sgoldfeder@google.com (Steven Goldfeder) */ public class AssistedInjectAndInjectOnConstructorsNegativeCases { /** Class has a single constructor with no annotation. */ public class TestClass1 { TestClass1() {} } /** Class has a constructor with a @javax.inject.Inject annotation. */ public class TestClass2 { @javax.inject.Inject public TestClass2() {} } /** Class has a constructor with a @com.google.inject.Inject annotation. */ public class TestClass3 { @com.google.inject.Inject public TestClass3() {} } /** Class has a constructor annotated with @AssistedInject */ public class TestClass4 { @AssistedInject public TestClass4() {} } /** Class has a constructor with a @AssistedInject annotation as well as an injectable field */ public class TestClass5 { @javax.inject.Inject private int n; @AssistedInject public TestClass5() {} } /** * Class has a constructor annotated with @javax.inject.Inject and another constructor annotated * with @AssistedInject. The warning is suppressed. */ @SuppressWarnings("AssistedInjectAndInjectOnConstructors") public class TestClass6 { @javax.inject.Inject public TestClass6() {} @AssistedInject public TestClass6(int n) {} } }
2,019
28.275362
98
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/apply/ImportStatementsTest.java
/* * Copyright 2012 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.apply; import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH; import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; import static com.google.errorprone.matchers.Description.NO_MATCH; import static com.google.errorprone.util.ASTHelpers.getSymbol; import static com.google.errorprone.util.MoreAnnotations.getAnnotationValue; import static java.util.stream.Collectors.joining; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugPattern; import com.google.errorprone.VisitorState; import com.google.errorprone.bugpatterns.BugChecker; import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher; import com.google.errorprone.fixes.SuggestedFix; import com.google.errorprone.matchers.Description; import com.google.errorprone.util.MoreAnnotations; import com.sun.source.tree.ClassTree; import com.sun.tools.javac.code.Attribute; import java.lang.annotation.ElementType; import java.lang.annotation.Target; import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Unit tests for {@link ImportStatements} * * @author eaftan@google.com (Eddie Aftandilian) */ @RunWith(JUnit4.class) public class ImportStatementsTest { @Target(ElementType.TYPE) public @interface ImportsToAdd { String[] toAdd() default {}; String[] toRemove() default {}; } @BugPattern(summary = "Refactoring to add imports", severity = ERROR) public static class ImportsToAddChecker extends BugChecker implements ClassTreeMatcher { @Override public Description matchClass(ClassTree tree, VisitorState state) { Optional<Attribute.Compound> annotation = getSymbol(tree).getAnnotationMirrors().stream() .filter( a -> a.type .tsym .getQualifiedName() .contentEquals(ImportsToAdd.class.getCanonicalName())) .findAny(); if (annotation.isEmpty()) { return NO_MATCH; } SuggestedFix.Builder fix = SuggestedFix.builder(); getAnnotationValue(annotation.get(), "toAdd") .map(MoreAnnotations::asStrings) .ifPresent( toAdd -> toAdd.forEach( i -> { if (i.startsWith("static ")) { fix.addStaticImport(i.substring("static ".length())); } else { fix.addImport(i); } })); getAnnotationValue(annotation.get(), "toRemove") .map(MoreAnnotations::asStrings) .ifPresent( toRemove -> toRemove.forEach( i -> { if (i.startsWith("static ")) { fix.removeStaticImport(i.substring("static ".length())); } else { fix.removeImport(i); } })); return describeMatch(tree, fix.build()); } } private static final ImmutableList<String> BASE_IMPORTS = ImmutableList.of( "static com.google.common.base.Preconditions.checkNotNull", "static java.lang.annotation.ElementType.TYPE_USE", "com.google.common.collect.ImmutableMap", "com.google.common.collect.ImmutableList", "org.joda.time.Interval", "org.joda.time.DateTime", "org.joda.time.DateTimeZone", "com.sun.tools.javac.tree.JCTree", "com.sun.source.tree.ImportTree", "com.sun.tools.javac.tree.JCTree.JCExpression", "com.sun.source.tree.CompilationUnitTree", "java.io.File", "java.util.Iterator", "java.io.IOException", "javax.tools.StandardJavaFileManager", "javax.tools.JavaFileObject", "javax.tools.JavaCompiler", "javax.tools.ToolProvider"); private final BugCheckerRefactoringTestHelper testHelper = BugCheckerRefactoringTestHelper.newInstance(ImportsToAddChecker.class, getClass()); private void testImports( Optional<String> pkg, ImmutableList<String> baseImports, ImmutableList<String> toAdd, ImmutableList<String> toRemove, String... expected) { String prefix = pkg.map(p -> String.format("package %s;\n", p)).orElse(""); String suffix = Joiner.on('\n') .join( "@com.google.errorprone.apply.ImportStatementsTest.ImportsToAdd(", " toAdd = {" + toAdd.stream().map(x -> "\"" + x + "\"").collect(joining(", ")) + "},", " toRemove = {" + toRemove.stream().map(x -> "\"" + x + "\"").collect(joining(", ")) + "})", "class Test {}"); testHelper .addInputLines( "Test.java", prefix, baseImports.stream().map(i -> String.format("import %s;", i)).collect(joining("\n")), "", suffix) .addOutputLines("Test.java", prefix, Joiner.on('\n').join(expected), suffix) .addModules("jdk.compiler/com.sun.tools.javac.tree") .doTest(TEXT_MATCH); } /** Test that adding a new import inserts it in the correct position. */ @Test public void shouldAddImportInCorrectPosition() { testImports( /* pkg= */ Optional.empty(), /* baseImports= */ BASE_IMPORTS, /* toAdd= */ ImmutableList.of("static org.junit.Assert.assertEquals"), /* toRemove= */ ImmutableList.of(), "import static com.google.common.base.Preconditions.checkNotNull;", "import static java.lang.annotation.ElementType.TYPE_USE;", "import static org.junit.Assert.assertEquals;", "", "import com.google.common.collect.ImmutableList;", "import com.google.common.collect.ImmutableMap;", "import com.sun.source.tree.CompilationUnitTree;", "import com.sun.source.tree.ImportTree;", "import com.sun.tools.javac.tree.JCTree;", "import com.sun.tools.javac.tree.JCTree.JCExpression;", "import java.io.File;", "import java.io.IOException;", "import java.util.Iterator;", "import javax.tools.JavaCompiler;", "import javax.tools.JavaFileObject;", "import javax.tools.StandardJavaFileManager;", "import javax.tools.ToolProvider;", "import org.joda.time.DateTime;", "import org.joda.time.DateTimeZone;", "import org.joda.time.Interval;"); } /** Test that adding multiple new imports using addAll() inserts them in the correct positions. */ @Test public void shouldAddMultipleImportsInCorrectPositions() { testImports( /* pkg= */ Optional.of("p"), /* baseImports= */ BASE_IMPORTS, /* toAdd= */ ImmutableList.of( "static org.junit.Assert.assertEquals", "javax.security.auth.spi.LoginModule", "com.google.common.graph.Graph"), /* toRemove= */ ImmutableList.of(), "import static com.google.common.base.Preconditions.checkNotNull;", "import static java.lang.annotation.ElementType.TYPE_USE;", "import static org.junit.Assert.assertEquals;", "", "import com.google.common.collect.ImmutableList;", "import com.google.common.collect.ImmutableMap;", "import com.google.common.graph.Graph;", "import com.sun.source.tree.CompilationUnitTree;", "import com.sun.source.tree.ImportTree;", "import com.sun.tools.javac.tree.JCTree;", "import com.sun.tools.javac.tree.JCTree.JCExpression;", "import java.io.File;", "import java.io.IOException;", "import java.util.Iterator;", "import javax.security.auth.spi.LoginModule;", "import javax.tools.JavaCompiler;", "import javax.tools.JavaFileObject;", "import javax.tools.StandardJavaFileManager;", "import javax.tools.ToolProvider;", "import org.joda.time.DateTime;", "import org.joda.time.DateTimeZone;", "import org.joda.time.Interval;"); } /** Test that adding an already-existing import doesn't change anything. */ @Test public void shouldNotAddExistingImport() { testImports( /* pkg= */ Optional.empty(), /* baseImports= */ BASE_IMPORTS, /* toAdd= */ ImmutableList.of("com.google.common.collect.ImmutableMap"), /* toRemove= */ ImmutableList.of(), "import static com.google.common.base.Preconditions.checkNotNull;", "import static java.lang.annotation.ElementType.TYPE_USE;", "import com.google.common.collect.ImmutableMap;", "import com.google.common.collect.ImmutableList;", "import org.joda.time.Interval;", "import org.joda.time.DateTime;", "import org.joda.time.DateTimeZone;", "import com.sun.tools.javac.tree.JCTree;", "import com.sun.source.tree.ImportTree;", "import com.sun.tools.javac.tree.JCTree.JCExpression;", "import com.sun.source.tree.CompilationUnitTree;", "import java.io.File;", "import java.util.Iterator;", "import java.io.IOException;", "import javax.tools.StandardJavaFileManager;", "import javax.tools.JavaFileObject;", "import javax.tools.JavaCompiler;", "import javax.tools.ToolProvider;"); } /** Test that removing an import works and the resulting output is correctly sorted. */ @Test public void shouldRemoveImportAndSort() { testImports( /* pkg= */ Optional.empty(), /* baseImports= */ BASE_IMPORTS, /* toAdd= */ ImmutableList.of(), /* toRemove= */ ImmutableList.of("com.sun.tools.javac.tree.JCTree"), "import static com.google.common.base.Preconditions.checkNotNull;", "import static java.lang.annotation.ElementType.TYPE_USE;", "", "import com.google.common.collect.ImmutableList;", "import com.google.common.collect.ImmutableMap;", "import com.sun.source.tree.CompilationUnitTree;", "import com.sun.source.tree.ImportTree;", "import com.sun.tools.javac.tree.JCTree.JCExpression;", "import java.io.File;", "import java.io.IOException;", "import java.util.Iterator;", "import javax.tools.JavaCompiler;", "import javax.tools.JavaFileObject;", "import javax.tools.StandardJavaFileManager;", "import javax.tools.ToolProvider;", "import org.joda.time.DateTime;", "import org.joda.time.DateTimeZone;", "import org.joda.time.Interval;"); } /** * Test that removing multiple imports using removeAll() works and the resulting output is * correctly sorted. */ @Test public void shouldRemoveMultipleImportsAndSort() { testImports( /* pkg= */ Optional.empty(), /* baseImports= */ BASE_IMPORTS, /* toAdd= */ ImmutableList.of(), /* toRemove= */ ImmutableList.of( "com.sun.tools.javac.tree.JCTree", "static com.google.common.base.Preconditions.checkNotNull", "org.joda.time.Interval"), "import static java.lang.annotation.ElementType.TYPE_USE;", "", "import com.google.common.collect.ImmutableList;", "import com.google.common.collect.ImmutableMap;", "import com.sun.source.tree.CompilationUnitTree;", "import com.sun.source.tree.ImportTree;", "import com.sun.tools.javac.tree.JCTree.JCExpression;", "import java.io.File;", "import java.io.IOException;", "import java.util.Iterator;", "import javax.tools.JavaCompiler;", "import javax.tools.JavaFileObject;", "import javax.tools.StandardJavaFileManager;", "import javax.tools.ToolProvider;", "import org.joda.time.DateTime;", "import org.joda.time.DateTimeZone;"); } /** Tests that a list of imports with no static imports is handled correctly. */ @Test public void noRemainingStaticImports() { testImports( /* pkg= */ Optional.empty(), /* baseImports= */ BASE_IMPORTS, /* toAdd= */ ImmutableList.of(), /* toRemove= */ ImmutableList.of( "static com.google.common.base.Preconditions.checkNotNull", "static java.lang.annotation.ElementType.TYPE_USE"), "import com.google.common.collect.ImmutableList;", "import com.google.common.collect.ImmutableMap;", "import com.sun.source.tree.CompilationUnitTree;", "import com.sun.source.tree.ImportTree;", "import com.sun.tools.javac.tree.JCTree;", "import com.sun.tools.javac.tree.JCTree.JCExpression;", "import java.io.File;", "import java.io.IOException;", "import java.util.Iterator;", "import javax.tools.JavaCompiler;", "import javax.tools.JavaFileObject;", "import javax.tools.StandardJavaFileManager;", "import javax.tools.ToolProvider;", "import org.joda.time.DateTime;", "import org.joda.time.DateTimeZone;", "import org.joda.time.Interval;"); } /** Test that removing a non-existent import doesn't change anything. */ @Test public void removingNonExistingImportShouldntChangeImports() { testImports( /* pkg= */ Optional.empty(), /* baseImports= */ BASE_IMPORTS, /* toAdd= */ ImmutableList.of(), /* toRemove= */ ImmutableList.of("org.joda.time.format.ISODateTimeFormat"), "import static com.google.common.base.Preconditions.checkNotNull;", "import static java.lang.annotation.ElementType.TYPE_USE;", "import com.google.common.collect.ImmutableMap;", "import com.google.common.collect.ImmutableList;", "import org.joda.time.Interval;", "import org.joda.time.DateTime;", "import org.joda.time.DateTimeZone;", "import com.sun.tools.javac.tree.JCTree;", "import com.sun.source.tree.ImportTree;", "import com.sun.tools.javac.tree.JCTree.JCExpression;", "import com.sun.source.tree.CompilationUnitTree;", "import java.io.File;", "import java.util.Iterator;", "import java.io.IOException;", "import javax.tools.StandardJavaFileManager;", "import javax.tools.JavaFileObject;", "import javax.tools.JavaCompiler;", "import javax.tools.ToolProvider;"); } @Test public void addingToEmptyImportList() { testImports( /* pkg= */ Optional.of("p"), /* baseImports= */ ImmutableList.of(), /* toAdd= */ ImmutableList.of("org.joda.time.Interval"), /* toRemove= */ ImmutableList.of(), "import org.joda.time.Interval;"); } @Test public void addingToEmptyImportListInDefaultPackage() { testImports( /* pkg= */ Optional.empty(), /* baseImports= */ ImmutableList.of(), /* toAdd= */ ImmutableList.of("org.joda.time.Interval"), /* toRemove= */ ImmutableList.of(), "import org.joda.time.Interval;"); } }
15,949
40.108247
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UForLoopTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.collect.ImmutableList; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import com.sun.source.tree.Tree.Kind; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UForLoop}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UForLoopTest extends AbstractUTreeTest { @Test public void equality() { new EqualsTester() .addEqualityGroup( UForLoop.create( ImmutableList.of( UVariableDecl.create("i", UPrimitiveTypeTree.INT, UFreeIdent.create("from"))), UBinary.create(Kind.LESS_THAN, ULocalVarIdent.create("i"), UFreeIdent.create("to")), ImmutableList.of( UExpressionStatement.create( UUnary.create(Kind.POSTFIX_INCREMENT, ULocalVarIdent.create("i")))), UBlock.create())) .addEqualityGroup( UForLoop.create( ImmutableList.of( UVariableDecl.create("i", UPrimitiveTypeTree.INT, UFreeIdent.create("from"))), UBinary.create(Kind.LESS_THAN, ULocalVarIdent.create("i"), UFreeIdent.create("to")), ImmutableList.<UExpressionStatement>of(), UBlock.create( UExpressionStatement.create( UUnary.create(Kind.POSTFIX_INCREMENT, ULocalVarIdent.create("i")))))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UForLoop.create( ImmutableList.of( UVariableDecl.create("i", UPrimitiveTypeTree.INT, UFreeIdent.create("from"))), UBinary.create(Kind.LESS_THAN, ULocalVarIdent.create("i"), UFreeIdent.create("to")), ImmutableList.of( UExpressionStatement.create( UUnary.create(Kind.POSTFIX_INCREMENT, ULocalVarIdent.create("i")))), UBlock.create())); } }
2,733
37.507042
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UNewClassTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UNewClass}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UNewClassTest extends AbstractUTreeTest { @Test public void equality() { new EqualsTester() .addEqualityGroup( UNewClass.create(UClassIdent.create("java.lang.String"), ULiteral.stringLit("123"))) .addEqualityGroup( UNewClass.create(UClassIdent.create("java.math.BigInteger"), ULiteral.stringLit("123"))) .addEqualityGroup( UNewClass.create(UClassIdent.create("java.lang.String"), ULiteral.stringLit("foobar"))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UNewClass.create(UClassIdent.create("java.lang.String"), ULiteral.stringLit("123"))); } @Test public void inline() { ImportPolicy.bind(context, ImportPolicy.IMPORT_TOP_LEVEL); assertInlines( "new String(\"123\")", UNewClass.create(UClassIdent.create("java.lang.String"), ULiteral.stringLit("123"))); } }
1,903
31.827586
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UPrimitiveTypeTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import javax.lang.model.type.TypeKind; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UPrimitiveType}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UPrimitiveTypeTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(UPrimitiveType.create(TypeKind.INT), UPrimitiveType.INT) .addEqualityGroup(UPrimitiveType.create(TypeKind.LONG), UPrimitiveType.LONG) .addEqualityGroup(UPrimitiveType.create(TypeKind.DOUBLE), UPrimitiveType.DOUBLE) .addEqualityGroup(UPrimitiveType.create(TypeKind.FLOAT), UPrimitiveType.FLOAT) .addEqualityGroup(UPrimitiveType.create(TypeKind.CHAR), UPrimitiveType.CHAR) .addEqualityGroup(UPrimitiveType.create(TypeKind.VOID), UPrimitiveType.VOID) .addEqualityGroup(UPrimitiveType.create(TypeKind.NULL), UPrimitiveType.NULL) .addEqualityGroup(UPrimitiveType.create(TypeKind.BOOLEAN), UPrimitiveType.BOOLEAN) .addEqualityGroup(UPrimitiveType.create(TypeKind.BYTE), UPrimitiveType.BYTE) .addEqualityGroup(UPrimitiveType.create(TypeKind.SHORT), UPrimitiveType.SHORT) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert(UPrimitiveType.INT); } }
2,090
37.722222
90
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UContinueTest.java
/* * Copyright 2014 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UContinue}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UContinueTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(UContinue.create(null)) .addEqualityGroup(UContinue.create("foo")) .addEqualityGroup(UContinue.create("bar")) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert(UContinue.create("bar")); } }
1,336
28.065217
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UTypeParameterTest.java
/* * Copyright 2014 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UTypeParameter}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UTypeParameterTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(UTypeParameter.create("T")) .addEqualityGroup(UTypeParameter.create("E")) .addEqualityGroup(UTypeParameter.create("T", UClassIdent.create("java.lang.CharSequence"))) .addEqualityGroup(UTypeParameter.create("T", UClassIdent.create("java.lang.Number"))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UTypeParameter.create("T", UClassIdent.create("java.lang.CharSequence"))); } }
1,546
32.630435
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UUnionTypeTest.java
/* * Copyright 2014 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UUnionType}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UUnionTypeTest { @Test public void equality() { new EqualsTester() .addEqualityGroup( UUnionType.create( UClassIdent.create("java.lang.IllegalArgumentException"), UClassIdent.create("java.lang.IllegalStateException"))) .addEqualityGroup( UUnionType.create( UClassIdent.create("java.lang.IllegalStateException"), UClassIdent.create("java.lang.IllegalArgumentException"))) .addEqualityGroup( UUnionType.create( UClassIdent.create("java.lang.IllegalStateException"), UClassIdent.create("java.lang.IllegalArgumentException"), UClassIdent.create("java.lang.IndexOutOfBoundsException"))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UUnionType.create( UClassIdent.create("java.lang.IllegalArgumentException"), UClassIdent.create("java.lang.IllegalStateException"))); } }
2,014
33.152542
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UStaticIdentTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UStaticIdent}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UStaticIdentTest extends AbstractUTreeTest { @Test public void equality() { new EqualsTester() .addEqualityGroup( UStaticIdent.create( "java.lang.Integer", "valueOf", UMethodType.create( UClassType.create("java.lang.Integer"), UClassType.create("java.lang.String")))) .addEqualityGroup( UStaticIdent.create( "java.lang.Integer", "valueOf", UMethodType.create( UClassType.create("java.lang.Integer"), UClassType.create("java.lang.String"), UPrimitiveType.INT))) .addEqualityGroup( UStaticIdent.create( "java.lang.Integer", "getInteger", UMethodType.create( UClassType.create("java.lang.Integer"), UClassType.create("java.lang.String")))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UStaticIdent.create( "java.lang.Integer", "valueOf", UMethodType.create( UClassType.create("java.lang.Integer"), UClassType.create("java.lang.String")))); } @Test public void inline() { ImportPolicy.bind(context, ImportPolicy.IMPORT_TOP_LEVEL); assertInlines( "Integer.valueOf", UStaticIdent.create( "java.lang.Integer", "valueOf", UMethodType.create( UClassType.create("java.lang.Integer"), UClassType.create("java.lang.String")))); } }
2,614
31.6875
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/CodeTransformerTestHelper.java
/* * Copyright 2014 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package com.google.errorprone.refaster; import static com.google.testing.compile.JavaFileObjects.forSourceString; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.io.CharStreams; import com.google.errorprone.CodeTransformer; import com.google.errorprone.FileManagers; import com.google.errorprone.apply.DescriptionBasedDiff; import com.google.errorprone.apply.ImportOrganizer; import com.google.errorprone.apply.SourceFile; import com.sun.source.tree.CompilationUnitTree; import com.sun.source.util.TreePath; import com.sun.tools.javac.api.JavacTaskImpl; import com.sun.tools.javac.api.JavacTool; import com.sun.tools.javac.tree.JCTree.JCClassDecl; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import java.io.IOException; import javax.tools.DiagnosticCollector; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.StandardJavaFileManager; /** * Test helper for {@link CodeTransformer} implementations. * * @author lowasser@google.com (Louis Wasserman) */ @AutoValue public abstract class CodeTransformerTestHelper { public static CodeTransformerTestHelper create(CodeTransformer transformer) { return new AutoValue_CodeTransformerTestHelper(transformer); } abstract CodeTransformer transformer(); public JavaFileObject transform(JavaFileObject original) { JavaCompiler compiler = JavacTool.create(); DiagnosticCollector<JavaFileObject> diagnosticsCollector = new DiagnosticCollector<>(); StandardJavaFileManager fileManager = FileManagers.testFileManager(); JavacTaskImpl task = (JavacTaskImpl) compiler.getTask( CharStreams.nullWriter(), fileManager, diagnosticsCollector, ImmutableList.<String>of(), null, ImmutableList.of(original)); try { SourceFile sourceFile = SourceFile.create(original); Iterable<? extends CompilationUnitTree> trees = task.parse(); task.analyze(); JCCompilationUnit tree = Iterables.getOnlyElement(Iterables.filter(trees, JCCompilationUnit.class)); DescriptionBasedDiff diff = DescriptionBasedDiff.create(tree, ImportOrganizer.STATIC_FIRST_ORGANIZER); transformer().apply(new TreePath(tree), task.getContext(), diff); diff.applyDifferences(sourceFile); return forSourceString( Iterables.getOnlyElement(Iterables.filter(tree.getTypeDecls(), JCClassDecl.class)) .sym .getQualifiedName() .toString(), sourceFile.getSourceText()); } catch (IOException e) { throw new RuntimeException(e); } } }
3,376
36.94382
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UArrayAccessTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UArrayAccess}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UArrayAccessTest extends AbstractUTreeTest { @Test public void unify() { UExpression arrayIdent = mock(UExpression.class); when(arrayIdent.unify(ident("array"), isA(Unifier.class))).thenReturn(Choice.of(unifier)); assertUnifies("array[5]", UArrayAccess.create(arrayIdent, ULiteral.intLit(5))); } @Test public void inline() throws CouldNotResolveImportException { UExpression arrayIdent = mock(UExpression.class); when(arrayIdent.inline(isA(Inliner.class))) .thenReturn(inliner.maker().Ident(inliner.asName("array"))); assertInlines("array[5]", UArrayAccess.create(arrayIdent, ULiteral.intLit(5))); } }
1,645
32.591837
94
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UAssignOpTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import com.sun.source.tree.Tree.Kind; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UAssignOp}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UAssignOpTest { @Test public void equality() { new EqualsTester() .addEqualityGroup( UAssignOp.create(UFreeIdent.create("x"), Kind.PLUS_ASSIGNMENT, UFreeIdent.create("y"))) .addEqualityGroup( UAssignOp.create(UFreeIdent.create("x"), Kind.PLUS_ASSIGNMENT, ULiteral.intLit(2))) .addEqualityGroup( UAssignOp.create(UFreeIdent.create("y"), Kind.PLUS_ASSIGNMENT, ULiteral.intLit(2))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UAssignOp.create(UFreeIdent.create("x"), Kind.PLUS_ASSIGNMENT, ULiteral.intLit(2))); } }
1,663
31.627451
99
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UIfTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.base.Joiner; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UIf}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UIfTest extends AbstractUTreeTest { @Test public void equality() { new EqualsTester() .addEqualityGroup( UIf.create( UFreeIdent.create("cond"), UBlock.create( UExpressionStatement.create( UAssign.create(UFreeIdent.create("x"), UFreeIdent.create("y")))), UBlock.create( UExpressionStatement.create( UAssign.create(UFreeIdent.create("x"), UFreeIdent.create("z")))))) .addEqualityGroup( UIf.create( UFreeIdent.create("cond"), UBlock.create( UExpressionStatement.create( UAssign.create(UFreeIdent.create("x"), UFreeIdent.create("y")))), null)) .addEqualityGroup( UIf.create( ULiteral.booleanLit(true), UBlock.create( UExpressionStatement.create( UAssign.create(UFreeIdent.create("x"), UFreeIdent.create("y")))), UBlock.create( UExpressionStatement.create( UAssign.create(UFreeIdent.create("x"), UFreeIdent.create("z")))))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UIf.create( UFreeIdent.create("cond"), UBlock.create( UExpressionStatement.create( UAssign.create(UFreeIdent.create("x"), UFreeIdent.create("y")))), UBlock.create( UExpressionStatement.create( UAssign.create(UFreeIdent.create("x"), UFreeIdent.create("z")))))); } @Test public void inlineWithElse() { UIf ifTree = UIf.create( UFreeIdent.create("cond"), UBlock.create( UExpressionStatement.create( UAssign.create(UFreeIdent.create("x"), UFreeIdent.create("y")))), UBlock.create( UExpressionStatement.create( UAssign.create(UFreeIdent.create("x"), UFreeIdent.create("z"))))); bind(new UFreeIdent.Key("cond"), parseExpression("true")); bind(new UFreeIdent.Key("x"), parseExpression("x")); bind(new UFreeIdent.Key("y"), parseExpression("\"foo\"")); bind(new UFreeIdent.Key("z"), parseExpression("\"bar\"")); assertInlines( Joiner.on(System.lineSeparator()) .join( "if (true) {", // " x = \"foo\";", "} else {", " x = \"bar\";", "}"), ifTree); } @Test public void inlineWithoutElse() { UIf ifTree = UIf.create( UFreeIdent.create("cond"), UBlock.create( UExpressionStatement.create( UAssign.create(UFreeIdent.create("x"), UFreeIdent.create("y")))), null); bind(new UFreeIdent.Key("cond"), parseExpression("true")); bind(new UFreeIdent.Key("x"), parseExpression("x")); bind(new UFreeIdent.Key("y"), parseExpression("\"foo\"")); assertInlines( Joiner.on(System.lineSeparator()) .join( "if (true) {", // " x = \"foo\";", "}"), ifTree); } }
4,357
34.145161
90
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/Match.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableMap; import java.util.Map; /** * A simplistic representation of a template match; can be used for expecting certain results from a * scan. * * @author lowasser@google.com (Louis Wasserman) */ @AutoValue public abstract class Match { public static Match create(TemplateMatch match) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); for (Map.Entry<Bindings.Key<?>, Object> entry : match.getUnifier().getBindings().entrySet()) { builder.put(entry.getKey().getIdentifier(), entry.getValue().toString()); } return create(builder.buildOrThrow()); } public static Match create(Map<String, String> bindings) { return new AutoValue_Match(ImmutableMap.copyOf(bindings)); } abstract ImmutableMap<String, String> bindings(); }
1,512
32.622222
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UConditionalTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UConditional}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UConditionalTest extends AbstractUTreeTest { @Test public void match() { assertUnifies( "true ? -1 : 1", UConditional.create(ULiteral.booleanLit(true), ULiteral.intLit(-1), ULiteral.intLit(1))); } @Test public void inline() { assertInlines( "true ? -1 : 1", UConditional.create(ULiteral.booleanLit(true), ULiteral.intLit(-1), ULiteral.intLit(1))); } @Test public void equality() { ULiteral trueLit = ULiteral.booleanLit(true); ULiteral falseLit = ULiteral.booleanLit(false); ULiteral negOneLit = ULiteral.intLit(-1); ULiteral oneLit = ULiteral.intLit(1); new EqualsTester() .addEqualityGroup(UConditional.create(trueLit, negOneLit, oneLit)) .addEqualityGroup(UConditional.create(trueLit, oneLit, oneLit)) .addEqualityGroup(UConditional.create(trueLit, negOneLit, negOneLit)) .addEqualityGroup(UConditional.create(falseLit, negOneLit, oneLit)) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UConditional.create(ULiteral.booleanLit(true), ULiteral.intLit(-1), ULiteral.intLit(1))); } }
2,140
30.955224
97
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UTemplaterTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import static com.google.common.truth.Truth.assertThat; import com.sun.tools.javac.tree.JCTree; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UTemplater}'s support for basic syntactic constructs. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UTemplaterTest extends AbstractUTreeTest { /** * Parses a Java expression, templates it using a {@link UTemplater}, and tests that the template * matches the original parsed expression. */ private void testTemplateWithoutTypes(String expression) { JCTree ast = parseExpression(expression); UTree<?> template = (UTree<?>) new UTemplater(context).template(ast); assertThat(template.unify(ast, unifier)).isNotNull(); } @Test public void literal() { testTemplateWithoutTypes("5L"); } @Test public void parens() { testTemplateWithoutTypes("(5L)"); } @Test public void binary() { testTemplateWithoutTypes("\"count:\" + 5"); } @Test public void conditional() { testTemplateWithoutTypes("true ? 3.14 : -5"); } @Test public void unary() { testTemplateWithoutTypes("~7"); } }
1,853
26.264706
99
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UClassTypeTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import static com.google.common.truth.Truth.assertThat; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import com.sun.tools.javac.code.Symtab; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UClassType}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UClassTypeTest extends AbstractUTreeTest { @Test public void equality() { UType stringType = UClassType.create("java.lang.String"); new EqualsTester() .addEqualityGroup(stringType) .addEqualityGroup(UClassType.create("java.util.List", stringType)) .addEqualityGroup(UClassType.create("java.util.Map", stringType, stringType)) .addEqualityGroup(UClassType.create("java.lang.Integer")) .addEqualityGroup( UClassType.create("java.util.List", UClassType.create("java.lang.Integer"))) .testEquals(); } @Test public void serialization() { UClassType stringType = UClassType.create("java.lang.String"); UClassType integerType = UClassType.create("java.lang.Integer"); SerializableTester.reserializeAndAssert(stringType); SerializableTester.reserializeAndAssert(integerType); SerializableTester.reserializeAndAssert(UClassType.create("java.util.List", stringType)); SerializableTester.reserializeAndAssert(UClassType.create("java.util.List", integerType)); SerializableTester.reserializeAndAssert( UClassType.create("java.util.Map", stringType, stringType)); } @Test public void unifies() { assertThat( UClassType.create("java.lang.String") .unify(Symtab.instance(context).stringType, unifier)) .isNotNull(); } }
2,433
34.794118
94
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/AbstractUTreeTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import static com.google.common.truth.Truth.assertWithMessage; import com.google.common.base.Joiner; import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.main.JavaCompiler; import com.sun.tools.javac.parser.Parser; import com.sun.tools.javac.parser.ParserFactory; import com.sun.tools.javac.tree.JCTree.JCExpression; import com.sun.tools.javac.tree.JCTree.JCIdent; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; import org.hamcrest.Description; import org.hamcrest.TypeSafeMatcher; import org.junit.Before; import org.mockito.hamcrest.MockitoHamcrest; /** * Basics for testing {@code UTree} implementations. * * @author lowasser@google.com (Louis Wasserman) */ public abstract class AbstractUTreeTest { protected Context context; protected Unifier unifier; protected Inliner inliner; @Before public void createContext() { context = new Context(); JavacFileManager.preRegister(context); JavaCompiler compiler = JavaCompiler.instance(context); compiler.initModules(List.nil()); unifier = new Unifier(context); inliner = unifier.createInliner(); } public void assertUnifiesAndInlines(String expression, UTree<?> template) { assertUnifies(expression, template); assertInlines(expression, template); } public void assertUnifies(String expression, UTree<?> template) { assertWithMessage( String.format("Expected template %s to unify with expression %s", template, expression)) .that(template.unify(parseExpression(expression), unifier).first()) .isPresent(); } public void assertInlines(String expression, UTree<?> template) { try { assertWithMessage( String.format( "Expected template %s to inline to expression %s", template, expression)) .that(template.inline(inliner).toString()) .isEqualTo(expression); } catch (CouldNotResolveImportException e) { throw new RuntimeException(e); } } public void assertInlines(String expression, UStatement template) { try { // javac's pretty-printer uses the platform line terminator assertWithMessage( String.format( "Expected template %s to inline to expression %s", template, expression)) .that(Joiner.on(System.lineSeparator()).join(template.inlineStatements(inliner))) .isEqualTo(expression); } catch (CouldNotResolveImportException e) { throw new RuntimeException(e); } } protected JCExpression parseExpression(String contents) { Parser parser = ParserFactory.instance(context) .newParser( contents, /* keepDocComments= */ false, /* keepEndPos= */ false, /* keepLineMap= */ true); return parser.parseExpression(); } protected <V> void bind(Bindings.Key<V> key, V value) { Bindings bindings = Bindings.create(inliner.bindings); bindings.putBinding(key, value); inliner = new Inliner(context, bindings); } protected JCExpression ident(String name) { return MockitoHamcrest.argThat( new TypeSafeMatcher<JCExpression>() { @Override public void describeTo(Description description) { description.appendText("Identifier matching \"" + name + "\""); } @Override public boolean matchesSafely(JCExpression item) { return item instanceof JCIdent && ((JCIdent) item).getName().contentEquals(name); } }); } }
4,223
33.064516
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/ULabeledStatementTest.java
/* * Copyright 2014 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link ULabeledStatement}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class ULabeledStatementTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(ULabeledStatement.create("foo", USkip.INSTANCE)) .addEqualityGroup(ULabeledStatement.create("bar", USkip.INSTANCE)) .addEqualityGroup(ULabeledStatement.create("bar", UBlock.create())) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert(ULabeledStatement.create("foo", USkip.INSTANCE)); } }
1,450
30.543478
93
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UBreakTest.java
/* * Copyright 2014 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UBreak}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UBreakTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(UBreak.create(null)) .addEqualityGroup(UBreak.create("foo")) .addEqualityGroup(UBreak.create("bar")) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert(UBreak.create("bar")); } }
1,318
27.673913
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/DescriptionBasedDiffTest.java
/* * Copyright 2014 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package com.google.errorprone.refaster; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; import com.google.common.collect.Iterables; import com.google.errorprone.BugPattern; import com.google.errorprone.BugPattern.SeverityLevel; import com.google.errorprone.apply.DescriptionBasedDiff; import com.google.errorprone.apply.ImportOrganizer; import com.google.errorprone.bugpatterns.BugChecker; import com.google.errorprone.fixes.SuggestedFix; import com.google.errorprone.matchers.Description; import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@code DescriptionBasedDiff}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class DescriptionBasedDiffTest extends CompilerBasedTest { private JCCompilationUnit compilationUnit; private static final String[] lines = { "package foo.bar;", "import org.bar.Baz;", "import com.foo.Bar;", "", "class Foo {", " public static void main(String[] args) {", " System.out.println(\"foo\");", " }", "}" }; @Before public void setUp() { compile(lines); compilationUnit = Iterables.getOnlyElement(compilationUnits); } private DescriptionBasedDiff createDescriptionBasedDiff() { return DescriptionBasedDiff.create(compilationUnit, ImportOrganizer.STATIC_FIRST_ORGANIZER); } @Test public void noDiffs() { DescriptionBasedDiff diff = createDescriptionBasedDiff(); diff.applyDifferences(sourceFile); assertThat(sourceFile.getLines()).containsExactly((Object[]) lines).inOrder(); } @Test public void oneDiff() { DescriptionBasedDiff diff = createDescriptionBasedDiff(); diff.onDescribed(dummyDescription(SuggestedFix.replace(137, 140, "bar"))); diff.applyDifferences(sourceFile); assertThat(sourceFile.getLines()) .containsExactly( "package foo.bar;", "import org.bar.Baz;", "import com.foo.Bar;", "", "class Foo {", " public static void main(String[] args) {", " System.out.println(\"bar\");", " }", "}") .inOrder(); } @Test public void prefixDiff() { DescriptionBasedDiff diff = createDescriptionBasedDiff(); diff.onDescribed(dummyDescription(SuggestedFix.replace(140, 140, "bar"))); diff.applyDifferences(sourceFile); assertThat(sourceFile.getLines()) .containsExactly( "package foo.bar;", "import org.bar.Baz;", "import com.foo.Bar;", "", "class Foo {", " public static void main(String[] args) {", " System.out.println(\"foobar\");", " }", "}") .inOrder(); } @Test public void twoDiffs() { DescriptionBasedDiff diff = createDescriptionBasedDiff(); diff.onDescribed( dummyDescription( SuggestedFix.builder().replace(124, 127, "longer").replace(137, 140, "bar").build())); diff.applyDifferences(sourceFile); assertThat(sourceFile.getLines()) .containsExactly( "package foo.bar;", "import org.bar.Baz;", "import com.foo.Bar;", "", "class Foo {", " public static void main(String[] args) {", " System.longer.println(\"bar\");", " }", "}") .inOrder(); } @Test public void overlappingDiffs_throws() { DescriptionBasedDiff diff = createDescriptionBasedDiff(); assertThrows( IllegalArgumentException.class, () -> diff.onDescribed( dummyDescription( SuggestedFix.builder() .replace(137, 140, "baz") .replace(137, 140, "bar") .build()))); DescriptionBasedDiff diff2 = createDescriptionBasedDiff(); diff2.onDescribed(dummyDescription(SuggestedFix.replace(137, 140, "baz"))); assertThrows( IllegalArgumentException.class, () -> diff2.onDescribed(dummyDescription(SuggestedFix.replace(137, 140, "bar")))); DescriptionBasedDiff diff3 = DescriptionBasedDiff.createIgnoringOverlaps( compilationUnit, ImportOrganizer.STATIC_FIRST_ORGANIZER); diff3.onDescribed(dummyDescription(SuggestedFix.replace(137, 140, "baz"))); // No throw, since it's lenient. Refactors to the first "baz" replacement and ignores this. diff3.onDescribed(dummyDescription(SuggestedFix.replace(137, 140, "bar"))); diff3.applyDifferences(sourceFile); assertThat(sourceFile.getLines()) .containsExactly( "package foo.bar;", "import org.bar.Baz;", "import com.foo.Bar;", "", "class Foo {", " public static void main(String[] args) {", " System.out.println(\"baz\");", " }", "}") .inOrder(); } @Test public void applyDifferences_addsImportAndSorts_whenAddingNewImport() { DescriptionBasedDiff diff = createDescriptionBasedDiff(); diff.onDescribed( dummyDescription(SuggestedFix.builder().addImport("com.google.foo.Bar").build())); diff.applyDifferences(sourceFile); assertThat(sourceFile.getLines()) .containsExactly( "package foo.bar;", "import com.foo.Bar;", "import com.google.foo.Bar;", "import org.bar.Baz;", "", "class Foo {", " public static void main(String[] args) {", " System.out.println(\"foo\");", " }", "}") .inOrder(); } @Test public void applyDifferences_preservesImportOrder_whenAddingExistingImport() { DescriptionBasedDiff diff = createDescriptionBasedDiff(); diff.onDescribed(dummyDescription(SuggestedFix.builder().addImport("com.foo.Bar").build())); diff.applyDifferences(sourceFile); assertThat(sourceFile.getLines()) .containsExactly( "package foo.bar;", "import org.bar.Baz;", "import com.foo.Bar;", "", "class Foo {", " public static void main(String[] args) {", " System.out.println(\"foo\");", " }", "}") .inOrder(); } @Test public void removeImport() { DescriptionBasedDiff diff = createDescriptionBasedDiff(); diff.onDescribed( dummyDescription( SuggestedFix.builder() .removeImport("com.foo.Bar") .removeImport("org.bar.Baz") .build())); diff.applyDifferences(sourceFile); assertThat(sourceFile.getLines()) .containsExactly( "package foo.bar;", "", "", "class Foo {", " public static void main(String[] args) {", " System.out.println(\"foo\");", " }", "}") .inOrder(); } @Test public void applyDifferences_preservesOrder_whenRemovingNonExistentImport() { DescriptionBasedDiff diff = createDescriptionBasedDiff(); diff.onDescribed( dummyDescription(SuggestedFix.builder().removeImport("com.google.foo.Bar").build())); diff.applyDifferences(sourceFile); assertThat(sourceFile.getLines()) .containsExactly( "package foo.bar;", "import org.bar.Baz;", "import com.foo.Bar;", "", "class Foo {", " public static void main(String[] args) {", " System.out.println(\"foo\");", " }", "}") .inOrder(); } @Test public void twoDiffsWithImport() { DescriptionBasedDiff diff = createDescriptionBasedDiff(); diff.onDescribed( dummyDescription( SuggestedFix.builder() .replace(124, 127, "longer") .replace(137, 140, "bar") .addImport("com.google.foo.Bar") .build())); diff.applyDifferences(sourceFile); assertThat(sourceFile.getLines()) .containsExactly( "package foo.bar;", "import com.foo.Bar;", "import com.google.foo.Bar;", "import org.bar.Baz;", "", "class Foo {", " public static void main(String[] args) {", " System.longer.println(\"bar\");", " }", "}") .inOrder(); } @BugPattern(name = "Test", summary = "", severity = SeverityLevel.WARNING) static final class DummyChecker extends BugChecker {} private static Description dummyDescription(SuggestedFix fix) { return new DummyChecker() .buildDescription( new DiagnosticPosition() { @Override public JCTree getTree() { return null; } @Override public int getStartPosition() { return 0; } @Override public int getPreferredPosition() { return 0; } @Override public int getEndPosition(EndPosTable endPosTable) { return 0; } }) .addFix(fix) .build(); } }
10,243
31.417722
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UEnhancedForLoopTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UEnhancedForLoop}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UEnhancedForLoopTest { @Test public void equality() { new EqualsTester() .addEqualityGroup( UEnhancedForLoop.create( UVariableDecl.create("c", UPrimitiveTypeTree.CHAR, null), UMethodInvocation.create( UMemberSelect.create( ULiteral.stringLit("foo"), "toCharArray", UMethodType.create(UArrayType.create(UPrimitiveType.CHAR)))), USkip.INSTANCE)) .addEqualityGroup( UEnhancedForLoop.create( UVariableDecl.create("c", UClassIdent.create("java.lang.Character"), null), UMethodInvocation.create( UMemberSelect.create( ULiteral.stringLit("foo"), "toCharArray", UMethodType.create(UArrayType.create(UPrimitiveType.CHAR)))), USkip.INSTANCE)) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UEnhancedForLoop.create( UVariableDecl.create("c", UPrimitiveTypeTree.CHAR, null), UMethodInvocation.create( UMemberSelect.create( ULiteral.stringLit("foo"), "toCharArray", UMethodType.create(UArrayType.create(UPrimitiveType.CHAR)))), USkip.INSTANCE)); } }
2,426
34.173913
91
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UnificationTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableClassToInstanceMap; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; import com.sun.source.tree.Tree.Kind; import com.sun.tools.javac.code.BoundKind; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.tree.TreeScanner; import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Test {@link UTree#unify} against real compiled ASTs. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UnificationTest extends CompilerBasedTest { public void expectMatches(Template<?> template, Match... expected) { Set<Match> expectedMatches = Sets.newHashSet(expected); TreeScanner matchScanner = new TreeScanner() { @Override public void scan(JCTree tree) { if (tree == null) { return; } for (TemplateMatch templateMatch : template.match(tree, context)) { Match match = Match.create(templateMatch); if (!expectedMatches.remove(match)) { fail(String.format("Unexpected match against template %s:%n%s", template, match)); } } super.scan(tree); } }; for (JCCompilationUnit unit : compilationUnits) { matchScanner.scan(unit); } for (Match missingMatch : expectedMatches) { fail( String.format( "Expected match against template %s not found: %s", template, missingMatch)); } } @Test public void binary() { // template: (a + b) / 2 ExpressionTemplate template = ExpressionTemplate.create( ImmutableMap.of( "a", UPrimitiveType.INT, "b", UPrimitiveType.INT), UBinary.create( Kind.DIVIDE, UParens.create( UBinary.create(Kind.PLUS, UFreeIdent.create("a"), UFreeIdent.create("b"))), ULiteral.intLit(2)), UPrimitiveType.INT); compile( "import java.util.Random;", "class BinaryExample {", " public void example(int x, int y) {", // positive examples " System.out.println((3 + 5) / 2);", " System.out.println((x + y) / 2 + 20);", " System.err.println((y + new Random().nextInt()) / 2);", // negative examples " System.out.println((x - y) / 2);", " System.out.println((x * y) / 2);", " System.out.println((x + y) / 3);", " System.out.println((x + 5L) / 2);", " }", "}"); expectMatches( template, Match.create(ImmutableMap.of("a", "3", "b", "5")), Match.create(ImmutableMap.of("a", "x", "b", "y")), Match.create(ImmutableMap.of("a", "y", "b", "new Random().nextInt()"))); } @Test public void compoundAssignment() { // template: String += int ExpressionTemplate template = ExpressionTemplate.create( ImmutableMap.of("str", UClassType.create("java.lang.String"), "n", UPrimitiveType.INT), UAssignOp.create( UFreeIdent.create("str"), Kind.PLUS_ASSIGNMENT, UFreeIdent.create("n")), UClassType.create("java.lang.String")); compile( "class CompoundAssignmentExample {", " public void example() {", " String foo = \"\";", " foo += 5;", " foo += \"bar\";", " foo += 10;", " }", "}"); expectMatches( template, Match.create(ImmutableMap.of("str", "foo", "n", "5")), Match.create(ImmutableMap.of("str", "foo", "n", "10"))); } @Test public void methodInvocation() { // template : md.digest(str.getBytes()) UType byteArrayType = UArrayType.create(UPrimitiveType.BYTE); ExpressionTemplate template = ExpressionTemplate.create( ImmutableMap.of( "md", UClassType.create("java.security.MessageDigest"), "str", UClassType.create("java.lang.String")), UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("md"), "digest", UMethodType.create(byteArrayType, byteArrayType)), UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("str"), "getBytes", UMethodType.create(byteArrayType)))), byteArrayType); compile( "import java.security.MessageDigest;", "import java.security.NoSuchAlgorithmException;", "import java.nio.charset.Charset;", "class MethodInvocationExample {", " public void example(MessageDigest digest, String string)", " throws NoSuchAlgorithmException {", // positive examples " MessageDigest.getInstance(\"MD5\").digest(\"foo\".getBytes());", " digest.digest(\"foo\".getBytes());", " MessageDigest.getInstance(\"SHA1\").digest(string.getBytes());", " digest.digest((string + 90).getBytes());", // negative examples " System.out.println(\"foo\".getBytes());", " }", "}"); expectMatches( template, Match.create(ImmutableMap.of("md", "MessageDigest.getInstance(\"MD5\")", "str", "\"foo\"")), Match.create(ImmutableMap.of("md", "digest", "str", "\"foo\"")), Match.create(ImmutableMap.of("md", "MessageDigest.getInstance(\"SHA1\")", "str", "string")), Match.create(ImmutableMap.of("md", "digest", "str", "(string + 90)"))); } @Test public void staticMethodInvocation() { // Template: BigInteger.valueOf(int) ExpressionTemplate template = ExpressionTemplate.create( ImmutableMap.of("x", UPrimitiveType.INT), UMethodInvocation.create( UStaticIdent.create( "java.math.BigInteger", "valueOf", UMethodType.create( UClassType.create("java.math.BigInteger"), UPrimitiveType.LONG)), UFreeIdent.create("x")), UClassType.create("java.math.BigInteger")); compile( "import java.math.BigInteger;", "class Foo {", " public void example(int x) {", // positive examples " BigInteger.valueOf(32);", " BigInteger.valueOf(x * 15);", " BigInteger.valueOf(Integer.parseInt(\"3\"));", // negative examples " BigInteger.valueOf(32L);", " super.equals(32);", " }", "}"); expectMatches( template, Match.create(ImmutableMap.of("x", "32")), Match.create(ImmutableMap.of("x", "x * 15")), Match.create(ImmutableMap.of("x", "Integer.parseInt(\"3\")"))); } @Test public void multipleMatch() { ExpressionTemplate template = ExpressionTemplate.create( ImmutableMap.of("x", UPrimitiveType.INT), UBinary.create(Kind.MINUS, UFreeIdent.create("x"), UFreeIdent.create("x")), UPrimitiveType.INT); compile( "import java.math.BigInteger;", "class MultipleMatchExample {", " public void example(int n) {", // positive examples " System.out.println(3 - 3);", " BigInteger.valueOf((n * 2) - (n * 2));", // negative examples " System.err.println(3 - 3L);", " System.err.println((n * 2) - n * 2);", " }", "}"); expectMatches( template, Match.create(ImmutableMap.of("x", "3")), Match.create(ImmutableMap.of("x", "(n * 2)"))); } @Test public void returnTypeMatters() { /* Template: * <E> List<E> template(List<E> list) { * return Collections.unmodifiableList(list); * } * * Note that Collections.unmodifiableList takes a List<? extends T>, * but we're restricting to the case where the return type is the same. */ UTypeVar tVar = UTypeVar.create("T"); UTypeVar eVar = UTypeVar.create("E"); ExpressionTemplate template = ExpressionTemplate.create( ImmutableClassToInstanceMap.of(), ImmutableList.of(eVar), ImmutableMap.of("list", UClassType.create("java.util.List", eVar)), UMethodInvocation.create( UStaticIdent.create( "java.util.Collections", "unmodifiableList", UForAll.create( ImmutableList.of(tVar), UMethodType.create( UClassType.create("java.util.List", tVar), UClassType.create( "java.util.List", UWildcardType.create(BoundKind.EXTENDS, tVar))))), UFreeIdent.create("list")), UClassType.create("java.util.List", eVar)); compile( "import java.util.ArrayList;", "import java.util.Collections;", "import java.util.List;", "class ReturnTypeMattersExample {", " public void example() {", // positive examples " Collections.unmodifiableList(new ArrayList<String>());", " List<Integer> ints = Collections.unmodifiableList(Collections.singletonList(1));", // negative examples " List<CharSequence> seqs = Collections.<CharSequence>unmodifiableList(", " new ArrayList<String>());", " }", "}"); expectMatches( template, Match.create( ImmutableMap.of( "list", "new ArrayList<String>()", "E", "java.lang.String")), Match.create( ImmutableMap.of( "list", "Collections.singletonList(1)", "E", "java.lang.Integer"))); } @Test public void recursiveType() { /* * Template: * <E extends Enum<E>> String example(E e) { * return e.name(); * } */ UTypeVar eTypeVar = UTypeVar.create("E"); eTypeVar.setUpperBound(UClassType.create("java.lang.Enum", eTypeVar)); ExpressionTemplate template = ExpressionTemplate.create( ImmutableClassToInstanceMap.of(), ImmutableList.of(eTypeVar), ImmutableMap.of("value", eTypeVar), UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("value"), "name", UMethodType.create(UClassType.create("java.lang.String")))), UClassType.create("java.lang.String")); compile( "import java.math.RoundingMode;", "class RecursiveTypeExample {", " public void example() {", " System.out.println(RoundingMode.FLOOR.name());", " }", "}"); expectMatches( template, Match.create( ImmutableMap.of( "value", "RoundingMode.FLOOR", "E", "java.math.RoundingMode"))); } @Test public void blockTemplate() { BlockTemplate blockTemplate = BlockTemplate.create( // <E> ImmutableList.of(UTypeVar.create("E")), ImmutableMap.of( // Collection<E> collection "collection", UClassType.create("java.util.Collection", UTypeVar.create("E")), // Comparator<? super E> comparator "comparator", UClassType.create( "java.util.Comparator", UWildcardType.create(BoundKind.SUPER, UTypeVar.create("E")))), UVariableDecl.create( "list", UTypeApply.create("java.util.List", UTypeVarIdent.create("E")), UNewClass.create( UTypeApply.create("java.util.ArrayList", UTypeVarIdent.create("E")), UFreeIdent.create("collection"))), UExpressionStatement.create( UMethodInvocation.create( UStaticIdent.create( "java.util.Collections", "sort", UForAll.create( ImmutableList.of(UTypeVar.create("T")), UMethodType.create( UPrimitiveType.VOID, UClassType.create("java.util.List", UTypeVar.create("T")), UClassType.create( "java.util.Comparator", UWildcardType.create(BoundKind.SUPER, UTypeVar.create("T")))))), ULocalVarIdent.create("list"), UFreeIdent.create("comparator")))); compile( "import java.util.ArrayList;", "import java.util.Comparator;", "import java.util.Collections;", "import java.util.List;", "class BlockTemplateExample {", " public void example(Comparator<String> cmp) {", " List<String> foo = new ArrayList<String>();", " foo.add(\"bar\");", " List<String> sorted = new ArrayList<String>(foo);", " Collections.sort(sorted, cmp);", " }", "}"); expectMatches( blockTemplate, Match.create( ImmutableMap.of( "collection", "foo", "comparator", "cmp", "E", "java.lang.String", "list", "sorted"))); } @Test public void ifBlockTemplate() { /* * Template: * * if (cond) { * x = y; * } else { * x = z; * } */ BlockTemplate blockTemplate = BlockTemplate.create( ImmutableList.of(UTypeVar.create("T")), ImmutableMap.of( "cond", UPrimitiveType.BOOLEAN, "x", UTypeVar.create("T"), "y", UTypeVar.create("T"), "z", UTypeVar.create("T")), UIf.create( UFreeIdent.create("cond"), UBlock.create( UExpressionStatement.create( UAssign.create(UFreeIdent.create("x"), UFreeIdent.create("y")))), UBlock.create( UExpressionStatement.create( UAssign.create(UFreeIdent.create("x"), UFreeIdent.create("z")))))); compile( "class IfBlockExample {", " public void example(String x) {", " if (Math.random() > 0.5) {", " x = \"foo\";", " } else {", " x = \"bar\";", " }", " }", "}"); expectMatches( blockTemplate, Match.create( ImmutableMap.of( "cond", "(Math.random() > 0.5)", "x", "x", "y", "\"foo\"", "z", "\"bar\"", "T", "java.lang.String"))); } @Test public void newArray() { // Template: new String[] {str} ExpressionTemplate template = ExpressionTemplate.create( ImmutableMap.of("str", UClassType.create("java.lang.String")), UNewArray.create( UClassIdent.create("java.lang.String"), ImmutableList.<UExpression>of(), ImmutableList.of(UFreeIdent.create("str"))), UArrayType.create(UClassType.create("java.lang.String"))); compile( "class Foo {", " public void example() {", // positive examples " String[] array1 = new String[] {\"foo\"};", // negative examples " String[] array2 = {\"bar\"};", " }", "}"); expectMatches(template, Match.create(ImmutableMap.of("str", "\"foo\""))); } }
16,666
35.232609
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UWildcardTypeTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.collect.ImmutableList; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import com.sun.tools.javac.code.BoundKind; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UWildcardType}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UWildcardTypeTest { @Test public void equality() { UType objectType = UClassType.create("java.lang.Object", ImmutableList.<UType>of()); UType setType = UClassType.create("java.util.Set", ImmutableList.<UType>of(objectType)); new EqualsTester() .addEqualityGroup(UWildcardType.create(BoundKind.UNBOUND, objectType)) // ? .addEqualityGroup(UWildcardType.create(BoundKind.EXTENDS, objectType)) // ? extends Object .addEqualityGroup(UWildcardType.create(BoundKind.EXTENDS, setType)) // ? extends Set<Object> .addEqualityGroup(UWildcardType.create(BoundKind.SUPER, setType)) // ? super Set<Object> .testEquals(); } @Test public void serialization() { UType numberType = UClassType.create("java.lang.Number", ImmutableList.<UType>of()); SerializableTester.reserializeAndAssert(UWildcardType.create(BoundKind.EXTENDS, numberType)); } }
1,964
36.075472
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UMemberSelectTest.java
/* * Copyright 2014 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import static org.mockito.Mockito.mock; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UMemberSelect}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UMemberSelectTest extends AbstractUTreeTest { @Test public void inline() { ULiteral fooLit = ULiteral.stringLit("foo"); UType type = mock(UType.class); UMemberSelect memberSelect = UMemberSelect.create(fooLit, "length", type); assertInlines("\"foo\".length", memberSelect); } @Test public void equality() { UType stringTy = UClassType.create("java.lang.String"); // int String.indexOf(int) UMethodType indexOfIntTy = UMethodType.create(UPrimitiveType.INT, UPrimitiveType.INT); // int String.indexOf(String) UMethodType indexOfStringTy = UMethodType.create(UPrimitiveType.INT, stringTy); UExpression fooLit = ULiteral.stringLit("foo"); UExpression barLit = ULiteral.stringLit("bar"); new EqualsTester() .addEqualityGroup(UMemberSelect.create(fooLit, "indexOf", indexOfIntTy)) .addEqualityGroup(UMemberSelect.create(fooLit, "indexOf", indexOfStringTy)) .addEqualityGroup(UMemberSelect.create(barLit, "indexOf", indexOfIntTy)) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UMemberSelect.create( ULiteral.stringLit("foo"), "indexOf", UMethodType.create(UPrimitiveType.INT, UPrimitiveType.INT))); } }
2,306
31.957143
90
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/TemplateIntegrationTest.java
/* * Copyright 2014 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assert_; import static com.google.testing.compile.JavaFileObjects.forResource; import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource; import static org.junit.Assert.assertThrows; import com.google.common.base.CharMatcher; import com.google.common.base.Function; import com.google.common.collect.FluentIterable; import com.google.common.collect.Iterables; import com.google.errorprone.CodeTransformer; import com.sun.source.tree.ClassTree; import com.sun.source.tree.CompilationUnitTree; import com.sun.source.tree.Tree; import java.io.IOException; import java.util.List; import javax.tools.JavaFileObject; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for Refaster templates. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class TemplateIntegrationTest extends CompilerBasedTest { private CodeTransformer extractRefasterRule(JavaFileObject object) { compile(object); ClassTree classTree = Iterables.getOnlyElement( FluentIterable.from(compilationUnits) .transformAndConcat( new Function<CompilationUnitTree, Iterable<? extends Tree>>() { @Override public List<? extends Tree> apply(CompilationUnitTree input) { return input.getTypeDecls(); } }) .filter(ClassTree.class)); return Iterables.getOnlyElement(RefasterRuleBuilderScanner.extractRules(classTree, context)); } private static void expectTransforms( CodeTransformer transformer, JavaFileObject input, JavaFileObject expectedOutput) throws IOException { JavaFileObject transformedInput = CodeTransformerTestHelper.create(transformer).transform(input); // TODO(lowasser): modify compile-testing to enable direct tree comparison assert_().about(javaSource()).that(transformedInput).compilesWithoutError(); String expectedSource = expectedOutput.getCharContent(false).toString(); String actualSource = transformedInput.getCharContent(false).toString(); assertThat(CharMatcher.whitespace().collapseFrom(actualSource, ' ')) .isEqualTo(CharMatcher.whitespace().collapseFrom(expectedSource, ' ')); } private static final String TEMPLATE_DIR = "com/google/errorprone/refaster/testdata/template"; private static final String INPUT_DIR = "com/google/errorprone/refaster/testdata/input"; private static final String OUTPUT_DIR = "com/google/errorprone/refaster/testdata/output"; private void runTest(String testName) throws IOException { CodeTransformer transformer = extractRefasterRule(forResource(String.format("%s/%s.java", TEMPLATE_DIR, testName))); JavaFileObject input = forResource(String.format("%s/%sExample.java", INPUT_DIR, testName)); JavaFileObject output = forResource(String.format("%s/%sExample.java", OUTPUT_DIR, testName)); expectTransforms(transformer, input, output); } @Test public void keyBindingError() { IllegalArgumentException failure = assertThrows(IllegalArgumentException.class, () -> runTest("KeyBindingErrorTemplate")); assertThat(failure) .hasMessageThat() .matches( "@AfterTemplate of .*\\.KeyBindingErrorTemplate defines arguments that are not present" + " in all @BeforeTemplate methods: \\[b, c\\]"); } @Test public void binary() throws IOException { runTest("BinaryTemplate"); } @Test public void parenthesesOptional() throws IOException { runTest("ParenthesesOptionalTemplate"); } @Test public void multipleReferencesToIdentifier() throws IOException { runTest("MultipleReferencesToIdentifierTemplate"); } @Test public void methodInvocation() throws IOException { runTest("MethodInvocationTemplate"); } @Test public void explicitTypesPreserved() throws IOException { runTest("ExplicitTypesPreservedTemplate"); } @Test public void implicitTypesInlined() throws IOException { runTest("ImplicitTypesInlinedTemplate"); } @Test public void autoboxing() throws IOException { runTest("AutoboxingTemplate"); } @Test public void array() throws IOException { runTest("ArrayTemplate"); } @Test public void precedenceSensitive() throws IOException { runTest("PrecedenceSensitiveTemplate"); } @Test public void staticField() throws IOException { runTest("StaticFieldTemplate"); } @Test public void isInstance() throws IOException { runTest("IsInstanceTemplate"); } @Test public void anyOf() throws IOException { runTest("AnyOfTemplate"); } @Test public void repeated() throws IOException { runTest("VarargTemplate"); } @Test public void ifTemplate() throws IOException { runTest("IfTemplate"); } @Test public void expressionForbidsAllowCodeBetweenLines() throws IOException { IllegalArgumentException ex = assertThrows( IllegalArgumentException.class, () -> runTest("ExpressionForbidsAllowCodeBetweenLinesTemplate")); assertThat(ex).hasMessageThat().contains("@AllowCodeBetweenLines"); assertThat(ex).hasMessageThat().contains("expression templates"); } @Test public void variableDecl() throws IOException { runTest("VariableDeclTemplate"); } @Test public void inferredThis() throws IOException { runTest("InferredThisTemplate"); } @Test public void twoLinesToOne() throws IOException { runTest("TwoLinesToOneTemplate"); } @Test public void oneLineToTwo() throws IOException { runTest("OneLineToTwoTemplate"); } @Test public void tryCatch() throws IOException { runTest("TryTemplate"); } @Test public void tryMultiCatch() throws IOException { runTest("TryMultiCatchTemplate"); } @Test public void wildcard() throws IOException { runTest("WildcardTemplate"); } @Test public void freeIdentWildcardCapture() throws IOException { runTest("WildcardUnificationTemplate"); } @Test public void labeledStatements() throws IOException { runTest("LabelTemplate"); } @Test public void expressionPlaceholder() throws IOException { runTest("PlaceholderTemplate"); } @Test public void expressionPlaceholderAllowsIdentity() throws IOException { runTest("PlaceholderAllowsIdentityTemplate"); } @Test public void voidExpressionPlaceholder() throws IOException { runTest("VoidExpressionPlaceholderTemplate"); } @Test public void blockPlaceholder() throws IOException { runTest("BlockPlaceholderTemplate"); } @Test public void genericPlaceholder() throws IOException { runTest("GenericPlaceholderTemplate"); } @Test public void mayOptionallyUse() throws IOException { runTest("MayOptionallyUseTemplate"); } @Test public void comparisonChain() throws IOException { runTest("ComparisonChainTemplate"); } @Test public void multibound() throws IOException { runTest("MultiBoundTemplate"); } @Test public void topLevel() throws IOException { runTest("TopLevelTemplate"); } @Test public void diamond() throws IOException { runTest("DiamondTemplate"); } @Test public void anonymousClass() throws IOException { runTest("AnonymousClassTemplate"); } @Test public void returnPlaceholder() throws IOException { runTest("ReturnPlaceholderTemplate"); } @Test public void literal() throws IOException { runTest("LiteralTemplate"); } @Test public void importClassDirectly() throws IOException { runTest("ImportClassDirectlyTemplate"); } @Test public void assertions() throws IOException { runTest("AssertTemplate"); } @Test @Ignore("TODO(b/67786978): investigate JDK 9 test failures") public void samePackageImports() throws IOException { runTest("SamePackageImportsTemplate"); } @Test public void ifFallthrough() throws IOException { runTest("IfFallthroughTemplate"); } @Test public void emitCommentBefore() throws IOException { runTest("EmitCommentBeforeTemplate"); } @Test public void emitComment() throws IOException { runTest("EmitCommentTemplate"); } @Test public void nestedClass() throws IOException { runTest("NestedClassTemplate"); } @Test public void inferLambdaType() throws IOException { runTest("InferLambdaType"); } @Test public void lambdaImplicitType() throws IOException { runTest("LambdaImplicitType"); } @Test public void inferLambdaBodyType() throws IOException { runTest("InferLambdaBodyType"); } @Test public void asVarargs() throws IOException { runTest("AsVarargsTemplate"); } @Test public void placeholderAllowedVars() throws IOException { runTest("PlaceholderAllowedVarsTemplate"); } @Test public void unnecessaryLambdaParens() throws IOException { runTest("UnnecessaryLambdaParens"); } @Test public void nonJdkType() throws IOException { runTest("NonJdkTypeTemplate"); } @Test public void staticImportClassToken() throws IOException { runTest("StaticImportClassTokenTemplate"); } @Test public void suppressWarnings() throws IOException { runTest("SuppressWarningsTemplate"); } @Test public void typeArgumentsMethodInvocation() throws IOException { runTest("TypeArgumentsMethodInvocationTemplate"); } }
10,253
26.126984
99
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UBlockTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UBlock}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UBlockTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(UBlock.create()) .addEqualityGroup( UBlock.create( UExpressionStatement.create( UMethodInvocation.create( UStaticIdent.create( "java.lang.System", "exit", UMethodType.create(UPrimitiveType.VOID, UPrimitiveType.INT)), ULiteral.intLit(0))))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UBlock.create( UExpressionStatement.create( UMethodInvocation.create( UStaticIdent.create( "java.lang.System", "exit", UMethodType.create(UPrimitiveType.VOID, UPrimitiveType.INT)), ULiteral.intLit(0))))); } }
1,960
31.147541
89
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/ChoiceTest.java
/* * Copyright 2014 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package com.google.errorprone.refaster; import static com.google.common.truth.Truth.assertThat; import com.google.common.base.Functions; import com.google.common.base.Optional; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@code Choice}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class ChoiceTest { @Test public void none() { assertThat(Choice.none().first()).isAbsent(); assertThat(Choice.none().condition(true)).isSameInstanceAs(Choice.none()); assertThat(Choice.none().condition(Predicates.alwaysTrue())).isSameInstanceAs(Choice.none()); assertThat(Choice.none().thenChoose(Functions.constant(Choice.of("foo")))) .isSameInstanceAs(Choice.none()); } @Test public void thenOption() { assertThat( Choice.from(ImmutableList.of(1, 2, 3)) .thenOption( Functions.forMap( ImmutableMap.of(2, Optional.of("foo")), Optional.<String>absent())) .asIterable()) .containsExactly("foo"); } @Test public void thenChoose() { assertThat( Choice.from(ImmutableList.of(1, 2, 3)) .thenChoose( Functions.forMap(ImmutableMap.of(2, Choice.of("foo")), Choice.<String>none())) .asIterable()) .containsExactly("foo"); } @Test public void or() { assertThat(Choice.of(2).or(Choice.from(ImmutableList.of(1, 3))).asIterable()) .containsExactly(2, 1, 3) .inOrder(); } }
2,331
31.388889
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UArrayTypeTreeTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UArrayTypeTree}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UArrayTypeTreeTest extends AbstractUTreeTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(UArrayTypeTree.create(UPrimitiveTypeTree.INT)) .addEqualityGroup(UArrayTypeTree.create(UClassIdent.create("java.lang.String"))) .addEqualityGroup(UArrayTypeTree.create(UArrayTypeTree.create(UPrimitiveTypeTree.INT))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert(UArrayTypeTree.create(UPrimitiveTypeTree.INT)); } @Test public void inline() { assertInlines("int[]", UArrayTypeTree.create(UPrimitiveTypeTree.INT)); } }
1,613
30.647059
95
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UIntersectionTypeTest.java
/* * Copyright 2014 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UIntersectionType}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UIntersectionTypeTest { @Test public void equality() { new EqualsTester() .addEqualityGroup( UIntersectionType.create( UClassIdent.create("java.lang.CharSequence"), UClassIdent.create("java.io.Serializable"))) .addEqualityGroup( UIntersectionType.create( UClassIdent.create("java.lang.Number"), UClassIdent.create("java.io.Serializable"))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UIntersectionType.create( UClassIdent.create("java.lang.CharSequence"), UClassIdent.create("java.io.Serializable"))); } }
1,671
31.784314
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UParensTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import com.sun.source.tree.Tree.Kind; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UParens}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UParensTest extends AbstractUTreeTest { @Test public void match() { assertUnifies("(5L)", UParens.create(ULiteral.longLit(5L))); } @Test public void inline() { assertInlines("(5L)", UParens.create(ULiteral.longLit(5L))); } @Test public void equality() { new EqualsTester() .addEqualityGroup(UParens.create(ULiteral.longLit(5L))) .addEqualityGroup(UParens.create(ULiteral.intLit(5))) .addEqualityGroup(UParens.create(UUnary.create(Kind.UNARY_MINUS, ULiteral.intLit(5)))) .addEqualityGroup( UParens.create(UBinary.create(Kind.PLUS, ULiteral.intLit(5), ULiteral.intLit(1)))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert(UParens.create(ULiteral.longLit(5L))); } }
1,805
29.610169
94
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/USkipTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link USkip}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class USkipTest { @Test public void serialization() { SerializableTester.reserializeAndAssert(USkip.INSTANCE); } }
1,034
27.75
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UArrayTypeTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UArrayType}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UArrayTypeTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(UArrayType.create(UPrimitiveType.INT)) .addEqualityGroup(UArrayType.create(UClassType.create("java.lang.String"))) .addEqualityGroup(UArrayType.create(UArrayType.create(UPrimitiveType.INT))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UArrayType.create(UClassType.create("java.lang.String"))); SerializableTester.reserializeAndAssert(UArrayType.create(UPrimitiveType.INT)); SerializableTester.reserializeAndAssert( UArrayType.create(UArrayType.create(UPrimitiveType.INT))); } }
1,657
32.16
83
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UWildcardTest.java
/* * Copyright 2014 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import com.sun.source.tree.Tree.Kind; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UWildcard}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UWildcardTest { @Test public void equality() { UExpression objectIdent = UClassIdent.create("java.lang.Object"); UExpression setIdent = UTypeApply.create("java.util.Set", objectIdent); new EqualsTester() .addEqualityGroup(UWildcard.create(Kind.UNBOUNDED_WILDCARD, null)) .addEqualityGroup(UWildcard.create(Kind.EXTENDS_WILDCARD, objectIdent)) .addEqualityGroup(UWildcard.create(Kind.EXTENDS_WILDCARD, setIdent)) // ? extends Set<Object> .addEqualityGroup(UWildcard.create(Kind.SUPER_WILDCARD, setIdent)) // ? super Set<Object> .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UWildcard.create(Kind.EXTENDS_WILDCARD, UClassIdent.create("java.lang.Number"))); } }
1,805
32.444444
89
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/URepeatedTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import static com.google.common.truth.Truth.assertThat; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import com.sun.tools.javac.tree.JCTree.JCExpression; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** Tests for {@link URepeated}. */ @RunWith(JUnit4.class) public class URepeatedTest extends AbstractUTreeTest { @Test public void unifies() { JCExpression expr = parseExpression("\"abcdefg\".charAt(x + 1)"); URepeated ident = URepeated.create("foo", UFreeIdent.create("foo")); assertThat(ident.unify(expr, unifier)).isNotNull(); assertThat(unifier.getBindings()).containsExactly(new UFreeIdent.Key("foo"), expr); } @Test public void equality() { new EqualsTester() .addEqualityGroup(URepeated.create("foo", UFreeIdent.create("foo"))) .addEqualityGroup(URepeated.create("bar", UFreeIdent.create("bar"))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert(URepeated.create("foo", UFreeIdent.create("foo"))); } }
1,771
32.433962
95
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/BindingsTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import static org.junit.Assert.assertThrows; import com.google.common.testing.EqualsTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link Bindings}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class BindingsTest { private static class Key extends Bindings.Key<String> { Key(String identifier) { super(identifier); } } private static class OtherKey extends Bindings.Key<String> { OtherKey(String identifier) { super(identifier); } } @Test public void putRestricts() { assertThrows(ClassCastException.class, () -> Bindings.create().put(new Key("foo"), 3)); } @Test public void keyClassesDistinct() { new EqualsTester() .addEqualityGroup(new Key("foo")) .addEqualityGroup(new Key("bar")) .addEqualityGroup(new OtherKey("foo")) .testEquals(); } }
1,593
26.016949
91
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UBinaryTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import com.sun.source.tree.Tree.Kind; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UBinary}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UBinaryTest extends AbstractUTreeTest { @Test public void plus() { assertUnifiesAndInlines( "4 + 17", UBinary.create(Kind.PLUS, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void minus() { assertUnifiesAndInlines( "4 - 17", UBinary.create(Kind.MINUS, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void times() { assertUnifiesAndInlines( "4 * 17", UBinary.create(Kind.MULTIPLY, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void divide() { assertUnifiesAndInlines( "4 / 17", UBinary.create(Kind.DIVIDE, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void mod() { assertUnifiesAndInlines( "4 % 17", UBinary.create(Kind.REMAINDER, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void lessThan() { assertUnifiesAndInlines( "4 < 17", UBinary.create(Kind.LESS_THAN, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void lessThanOrEqual() { assertUnifiesAndInlines( "4 <= 17", UBinary.create(Kind.LESS_THAN_EQUAL, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void greaterThan() { assertUnifiesAndInlines( "4 > 17", UBinary.create(Kind.GREATER_THAN, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void greaterThanOrEqual() { assertUnifiesAndInlines( "4 >= 17", UBinary.create(Kind.GREATER_THAN_EQUAL, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void equal() { assertUnifiesAndInlines( "4 == 17", UBinary.create(Kind.EQUAL_TO, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void notEqual() { assertUnifiesAndInlines( "4 != 17", UBinary.create(Kind.NOT_EQUAL_TO, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void leftShift() { assertUnifiesAndInlines( "4 << 17", UBinary.create(Kind.LEFT_SHIFT, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void signedRightShift() { assertUnifiesAndInlines( "4 >> 17", UBinary.create(Kind.RIGHT_SHIFT, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void unsignedRightShift() { assertUnifiesAndInlines( "4 >>> 17", UBinary.create(Kind.UNSIGNED_RIGHT_SHIFT, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void bitwiseAnd() { assertUnifiesAndInlines( "4 & 17", UBinary.create(Kind.AND, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void bitwiseOr() { assertUnifiesAndInlines( "4 | 17", UBinary.create(Kind.OR, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void bitwiseXor() { assertUnifiesAndInlines( "4 ^ 17", UBinary.create(Kind.XOR, ULiteral.intLit(4), ULiteral.intLit(17))); } @Test public void conditionalAnd() { assertUnifiesAndInlines( "true && false", UBinary.create( Kind.CONDITIONAL_AND, ULiteral.booleanLit(true), ULiteral.booleanLit(false))); } @Test public void conditionalOr() { assertUnifiesAndInlines( "true || false", UBinary.create(Kind.CONDITIONAL_OR, ULiteral.booleanLit(true), ULiteral.booleanLit(false))); } @Test public void equality() { ULiteral oneLit = ULiteral.intLit(1); ULiteral twoLit = ULiteral.intLit(2); ULiteral piLit = ULiteral.doubleLit(Math.PI); ULiteral trueLit = ULiteral.booleanLit(true); ULiteral falseLit = ULiteral.booleanLit(false); new EqualsTester() .addEqualityGroup(UBinary.create(Kind.PLUS, oneLit, twoLit)) .addEqualityGroup(UBinary.create(Kind.PLUS, oneLit, piLit)) .addEqualityGroup(UBinary.create(Kind.PLUS, piLit, twoLit)) .addEqualityGroup(UBinary.create(Kind.MINUS, oneLit, twoLit)) .addEqualityGroup(UBinary.create(Kind.XOR, oneLit, twoLit)) .addEqualityGroup(UBinary.create(Kind.CONDITIONAL_OR, trueLit, falseLit)) .addEqualityGroup(UBinary.create(Kind.OR, trueLit, falseLit)) .testEquals(); } @Test public void serialization() { ULiteral oneLit = ULiteral.intLit(1); ULiteral twoLit = ULiteral.intLit(2); ULiteral piLit = ULiteral.doubleLit(Math.PI); ULiteral trueLit = ULiteral.booleanLit(true); ULiteral falseLit = ULiteral.booleanLit(false); SerializableTester.reserializeAndAssert(UBinary.create(Kind.PLUS, oneLit, twoLit)); SerializableTester.reserializeAndAssert(UBinary.create(Kind.PLUS, oneLit, piLit)); SerializableTester.reserializeAndAssert(UBinary.create(Kind.PLUS, piLit, twoLit)); SerializableTester.reserializeAndAssert(UBinary.create(Kind.MINUS, oneLit, twoLit)); SerializableTester.reserializeAndAssert(UBinary.create(Kind.XOR, oneLit, twoLit)); SerializableTester.reserializeAndAssert(UBinary.create(Kind.CONDITIONAL_OR, trueLit, falseLit)); SerializableTester.reserializeAndAssert(UBinary.create(Kind.OR, trueLit, falseLit)); } }
5,973
30.776596
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UVariableDeclTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UVariableDecl}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UVariableDeclTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(UVariableDecl.create("foo", UClassIdent.create("java.lang.String"), null)) .addEqualityGroup( UVariableDecl.create( "foo", UClassIdent.create("java.lang.String"), ULiteral.stringLit("bar"))) .addEqualityGroup( UVariableDecl.create("foo", UClassIdent.create("java.lang.Integer"), null)) .addEqualityGroup(UVariableDecl.create("baz", UClassIdent.create("java.lang.String"), null)) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UVariableDecl.create( "foo", UClassIdent.create("java.lang.String"), ULiteral.stringLit("bar"))); } }
1,754
32.75
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UClassIdentTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.collect.ImmutableSet; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import com.sun.tools.javac.code.Symbol.PackageSymbol; import com.sun.tools.javac.code.Symtab; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UClassIdent}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UClassIdentTest extends AbstractUTreeTest { @Test public void equality() throws CouldNotResolveImportException { new EqualsTester() .addEqualityGroup(UClassIdent.create("java.util.List")) .addEqualityGroup(UClassIdent.create("com.sun.tools.javac.util.List")) .addEqualityGroup( UClassIdent.create("java.lang.String"), UClassIdent.create(inliner.resolveClass("java.lang.String"))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert(UClassIdent.create("java.math.BigInteger")); } @Test public void inline() { ImportPolicy.bind(context, ImportPolicy.IMPORT_TOP_LEVEL); context.put(PackageSymbol.class, Symtab.instance(context).rootPackage); assertInlines("List", UClassIdent.create("java.util.List")); assertInlines("Map.Entry", UClassIdent.create("java.util.Map.Entry")); } @Test public void importConflicts() { ImportPolicy.bind(context, ImportPolicy.IMPORT_TOP_LEVEL); context.put(PackageSymbol.class, Symtab.instance(context).rootPackage); // Test fully qualified class names inliner.addImport("package.Exception"); assertInlines("Exception", UClassIdent.create("package.Exception")); // Will import "anotherPackage.Exception" due to conflicts assertInlines("anotherPackage.Exception", UClassIdent.create("anotherPackage.Exception")); new EqualsTester() .addEqualityGroup(inliner.getImportsToAdd(), ImmutableSet.of("package.Exception")) .testEquals(); // Test nested class names inliner.addImport("package.subpackage.Foo.Bar"); // Will import "package.Foo" assertInlines("Foo.Bar", UClassIdent.create("package.Foo.Bar")); assertInlines("Bar", UClassIdent.create("package.subpackage.Foo.Bar")); // Will not import "anotherPackage.Foo" due to conflicts assertInlines("anotherPackage.Foo.Bar", UClassIdent.create("anotherPackage.Foo.Bar")); new EqualsTester() .addEqualityGroup( inliner.getImportsToAdd(), ImmutableSet.of("package.Exception", "package.subpackage.Foo.Bar", "package.Foo")) .testEquals(); } }
3,284
37.647059
94
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UMethodInvocationTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UMethodInvocation}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UMethodInvocationTest extends AbstractUTreeTest { @Test public void match() { UExpression fooIdent = mock(UExpression.class); when(fooIdent.unify(ident("foo"), isA(Unifier.class))).thenReturn(Choice.of(unifier)); ULiteral oneLit = ULiteral.intLit(1); ULiteral barLit = ULiteral.stringLit("bar"); UMethodInvocation invocation = UMethodInvocation.create( ImmutableList.of(), fooIdent, ImmutableList.<UExpression>of(oneLit, barLit)); assertUnifies("foo(1, \"bar\")", invocation); } @Test public void inline() throws CouldNotResolveImportException { UExpression fooIdent = mock(UExpression.class); when(fooIdent.inline(isA(Inliner.class))) .thenReturn(inliner.maker().Ident(inliner.asName("foo"))); ULiteral oneLit = ULiteral.intLit(1); ULiteral barLit = ULiteral.stringLit("bar"); UMethodInvocation invocation = UMethodInvocation.create(fooIdent, oneLit, barLit); assertInlines("foo(1, \"bar\")", invocation); } @Test public void equality() { UMethodType indexOfIntTy = UMethodType.create(UPrimitiveType.INT, UPrimitiveType.INT); UExpression fooLit = ULiteral.stringLit("foo"); UType isEmptyTy = UMethodType.create(UPrimitiveType.BOOLEAN, ImmutableList.<UType>of()); new EqualsTester() .addEqualityGroup( UMethodInvocation.create( UMemberSelect.create(fooLit, "indexOf", indexOfIntTy), ULiteral.charLit('a'))) .addEqualityGroup( UMethodInvocation.create( UMemberSelect.create(fooLit, "indexOf", indexOfIntTy), ULiteral.charLit('b'))) .addEqualityGroup( UMethodInvocation.create(UMemberSelect.create(fooLit, "isEmpty", isEmptyTy))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UMethodInvocation.create( UMemberSelect.create( ULiteral.stringLit("foo"), "indexOf", UMethodType.create(UPrimitiveType.INT, UPrimitiveType.INT)), ULiteral.charLit('a'))); } }
3,253
35.561798
94
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UForAllTest.java
/* * Copyright 2013 The Error Prone Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.errorprone.refaster; import com.google.common.collect.ImmutableList; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import javax.lang.model.type.TypeKind; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UForAll}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UForAllTest { @Test public void equality() { UType objectType = UClassType.create("java.lang.Object", ImmutableList.<UType>of()); UTypeVar eType = UTypeVar.create("E", objectType); UTypeVar tType = UTypeVar.create("T", objectType); UType listOfEType = UClassType.create("java.util.List", ImmutableList.<UType>of(eType)); new EqualsTester() .addEqualityGroup(UForAll.create(ImmutableList.of(eType), eType)) // <E> E .addEqualityGroup(UForAll.create(ImmutableList.of(eType), listOfEType)) // <E> List<E> .addEqualityGroup(UForAll.create(ImmutableList.of(tType), tType)) // <T> T .testEquals(); } @Test public void serialization() { UType nullType = UPrimitiveType.create(TypeKind.NULL); UType objectType = UClassType.create("java.lang.Object", ImmutableList.<UType>of()); UTypeVar eType = UTypeVar.create("E", nullType, objectType); UType listOfEType = UClassType.create("java.util.List", ImmutableList.<UType>of(eType)); SerializableTester.reserializeAndAssert(UForAll.create(ImmutableList.of(eType), listOfEType)); } }
2,155
37.5
98
java