Skip to content

Commit

Permalink
Improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
mernst committed Mar 11, 2019
1 parent ae06f51 commit 0545996
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,11 @@ public Effect getDeclaredEffect(ExecutableElement methodElt) {
* Get the effect of a method call at its callsite, acknowledging polymorphic instantiation
* using type use annotations.
*
* @param node The method invocation as an AST node.
* @param callerReceiver The type of the receiver object if available. Used to resolve direct
* @param node the method invocation as an AST node
* @param callerReceiver the type of the receiver object if available. Used to resolve direct
* calls like "super()"
* @param methodElt The element of the callee method.
* @return The computed effect (SafeEffect or UIEffect) for the method call.
* @param methodElt the element of the callee method
* @return the computed effect (SafeEffect or UIEffect) for the method call
*/
public Effect getComputedEffectAtCallsite(
MethodInvocationTree node,
Expand Down Expand Up @@ -332,8 +332,8 @@ public Effect getComputedEffectAtCallsite(
* with @PolyUIEffect functional interfaces as being explicitly UI-affecting using the {@link
* #constrainLambdaToUI(LambdaExpressionTree) constrainLambdaToUI} method.
*
* @param lambdaTree A lambda expression's AST node.
* @return The inferred effect of the lambda.
* @param lambdaTree a lambda expression's AST node
* @return the inferred effect of the lambda
*/
public Effect getInferedEffectForLambdaExpression(LambdaExpressionTree lambdaTree) {
// @UI type if annotated on the lambda expression explicitly
Expand All @@ -356,8 +356,8 @@ public Effect getInferedEffectForLambdaExpression(LambdaExpressionTree lambdaTre
* considered here, for the properly computed type of the expression, use {@link
* #getAnnotatedType(Tree)} instead.
*
* @param tree The tree to check.
* @return Whether it is a lambda expression or new class marked as UI by inference
* @param tree the tree to check
* @return whether it is a lambda expression or new class marked as UI by inference
*/
public boolean isDirectlyMarkedUIThroughInference(Tree tree) {
if (tree.getKind() == Tree.Kind.LAMBDA_EXPRESSION) {
Expand Down Expand Up @@ -610,7 +610,7 @@ protected TreeAnnotator createTreeAnnotator() {
* <p>Used by GuiEffectVisitor to mark as UIEffect all lambdas that perform UIEffect calls
* inside their bodies.
*
* @param lambdaExpressionTree A lambda expression's AST node.
* @param lambdaExpressionTree a lambda expression's AST node
*/
public void constrainLambdaToUI(LambdaExpressionTree lambdaExpressionTree) {
uiLambdas.add(lambdaExpressionTree);
Expand All @@ -623,7 +623,7 @@ public void constrainLambdaToUI(LambdaExpressionTree lambdaExpressionTree) {
* PolyUIType annotated superclass, override a PolyUIEffect method from said superclass, and
* perform UIEffect calls inside the body of this method.
*
* @param classElt The TypeElement corresponding to the anonymous inner class to mark as an @UI
* @param classElt the TypeElement corresponding to the anonymous inner class to mark as an @UI
* instantiation of an UI-polymorphic superclass.
*/
public void constrainAnonymousClassToUI(TypeElement classElt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void tryFormatSatisfiability(String format) throws IllegalFormatEx
* Returns a {@link I18nConversionCategory} for every conversion found in the format string.
*
* @param format the format string to parse
* @throws IllegalFormatException if the format is not syntactically valid.
* @throws IllegalFormatException if the format is not syntactically valid
*/
public static I18nConversionCategory[] formatParameterCategories(String format)
throws IllegalFormatException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
* <ul>
* <li>give appropriate types to compile time constants. For example, the type of 7 is Positive, 0
* is NonNegative, etc.
* <li>in a subtraction expression of the form `a.length - x`, if x is a compile time constant,
* and if the minimum length of a &gt; x, the resulting expression is non-negative.
* <li>when typing an array length (i.e. `a.length`), if the minimum length of the array is &gt;=
* 1, then the type is @Positive; if its MinLen is zero, then the type is @NonNegative.
* <li>in a subtraction expression of the form {@code a.length - x}, if x is a compile-time
* constant, and if the minimum length of a &gt; x, the resulting expression is non-negative.
* <li>when typing an array length (i.e. {@code a.length}), if the minimum length of the array is
* &ge; 1, then the type is @Positive; if its MinLen is zero, then the type is @NonNegative.
* </ul>
*
* <p>The Upper Bound Checker depends on all three other checkers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ public AnnotationMirror greatestLowerBound(AnnotationMirror a1, AnnotationMirror
}
}

/** @return Is left less than right? */
/** @return is left less than right? */
public boolean isLessThan(Tree left, String right) {
AnnotatedTypeMirror leftATM = getAnnotatedType(left);
return isLessThan(leftATM.getAnnotationInHierarchy(UNKNOWN), right);
}

/** @return Is left less than right? */
/** @return is left less than right? */
public static boolean isLessThan(AnnotationMirror left, String right) {
List<String> expressions = getLessThanExpressions(left);
if (expressions == null) {
Expand Down Expand Up @@ -211,13 +211,13 @@ private long getMinValueFromString(String expression, Tree tree, TreePath path)
return Long.MIN_VALUE;
}

/** @return Is left less than or equal to right? */
/** @return is left less than or equal to right? */
public boolean isLessThanOrEqual(Tree left, String right) {
AnnotatedTypeMirror leftATM = getAnnotatedType(left);
return isLessThanOrEqual(leftATM.getAnnotationInHierarchy(UNKNOWN), right);
}

/** @return Is left less than or equal to right? */
/** @return is left less than or equal to right? */
public static boolean isLessThanOrEqual(AnnotationMirror left, String right) {
List<String> expressions = getLessThanExpressions(left);
if (expressions == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private boolean isOptionalCreation(MethodInvocationTree methInvok) {

/**
* @return true iff expression is a call to Optional elimination: get, orElse, orElseGet,
* orElseThrow.
* orElseThrow
*/
private boolean isOptionalElimation(MethodInvocationTree methInvok) {
ProcessingEnvironment env = checker.getProcessingEnvironment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public enum When {
ALWAYS,
/** nothing definitive is known about the relation between S and T */
UNKNOWN,
/** S intersection T is non empty and S - T is nonempty */
/** S intersection T is non empty and S - T is nonempty. */
MAYBE,
/** S intersection T is empty */
/** S intersection T is empty. */
NEVER;
}
4 changes: 3 additions & 1 deletion checker/tests/index/Issue194.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public boolean m(Custom a, Custom b) {
return false;
}
for (int i = 0; i < a.length(); ++i) {
if (a.get(i) != b.get(i)) return false;
if (a.get(i) != b.get(i)) {
return false;
}
}
return true;
}
Expand Down
4 changes: 3 additions & 1 deletion checker/tests/index/LTLengthOfPostcondition.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public void useShiftIndex(@NonNegative int x) {
offset = "#1 - 1")
public boolean tryShiftIndex(@NonNegative int x) {
int newEnd = end - x;
if (newEnd < 0) return false;
if (newEnd < 0) {
return false;
}
end = newEnd;
return true;
}
Expand Down
16 changes: 12 additions & 4 deletions checker/tests/interning/Heuristics.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ public int compare(String s1, String s2) {
public boolean equals(Object o) {
// Using == is OK if it's the first statement in the equals method
// and it compares "this" against the argument.
if (this == o) return true;
if (this == o) {
return true;
}
// Not the first statement in the method.
// :: error: (not.interned)
if (o == this) return true;
if (o == this) {
return true;
}
return false;
}

Expand All @@ -31,10 +35,14 @@ public int compareTo(Heuristics o) {
// Using == is OK if it's the first statement in the equals method
// and it compares "this" against the argument.

if (o == this) return 0;
if (o == this) {
return 0;
}
// Not the first statement in the method.
// :: error: (not.interned)
if (this == o) return 0;
if (this == o) {
return 0;
}
return 0;
}

Expand Down
12 changes: 9 additions & 3 deletions checker/tests/nullness/AssertIfChecked.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ boolean testParam(final @Nullable Object param) {

@EnsuresNonNullIf(result = true, expression = "#1")
boolean testLitTTgood1(final @Nullable Object param) {
if (param == null) return false;
if (param == null) {
return false;
}
return true;
}

Expand All @@ -85,14 +87,18 @@ boolean testLitFFgood1(final @Nullable Object param) {

@EnsuresNonNullIf(result = false, expression = "#1")
boolean testLitFFgood2(final @Nullable Object param) {
if (param == null) return true;
if (param == null) {
return true;
}
return false;
}

@EnsuresNonNullIf(result = false, expression = "#1")
boolean testLitFFbad1(final @Nullable Object param) {
// :: error: (contracts.conditional.postcondition.not.satisfied)
if (param == null) return false;
if (param == null) {
return false;
}
return true;
}

Expand Down
4 changes: 3 additions & 1 deletion checker/tests/nullness/Issue1922.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public class Issue1922 {
// A method to find a K in the collection and return it, or return null.
public static <K> @Nullable K findKey(Collection<@NonNull K> keys, Object target) {
for (K key : keys) {
if (target.equals(key)) return key;
if (target.equals(key)) {
return key;
}
}
return null;
}
Expand Down
5 changes: 3 additions & 2 deletions checker/tests/nullness/java8/lambda/LambdaNullness.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ class LambdaNullness {
// Complex block body with returns
Supplier<Integer> f6 =
() -> {
if (true) return 12;
else {
if (true) {
return 12;
} else {
int result = 15;
for (int i = 1; i < 10; i++) {
result *= i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public HashMap<Element, A> getFinalLocalValues() {
* Callers of this method should always iterate through the returned set, possibly ignoring all
* {@code Node}s they are not interested in.
*
* @return the set of {@link Node}s for a given {@link Tree}.
* @return the set of {@link Node}s for a given {@link Tree}
*/
public @Nullable Set<Node> getNodesForTree(Tree tree) {
return treeLookup.get(tree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2587,7 +2587,7 @@ protected VariableTree getAssertionsEnabledVariable() {
/**
* Find nearest owner element(Method or Class) which holds current tree.
*
* @return Nearest owner element of current tree
* @return nearest owner element of current tree
*/
private Element findOwner() {
MethodTree enclosingMethod = TreeUtils.enclosingMethod(getCurrentPath());
Expand Down Expand Up @@ -4684,9 +4684,9 @@ public Node visitUnary(UnaryTree tree, Void p) {
*
* @param target Target tree for assignment node. If it's null, corresponding assignment
* tree will be generated.
* @param expr Expression node to be incremented or decremented
* @param isIncrement True when it's increment
* @return Assignment node for corresponding increment or decrement
* @param expr expression node to be incremented or decremented
* @param isIncrement true when it's increment
* @return assignment node for corresponding increment or decrement
*/
private AssignmentNode createIncrementOrDecrementAssign(
Tree target, Node expr, boolean isIncrement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public Node getResult() {

/**
* Returns the {@link ExpressionTree} corresponding to the body of a lambda expression with an
* expression body (e.g. X for (<code>o -&gt; X</code>) where X is an expression and not a {...}
* block).
* expression body (e.g. X for ({@code o -> X}) where X is an expression and not a {...} block).
*/
@Override
public ExpressionTree getTree() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public static String getDefaultClassPath() {
/**
* The path to the annotated JDK, looked up from the system property "JDK_JAR".
*
* @return the value of the system property "JDK_JAR".
* @return the value of the system property "JDK_JAR"
*/
public static String getJdkJarPathFromProperty() {
return System.getProperty("JDK_JAR");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public ParameterizedExecutableType methodFromUse(
* Finds the appropriate value for the {@code from} value of an annotated type mirror containing
* an {@code IntRange} annotation.
*
* @param atm An annotated type mirror that contains an {@code IntRange} annotation.
* @param atm an annotated type mirror that contains an {@code IntRange} annotation.
* @return either the from value from the passed int range annotation, or the minimum value of
* the domain of the underlying type (i.e. Integer.MIN_VALUE if the underlying type is int)
*/
Expand Down Expand Up @@ -361,7 +361,7 @@ public long getFromValueFromIntRange(AnnotatedTypeMirror atm) {
* Finds the appropriate value for the {@code to} value of an annotated type mirror containing
* an {@code IntRange} annotation.
*
* @param atm An annotated type mirror that contains an {@code IntRange} annotation.
* @param atm an annotated type mirror that contains an {@code IntRange} annotation.
* @return either the to value from the passed int range annotation, or the maximum value of the
* domain of the underlying type (i.e. Integer.MAX_VALUE if the underlying type is int)
*/
Expand Down Expand Up @@ -1642,7 +1642,7 @@ private AnnotationMirror convertIntValToDoubleVal(AnnotationMirror intValAnno) {
return createDoubleValAnnotation(convertLongListToDoubleList(intValues));
}

/** Convert a {@code List&lt;Long&gt;} to a {@code List&lt;Double&gt;}. */
/** Convert a {@code List<Long>} to a {@code List<Double>}. */
private List<Double> convertLongListToDoubleList(List<Long> intValues) {
List<Double> doubleValues = new ArrayList<>(intValues.size());
for (Long intValue : intValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected boolean checkOverride(
* prevent these annotations from being required on the left hand side of assignments.
*
* @param varType an annotated type mirror that may contain IntRangeFromX annotations, which
* will be used on the lhs of an assignment or pseudo-assignment.
* will be used on the lhs of an assignment or pseudo-assignment
*/
private void replaceSpecialIntRangeAnnotations(AnnotatedTypeMirror varType) {
AnnotatedTypeScanner<Void, Void> replaceSpecialIntRangeAnnotations =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3668,7 +3668,7 @@ public AnnotatedTypeMirror widenToUpperBound(
* <p>The target type of a member reference is the type to which it is assigned or casted.
*
* @param tree member reference tree
* @return the functional interface and the function type that this method reference targets.
* @return the functional interface and the function type that this method reference targets
*/
public Pair<AnnotatedDeclaredType, AnnotatedExecutableType> getFnInterfaceFromTree(
MemberReferenceTree tree) {
Expand All @@ -3684,7 +3684,7 @@ public Pair<AnnotatedDeclaredType, AnnotatedExecutableType> getFnInterfaceFromTr
* <p>The target type of a lambda is the type to which it is assigned or casted.
*
* @param tree lambda expression tree
* @return the functional interface and the function type that this lambda targets.
* @return the functional interface and the function type that this lambda targets
*/
public Pair<AnnotatedDeclaredType, AnnotatedExecutableType> getFnInterfaceFromTree(
LambdaExpressionTree tree) {
Expand All @@ -3703,7 +3703,7 @@ public Pair<AnnotatedDeclaredType, AnnotatedExecutableType> getFnInterfaceFromTr
*
* @param tree lambda expression tree or member reference tree
* @return the functional interface and the function type that this method reference or lambda
* targets.
* targets
*/
private Pair<AnnotatedDeclaredType, AnnotatedExecutableType> getFnInterfaceFromTree(Tree tree) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ private final Set<String> getBundledAnnotationNamesFromJar(final JarFile jar) {
* @param annoName canonical name of an external annotation class, e.g.
* "myproject.qual.myannotation"
* @return the loaded annotation class, or null if it was not a supported annotation as decided
* by {@link #isSupportedAnnotationClass(Class)}.
* by {@link #isSupportedAnnotationClass(Class)}
*/
public final @Nullable Class<? extends Annotation> loadExternalAnnotationClass(
final String annoName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class BoundsInitializer {
* is set to the upper bound of the type parameter for which it is an argument. If {@code
* declaredType} is raw, then the type arguments are uninferred wildcards.
*
* @param declaredType type whose arguments are initialized.
* @param declaredType type whose arguments are initialized
*/
public static void initializeTypeArgs(AnnotatedDeclaredType declaredType) {
final DeclaredType actualType = (DeclaredType) declaredType.actualType;
Expand Down Expand Up @@ -433,7 +433,7 @@ public Void visitExecutable(AnnotatedExecutableType type, Void aVoid) {
* If the underlying type of (@code type} has been visited before, return the previous
* AnnotatedTypeMirror. Otherwise, visit {@code type} and return it.
*
* @param type type to visit.
* @param type type to visit
* @return {@code type} or an AnnotatedTypeMirror with the same underlying type that was
* previously visited.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ public Store getStoreAfter(Node node) {

/**
* @see org.checkerframework.dataflow.analysis.AnalysisResult#getNodesForTree(Tree)
* @return the {@link Node}s for a given {@link Tree}.
* @return the {@link Node}s for a given {@link Tree}
*/
public Set<Node> getNodesForTree(Tree tree) {
return flowResult.getNodesForTree(tree);
Expand Down
Loading

0 comments on commit 0545996

Please sign in to comment.