Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e6266aa
Test case for guardedbychecker bug.
Mar 15, 2019
3b45e8f
RELNOTES: Enable AnnotateFormatMethod by default, and add a strong wa…
graememorgan Mar 19, 2019
07f9c7f
Add fixes for incompatible/required modifiers checks
cushon Mar 20, 2019
c5f99f3
Delete DeprecatedThreadMethods in favour of general-purpose deprecati…
cushon Mar 20, 2019
55a9e0a
New error for reference equality on boxed primitives
cushon Mar 22, 2019
3269b66
Support renaming fields in renameVariable
cushon Mar 22, 2019
66cdb01
Add a defensive null-check
cushon Mar 27, 2019
13f2d76
Make IncompatibleModifiers an error
cushon Mar 28, 2019
885319a
Fix BadImport on ParameterizedType with TYPE_USE annotation
dx404 Mar 28, 2019
d055fdb
Add ModifySourceCollectionInStream check
dx404 Mar 30, 2019
eba27ed
Updated JavaTimeDefaultTimeZone to avoid NPE'ing when the function it
nick-someone Apr 2, 2019
95ebe6a
Add a check for local variables which are of boxed type but do not ne…
awturner Apr 3, 2019
8ef14ba
Provide suggestions for using Truth's Subject.check(...) in 3 cases:
cpovirk Apr 3, 2019
8aa3f18
Omit enclosing class names of constructors in diagnostics
cushon Apr 3, 2019
e66c65a
Add a refactoring to replace trivial lambdas with method references
cushon Apr 5, 2019
e1918bb
Clean up description creation
cushon Apr 5, 2019
b59a3fb
Use a prebuilt JDK 7 -> 8 API diff
cushon Apr 8, 2019
21a262c
New a check to simplify description creation
cushon Apr 8, 2019
427ccb4
Handle casts in SelfAssignment
cushon Apr 8, 2019
ac1b717
Don't complain about deprecated java.lang.Compiler API in JavaLangClash
cushon Apr 8, 2019
dd01c04
Clean up unnecessary lambdas
cushon Apr 8, 2019
45be640
Add a WARNING for using .valueOf(String) on lite proto buffer enums
sumitbhagwani Apr 9, 2019
69709fc
Return -> Returning
graememorgan Apr 9, 2019
b0218c1
Open-source @DoNotMock
Apr 9, 2019
8865ac4
Add Check for Leaking/Mutating an already-forked mutable instance (Bu…
dx404 Apr 10, 2019
c5d9072
Add EmptyBlockTag error-prone check
ash211 Apr 10, 2019
8be863d
Fix a crash in SelfAssignment
cushon Apr 10, 2019
94f0acc
Revert some unnecessary changes
cushon Apr 10, 2019
7fc1daf
Add java.time.temporal.ValueRange#checkValidValue as a method that
nick-someone Apr 11, 2019
ad16bb7
Recognize that it's safe to migrate from == to isEqualTo() for enums.
cpovirk Apr 11, 2019
bc9c078
In UnnecessaryLambda, don't refactor uses that call methods other tha…
cushon Apr 15, 2019
b717c49
Update Gradle plugin check example
tbroyer Apr 15, 2019
3f00c36
TypeParameterUnusedInFormals: Replace `.bound` by
don-vip Apr 15, 2019
6bbafbd
Fix for error-prone ImmutableEnumChecker warning
sumitbhagwani Apr 15, 2019
a902d79
Fix for error-prone AutoValueFinalMethods warning
sumitbhagwani Apr 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Omit enclosing class names of constructors in diagnostics
RELNOTES: N/A

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=241829483
  • Loading branch information
cushon authored and ronshapiro committed Apr 16, 2019
commit 8aa3f181e2f5e656a72e14cac4e440a5e711d6aa
18 changes: 13 additions & 5 deletions check_api/src/main/java/com/google/errorprone/util/Signatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,23 @@ public String toString() {
*/
public static String prettyMethodSignature(ClassSymbol origin, MethodSymbol m) {
StringBuilder sb = new StringBuilder();
if (!m.owner.equals(origin)) {
sb.append(m.owner.getSimpleName()).append('.');
if (m.isConstructor()) {
Name name = m.owner.enclClass().getSimpleName();
if (name.isEmpty()) {
// use the superclass name of anonymous classes
name = m.owner.enclClass().getSuperclass().asElement().getSimpleName();
}
sb.append(name);
} else {
if (!m.owner.equals(origin)) {
sb.append(m.owner.getSimpleName()).append('.');
}
sb.append(m.getSimpleName());
}
sb.append(m.isConstructor() ? origin.getSimpleName() : m.getSimpleName()).append('(');
sb.append(
m.getParameters().stream()
.map(v -> v.type.accept(PRETTY_TYPE_VISITOR, null))
.collect(joining(", ")));
sb.append(')');
.collect(joining(", ", "(", ")")));
return sb.toString();
}

Expand Down
94 changes: 94 additions & 0 deletions core/src/test/java/com/google/errorprone/util/SignaturesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright 2019 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.util;

import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.common.collect.ImmutableList;
import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import com.sun.source.tree.NewClassTree;
import com.sun.source.util.JavacTask;
import com.sun.source.util.TaskEvent;
import com.sun.source.util.TaskEvent.Kind;
import com.sun.source.util.TaskListener;
import com.sun.source.util.TreePathScanner;
import com.sun.tools.javac.api.JavacTool;
import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.util.Context;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** {@link Signatures}Test */
@RunWith(JUnit4.class)
public class SignaturesTest {

@Test
public void prettyMethodSignature() throws Exception {
FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix());
Path source = fileSystem.getPath("Test.java");
Files.write(
source,
ImmutableList.of(
"class Test {", //
" void f() {",
" new Test();",
" new Test() {};",
" }",
"}"),
UTF_8);
JavacFileManager fileManager = new JavacFileManager(new Context(), false, UTF_8);
List<String> signatures = new ArrayList<>();
JavacTask task =
JavacTool.create()
.getTask(
/* out= */ null,
fileManager,
/* diagnosticListener= */ null,
/* options= */ ImmutableList.of(),
/* classes= */ ImmutableList.of(),
fileManager.getJavaFileObjects(source));
task.addTaskListener(
new TaskListener() {
@Override
public void finished(TaskEvent e) {
if (e.getKind() != Kind.ANALYZE) {
return;
}
new TreePathScanner<Void, Void>() {
@Override
public Void visitNewClass(NewClassTree node, Void unused) {
signatures.add(
Signatures.prettyMethodSignature(
(ClassSymbol) e.getTypeElement(), ASTHelpers.getSymbol(node)));
return super.visitNewClass(node, null);
}
}.scan(e.getCompilationUnit(), null);
}
});
assertThat(task.call()).isTrue();
assertThat(signatures).containsExactly("Test()", "Test()");
}
}