mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
method contracts: use underscore instead of "any"
This commit is contained in:
+2
-2
@@ -1512,8 +1512,8 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
if ("false".equals(name)) return ValueConstraint.FALSE_VALUE;
|
||||
if ("exit".equals(name)) return ValueConstraint.SYSTEM_EXIT;
|
||||
if ("fail".equals(name)) return ValueConstraint.THROW_EXCEPTION;
|
||||
if ("any".equals(name)) return ValueConstraint.ANY_VALUE;
|
||||
throw new ParseException("Constraint should be one of: null, !null, true, false, exit, fail, any. Found: " + name);
|
||||
if ("_".equals(name)) return ValueConstraint.ANY_VALUE;
|
||||
throw new ParseException("Constraint should be one of: null, !null, true, false, exit, fail, _. Found: " + name);
|
||||
}
|
||||
|
||||
private static class ParseException extends Exception {
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.lang.annotation.*;
|
||||
*
|
||||
* The constraints denote the following:<br/>
|
||||
* <ul>
|
||||
* <li> any - any value
|
||||
* <li> _ - any value
|
||||
* <li> null - null value
|
||||
* <li> !null - a value statically proved to be not-null
|
||||
* <li> true - true boolean value
|
||||
@@ -39,8 +39,8 @@ import java.lang.annotation.*;
|
||||
* <li> exit - the method terminates the current process, if the arguments satisfy argument constraints
|
||||
* </ul>
|
||||
* Examples:<p/>
|
||||
* <code>@Contract("any, null -> null")</code> - method returns null if its second argument is null<br/>
|
||||
* <code>@Contract("any, null -> null; any, !null -> !null")</code> - method returns null if its second argument is null and not-null otherwise<br/>
|
||||
* <code>@Contract("_, null -> null")</code> - method returns null if its second argument is null<br/>
|
||||
* <code>@Contract("_, null -> null; _, !null -> !null")</code> - method returns null if its second argument is null and not-null otherwise<br/>
|
||||
* <code>@Contract("true -> fail")</code> - a typical assertFalse method which throws an exception if <code>true</code> is passed to it<br/>
|
||||
*
|
||||
* @author peter
|
||||
|
||||
@@ -51,7 +51,7 @@ public class PsiTreeUtil {
|
||||
* @param strict whether return true if ancestor and parent are the same.
|
||||
* @return true if element has ancestor as its parent somewhere in the hierarchy and false otherwise.
|
||||
*/
|
||||
@Contract("null, any, any -> false")
|
||||
@Contract("null, _, _ -> false")
|
||||
public static boolean isAncestor(@Nullable PsiElement ancestor, @NotNull PsiElement element, boolean strict) {
|
||||
if (ancestor == null) return false;
|
||||
// fast path to avoid loading tree
|
||||
@@ -79,7 +79,7 @@ public class PsiTreeUtil {
|
||||
* @param strict whether return true if ancestor and parent are the same.
|
||||
* @return true if element has ancestor as its parent somewhere in the hierarchy and false otherwise.
|
||||
*/
|
||||
@Contract("null, any, any -> false")
|
||||
@Contract("null, _, _ -> false")
|
||||
public static boolean isContextAncestor(@Nullable PsiElement ancestor, @NotNull PsiElement element, boolean strict) {
|
||||
if (ancestor == null) return false;
|
||||
boolean stopAtFileLevel = !(ancestor instanceof PsiFile || ancestor instanceof PsiDirectory);
|
||||
@@ -223,7 +223,7 @@ public class PsiTreeUtil {
|
||||
* @return first found element, or null if nothing found.
|
||||
*/
|
||||
@Nullable
|
||||
@Contract("null, any, any -> null")
|
||||
@Contract("null, _, _ -> null")
|
||||
public static <T extends PsiElement> T findChildOfAnyType(@Nullable final PsiElement element, @NotNull final Class<? extends T>... classes) {
|
||||
return findChildOfAnyType(element, true, classes);
|
||||
}
|
||||
@@ -238,7 +238,7 @@ public class PsiTreeUtil {
|
||||
* @return first found element, or null if nothing found.
|
||||
*/
|
||||
@Nullable
|
||||
@Contract("null, any, any -> null")
|
||||
@Contract("null, _, _ -> null")
|
||||
public static <T extends PsiElement> T findChildOfAnyType(@Nullable final PsiElement element,
|
||||
final boolean strict,
|
||||
@NotNull final Class<? extends T>... classes) {
|
||||
@@ -378,7 +378,7 @@ public class PsiTreeUtil {
|
||||
* @since 5.1
|
||||
*/
|
||||
@Nullable
|
||||
@Contract("null, any -> null")
|
||||
@Contract("null, _ -> null")
|
||||
public static <T extends PsiElement> T getChildOfAnyType(@Nullable PsiElement element, @NotNull Class<? extends T>... classes) {
|
||||
if (element == null) return null;
|
||||
for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
@@ -393,7 +393,7 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null, any -> null")
|
||||
@Contract("null, _ -> null")
|
||||
public static <T extends PsiElement> T getNextSiblingOfType(@Nullable PsiElement sibling, @NotNull Class<T> aClass) {
|
||||
if (sibling == null) return null;
|
||||
for (PsiElement child = sibling.getNextSibling(); child != null; child = child.getNextSibling()) {
|
||||
@@ -406,7 +406,7 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null, any -> null")
|
||||
@Contract("null, _ -> null")
|
||||
public static <T extends PsiElement> T getPrevSiblingOfType(@Nullable PsiElement sibling, @NotNull Class<T> aClass) {
|
||||
if (sibling == null) return null;
|
||||
for (PsiElement child = sibling.getPrevSibling(); child != null; child = child.getPrevSibling()) {
|
||||
@@ -419,7 +419,7 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null, any -> null")
|
||||
@Contract("null, _ -> null")
|
||||
public static <T extends PsiElement> T getTopmostParentOfType(@Nullable PsiElement element, @NotNull Class<T> aClass) {
|
||||
T answer = getParentOfType(element, aClass);
|
||||
|
||||
@@ -434,7 +434,7 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null, any -> null")
|
||||
@Contract("null, _ -> null")
|
||||
public static <T extends PsiElement> T getParentOfType(@Nullable PsiElement element, @NotNull Class<T> aClass) {
|
||||
return getParentOfType(element, aClass, true);
|
||||
}
|
||||
@@ -454,7 +454,7 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null, any -> null")
|
||||
@Contract("null, _ -> null")
|
||||
public static <E extends PsiElement> E getStubOrPsiParentOfType(@Nullable PsiElement element, @NotNull Class<E> parentClass) {
|
||||
if (element instanceof StubBasedPsiElement) {
|
||||
StubBase stub = (StubBase)((StubBasedPsiElement)element).getStub();
|
||||
@@ -467,7 +467,7 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null, any, any, any -> null")
|
||||
@Contract("null, _, _, _ -> null")
|
||||
public static <T extends PsiElement> T getContextOfType(@Nullable PsiElement element,
|
||||
@NotNull Class<T> aClass,
|
||||
boolean strict,
|
||||
@@ -487,7 +487,7 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null, any, any -> null")
|
||||
@Contract("null, _, _ -> null")
|
||||
public static <T extends PsiElement> T getContextOfType(@Nullable PsiElement element,
|
||||
@NotNull Class<? extends T> aClass,
|
||||
boolean strict) {
|
||||
@@ -500,7 +500,7 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null, any, any -> null")
|
||||
@Contract("null, _, _ -> null")
|
||||
public static <T extends PsiElement> T getContextOfType(@Nullable PsiElement element,
|
||||
boolean strict,
|
||||
@NotNull Class<? extends T>... classes) {
|
||||
@@ -518,7 +518,7 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null, any, any -> null")
|
||||
@Contract("null, _, _ -> null")
|
||||
public static <T extends PsiElement> T getParentOfType(@Nullable PsiElement element, @NotNull Class<T> aClass, boolean strict) {
|
||||
if (element == null) return null;
|
||||
if (strict) {
|
||||
@@ -538,7 +538,7 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null, any, any, any -> null")
|
||||
@Contract("null, _, _, _ -> null")
|
||||
public static <T extends PsiElement> T getParentOfType(@Nullable PsiElement element,
|
||||
@NotNull Class<T> aClass,
|
||||
boolean strict,
|
||||
@@ -559,7 +559,7 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null, any -> null")
|
||||
@Contract("null, _ -> null")
|
||||
public static PsiElement skipSiblingsForward(@Nullable PsiElement element, @NotNull Class... elementClasses) {
|
||||
if (element == null) return null;
|
||||
NextSibling:
|
||||
@@ -571,7 +571,7 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null, any -> null")
|
||||
@Contract("null, _ -> null")
|
||||
public static PsiElement skipSiblingsBackward(@Nullable PsiElement element, @NotNull Class... elementClasses) {
|
||||
if (element == null) return null;
|
||||
NextSibling:
|
||||
@@ -583,7 +583,7 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null, any -> null")
|
||||
@Contract("null, _ -> null")
|
||||
public static PsiElement skipParentsOfType(@Nullable PsiElement element, @NotNull Class... parentClasses) {
|
||||
if (element == null) return null;
|
||||
NextSibling:
|
||||
@@ -595,7 +595,7 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null, any -> null")
|
||||
@Contract("null, _ -> null")
|
||||
public static <T extends PsiElement> T getParentOfType(@Nullable final PsiElement element,
|
||||
@NotNull final Class<? extends T>... classes) {
|
||||
if (element == null) return null;
|
||||
@@ -605,7 +605,7 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null, any -> null")
|
||||
@Contract("null, _ -> null")
|
||||
public static <T extends PsiElement> T getNonStrictParentOfType(@Nullable final PsiElement element,
|
||||
@NotNull final Class<? extends T>... classes) {
|
||||
PsiElement run = element;
|
||||
@@ -648,7 +648,7 @@ public class PsiTreeUtil {
|
||||
return processor.getCollection();
|
||||
}
|
||||
|
||||
@Contract("null, any -> true")
|
||||
@Contract("null, _ -> true")
|
||||
public static boolean processElements(@Nullable PsiElement element, @NotNull final PsiElementProcessor processor) {
|
||||
if (element == null) return true;
|
||||
if (element instanceof PsiCompiledElement || !element.isPhysical()) { // DummyHolders cannot be visited by walking visitors because children/parent relationship is broken there
|
||||
|
||||
Reference in New Issue
Block a user