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/refaster/UAnnotationTest.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 UAnnotation}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UAnnotationTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(UAnnotation.create(UClassIdent.create("java.lang.Override"))) .addEqualityGroup(UAnnotation.create(UClassIdent.create("java.lang.Deprecated"))) .addEqualityGroup( UAnnotation.create( UClassIdent.create("java.lang.SuppressWarnings"), ULiteral.stringLit("cast"))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UAnnotation.create( UClassIdent.create("java.lang.SuppressWarnings"), ULiteral.stringLit("cast"))); } }
1,615
31.32
94
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UTypeVarIdentTest.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.collect.ImmutableSet; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import com.google.errorprone.refaster.UTypeVar.TypeWithExpression; import com.sun.tools.javac.code.Symtab; import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type.ClassType; import com.sun.tools.javac.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UTypeVarIdent}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UTypeVarIdentTest extends AbstractUTreeTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(UTypeVarIdent.create("E")) .addEqualityGroup(UTypeVarIdent.create("T")) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert(UTypeVarIdent.create("E")); } @Test public void inline() { ImportPolicy.bind(context, ImportPolicy.IMPORT_TOP_LEVEL); Symtab symtab = Symtab.instance(context); Type listType = symtab.listType; bind( new UTypeVar.Key("E"), TypeWithExpression.create( new ClassType(listType, List.<Type>of(symtab.stringType), listType.tsym))); assertInlines("List<String>", UTypeVarIdent.create("E")); assertThat(inliner.getImportsToAdd()).isEqualTo(ImmutableSet.of("java.util.List")); } }
2,159
31.727273
87
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UMethodTypeTest.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 UMethodType}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UMethodTypeTest { @Test public void equality() { UType stringTy = UClassType.create("java.lang.String"); new EqualsTester() .addEqualityGroup(UMethodType.create(stringTy, UPrimitiveType.INT)) .addEqualityGroup(UMethodType.create(stringTy, UPrimitiveType.INT, UPrimitiveType.INT)) .addEqualityGroup(UMethodType.create(UPrimitiveType.INT, UPrimitiveType.INT)) .addEqualityGroup(UMethodType.create(stringTy, stringTy)) .addEqualityGroup(UMethodType.create(stringTy)) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UMethodType.create(UClassType.create("java.lang.String"), UPrimitiveType.INT)); } }
1,691
32.84
95
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UUnaryTest.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 static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import com.google.common.testing.EqualsTester; import com.google.common.testing.SerializableTester; import com.sun.source.tree.Tree.Kind; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UUnary}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UUnaryTest extends AbstractUTreeTest { UExpression fooIdent; @Before public void initializeFooIdentifier() throws CouldNotResolveImportException { fooIdent = mock(UExpression.class); when(fooIdent.unify(ident("foo"), isA(Unifier.class))).thenReturn(Choice.of(unifier)); when(fooIdent.inline(isA(Inliner.class))) .thenReturn(inliner.maker().Ident(inliner.asName("foo"))); } @Test public void rejectsNonUnaryOperations() { ULiteral sevenLit = ULiteral.intLit(7); assertThrows(IllegalArgumentException.class, () -> UUnary.create(Kind.PLUS, sevenLit)); } @Test public void complement() { assertUnifiesAndInlines("~7", UUnary.create(Kind.BITWISE_COMPLEMENT, ULiteral.intLit(7))); } @Test public void logicalNegation() { assertUnifiesAndInlines( "!false", UUnary.create(Kind.LOGICAL_COMPLEMENT, ULiteral.booleanLit(false))); } @Test public void unaryPlus() { assertUnifiesAndInlines("+foo", UUnary.create(Kind.UNARY_PLUS, fooIdent)); } @Test public void unaryNegation() { assertUnifiesAndInlines("-foo", UUnary.create(Kind.UNARY_MINUS, fooIdent)); } @Test public void preIncrement() { assertUnifiesAndInlines("++foo", UUnary.create(Kind.PREFIX_INCREMENT, fooIdent)); } @Test public void postIncrement() { assertUnifiesAndInlines("foo++", UUnary.create(Kind.POSTFIX_INCREMENT, fooIdent)); } @Test public void preDecrement() { assertUnifiesAndInlines("--foo", UUnary.create(Kind.PREFIX_DECREMENT, fooIdent)); } @Test public void postDecrement() { assertUnifiesAndInlines("foo--", UUnary.create(Kind.POSTFIX_DECREMENT, fooIdent)); } @Test public void equality() { ULiteral sevenLit = ULiteral.intLit(7); ULiteral threeLit = ULiteral.intLit(3); ULiteral falseLit = ULiteral.booleanLit(false); new EqualsTester() .addEqualityGroup(UUnary.create(Kind.UNARY_MINUS, sevenLit)) .addEqualityGroup(UUnary.create(Kind.UNARY_MINUS, threeLit)) .addEqualityGroup(UUnary.create(Kind.BITWISE_COMPLEMENT, sevenLit)) .addEqualityGroup(UUnary.create(Kind.LOGICAL_COMPLEMENT, falseLit)) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UUnary.create(Kind.BITWISE_COMPLEMENT, ULiteral.intLit(7))); } }
3,541
29.8
94
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/USynchronizedTest.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 USynchronized}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class USynchronizedTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(USynchronized.create(UFreeIdent.create("foo"), UBlock.create())) .addEqualityGroup(USynchronized.create(UFreeIdent.create("bar"), UBlock.create())) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( USynchronized.create(UFreeIdent.create("foo"), UBlock.create())); } }
1,423
29.956522
90
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/ULocalVarIdentTest.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 ULocalVarIdent}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class ULocalVarIdentTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(ULocalVarIdent.create("foo")) .addEqualityGroup(ULocalVarIdent.create("bar")) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert(ULocalVarIdent.create("foo")); } }
1,311
28.155556
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UAssignTest.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 UAssign}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UAssignTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(UAssign.create(UFreeIdent.create("foo"), ULiteral.intLit(5))) .addEqualityGroup(UAssign.create(UFreeIdent.create("bar"), ULiteral.intLit(5))) .addEqualityGroup(UAssign.create(UFreeIdent.create("foo"), ULiteral.intLit(20))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UAssign.create(UFreeIdent.create("foo"), ULiteral.intLit(5))); } }
1,491
30.744681
88
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UTypeCastTest.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 UTypeCast}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UTypeCastTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(UTypeCast.create(UPrimitiveTypeTree.BYTE, ULiteral.intLit(100))) .addEqualityGroup(UTypeCast.create(UPrimitiveTypeTree.BYTE, ULiteral.intLit(150))) .addEqualityGroup(UTypeCast.create(UPrimitiveTypeTree.CHAR, ULiteral.intLit(100))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UTypeCast.create(UPrimitiveTypeTree.BYTE, ULiteral.intLit(100))); } }
1,506
31.06383
90
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/ULiteralTest.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.source.tree.Tree.Kind; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link ULiteral}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class ULiteralTest extends AbstractUTreeTest { @Test public void nullLiteral() { ULiteral lit = ULiteral.nullLit(); assertUnifiesAndInlines("null", lit); assertThat(lit.getKind()).isEqualTo(Kind.NULL_LITERAL); } @Test public void stringLiteral() { ULiteral lit = ULiteral.stringLit("foo"); assertUnifiesAndInlines("\"foo\"", lit); assertThat(lit.getKind()).isEqualTo(Kind.STRING_LITERAL); } @Test public void intLiteral() { ULiteral lit = ULiteral.intLit(123); assertUnifiesAndInlines("123", lit); assertThat(lit.getKind()).isEqualTo(Kind.INT_LITERAL); } @Test public void longLiteral() { ULiteral lit = ULiteral.longLit(123L); assertUnifiesAndInlines("123L", lit); assertThat(lit.getKind()).isEqualTo(Kind.LONG_LITERAL); } @Test public void charLiteral() { ULiteral lit = ULiteral.create(Kind.CHAR_LITERAL, '%'); assertUnifiesAndInlines("'%'", lit); assertThat(lit.getKind()).isEqualTo(Kind.CHAR_LITERAL); } @Test public void doubleLiteral() { ULiteral lit = ULiteral.doubleLit(1.23); assertUnifiesAndInlines("1.23", lit); assertThat(lit.getKind()).isEqualTo(Kind.DOUBLE_LITERAL); } @Test public void floatLiteral() { ULiteral lit = ULiteral.floatLit(1.23F); assertUnifiesAndInlines("1.23F", lit); assertThat(lit.getKind()).isEqualTo(Kind.FLOAT_LITERAL); } @Test public void booleanLiteral() { ULiteral lit = ULiteral.booleanLit(false); assertUnifiesAndInlines("false", lit); assertThat(lit.getKind()).isEqualTo(Kind.BOOLEAN_LITERAL); } @Test public void equality() { new EqualsTester() .addEqualityGroup(ULiteral.intLit(1)) .addEqualityGroup(ULiteral.intLit(2)) .addEqualityGroup(ULiteral.longLit(1L)) .addEqualityGroup(ULiteral.doubleLit(1.0)) .addEqualityGroup(ULiteral.stringLit("foo")) .addEqualityGroup(ULiteral.nullLit()) .addEqualityGroup(ULiteral.charLit('0')) .addEqualityGroup(ULiteral.intLit('0')) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert(ULiteral.intLit(1)); SerializableTester.reserializeAndAssert(ULiteral.longLit(1L)); SerializableTester.reserializeAndAssert(ULiteral.doubleLit(1.0)); SerializableTester.reserializeAndAssert(ULiteral.floatLit(1.0f)); SerializableTester.reserializeAndAssert(ULiteral.stringLit("foo")); SerializableTester.reserializeAndAssert(ULiteral.nullLit()); SerializableTester.reserializeAndAssert(ULiteral.booleanLit(true)); SerializableTester.reserializeAndAssert(ULiteral.charLit('0')); } }
3,712
30.735043
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/CompilerBasedTest.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.collect.ImmutableMap; import com.google.common.io.CharStreams; import com.google.errorprone.FileManagers; import com.google.errorprone.apply.SourceFile; import com.google.testing.compile.JavaFileObjects; import com.sun.source.tree.CompilationUnitTree; import com.sun.tools.javac.api.JavacTaskImpl; import com.sun.tools.javac.api.JavacTool; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.tree.JCTree.JCMethodDecl; import com.sun.tools.javac.tree.TreeInfo; import com.sun.tools.javac.tree.TreeScanner; import com.sun.tools.javac.util.Context; import java.io.IOException; import javax.tools.DiagnosticCollector; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.StandardJavaFileManager; /** * Abstract skeleton for tests that run the compiler on the fly. * * @author lowasser@google.com (Louis Wasserman) */ public class CompilerBasedTest { protected Context context; protected SourceFile sourceFile; protected ImmutableList<JCCompilationUnit> compilationUnits; private ImmutableMap<String, JCMethodDecl> methods; protected void compile(TreeScanner scanner, JavaFileObject fileObject) { 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(fileObject)); try { this.sourceFile = SourceFile.create(fileObject); Iterable<? extends CompilationUnitTree> trees = task.parse(); task.analyze(); for (CompilationUnitTree tree : trees) { scanner.scan((JCCompilationUnit) tree); } } catch (IOException e) { throw new RuntimeException(e); } this.context = task.getContext(); } protected void compile(TreeScanner scanner, String... lines) { compile(scanner, JavaFileObjects.forSourceLines("CompilerBasedTestInput", lines)); } protected void compile(JavaFileObject fileObject) { ImmutableMap.Builder<String, JCMethodDecl> methodsBuilder = ImmutableMap.builder(); ImmutableList.Builder<JCCompilationUnit> compilationUnitsBuilder = ImmutableList.builder(); compile( new TreeScanner() { @Override public void visitMethodDef(JCMethodDecl tree) { if (!TreeInfo.isConstructor(tree)) { methodsBuilder.put(tree.getName().toString(), tree); } } @Override public void visitTopLevel(JCCompilationUnit tree) { compilationUnitsBuilder.add(tree); super.visitTopLevel(tree); } }, fileObject); this.methods = methodsBuilder.buildOrThrow(); this.compilationUnits = compilationUnitsBuilder.build(); } protected void compile(String... lines) { compile(JavaFileObjects.forSourceLines("CompilerBasedTestInput", lines)); } protected JCMethodDecl getMethodDeclaration(String name) { return methods.get(name); } }
3,994
34.990991
95
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/TemplatingTest.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.collect.ImmutableClassToInstanceMap; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.sun.source.tree.Tree.Kind; import com.sun.tools.javac.code.BoundKind; import com.sun.tools.javac.code.Flags; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link UTemplater#createTemplate} against real compiled code. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class TemplatingTest extends CompilerBasedTest { @Test public void arrayAccess() { compile( "class ArrayAccessExample {", " public double example(double[] array) {", " return array[5];", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( ImmutableMap.of("array", UArrayType.create(UPrimitiveType.DOUBLE)), UArrayAccess.create(UFreeIdent.create("array"), ULiteral.intLit(5)), UPrimitiveType.DOUBLE)); } @Test public void binary() { compile( "class BinaryExample {", " public int example(int x, int y) {", " return (x + y) / 2;", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( ImmutableMap.of( "x", UPrimitiveType.INT, "y", UPrimitiveType.INT), UBinary.create( Kind.DIVIDE, UParens.create( UBinary.create(Kind.PLUS, UFreeIdent.create("x"), UFreeIdent.create("y"))), ULiteral.intLit(2)), UPrimitiveType.INT)); } @Test public void conditional() { compile( "class ConditionalExample {", " public String example(boolean foo) {", " return foo ? null : \"bar\";", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( ImmutableMap.of("foo", UPrimitiveType.BOOLEAN), UConditional.create( UFreeIdent.create("foo"), ULiteral.nullLit(), ULiteral.stringLit("bar")), UClassType.create("java.lang.String"))); } @Test public void whileLoop() { compile( "import java.util.Iterator;", "class WhileLoopExample {", " public void example(Iterator<?> itr) {", " while (itr.hasNext()) {", " itr.next();", " }", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( BlockTemplate.create( ImmutableMap.of( "itr", UClassType.create("java.util.Iterator", UWildcardType.create())), UWhileLoop.create( UParens.create( UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("itr"), "hasNext", UMethodType.create(UPrimitiveType.BOOLEAN)))), UBlock.create( UExpressionStatement.create( UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("itr"), "next", UMethodType.create(UTypeVar.create("E"))))))))); } @Test public void fullyQualifiedGlobalIdent() { compile( "class FullyQualifiedIdentExample {", " public java.math.RoundingMode example() {", " return java.math.RoundingMode.FLOOR;", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( UStaticIdent.create( "java.math.RoundingMode", "FLOOR", UClassType.create("java.math.RoundingMode")), UClassType.create("java.math.RoundingMode"))); } @Test public void qualifiedGlobalIdent() { compile( "import java.math.RoundingMode;", "class QualifiedIdentExample {", " public RoundingMode example() {", " return RoundingMode.FLOOR;", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( UStaticIdent.create( "java.math.RoundingMode", "FLOOR", UClassType.create("java.math.RoundingMode")), UClassType.create("java.math.RoundingMode"))); } @Test public void staticImportedGlobalIdent() { compile( "import java.math.RoundingMode;", "import static java.math.RoundingMode.FLOOR;", "class StaticImportedIdentExample {", " public RoundingMode example() {", " return FLOOR;", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( UStaticIdent.create( "java.math.RoundingMode", "FLOOR", UClassType.create("java.math.RoundingMode")), UClassType.create("java.math.RoundingMode"))); } @Test public void staticMethodInvocation() { compile( "import java.math.BigInteger;", "class StaticMethodExample {", " public BigInteger example(int x) {", " return BigInteger.valueOf(x);", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( 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"))); } @Test public void instanceMethodInvocation() { compile( "class InstanceMethodExample {", " public char example(String str) {", " return str.charAt(5);", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( ImmutableMap.of("str", UClassType.create("java.lang.String")), UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("str"), "charAt", UMethodType.create(UPrimitiveType.CHAR, UPrimitiveType.INT)), ULiteral.intLit(5)), UPrimitiveType.CHAR)); } @Test public void anyOf() { compile( "import com.google.errorprone.refaster.Refaster;", "class InstanceMethodExample {", " public char example(String str) {", " return str.charAt(Refaster.anyOf(1, 3, 5));", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( ImmutableMap.of("str", UClassType.create("java.lang.String")), UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("str"), "charAt", UMethodType.create(UPrimitiveType.CHAR, UPrimitiveType.INT)), UAnyOf.create(ULiteral.intLit(1), ULiteral.intLit(3), ULiteral.intLit(5))), UPrimitiveType.CHAR)); } @Test public void unary() { compile( "import java.util.Arrays;", "class UnaryExample {", " public int example(int[] array, int key) {", " return ~Arrays.binarySearch(array, key);", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( ImmutableMap.of( "array", UArrayType.create(UPrimitiveType.INT), "key", UPrimitiveType.INT), UUnary.create( Kind.BITWISE_COMPLEMENT, UMethodInvocation.create( UStaticIdent.create( "java.util.Arrays", "binarySearch", UMethodType.create( UPrimitiveType.INT, UArrayType.create(UPrimitiveType.INT), UPrimitiveType.INT)), UFreeIdent.create("array"), UFreeIdent.create("key"))), UPrimitiveType.INT)); } @Test public void genericTemplate() { compile( "import java.util.List;", "class GenericTemplateExample {", " public <E> E example(List<E> list) {", " return list.get(0);", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( ImmutableClassToInstanceMap.of(), ImmutableList.of(UTypeVar.create("E")), ImmutableMap.of("list", UClassType.create("java.util.List", UTypeVar.create("E"))), UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("list"), "get", UMethodType.create(UTypeVar.create("E"), UPrimitiveType.INT)), ULiteral.intLit(0)), UTypeVar.create("E"))); } @Test public void genericMethodInvocation() { compile( "import java.util.Collections;", "import java.util.List;", "class GenericTemplateExample {", " public <E> List<E> example(List<E> list) {", " return Collections.unmodifiableList(list);", " }", "}"); UTypeVar tVar = UTypeVar.create("T"); UTypeVar eVar = UTypeVar.create("E"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( 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))); } @Test public void doWhile() { compile( "class DoWhileExample {", " public void example(String str) {", " int old = 0;", " do {", " old = str.indexOf(' ', old + 1);", " } while (old != -1);", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( BlockTemplate.create( ImmutableMap.of("str", UClassType.create("java.lang.String")), UVariableDecl.create("old", UPrimitiveTypeTree.INT, ULiteral.intLit(0)), UDoWhileLoop.create( UBlock.create( UExpressionStatement.create( UAssign.create( ULocalVarIdent.create("old"), UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("str"), "indexOf", UMethodType.create( UPrimitiveType.INT, UPrimitiveType.INT, UPrimitiveType.INT)), ULiteral.charLit(' '), UBinary.create( Kind.PLUS, ULocalVarIdent.create("old"), ULiteral.intLit(1)))))), UParens.create( UBinary.create( Kind.NOT_EQUAL_TO, ULocalVarIdent.create("old"), ULiteral.intLit(-1)))))); } @Test public void voidReturn() { compile( "import java.security.MessageDigest;", "class VoidExample {", " public void example(MessageDigest md, byte[] bytes) {", " md.update(bytes);", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( BlockTemplate.create( ImmutableMap.of( "md", UClassType.create("java.security.MessageDigest"), "bytes", UArrayType.create(UPrimitiveType.BYTE)), UExpressionStatement.create( UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("md"), "update", UMethodType.create( UPrimitiveType.VOID, UArrayType.create(UPrimitiveType.BYTE))), UFreeIdent.create("bytes"))))); } @Test public void arrayCast() { compile( "class ArrayCastExample {", " public String[] example(Object o) {", " return (String[]) o;", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( ImmutableMap.of("o", UClassType.create("java.lang.Object")), UTypeCast.create( UArrayTypeTree.create(UClassIdent.create("java.lang.String")), UFreeIdent.create("o")), UArrayType.create(UClassType.create("java.lang.String")))); } @Test public void primitiveCast() { compile( "class PrimitiveCastExample {", " public char example(int x) {", " return (char) x;", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( ImmutableMap.of("x", UPrimitiveType.INT), UTypeCast.create(UPrimitiveTypeTree.CHAR, UFreeIdent.create("x")), UPrimitiveType.CHAR)); } @Test public void objectCast() { compile( "class ObjectCastExample {", " public String example(Object o) {", " return (String) o;", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( ImmutableMap.of("o", UClassType.create("java.lang.Object")), UTypeCast.create(UClassIdent.create("java.lang.String"), UFreeIdent.create("o")), UClassType.create("java.lang.String"))); } @Test public void constructor() { compile( "import java.util.ArrayList;", "class ConstructorExample {", " public String example() {", " return new String(\"foo\");", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( UNewClass.create(UClassIdent.create("java.lang.String"), ULiteral.stringLit("foo")), UClassType.create("java.lang.String"))); } @Test public void forLoop() { compile( "class ForLoopExample {", " public void example(int from, int to) {", " for (int i = from; i < to; i++) {", " }", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( BlockTemplate.create( ImmutableMap.of( "from", UPrimitiveType.INT, "to", UPrimitiveType.INT), 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()))); } @Test public void forLoopNoStep() { compile( "class ForLoopExample {", " public void example(int from, int to) {", " for (int i = from; i < to;) {", " }", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( BlockTemplate.create( ImmutableMap.of( "from", UPrimitiveType.INT, "to", UPrimitiveType.INT), 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()))); } @Test public void forLoopNoCondition() { compile( "class ForLoopExample {", " public void example(int from, int to) {", " for (int i = from; ; i++) {", " }", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( BlockTemplate.create( ImmutableMap.of( "from", UPrimitiveType.INT, "to", UPrimitiveType.INT), UForLoop.create( ImmutableList.of( UVariableDecl.create( "i", UPrimitiveTypeTree.INT, UFreeIdent.create("from"))), null, ImmutableList.of( UExpressionStatement.create( UUnary.create(Kind.POSTFIX_INCREMENT, ULocalVarIdent.create("i")))), UBlock.create()))); } @Test public void forLoopNoStart() { compile( "class ForLoopExample {", " public void example(int from, int to) {", " for (; from < to; from++) {", " }", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( BlockTemplate.create( ImmutableMap.of( "from", UPrimitiveType.INT, "to", UPrimitiveType.INT), UForLoop.create( ImmutableList.<UStatement>of(), UBinary.create( Kind.LESS_THAN, UFreeIdent.create("from"), UFreeIdent.create("to")), ImmutableList.of( UExpressionStatement.create( UUnary.create(Kind.POSTFIX_INCREMENT, UFreeIdent.create("from")))), UBlock.create()))); } @Test public void parameterizedCast() { compile( "import java.util.Collection;", "import java.util.List;", "class ParameterizedCastExample {", " public List<String> example(Collection<String> elements) {", " return (List<String>) elements;", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( ImmutableMap.of( "elements", UClassType.create( "java.util.Collection", UClassType.create("java.lang.String"))), UTypeCast.create( UTypeApply.create( UClassIdent.create("java.util.List"), UClassIdent.create("java.lang.String")), UFreeIdent.create("elements")), UClassType.create("java.util.List", UClassType.create("java.lang.String")))); } @Test public void instanceOf() { compile( "class InstanceOfExample {", " public boolean example(Object foo) {", " return foo instanceof CharSequence;", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( ImmutableMap.of("foo", UClassType.create("java.lang.Object")), UInstanceOf.create( UFreeIdent.create("foo"), UClassIdent.create("java.lang.CharSequence")), UPrimitiveType.BOOLEAN)); } @Test public void assignment() { compile( "class AssignmentExample {", " public String example(String foo) {", " return foo = \"bar\";", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( ExpressionTemplate.create( ImmutableMap.of("foo", UClassType.create("java.lang.String")), UAssign.create(UFreeIdent.create("foo"), ULiteral.stringLit("bar")), UClassType.create("java.lang.String"))); } @Test public void recursiveTypes() { compile( "class RecursiveTypeExample {", " public <E extends Enum<E>> E example(E e) {", " return e;", " }", "}"); Template<?> template = UTemplater.createTemplate(context, getMethodDeclaration("example")); UTypeVar eVar = Iterables.getOnlyElement(template.templateTypeVariables()); assertThat(template) .isEqualTo( ExpressionTemplate.create( ImmutableClassToInstanceMap.of(), ImmutableList.of(UTypeVar.create("E", UClassType.create("java.lang.Enum", eVar))), ImmutableMap.of("e", eVar), UFreeIdent.create("e"), eVar)); } @Test public void localVariable() { compile( "import java.util.ArrayList;", "import java.util.Comparator;", "import java.util.Collection;", "import java.util.Collections;", "import java.util.List;", "class LocalVariableExample {", " public <E> void example(Collection<E> collection, Comparator<? super E> comparator) {", " List<E> list = new ArrayList<E>(collection);", " Collections.sort(list, comparator);", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( BlockTemplate.create( ImmutableList.of(UTypeVar.create("E")), ImmutableMap.of( "collection", UClassType.create("java.util.Collection", UTypeVar.create("E")), "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"))))); } @Test public void throwException() { compile( "class ThrowExceptionExample {", " public void example() {", " throw new IllegalArgumentException();", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( BlockTemplate.create( UThrow.create( UNewClass.create(UClassIdent.create("java.lang.IllegalArgumentException"))))); } @Test public void forEach() { compile( "class ForEachExample {", " public void example(int[] array) {", " int sum = 0;", " for (int value : array) {", " sum += value;", " }", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( BlockTemplate.create( ImmutableMap.of("array", UArrayType.create(UPrimitiveType.INT)), UVariableDecl.create("sum", UPrimitiveTypeTree.INT, ULiteral.intLit(0)), UEnhancedForLoop.create( UVariableDecl.create("value", UPrimitiveTypeTree.INT), UFreeIdent.create("array"), UBlock.create( UExpressionStatement.create( UAssignOp.create( ULocalVarIdent.create("sum"), Kind.PLUS_ASSIGNMENT, ULocalVarIdent.create("value"))))))); } @Test public void synchronizd() { compile( "class SynchronizedExample {", " public void example(int[] array) {", " int sum = 0;", " synchronized (array) {", " for (int value : array) {", " sum += value;", " }", " }", " }", "}"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( BlockTemplate.create( ImmutableMap.of("array", UArrayType.create(UPrimitiveType.INT)), UVariableDecl.create("sum", UPrimitiveTypeTree.INT, ULiteral.intLit(0)), USynchronized.create( UParens.create(UFreeIdent.create("array")), UBlock.create( UEnhancedForLoop.create( UVariableDecl.create("value", UPrimitiveTypeTree.INT), UFreeIdent.create("array"), UBlock.create( UExpressionStatement.create( UAssignOp.create( ULocalVarIdent.create("sum"), Kind.PLUS_ASSIGNMENT, ULocalVarIdent.create("value"))))))))); } @Test public void anonymousClass() { compile( "import java.util.Collections;", "import java.util.Comparator;", "import java.util.List;", "class AnonymousClassExample {", " public void example(List<String> list) {", " Collections.sort(list, new Comparator<String>() {", " @Override public int compare(String a, String b) {", " return a.compareTo(b);", " }", " });", " }", "}"); UTypeVar tVar = UTypeVar.create("T"); assertThat(UTemplater.createTemplate(context, getMethodDeclaration("example"))) .isEqualTo( BlockTemplate.create( ImmutableMap.of( "list", UClassType.create("java.util.List", UClassType.create("java.lang.String"))), UExpressionStatement.create( UMethodInvocation.create( UStaticIdent.create( "java.util.Collections", "sort", UForAll.create( ImmutableList.of(tVar), UMethodType.create( UPrimitiveType.VOID, UClassType.create("java.util.List", tVar), UClassType.create( "java.util.Comparator", UWildcardType.create(BoundKind.SUPER, tVar))))), UFreeIdent.create("list"), UNewClass.create( null, ImmutableList.<UExpression>of(), UTypeApply.create( "java.util.Comparator", UClassIdent.create("java.lang.String")), ImmutableList.<UExpression>of(), UClassDecl.create( UMethodDecl.create( UModifiers.create( Flags.PUBLIC, UAnnotation.create( UClassIdent.create("java.lang.Override"))), "compare", UPrimitiveTypeTree.INT, ImmutableList.of( UVariableDecl.create( "a", UClassIdent.create("java.lang.String")), UVariableDecl.create( "b", UClassIdent.create("java.lang.String"))), ImmutableList.<UExpression>of(), UBlock.create( UReturn.create( UMethodInvocation.create( UMemberSelect.create( ULocalVarIdent.create("a"), "compareTo", UMethodType.create( UPrimitiveType.INT, UClassType.create("java.lang.String"))), ULocalVarIdent.create("b"))))))))))); } }
33,308
38.986795
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UThrowTest.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 UThrow}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UThrowTest { @Test public void equality() { new EqualsTester() .addEqualityGroup( UThrow.create( UNewClass.create(UClassIdent.create("java.lang.IllegalArgumentException")))) .addEqualityGroup( UThrow.create(UNewClass.create(UClassIdent.create("java.lang.IllegalStateException")))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UThrow.create(UNewClass.create(UClassIdent.create("java.lang.IllegalArgumentException")))); } }
1,527
30.183673
99
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UFreeIdentTest.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 UFreeIdent}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UFreeIdentTest extends AbstractUTreeTest { @Test public void inlinesExpression() { bind(new UFreeIdent.Key("foo"), parseExpression("\"abcdefg\".charAt(x + 1)")); assertInlines( parseExpression("\"abcdefg\".charAt(x + 1)").toString(), UFreeIdent.create("foo")); } @Test public void binds() { JCExpression expr = parseExpression("\"abcdefg\".charAt(x + 1)"); UFreeIdent ident = 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(UFreeIdent.create("foo")) .addEqualityGroup(UFreeIdent.create("bar")) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert(UFreeIdent.create("foo")); } }
1,970
30.285714
91
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UTypeApplyTest.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 UTypeApply}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UTypeApplyTest extends AbstractUTreeTest { @Test public void equality() { new EqualsTester() .addEqualityGroup( UTypeApply.create( UClassIdent.create("java.util.List"), UClassIdent.create("java.lang.String"))) .addEqualityGroup( UTypeApply.create( UClassIdent.create("java.util.Set"), UClassIdent.create("java.lang.String"))) .addEqualityGroup( UTypeApply.create( UClassIdent.create("java.util.List"), UClassIdent.create("java.lang.Integer"))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UTypeApply.create( UClassIdent.create("java.util.List"), UClassIdent.create("java.lang.String"))); } @Test public void inline() { ImportPolicy.bind(context, ImportPolicy.IMPORT_TOP_LEVEL); assertInlines( "List<String>", UTypeApply.create( UClassIdent.create("java.util.List"), UClassIdent.create("java.lang.String"))); } }
2,028
31.206349
95
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UExpressionStatementTest.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 UExpressionStatement} * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UExpressionStatementTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(UExpressionStatement.create(UFreeIdent.create("foo"))) .addEqualityGroup( UExpressionStatement.create( UBinary.create(Kind.PLUS, ULiteral.intLit(5), ULiteral.intLit(2)))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UExpressionStatement.create( UBinary.create(Kind.PLUS, ULiteral.intLit(5), ULiteral.intLit(2)))); } }
1,569
30.4
83
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UReturnTest.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 UReturn}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UReturnTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(UReturn.create(ULiteral.stringLit("foo"))) .addEqualityGroup(UReturn.create(ULiteral.intLit(5))) .addEqualityGroup(UReturn.create(null)) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert(UReturn.create(ULiteral.stringLit("foo"))); } }
1,377
28.956522
87
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UInstanceOfTest.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 UInstanceOf}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UInstanceOfTest { @Test public void equality() { new EqualsTester() .addEqualityGroup( UInstanceOf.create(UFreeIdent.create("o"), UClassIdent.create("java.lang.String"))) .addEqualityGroup( UInstanceOf.create(UFreeIdent.create("o"), UClassIdent.create("java.lang.Integer"))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UInstanceOf.create(UFreeIdent.create("o"), UClassIdent.create("java.lang.String"))); } }
1,503
30.333333
96
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/RefasterRuleTest.java
/* * Copyright 2015 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 org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** Tests for {@code RefasterRule}. */ @RunWith(JUnit4.class) public final class RefasterRuleTest { @Test public void fromSecondLevel() { assertThat( RefasterRule.fromSecondLevel( "com.google.devtools.javatools.refactory.refaster.cleanups.MergeNestedIf")) .isEqualTo("MergeNestedIf"); assertThat( RefasterRule.fromSecondLevel( "com.google.devtools.javatools.refactory.refaster.cleanups.HashingShortcuts.HashEntireByteArray")) .isEqualTo("HashEntireByteArray"); assertThat( RefasterRule.fromSecondLevel( "com.google.devtools.javatools.refactory.refaster.cleanups.PrimitiveComparisons.Compare.Ints")) .isEqualTo("Compare_Ints"); } }
1,552
34.295455
114
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UDoWhileLoopTest.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 UDoWhileLoop}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UDoWhileLoopTest extends AbstractUTreeTest { @Test public void equality() { new EqualsTester() .addEqualityGroup( UDoWhileLoop.create( UBlock.create( UExpressionStatement.create( UAssign.create( ULocalVarIdent.create("old"), UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("str"), "indexOf", UMethodType.create( UPrimitiveType.INT, UPrimitiveType.INT, UPrimitiveType.INT)), ULiteral.charLit(' '), UBinary.create( Kind.PLUS, ULocalVarIdent.create("old"), ULiteral.intLit(1)))))), UParens.create( UBinary.create( Kind.NOT_EQUAL_TO, ULocalVarIdent.create("old"), ULiteral.intLit(-1))))) .addEqualityGroup( UDoWhileLoop.create( UBlock.create( UExpressionStatement.create( UAssign.create( ULocalVarIdent.create("old"), UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("str"), "indexOf", UMethodType.create( UPrimitiveType.INT, UPrimitiveType.INT, UPrimitiveType.INT)), ULiteral.charLit(' '), UBinary.create( Kind.PLUS, ULocalVarIdent.create("old"), ULiteral.intLit(1)))))), UParens.create( UBinary.create( Kind.GREATER_THAN_EQUAL, ULocalVarIdent.create("old"), ULiteral.intLit(0))))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UDoWhileLoop.create( UBlock.create( UExpressionStatement.create( UAssign.create( ULocalVarIdent.create("old"), UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("str"), "indexOf", UMethodType.create( UPrimitiveType.INT, UPrimitiveType.INT, UPrimitiveType.INT)), ULiteral.charLit(' '), UBinary.create( Kind.PLUS, ULocalVarIdent.create("old"), ULiteral.intLit(1)))))), UParens.create( UBinary.create( Kind.NOT_EQUAL_TO, ULocalVarIdent.create("old"), ULiteral.intLit(-1))))); } }
4,441
40.514019
97
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UTypeVarTest.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 UTypeVar}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UTypeVarTest { @Test public void equality() { UType nullType = UPrimitiveType.create(TypeKind.NULL); UType objectType = UClassType.create("java.lang.Object", ImmutableList.<UType>of()); UType charSequenceType = UClassType.create("java.lang.CharSequence", ImmutableList.<UType>of()); UType stringType = UClassType.create("java.lang.String", ImmutableList.<UType>of()); new EqualsTester() .addEqualityGroup(UTypeVar.create("T", nullType, charSequenceType)) // T extends CharSequence .addEqualityGroup(UTypeVar.create("T", stringType, charSequenceType)) // T extends CharSequence super String .addEqualityGroup(UTypeVar.create("T", nullType, objectType)) // T extends Object .addEqualityGroup(UTypeVar.create("E", nullType, charSequenceType)) // E extends CharSequence .testEquals(); } @Test public void serialization() { UType nullType = UPrimitiveType.create(TypeKind.NULL); UType charSequenceType = UClassType.create("java.lang.CharSequence", ImmutableList.<UType>of()); SerializableTester.reserializeAndAssert(UTypeVar.create("T", nullType, charSequenceType)); } }
2,236
36.283333
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UPrimitiveTypeTreeTest.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.tools.javac.code.TypeTag; 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 UPrimitiveTypeTreeTest { @Test public void equality() { new EqualsTester() .addEqualityGroup(UPrimitiveTypeTree.create(TypeTag.INT), UPrimitiveTypeTree.INT) .addEqualityGroup(UPrimitiveTypeTree.create(TypeTag.LONG), UPrimitiveTypeTree.LONG) .addEqualityGroup(UPrimitiveTypeTree.create(TypeTag.DOUBLE), UPrimitiveTypeTree.DOUBLE) .addEqualityGroup(UPrimitiveTypeTree.create(TypeTag.FLOAT), UPrimitiveTypeTree.FLOAT) .addEqualityGroup(UPrimitiveTypeTree.create(TypeTag.CHAR), UPrimitiveTypeTree.CHAR) .addEqualityGroup(UPrimitiveTypeTree.create(TypeTag.VOID), UPrimitiveTypeTree.VOID) .addEqualityGroup(UPrimitiveTypeTree.create(TypeTag.BOT), UPrimitiveTypeTree.NULL) .addEqualityGroup(UPrimitiveTypeTree.create(TypeTag.BOOLEAN), UPrimitiveTypeTree.BOOLEAN) .addEqualityGroup(UPrimitiveTypeTree.create(TypeTag.BYTE), UPrimitiveTypeTree.BYTE) .addEqualityGroup(UPrimitiveTypeTree.create(TypeTag.SHORT), UPrimitiveTypeTree.SHORT) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert(UPrimitiveTypeTree.INT); } }
2,169
39.185185
97
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/UWhileLoopTest.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 UWhileLoop}. * * @author lowasser@google.com (Louis Wasserman) */ @RunWith(JUnit4.class) public class UWhileLoopTest extends AbstractUTreeTest { @Test public void equality() { new EqualsTester() .addEqualityGroup( UWhileLoop.create( UParens.create( UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("itr"), "hasNext", UMethodType.create(UPrimitiveType.BOOLEAN)))), UBlock.create( UExpressionStatement.create( UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("itr"), "next", UMethodType.create(UTypeVar.create("E")))))))) .addEqualityGroup( UWhileLoop.create( UParens.create( UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("elements"), "hasNext", UMethodType.create(UPrimitiveType.BOOLEAN)))), UBlock.create( UExpressionStatement.create( UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("elements"), "next", UMethodType.create(UTypeVar.create("E")))))))) .testEquals(); } @Test public void serialization() { SerializableTester.reserializeAndAssert( UWhileLoop.create( UParens.create( UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("itr"), "hasNext", UMethodType.create(UPrimitiveType.BOOLEAN)))), UBlock.create( UExpressionStatement.create( UMethodInvocation.create( UMemberSelect.create( UFreeIdent.create("itr"), "next", UMethodType.create(UTypeVar.create("E")))))))); } }
3,236
36.206897
78
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/WildcardTemplateExample.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.testdata; import com.google.common.collect.ImmutableList; import java.util.Collections; import java.util.List; /** * Test input for {@code WildcardTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class WildcardTemplateExample { public void example() { List<?> myList = ImmutableList.of(); System.out.println(myList); } }
1,001
29.363636
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/SamePackageImportsTemplateExample.java
/* * Copyright 2015 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.common.collect; import com.google.common.collect.ImmutableMap.Builder; /** * Test data for {@code SamePackageImportsTemplate}. */ public class SamePackageImportsTemplateExample { public void example() { ImmutableMap.Builder<String, Integer> builder = new Builder<>(); System.out.println(builder.buildOrThrow()); } }
958
30.966667
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/TryTemplateExample.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.testdata; import com.google.common.base.MoreObjects; import com.google.common.primitives.Ints; /** * Test input for {@code TryTemplate}. * * @author lowasser@google.com */ public class TryTemplateExample { int foo(String str) { int result; result = MoreObjects.firstNonNull(Ints.tryParse(str), 0); return result; } }
986
28.029412
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/TopLevelTemplateExample.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.testdata; import java.util.logging.Logger; /** * Test data for {@code TopLevelTemplate}. */ public class TopLevelTemplateExample { private static final Logger logger = Logger.getLogger("foobar"); }
850
30.518519
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/NestedClassTemplateExample.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.refaster.testdata; import java.util.concurrent.locks.AbstractQueuedSynchronizer; import java.util.concurrent.locks.AbstractQueuedSynchronizer.ConditionObject; /** * Sample data for {@code NestedClassTemplate}. * * @author cpovirk@google.com (Chris Povirk) */ public class NestedClassTemplateExample { ConditionObject example(AbstractQueuedSynchronizer sync) { return null; } }
1,028
31.15625
77
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/VarargTemplateExample.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.testdata; /** * Test case for {@code VarargTemplate}. * * @author juanch@google.com (Juan Chen) */ public class VarargTemplateExample { public String foo0() { return String.format("first: %s, second: %s"); } public String foo0_empty() { return String.format("first: %s, second: %s"); } public String foo1() { return String.format("first: %s, second: %s", "first"); } public String foo2() { return String.format("first: %s, second: %s", "first", "second"); } public String foo3() { return String.format("first: %s, second: %s", "first", "second", "third"); } }
1,257
26.347826
78
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/PrecedenceSensitiveTemplateExample.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.testdata; import java.util.Objects; /** * Test data for {@code PrecedenceSensitiveTemplate}. * * @author mdempsky@google.com (Matthew Dempsky) */ public class PrecedenceSensitiveTemplateExample { public void foo(String a, String b) { if (a == b) { System.out.println("same"); } if (!(a == b)) { System.out.println("different"); } } }
1,011
27.914286
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/ExplicitTypesPreservedTemplateExample.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.testdata; import java.util.ArrayList; import java.util.LinkedList; import java.util.Map.Entry; /** * Sample data for {@code ExplicitTypesPreservedTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class ExplicitTypesPreservedTemplateExample { public void example() { // positive examples System.out.println(new ArrayList<String>()); System.out.println(new ArrayList<Entry<String, Integer>>()); // negative examples System.out.println(new LinkedList<String>() {{ add("foo"); }}); } }
1,190
29.538462
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/IsInstanceTemplateExample.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.testdata; /** * Test input for {@code IsInstanceTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class IsInstanceTemplateExample { public void foo() { System.out.println("foo" instanceof String); } }
873
31.37037
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/ParenthesesOptionalTemplateExample.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.testdata; /** * Test input for {@code ParenthesesOptionalTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class ParenthesesOptionalTemplateExample { public void example(int x) { System.out.println(5 + (x * 5)); } }
888
31.925926
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/AssertTemplateExample.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.testdata; import org.junit.Assert; /** * Test data for {@code AssertTemplate}. */ public class AssertTemplateExample { public void example(String s) { Assert.assertTrue(s + " must not be empty", !s.isEmpty()); assert !s.isEmpty(); System.out.println(s); } }
924
28.83871
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/AnonymousClassTemplateExample.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.testdata; import java.util.AbstractList; import java.util.Collections; /** * Test data for {@code AnonymousClassTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class AnonymousClassTemplateExample { public void sameOrderNoVariableConflicts() { System.out.println(Collections.nCopies(5, 17)); } public void sameOrderVariableConflicts() { System.out.println(Collections.nCopies(5, 17)); } public void differentOrderNoVariableConflicts() { System.out.println(Collections.nCopies(5, 17)); } public void differentOrderVariableConflicts() { System.out.println(Collections.nCopies(5, 17)); } public void fewerMethods() { System.out.println(new AbstractList<Integer>() { @Override public Integer get(int index) { return 17; } @Override public int size() { return 5; } }); } public void moreMethods() { System.out.println(new AbstractList<Integer>() { @Override public Integer get(int index) { return 17; } @Override public Integer set(int index, Integer element) { throw new UnsupportedOperationException(); } @Override public int size() { return 5; } @Override public void clear() { throw new UnsupportedOperationException(); } }); } }
2,018
24.2375
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/ImplicitTypesInlinedTemplateExample.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.testdata; import static java.util.Collections.emptyList; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * Test data for {@code ImplicitTypesInlinedTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class ImplicitTypesInlinedTemplateExample { @SuppressWarnings("unused") public void foo() { List<String> stringList = Collections.unmodifiableList(new ArrayList<String>()); List<Double> doubleList = Collections.unmodifiableList(new ArrayList<Double>()); List<Integer> intList = Collections.synchronizedList(Collections.unmodifiableList(new ArrayList<Integer>())); } }
1,287
34.777778
113
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/IfTemplateExample.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.testdata; import java.util.Comparator; /** * Test data for {@code IfTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class IfTemplateExample { public String example() { String foo; foo = (Math.random() < 0.5) ? "bar" : "baz"; Comparator<String> comparator; comparator = (true) ? new Comparator<String>() { @Override public int compare(String a, String b) { return a.length() - b.length(); } } : String.CASE_INSENSITIVE_ORDER; System.out.println(comparator); return foo; } }
1,208
30
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/MayOptionallyUseTemplateExample.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.testdata; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; /** * Test data for {@code MayOptionallyUseTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class MayOptionallyUseTemplateExample { public void example1() { System.out.println(new String(new byte[0], StandardCharsets.UTF_8)); } public void example2() { System.out.println(new String(new byte[0], StandardCharsets.UTF_8)); } }
1,114
30.857143
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/InferredThisTemplateExample.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.testdata; /** * Test data for {@code InferredThisTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class InferredThisTemplateExample { public void example() { new Thread() { @Override public void run() { this.setName("foo"); this.setName("foo"); } }.start(); } }
982
27.085714
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/BinaryTemplateExample.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.testdata; import java.util.Random; /** * Test input for {@code BinaryTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ class BinaryTemplateExample { public void example(int x, int y) { // positive examples System.out.println((0xFF + 5) >> 1); System.out.println(((x + y) >> 1) + 20); System.err.println((y + new Random().nextInt()) >> 1); // negative examples System.out.println((x + y /* signed division */) / 2 + 20); System.out.println(x + y / 2); System.out.println((x - y) / 2); System.out.println((x * y) / 2); System.out.println((x + y) / 3); System.out.println((x + 5L) / 2); } }
1,303
30.804878
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/EmitCommentBeforeTemplateExample.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.refaster.testdata; public class EmitCommentBeforeTemplateExample { public void example() { System.out.println(/* comment here */ "foobar".length()); } }
791
35
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/StaticImportClassTokenTemplateExample.java
/* * Copyright 2015 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.testdata; import static java.lang.Boolean.valueOf; /** Test data for {@code StaticImportClassTokenTemplate}. */ public class StaticImportClassTokenTemplateExample { public void example() { boolean eq = valueOf(String.class.isInstance("a")); } }
901
32.407407
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/AnyOfTemplateExample.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.testdata; /** * Test input for {@code AnyOfTemplate} refactoring. * * @author lowasser@google.com (Louis Wasserman) */ public class AnyOfTemplateExample { public void foo(double d) { if (d == 0.0) { System.out.println("zero"); } if (d == 0.0) { System.out.println("also zero"); } } }
960
29.03125
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/ArrayTemplateExample.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.testdata; import java.util.Arrays; import java.util.List; /** * Test data for {@code ArrayTemplate}. * * @author mdempsky@google.com (Matthew Dempsky) */ public class ArrayTemplateExample { public void foo() { List<String> list = Arrays.asList("foo", "bar"); System.out.println(list.toArray(new String[0])[1]); } }
972
30.387097
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/ImportClassDirectlyTemplateExample.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.testdata; import java.util.Map; import java.util.Map.Entry; /** * Test input for {@code ImportClassDirectlyTemplate}. * * @author Louis Wasserman */ public class ImportClassDirectlyTemplateExample { public void example(Map<String, Integer> map) { for (Entry<String, Integer> entry : map.entrySet()) { System.out.println(entry.getKey() + " " + entry.getValue()); } } }
1,033
28.542857
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/LambdaImplicitTypeExample.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.refaster.testdata; import java.util.Arrays; import java.util.stream.Collectors; public class LambdaImplicitTypeExample { public void example() { System.out.println( Arrays.asList("foo", "bar").stream().reduce((a,b)->b)); } }
880
30.464286
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/AsVarargsTemplateExample.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.refaster.testdata; import java.util.stream.IntStream; import java.util.stream.Stream; /** * Test data for AsVarargsTemplate. * * @author Louis Wasserman */ public class AsVarargsTemplateExample { public void example() { System.out.println( Stream.of(IntStream.of(1), IntStream.of(2)).flatMapToInt((IntStream s)->s).sum()); // unchanged, it's not using the varargs overload System.out.println( Stream.of(IntStream.of(1)).flatMap(s -> s.boxed()).mapToInt(i -> i).sum()); } }
1,154
30.216216
90
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/NonJdkTypeTemplateExample.java
/* * Copyright 2020 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.testdata; import static com.google.common.collect.ImmutableList.toImmutableList; import com.google.common.collect.ImmutableList; import java.util.stream.Stream; /** Test data for {@code NonJdkTypeTemplate}. */ public class NonJdkTypeTemplateExample { ImmutableList<Integer> example() { return Stream.of(1).collect(toImmutableList()); } }
995
32.2
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/LabelTemplateExample.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.testdata; import com.google.common.base.Joiner; import java.math.BigInteger; /** * Test data for {@code LabelTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class LabelTemplateExample { public void example(BigInteger[] array) { StringBuilder builder = new StringBuilder("["); Joiner.on(',').appendTo(builder, array); Joiner.on(',').appendTo(builder, array); Joiner.on(',').appendTo(builder, array); System.out.println(builder); } }
1,132
30.472222
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/DiamondTemplateExample.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.testdata; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; /** * Test data for {@code DiamondTemplate}. */ public class DiamondTemplateExample { public void example() { List<Integer> explicit = new ArrayList<>(); List<Integer> diamond = new ArrayList<>(); @SuppressWarnings("rawtypes") List<Integer> raw = new LinkedList(); System.out.println(explicit + " " + diamond + " " + raw); } }
1,083
31.848485
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/EmitCommentTemplateExample.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.refaster.testdata; public class EmitCommentTemplateExample { public void example() { // comment System.out.println("foobar"); } }
772
32.608696
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/ReturnPlaceholderTemplateExample.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.testdata; import com.google.common.collect.Ordering; /** * Test data for {@code ReturnPlaceholderTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class ReturnPlaceholderTemplateExample { public static final Ordering<String> LENGTH_THEN_LOWER_CASE_ONE_LINE = new Ordering<String>(){ @Override public int compare(String left, String right) { return Integer.compare(left.length(), right.length()); } }.compound(new Ordering<String>(){ @Override public int compare(String left, String right) { return left.toLowerCase().compareTo(right.toLowerCase()); } }); public static final Ordering<String> LENGTH_THEN_LOWER_CASE_MULTI_LINE = new Ordering<String>(){ @Override public int compare(String left, String right) { return Integer.compare(left.length(), right.length()); } }.compound(new Ordering<String>(){ @Override public int compare(String left, String right) { String leftLower = left.toLowerCase(); String rightLower = right.toLowerCase(); return leftLower.compareTo(rightLower); } }); }
1,776
31.309091
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/InferLambdaBodyTypeExample.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.refaster.testdata; import java.util.Collection; /** Sample data for InferLambdaBodyType. */ public class InferLambdaBodyTypeExample { static void example(Collection<Integer> collection) { collection.forEach((Integer i)->System.out.println(i)); collection.forEach((Integer i)->{ int j = i + 1; System.out.println(j); }); } }
975
33.857143
79
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/BlockPlaceholderTemplateExample.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.testdata; import com.google.common.io.ByteStreams; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; /** * Test data for {@code BlockPlaceholderTemplate}. */ public class BlockPlaceholderTemplateExample { public void positiveExample1() throws IOException { try (InputStream stream = new FileInputStream("foo.bar")){ System.out.println(ByteStreams.toByteArray(stream).length); } } public void positiveExample2() throws IOException { try (InputStream stream = new FileInputStream("foo.bar")){ int count = 0; while (true) { int b = stream.read(); if (b == -1) { break; } count++; } System.out.println(count); } } public void negativeExample1() throws IOException { // modifies placeholder parameter InputStream stream = null; try { stream = new FileInputStream("foo.bar"); System.out.println(ByteStreams.toByteArray(stream).length); } finally { stream.close(); } } public void negativeExample2() throws IOException { // changes control flow for (int i = 0; i < 10; i++) { InputStream stream = new FileInputStream("foo.bar"); try { System.out.println(ByteStreams.toByteArray(stream).length); break; } finally { stream.close(); } } } }
2,016
27.013889
87
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/TwoLinesToOneTemplateExample.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.testdata; import java.util.Random; /** * Test data for {@code TwoLinesTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class TwoLinesToOneTemplateExample { public int example() { Random rng = new Random(); int x = rng.nextInt(); x = x + rng.nextInt() + 20; x = x + 5 + rng.nextInt(30); x = x + 20; // comments should block matching x = x + rng.nextInt(); return x; } }
1,081
27.473684
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/VariableDeclTemplateExample.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.testdata; /** * Test data for {@code VariableDeclTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class VariableDeclTemplateExample { @SuppressWarnings("unused") public void example() { int a = Integer.parseInt("3"); Integer b = Integer.valueOf("3"); final int c = Integer.parseInt("3"); } }
984
29.78125
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/InferLambdaTypeExample.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.refaster.testdata; import java.util.Arrays; import java.util.stream.Collectors; public class InferLambdaTypeExample { public void example() { System.out.println( Arrays.asList("foo", "bar") .stream().reduce((String a, String b)->b)); System.out.println( Arrays.asList("foo", "bar").stream().reduce((String a, String b)->b)); } }
1,008
31.548387
78
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/TryMultiCatchTemplateExample.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.testdata; /** * Test data for {@code TryMultiCatchTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class TryMultiCatchTemplateExample { public void foo() { String str = null; try { str = String.class.newInstance(); } catch (ReflectiveOperationException | SecurityException tolerated) { tolerated.printStackTrace(); } System.out.println(str); } }
1,044
28.857143
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/PlaceholderAllowedVarsTemplateExample.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.refaster.testdata; public class PlaceholderAllowedVarsTemplateExample { public void shouldMatch() { String accum = "foo"; System.out.println("found match: " + accum); System.out.println("foo"); } public void shouldNotMatch() { String accum = "foo"; if (!"foo".equals("bar")) { System.out.println(accum); accum += "bar"; } System.out.println("foo"); } }
1,032
30.30303
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/PlaceholderTemplateExample.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.testdata; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import java.util.Iterator; import java.util.List; /** * Test data for {@code PlaceholderTemplate}. */ public class PlaceholderTemplateExample { public void positiveExample(List<Integer> list) { Iterables.removeIf(list, new Predicate<Integer>(){ @Override public boolean apply(Integer input) { return input < 0; } }); } public void negativeIdentityExample(List<Boolean> list) { Iterator<Boolean> itr = list.iterator(); while (itr.hasNext()) { if (itr.next()) { itr.remove(); } } } public void refersToForbiddenVariable(List<Integer> list) { Iterator<Integer> itr = list.iterator(); while (itr.hasNext()) { if (itr.next() < list.size()) { itr.remove(); } } } }
1,518
25.649123
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/GenericPlaceholderTemplateExample.java
/* * Copyright 2015 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.testdata; import com.google.common.base.Joiner; import java.util.ArrayList; import java.util.List; import java.util.UUID; /** * Example usage of {@code GenericPlaceholderTemplate}. */ public class GenericPlaceholderTemplateExample { public static void main(String[] args) { List<UUID> list = new ArrayList<>(); for (int i = 0; i < 10; i++) { list.add(UUID.randomUUID()); } System.out.println(Joiner.on('\n').join(list)); } }
1,079
30.764706
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/VoidExpressionPlaceholderTemplateExample.java
/* * Copyright 2022 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.testdata; import java.util.List; /** Test data for {@code VoidExpressionPlaceholderTemplate}. */ public class VoidExpressionPlaceholderTemplateExample { public static void foo(String s) { s.length(); } public void positiveExample(List<String> list) { list.forEach(x->foo(x)); } }
945
29.516129
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/AutoboxingTemplateExample.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.testdata; import java.util.Arrays; import java.util.Collections; /** * Test data for {@code AutoboxingTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class AutoboxingTemplateExample { public void foo() { System.out.println(Arrays.asList(5)); } }
921
29.733333
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/TypeArgumentsMethodInvocationTemplateExample.java
/* * Copyright 2022 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.testdata; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; /** Test data for {@code TypeArgumentsMethodInvocationTemplate}. */ public class TypeArgumentsMethodInvocationTemplateExample { public Future<Object> example() { ExecutorService executorService = Executors.newSingleThreadExecutor(); return executorService.<Object>submit(() -> new Object()); } }
1,078
37.535714
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/MultiBoundTemplateExample.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.testdata; import java.nio.CharBuffer; /** * Test data for {@code MultiBoundTemplate}. */ public class MultiBoundTemplateExample { public void example() { System.err.println(new StringBuilder("foo")); System.out.println(CharBuffer.wrap("foo")); } }
910
29.366667
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/MultipleReferencesToIdentifierTemplateExample.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.testdata; /** * Example input for {@code MultipleReferencesToIdentifierTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class MultipleReferencesToIdentifierTemplateExample { public void example(int x, int y, String text) { // positive examples System.out.println(true); System.out.println((x == y)); System.out.println(text.contains("棒球場")); // negative examples System.out.println((x == y) || (y == x)); } }
1,103
33.5
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/SuppressWarningsTemplateExample.java
/* * Copyright 2021 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.testdata; /** Test data for {@code SuppressWarningsTemplate}. */ public class SuppressWarningsTemplateExample { @SuppressWarnings("SuppressWarningsTemplate") public int abs1(int x) { return x < 0 ? -x : x; } @SuppressWarnings("SuppressWarningsTemplate") static class Inner { public int abs2(int x) { return x < 0 ? -x : x; } } public int abs3(int x) { @SuppressWarnings("SuppressWarningsTemplate") int r = x < 0 ? -x : x; return r; } public int abs4(int x) { return Math.abs(x); } }
1,187
26.627907
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/StaticFieldTemplateExample.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.testdata; import java.util.Collections; import java.util.List; /** * Test data for {@code StaticFieldTemplate}. * * @author mdempsky@google.com (Matthew Dempsky) */ public class StaticFieldTemplateExample { public void foo() { @SuppressWarnings("unchecked") List<Integer> list = Collections.emptyList(); System.out.println(list); } }
994
30.09375
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/IfFallthroughTemplateExample.java
/* * Copyright 2015 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.testdata; import com.google.common.collect.Ordering; import java.util.Comparator; /** * Test data for {@code IfFallthroughTemplate}. */ public class IfFallthroughTemplateExample { public Comparator<String> example1() { return new Comparator<String>() { @Override public int compare(String o1, String o2) { return Ordering.natural().nullsFirst().compare(o1, o2); } }; } public Comparator<String> example2() { return new Comparator<String>() { @Override public int compare(String o1, String o2) { return Ordering.natural().nullsFirst().compare(o1, o2); } }; } }
1,287
28.272727
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/UnnecessaryLambdaParensExample.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.refaster.testdata; import java.util.Arrays; import java.util.stream.Collectors; public class UnnecessaryLambdaParensExample { public void example() { System.out.println(Arrays.asList("foo", "bar").stream().map(x->x).reduce((a,b)->b)); } }
886
31.851852
88
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/MethodInvocationTemplateExample.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.testdata; import java.nio.charset.Charset; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /** * Example input for {@code MethodInvocationTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class MethodInvocationTemplateExample { public void example(MessageDigest digest, String string) throws NoSuchAlgorithmException { // positive examples MessageDigest.getInstance("MD5").digest("foo".getBytes(Charset.defaultCharset())); digest.digest("foo".getBytes(Charset.defaultCharset())); MessageDigest.getInstance("SHA1").digest(string.getBytes(Charset.defaultCharset())); digest.digest((string + 90).getBytes(Charset.defaultCharset())); // negative examples System.out.println("foo".getBytes()); } }
1,434
35.794872
92
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/OneLineToTwoTemplateExample.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.testdata; import java.util.Random; /** * Test data for {@code OneLineToTwoTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class OneLineToTwoTemplateExample { public int example() { Random rng = new Random(); int x = rng.nextInt(); x = x + rng.nextInt(); x = x + 20; x = x + 5; x = x + rng.nextInt(30); return x; } }
1,008
27.828571
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/PlaceholderAllowsIdentityTemplateExample.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.testdata; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import java.util.Iterator; import java.util.List; /** * Test data for {@code PlaceholderTemplate}. */ public class PlaceholderAllowsIdentityTemplateExample { public void positiveExample(List<Integer> list) { Iterables.removeIf(list, new Predicate<Integer>(){ @Override public boolean apply(Integer input) { return input < 0; } }); } public void positiveIdentityExample(List<Boolean> list) { Iterables.removeIf(list, new Predicate<Boolean>(){ @Override public boolean apply(Boolean input) { return input; } }); } public void refersToForbiddenVariable(List<Integer> list) { Iterator<Integer> itr = list.iterator(); while (itr.hasNext()) { if (itr.next() < list.size()) { itr.remove(); } } } }
1,555
27.290909
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/LiteralTemplateExample.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.testdata; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; /** * Test data for {@code LiteralTemplate}. * * @author lowasser@google.com (Louis Wasserman) */ public class LiteralTemplateExample { public void example() { System.out.println(new String(new byte[0], StandardCharsets.UTF_8)); } }
979
29.625
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/WildcardUnificationTemplateExample.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.testdata; import static com.google.common.truth.Truth.assertThat; import com.google.common.collect.ImmutableList; /** * Test data for {@code WildcardUnificationTemplate}. * * @author kak@google.com (Kurt Kluever) */ public class WildcardUnificationTemplateExample { public void example() { ImmutableList<String> actual = ImmutableList.of("kurt", "kluever"); ImmutableList<String> expected = ImmutableList.of("kluever", "kurt"); assertThat(actual).containsExactlyElementsIn(expected); } }
1,158
32.114286
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/output/ComparisonChainTemplateExample.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.testdata; import com.google.common.collect.ComparisonChain; /** * Test data for {@code ComparisonChainTemplate}. */ public class ComparisonChainTemplateExample { public int compare(String a, String b) { return ComparisonChain.start().compare(Integer.valueOf(a.length()), Integer.valueOf(b.length())).compare(a, b).result(); } }
983
34.142857
124
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/VarargTemplate.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.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import com.google.errorprone.refaster.annotation.Repeated; /** * Example Refaster rule matching varargs. * * @author juanch@google.com (Juan Chen) */ public class VarargTemplate { @BeforeTemplate public String before(String template, @Repeated Object vararg) { return String.format(template, new Object[] {vararg}); } @AfterTemplate public String after(String template, @Repeated Object vararg) { return String.format(template, vararg); } }
1,262
31.384615
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/TopLevelTemplate.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.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import java.util.logging.Logger; /** Example Refaster refactoring that refactors top-level declarations. */ public class TopLevelTemplate { @BeforeTemplate void declareAnonymousLogger(String name) { Logger logger = Logger.getAnonymousLogger(name); } @AfterTemplate void declareLogger(String name) { Logger logger = Logger.getLogger(name); } }
1,160
32.171429
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/LabelTemplate.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.testdata.template; import com.google.common.base.Joiner; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; /** * Example Refaster template using labeled statements, {@code break}, and {@code continue}. * * @author lowasser@google.com (Louis Wasserman) */ public class LabelTemplate { @BeforeTemplate void join1(StringBuilder builder, Object[] elements) { for (int i = 0; i < elements.length; i++) { builder.append(elements[i]); if (i == elements.length - 1) { break; } builder.append(','); } } @BeforeTemplate void join2(StringBuilder builder, Object[] elements) { loop: for (int i = 0; i < elements.length; i++) { builder.append(elements[i]); if (i == elements.length - 1) { break loop; } builder.append(','); } } @BeforeTemplate void join3(StringBuilder builder, Object[] elements) { loop: for (int i = 0; i < elements.length; i++) { builder.append(elements[i]); if (i == elements.length - 1) { continue loop; } builder.append(','); } } @AfterTemplate void joiner(StringBuilder builder, Object[] elements) { Joiner.on(',').appendTo(builder, elements); } }
1,948
27.246377
91
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/ComparisonChainTemplate.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.testdata.template; import com.google.common.collect.ComparisonChain; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import com.google.errorprone.refaster.annotation.Placeholder; /** Example use of placeholder methods in a {@code ComparisonChain} refactoring. */ public abstract class ComparisonChainTemplate<A extends Comparable<A>, B extends Comparable<B>> { @Placeholder(allowsIdentity = true) abstract <T> A propertyA(T t); @Placeholder(allowsIdentity = true) abstract <T> B propertyB(T t); @BeforeTemplate <T> int before(T left, T right) { int cmp = propertyA(left).compareTo(propertyA(right)); if (cmp == 0) { return propertyB(left).compareTo(propertyB(right)); } else { return cmp; } } @AfterTemplate <T> int after(T left, T right) { return ComparisonChain.start() .compare(propertyA(left), propertyA(right)) .compare(propertyB(left), propertyB(right)) .result(); } }
1,675
33.916667
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/ExpressionForbidsAllowCodeBetweenLinesTemplate.java
/* * Copyright 2020 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.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.AllowCodeBetweenLines; import com.google.errorprone.refaster.annotation.BeforeTemplate; import java.util.Objects; /** * Test case demonstrating that {@code @AllowCodeBetweenLines} is forbidden with expression * templates. * * @author jhecht@google.com (Joshua Hecht) */ @AllowCodeBetweenLines public abstract class ExpressionForbidsAllowCodeBetweenLinesTemplate { @BeforeTemplate String before(Object o) { return o.toString(); } @AfterTemplate String after(Object o) { return Objects.toString(o); } }
1,307
30.142857
91
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/BlockPlaceholderTemplate.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.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import com.google.errorprone.refaster.annotation.Placeholder; /** Example of a Refaster template using block placeholders. */ public abstract class BlockPlaceholderTemplate<T extends AutoCloseable> { @Placeholder abstract T open(); @Placeholder abstract void operateOn(T resource); @BeforeTemplate void before() throws Exception { T resource = open(); try { operateOn(resource); } finally { resource.close(); } } @AfterTemplate void after() throws Exception { try (T resource = open()) { operateOn(resource); } } }
1,376
27.6875
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/IfFallthroughTemplate.java
/* * Copyright 2015 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.testdata.template; import com.google.common.collect.Ordering; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; /** Test template to make sure if fallthrough works. */ public class IfFallthroughTemplate<T> { @BeforeTemplate public int before(T left, T right, Ordering<? super T> ordering) { if (left == null && right == null) { return 0; } else if (left == null) { return -1; } else if (right == null) { return 1; } else { return ordering.compare(left, right); } } @AfterTemplate int after(T left, T right, Ordering<? super T> ordering) { return ordering.nullsFirst().compare(left, right); } }
1,374
32.536585
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/AssertTemplate.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.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import org.junit.Assert; /** * Example template using the assert keyword. * * @author lowasser@google.com (Louis Wasserman) */ public class AssertTemplate { @BeforeTemplate void directAssert(boolean cond, String message) { assert cond : message; } @AfterTemplate void junitAssert(boolean cond, String message) { Assert.assertTrue(message, cond); } }
1,171
29.051282
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/MultiBoundTemplate.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.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import java.io.Serializable; /** Example of a Refaster template using multiply bounded type parameters. */ public class MultiBoundTemplate { @BeforeTemplate <T extends CharSequence & Serializable> void before(T t) { System.out.println(t); } @AfterTemplate <T extends CharSequence & Serializable> void after(T t) { System.err.println(t); } }
1,158
32.114286
77
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/ImplicitTypesInlinedTemplate.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.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * Refaster rule demonstrating that implicit types in the @BeforeTemplate are inferred and can be * inlined in the @AfterTemplate. * * @author lowasser@google.com (Louis Wasserman) */ public class ImplicitTypesInlinedTemplate { @BeforeTemplate public <E> List<E> emptyList() { return Collections.emptyList(); } @AfterTemplate public <E> List<E> unmodifiableArrayList() { return Collections.unmodifiableList(new ArrayList<E>()); } }
1,330
32.275
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/InferLambdaBodyType.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.refaster.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import com.google.errorprone.refaster.annotation.Placeholder; import java.util.Collection; /** Template to verify that block placeholders get inlined with the correct lambda body type. */ abstract class InferLambdaBodyType<E> { @Placeholder abstract void doSomething(E function); @BeforeTemplate void before(Collection<E> collection) { for (E e : collection) { doSomething(e); } } @AfterTemplate void after(Collection<E> collection) { collection.forEach((E e) -> doSomething(e)); } }
1,316
31.121951
96
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/ExplicitTypesPreservedTemplate.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.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; /** * Refaster template that should preserve types named in the original source. * * @author lowasser@google.com (Louis Wasserman) */ public class ExplicitTypesPreservedTemplate { @BeforeTemplate public <E> List<E> linkedList() { return new LinkedList<E>(); } @AfterTemplate public <E> List<E> arrayList() { return new ArrayList<E>(); } }
1,240
29.268293
77
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/ParenthesesOptionalTemplate.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.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; /** * Template to demonstrate that parentheses in a Refaster @BeforeTemplate are treated as optional. * * @author lowasser@google.com (Louis Wasserman) */ public class ParenthesesOptionalTemplate { @BeforeTemplate public int before(int a, int b) { return (a * b) + 5; } @AfterTemplate public int after(int a, int b) { return 5 + (a * b); } }
1,155
31.111111
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/ReturnPlaceholderTemplate.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.testdata.template; import com.google.common.collect.Ordering; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import com.google.errorprone.refaster.annotation.Placeholder; /** * Example template calling {@code return} on a placeholder invocation. * * @author lowasser@google.com (Louis Wasserman) */ public abstract class ReturnPlaceholderTemplate<T> { // This particular example is inspired by a much more practically useful example with Java 8... @Placeholder abstract int firstCompare(T left, T right); @Placeholder abstract int secondCompare(T left, T right); @BeforeTemplate Ordering<T> combined() { return new Ordering<T>() { @Override public int compare(T left, T right) { int cmp = firstCompare(left, right); if (cmp != 0) { return cmp; } return secondCompare(left, right); } }; } @AfterTemplate Ordering<T> split() { return new Ordering<T>() { @Override public int compare(T left, T right) { /* * firstCompare was used as a one-line expression in @BeforeTemplate, but will be a return * placeholder here */ return firstCompare(left, right); } }.compound( new Ordering<T>() { @Override public int compare(T left, T right) { return secondCompare(left, right); } }); } }
2,123
29.342857
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/InferredThisTemplate.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.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; /** * Sample Refaster template that can replace instance methods with an implicit this. * * @author lowasser@google.com (Louis Wasserman) */ public class InferredThisTemplate { @BeforeTemplate public void before(Thread thread) { thread.setName(thread.getName()); } @AfterTemplate public void after(Thread thread) { thread.setName("foo"); } }
1,163
29.631579
84
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/AsVarargsTemplate.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.refaster.testdata.template; import com.google.errorprone.refaster.Refaster; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import com.google.errorprone.refaster.annotation.Repeated; import java.util.stream.IntStream; import java.util.stream.Stream; /** * Template using {@code Refaster.asVarargs}. * * @author Louis Wasserman */ public class AsVarargsTemplate { @BeforeTemplate IntStream before(@Repeated IntStream streams) { return Stream.of(Refaster.asVarargs(streams)).flatMap(s -> s.boxed()).mapToInt(i -> i); } @AfterTemplate IntStream after(@Repeated IntStream streams) { return Stream.of(streams).flatMapToInt((IntStream s) -> s); } }
1,388
32.071429
91
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/WildcardTemplate.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.testdata.template; import com.google.common.collect.ImmutableList; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import java.util.Collections; import java.util.List; /** * Sample Refaster rule using wildcards. * * @author lowasser@google.com (Louis Wasserman) */ public class WildcardTemplate { @BeforeTemplate void before() { List<?> list = Collections.emptyList(); } @AfterTemplate void after() { List<?> list = ImmutableList.of(); } }
1,186
29.435897
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/EmitCommentBeforeTemplate.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.refaster.testdata.template; import com.google.errorprone.refaster.ImportPolicy; import com.google.errorprone.refaster.Refaster; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import com.google.errorprone.refaster.annotation.UseImportPolicy; public class EmitCommentBeforeTemplate { @BeforeTemplate int before(String str) { return str.length(); } @AfterTemplate @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) int after(String str) { return Refaster.emitCommentBefore("comment here", str.length()); } }
1,241
35.529412
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/TwoLinesToOneTemplate.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.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; /** * Example of a multi-line template that may have multiple overlapping matches. * * @author lowasser@google.com (Louis Wasserman) */ public class TwoLinesToOneTemplate { @BeforeTemplate public void twoAdditions(int x, int y, int z) { x = x + y; x = x + z; } @AfterTemplate public void oneAddition(int x, int y, int z) { x = x + y + z; } }
1,159
30.351351
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/KeyBindingErrorTemplate.java
/* * Copyright 2021 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.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; /** * Refaster template which triggers an {@link IllegalArgumentException} upon compilation. * * <p>The {@code @AfterTemplate} defines parameters that are not present in all * {@code @BeforeTemplate} methods. */ public class KeyBindingErrorTemplate { @BeforeTemplate public int before1(int a, int b) { return a + b; } @BeforeTemplate public int before2(int a, int c) { return a + c; } @AfterTemplate public int after(int a, int b, int c) { return a + b + c; } }
1,295
28.454545
89
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/LiteralTemplate.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.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; /** * Test template to demonstrate matching literals, either inline or via constants. * * @author lowasser@google.com (Louis Wasserman) */ public class LiteralTemplate { @BeforeTemplate Charset forName() { return Charset.forName("UTF-8"); } @AfterTemplate Charset utf8() { return StandardCharsets.UTF_8; } }
1,204
29.125
82
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/OneLineToTwoTemplate.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.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; /** * Example template taking one line in input to two lines in output. * * @author lowasser@google.com (Louis Wasserman) */ public class OneLineToTwoTemplate { @BeforeTemplate public void oneStatement(int x, int y, int z) { x = x + y + z; } @AfterTemplate public void replacement(int x, int y, int z) { x = x + y; x = x + z; } }
1,147
30.027027
100
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/MethodInvocationTemplate.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.testdata.template; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import java.nio.charset.Charset; import java.security.MessageDigest; /** * Sample Refaster template matching a method invocation. * * @author lowasser@google.com (Louis Wasserman) */ public class MethodInvocationTemplate { @BeforeTemplate public byte[] implicit(MessageDigest md, String str) { return md.digest(str.getBytes()); } @AfterTemplate public byte[] explicit(MessageDigest md, String str) { return md.digest(str.getBytes(Charset.defaultCharset())); } }
1,283
31.1
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/PlaceholderTemplate.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.testdata.template; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import com.google.errorprone.refaster.annotation.Placeholder; import java.util.Collection; import java.util.Iterator; /** * Test case demonstrating use of Refaster placeholder methods. * * @author lowasser@google.com (Louis Wasserman) */ public abstract class PlaceholderTemplate { @BeforeTemplate <E> void iteratorRemoveIf(Collection<E> collection) { Iterator<E> iterator = collection.iterator(); while (iterator.hasNext()) { if (someBooleanCondition(iterator.next())) { iterator.remove(); } } } @AfterTemplate <E> void iterablesRemoveIf(Collection<E> collection) { Iterables.removeIf( collection, new Predicate<E>() { @Override public boolean apply(E input) { return someBooleanCondition(input); } }); } @Placeholder abstract <E> boolean someBooleanCondition(E e); }
1,774
29.603448
75
java
error-prone
error-prone-master/core/src/test/java/com/google/errorprone/refaster/testdata/template/StaticFieldTemplate.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.testdata.template; import static java.util.Collections.EMPTY_LIST; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import java.util.Collections; import java.util.List; /** * Example template referencing a static field. * * @author mdempsky@google.com (Matthew Dempsky) */ public class StaticFieldTemplate { @BeforeTemplate List<?> before() { return EMPTY_LIST; } @AfterTemplate List<?> after() { return Collections.emptyList(); } }
1,187
27.285714
75
java