Skip to content

Commit

Permalink
google-java-format
Browse files Browse the repository at this point in the history
MOE_MIGRATED_REVID=209463794
  • Loading branch information
cushon committed Aug 21, 2018
1 parent 0ebb747 commit 34ac40e
Show file tree
Hide file tree
Showing 110 changed files with 244 additions and 500 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ static void checkCompilePolicy(@Nullable String compilePolicy) {
* Sets javac's {@code -XDcompilePolicy} flag to ensure that all classes in a file are attributed
* before any of them are lowered. Error Prone depends on this behavior when analyzing files that
* contain multiple top-level classes.
*
*/
private static ImmutableList<String> setCompilePolicyToByFile(ImmutableList<String> args) {
for (String arg : args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,19 +270,15 @@ public void setDisableWarningsInGeneratedCode(boolean disableWarningsInGenerated
}

public void setDropErrorsToWarnings(boolean dropErrorsToWarnings) {
severityMap
.entrySet()
.stream()
severityMap.entrySet().stream()
.filter(e -> e.getValue() == Severity.ERROR)
.forEach(e -> e.setValue(Severity.WARN));
this.dropErrorsToWarnings = dropErrorsToWarnings;
}

public void setEnableAllChecksAsWarnings(boolean enableAllChecksAsWarnings) {
// Checks manually disabled before this flag are reset to warning-level
severityMap
.entrySet()
.stream()
severityMap.entrySet().stream()
.filter(e -> e.getValue() == Severity.OFF)
.forEach(e -> e.setValue(Severity.WARN));
this.enableAllChecksAsWarnings = enableAllChecksAsWarnings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ private JavacErrorDescriptionListener(
@Override
public void onDescribed(Description description) {
List<AppliedFix> appliedFixes =
description
.fixes
.stream()
description.fixes.stream()
.filter(f -> !shouldSkipImportTreeFix(description.node, f))
.map(fixToAppliedFix)
.filter(Objects::nonNull)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

package com.google.errorprone;

import com.google.common.base.Optional;
import com.google.common.base.Splitter;
import com.google.common.cache.CacheBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ public OrganizedImports organizeImports(List<Import> imports) {
private void organizePartition(OrganizedImports organized, List<Import> imports) {

Map<String, ImmutableSortedSet<Import>> groupedByRoot =
imports
.stream()
imports.stream()
.collect(
Collectors.groupingBy(
// Group by root package.
Expand All @@ -102,9 +101,7 @@ private void organizePartition(OrganizedImports organized, List<Import> imports)

// Get the third party roots by removing the roots that are handled specially and sorting.
Set<String> thirdParty =
groupedByRoot
.keySet()
.stream()
groupedByRoot.keySet().stream()
.filter(r -> !SPECIAL_ROOTS.contains(r))
.collect(toImmutableSortedSet(Ordering.natural()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public OrganizedImports organizeImports(List<Import> imports) {

// Group into static and non-static. Each group is a set sorted by type.
Map<Boolean, ImmutableSortedSet<Import>> partionedByStatic =
imports
.stream()
imports.stream()
.collect(
Collectors.partitioningBy(
Import::isStatic, toImmutableSortedSet(Comparator.comparing(Import::getType))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,7 @@ Nullness visitInstanceOf(
@Override
Nullness visitTypeCast(TypeCastNode node, SubNodeValues inputs) {
ImmutableList<String> annotations =
node.getType()
.getAnnotationMirrors()
.stream()
node.getType().getAnnotationMirrors().stream()
.map(Object::toString)
.collect(ImmutableList.toImmutableList());
return Nullness.fromAnnotations(annotations)
Expand Down Expand Up @@ -793,9 +791,7 @@ private Nullness returnValueNullness(@Nullable ClassAndMethod callee, MethodInvo
ImmutableList.<String>builder()
.addAll(inheritedAnnotations(node.getTarget().getMethod().getReturnType()))
.addAll(
node.getType()
.getAnnotationMirrors()
.stream()
node.getType().getAnnotationMirrors().stream()
.map(Object::toString)
.collect(ImmutableList.toImmutableList()))
.build();
Expand Down Expand Up @@ -828,20 +824,17 @@ private static ImmutableList<String> inheritedAnnotations(TypeMirror type) {
Element genericElt = ((TypeParameterElement) typeVar.asElement()).getGenericElement();
if (genericElt.getKind().isClass() || genericElt.getKind().isInterface()) {
((TypeElement) genericElt)
.getTypeParameters()
.stream()
.filter(
typeParam ->
typeParam.getSimpleName().equals(typeVar.asElement().getSimpleName()))
.findFirst()
// Annotations at class/interface type variable declaration
.ifPresent(decl -> inheritedAnnotations.addAll(decl.getAnnotationMirrors()));
.getTypeParameters().stream()
.filter(
typeParam ->
typeParam.getSimpleName().equals(typeVar.asElement().getSimpleName()))
.findFirst()
// Annotations at class/interface type variable declaration
.ifPresent(decl -> inheritedAnnotations.addAll(decl.getAnnotationMirrors()));
}
}
}
return inheritedAnnotations
.build()
.stream()
return inheritedAnnotations.build().stream()
.map(Object::toString)
.collect(ImmutableList.toImmutableList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class TrustingNullnessPropagation extends NullnessPropagationTransfer {
super(Nullness.NONNULL, TrustReturnAnnotation.INSTANCE);
}


@Override
Nullness fieldNullness(
@Nullable ClassAndField accessed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ private Optional<Nullness> getLowerBound(InferenceVariable iv) {
lowerBoundMemoTable.put(iv, Optional.empty());

result =
constraintGraph
.predecessors(iv)
.stream()
constraintGraph.predecessors(iv).stream()
.map(this::getLowerBound)
.filter(Optional::isPresent)
.map(Optional::get)
Expand All @@ -108,9 +106,7 @@ private Optional<Nullness> getUpperBound(InferenceVariable iv) {
upperBoundMemoTable.put(iv, Optional.empty());

result =
constraintGraph
.successors(iv)
.stream()
constraintGraph.successors(iv).stream()
.map(this::getUpperBound)
.filter(Optional::isPresent)
.map(Optional::get)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ public Void visitMethodInvocation(MethodInvocationTree node, Void unused) {
ImmutableList<Type> formalParameters =
callee.isVarArgs()
? expandVarargsToArity(callee.getParameters(), sourceNode.args.size())
: callee
.getParameters()
.stream()
: callee.getParameters().stream()
.map(var -> var.type)
.collect(ImmutableList.toImmutableList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ private static void addRemainingModifiers(
: ((JCTree) tree).getStartPosition();
int base = ((JCTree) tree).getStartPosition();
Optional<Integer> insert =
state
.getTokensForNode(tree)
.stream()
state.getTokensForNode(tree).stream()
.map(token -> token.pos() + base)
.filter(thisPos -> thisPos >= pos)
.findFirst();
Expand Down Expand Up @@ -754,9 +752,7 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept
}

private static long countErrors(DiagnosticCollector<JavaFileObject> diagnosticCollector) {
return diagnosticCollector
.getDiagnostics()
.stream()
return diagnosticCollector.getDiagnostics().stream()
.filter(d -> d.getKind() == Diagnostic.Kind.ERROR)
.count();
}
Expand Down Expand Up @@ -790,8 +786,7 @@ public String visitClassType(Type.ClassType t, Void unused) {
if (t.getTypeArguments().nonEmpty()) {
sb.append('<');
sb.append(
t.getTypeArguments()
.stream()
t.getTypeArguments().stream()
.map(a -> a.accept(this, null))
.collect(joining(", ")));
sb.append(">");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,17 @@ public double getNormalizedEditDistance(String source, String target) {

// costMatrix[s][t] is the edit distance between source term s and target term t
double[][] costMatrix =
sourceTerms
.stream()
sourceTerms.stream()
.map(s -> targetTerms.stream().mapToDouble(t -> editDistanceFn.apply(s, t)).toArray())
.toArray(double[][]::new);

// worstCaseMatrix[s][t] is the worst case distance between source term s and target term t
double[][] worstCaseMatrix =
sourceTerms
.stream()
sourceTerms.stream()
.map(s -> s.length())
.map(
s ->
targetTerms
.stream()
targetTerms.stream()
.map(t -> t.length())
.mapToDouble(t -> maxDistanceFn.apply(s, t))
.toArray())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,13 @@ public ScannerSupplier applyOverrides(ErrorProneOptions errorProneOptions)
}

if (errorProneOptions.isDropErrorsToWarnings()) {
getAllChecks()
.values()
.stream()
getAllChecks().values().stream()
.filter(c -> c.defaultSeverity() == SeverityLevel.ERROR && c.disableable())
.forEach(c -> severities.put(c.canonicalName(), SeverityLevel.WARNING));
}

if (errorProneOptions.isDisableAllChecks()) {
getAllChecks()
.values()
.stream()
getAllChecks().values().stream()
.filter(c -> c.disableable())
.forEach(c -> disabled.add(c.canonicalName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ private BugChecker instantiateChecker(BugCheckerInfo checker) {
@Override
public ErrorProneScanner get() {
return new ErrorProneScanner(
getEnabledChecks()
.stream()
getEnabledChecks().stream()
.map(this::instantiateChecker)
.collect(ImmutableSet.toImmutableSet()),
severities);
Expand All @@ -112,9 +111,7 @@ protected ImmutableSet<String> disabled() {

@Override
public ImmutableSet<BugCheckerInfo> getEnabledChecks() {
return getAllChecks()
.values()
.stream()
return getAllChecks().values().stream()
.filter(input -> !disabled.contains(input.canonicalName()))
.collect(ImmutableSet.toImmutableSet());
}
Expand Down
18 changes: 5 additions & 13 deletions check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ public static boolean requiresParentheses(ExpressionTree expression, VisitorStat
return false;
}
// TODO(b/112139121): work around for javac's too-early constant string folding
return ErrorProneTokens.getTokens(state.getSourceForNode(expression), state.context)
.stream()
return ErrorProneTokens.getTokens(state.getSourceForNode(expression), state.context).stream()
.anyMatch(t -> t.kind() == TokenKind.PLUS);
}
if (expression instanceof UnaryTree) {
Expand Down Expand Up @@ -569,9 +568,7 @@ public static Optional<MethodSymbol> findSuperMethod(MethodSymbol methodSymbol,
private static Stream<MethodSymbol> findSuperMethods(
MethodSymbol methodSymbol, Types types, boolean skipInterfaces) {
TypeSymbol owner = (TypeSymbol) methodSymbol.owner;
return types
.closure(owner.type)
.stream()
return types.closure(owner.type).stream()
.filter(closureTypes -> skipInterfaces ? !closureTypes.isInterface() : true)
.map(type -> findSuperMethodInType(methodSymbol, type, types))
.filter(Objects::nonNull);
Expand Down Expand Up @@ -676,8 +673,7 @@ private static boolean isInherited(VisitorState state, String annotationName) {
}

private static boolean hasAttribute(Symbol sym, Name annotationName) {
return sym.getRawAttributes()
.stream()
return sym.getRawAttributes().stream()
.anyMatch(a -> a.type.tsym.getQualifiedName().equals(annotationName));
}

Expand Down Expand Up @@ -1114,10 +1110,7 @@ public static ImmutableSet<String> getGeneratedBy(ClassSymbol symbol, VisitorSta
return ImmutableSet.of();
}
Optional<Attribute> values =
c.get()
.getElementValues()
.entrySet()
.stream()
c.get().getElementValues().entrySet().stream()
.filter(e -> e.getKey().getSimpleName().contentEquals("value"))
.map(e -> e.getValue())
.findAny();
Expand Down Expand Up @@ -1534,8 +1527,7 @@ public static AnnotationMirror getAnnotationMirror(AnnotationTree annotationTree

/** Returns whether the given {@code tree} contains any comments in its source. */
public static boolean containsComments(Tree tree, VisitorState state) {
return ErrorProneTokens.getTokens(state.getSourceForNode(tree), state.context)
.stream()
return ErrorProneTokens.getTokens(state.getSourceForNode(tree), state.context).stream()
.anyMatch(t -> !t.comments().isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ private static ImmutableList<Commented<ExpressionTree>> findCommentsForArguments

private static ImmutableList<Commented<ExpressionTree>> noComments(
List<? extends ExpressionTree> arguments) {
return arguments
.stream()
return arguments.stream()
.map(a -> Commented.<ExpressionTree>builder().setTree(a).build())
.collect(toImmutableList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ public static LinkedHashSet<VarSymbol> findAllIdents(VisitorState state) {
}

// TODO(eaftan): switch out collector for ImmutableSet.toImmutableSet()
return result
.build()
.stream()
return result.build().stream()
.filter(var -> isVisible(var, state.getPath()))
.collect(Collectors.toCollection(LinkedHashSet::new));
}
Expand Down Expand Up @@ -279,10 +277,7 @@ public static ImmutableSet<Symbol> findReferencedIdentifiers(Tree tree) {
/** Finds all the visible fields declared or inherited in the target class */
public static List<VarSymbol> findAllFields(Type classType, VisitorState state) {
// TODO(andrewrice): Switch collector to ImmutableList.toImmutableList() when released
return state
.getTypes()
.closure(classType)
.stream()
return state.getTypes().closure(classType).stream()
.flatMap(
type -> {
TypeSymbol tsym = type.tsym;
Expand All @@ -293,8 +288,7 @@ public static List<VarSymbol> findAllFields(Type classType, VisitorState state)
if (scope == null) {
return ImmutableList.<VarSymbol>of().stream();
}
return ImmutableList.copyOf(scope.getSymbols(VarSymbol.class::isInstance))
.reverse()
return ImmutableList.copyOf(scope.getSymbols(VarSymbol.class::isInstance)).reverse()
.stream()
.map(v -> (VarSymbol) v)
.filter(v -> isVisible(v, state.getPath()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ public static Stream<Attribute.Compound> getDeclarationAndTypeAttributes(Symbol
}
return Streams.concat(
sym.getRawAttributes().stream(),
typeAnnotationOwner
.getRawTypeAttributes()
.stream()
typeAnnotationOwner.getRawTypeAttributes().stream()
.filter(anno -> isAnnotationOnType(sym, anno.position)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ public static String prettyMethodSignature(ClassSymbol origin, MethodSymbol m) {
}
sb.append(m.isConstructor() ? origin.getSimpleName() : m.getSimpleName()).append('(');
sb.append(
m.getParameters()
.stream()
m.getParameters().stream()
.map(v -> v.type.accept(PRETTY_TYPE_VISITOR, null))
.collect(joining(", ")));
sb.append(')');
Expand Down Expand Up @@ -124,8 +123,7 @@ public String visitClassType(Type.ClassType t, Void s) {
if (t.getTypeArguments().nonEmpty()) {
sb.append('<');
sb.append(
t.getTypeArguments()
.stream()
t.getTypeArguments().stream()
.map(a -> a.accept(this, null))
.collect(joining(", ")));
sb.append(">");
Expand Down
Loading

0 comments on commit 34ac40e

Please sign in to comment.