use of org.jetbrains.annotations.Contract in project intellij-community by JetBrains.
the class UnclearBinaryExpressionInspection method isUnclearExpression.
@Contract("null, _ -> false")
public static boolean isUnclearExpression(PsiExpression expression, PsiElement parent) {
if (expression instanceof PsiAssignmentExpression) {
final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression) expression;
final IElementType tokenType = assignmentExpression.getOperationTokenType();
if (parent instanceof PsiVariable) {
if (!tokenType.equals(JavaTokenType.EQ)) {
return true;
}
} else if (parent instanceof PsiAssignmentExpression) {
final PsiAssignmentExpression nestedAssignment = (PsiAssignmentExpression) parent;
final IElementType nestedTokenType = nestedAssignment.getOperationTokenType();
if (!tokenType.equals(nestedTokenType)) {
return true;
}
}
return isUnclearExpression(assignmentExpression.getRExpression(), assignmentExpression);
} else if (expression instanceof PsiConditionalExpression) {
final PsiConditionalExpression conditionalExpression = (PsiConditionalExpression) expression;
if (PsiUtilCore.hasErrorElementChild(expression)) {
return false;
}
return (parent instanceof PsiConditionalExpression) || isUnclearExpression(conditionalExpression.getCondition(), conditionalExpression) || isUnclearExpression(conditionalExpression.getThenExpression(), conditionalExpression) || isUnclearExpression(conditionalExpression.getElseExpression(), conditionalExpression);
} else if (expression instanceof PsiPolyadicExpression) {
if ((parent instanceof PsiConditionalExpression) || (parent instanceof PsiPolyadicExpression) || (parent instanceof PsiInstanceOfExpression)) {
return true;
}
final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression) expression;
for (PsiExpression operand : polyadicExpression.getOperands()) {
final PsiType type = operand.getType();
if ((type == null) || type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
return false;
}
if (isUnclearExpression(operand, polyadicExpression)) {
return true;
}
}
} else if (expression instanceof PsiInstanceOfExpression) {
if ((parent instanceof PsiPolyadicExpression) || (parent instanceof PsiConditionalExpression)) {
return true;
}
final PsiInstanceOfExpression instanceOfExpression = (PsiInstanceOfExpression) expression;
return isUnclearExpression(instanceOfExpression.getOperand(), instanceOfExpression);
} else if (expression instanceof PsiParenthesizedExpression) {
final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression) expression;
final PsiExpression nestedExpression = parenthesizedExpression.getExpression();
return isUnclearExpression(nestedExpression, parenthesizedExpression);
}
return false;
}
use of org.jetbrains.annotations.Contract in project intellij-community by JetBrains.
the class IdeFrameFixture method findFileByRelativePath.
@Nullable
@Contract("_, true -> !null")
public VirtualFile findFileByRelativePath(@NotNull String relativePath, boolean requireExists) {
//noinspection Contract
assertFalse("Should use '/' in test relative paths, not File.separator", relativePath.contains("\\"));
Project project = getProject();
VirtualFile file = project.getBaseDir().findFileByRelativePath(relativePath);
if (requireExists) {
//noinspection Contract
assertNotNull("Unable to find file with relative path " + quote(relativePath), file);
}
return file;
}
use of org.jetbrains.annotations.Contract in project intellij-community by JetBrains.
the class StringUtil method getWordIndicesIn.
@NotNull
@Contract(pure = true)
public static List<TextRange> getWordIndicesIn(@NotNull String text) {
List<TextRange> result = new SmartList<TextRange>();
int start = -1;
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
boolean isIdentifierPart = Character.isJavaIdentifierPart(c);
if (isIdentifierPart && start == -1) {
start = i;
}
if (isIdentifierPart && i == text.length() - 1 && start != -1) {
result.add(new TextRange(start, i + 1));
} else if (!isIdentifierPart && start != -1) {
result.add(new TextRange(start, i));
start = -1;
}
}
return result;
}
use of org.jetbrains.annotations.Contract in project intellij-community by JetBrains.
the class ScalaGradleProjectResolverExtension method create.
@Nullable
@Contract("null -> null")
private static ScalaCompileOptionsData create(@Nullable ScalaCompileOptions options) {
if (options == null)
return null;
ScalaCompileOptionsData result = new ScalaCompileOptionsData();
result.setAdditionalParameters(options.getAdditionalParameters());
result.setDaemonServer(options.getDaemonServer());
result.setDebugLevel(options.getDebugLevel());
result.setDeprecation(options.isDeprecation());
result.setEncoding(options.getEncoding());
result.setFailOnError(options.isFailOnError());
result.setForce(options.getForce());
result.setFork(options.isFork());
result.setListFiles(options.isListFiles());
result.setLoggingLevel(options.getLoggingLevel());
result.setDebugLevel(options.getDebugLevel());
result.setLoggingPhases(options.getLoggingPhases());
result.setOptimize(options.isOptimize());
result.setUnchecked(options.isUnchecked());
result.setUseAnt(options.isUseAnt());
result.setUseCompileDaemon(options.isUseCompileDaemon());
result.setForkOptions(create(options.getForkOptions()));
return result;
}
use of org.jetbrains.annotations.Contract in project intellij-community by JetBrains.
the class WritesCounterDFAInstance method getVariable.
@Contract("null -> null")
@Nullable
private static GrVariable getVariable(@Nullable PsiElement instructionElement) {
final GrVariable variable;
if (instructionElement instanceof GrReferenceExpression) {
final PsiElement resolved = ((GrReferenceExpression) instructionElement).resolve();
variable = resolved instanceof GrVariable ? (GrVariable) resolved : null;
} else if (instructionElement instanceof GrVariable) {
variable = (GrVariable) instructionElement;
} else {
variable = null;
}
return variable != null && PsiUtil.isLocalOrParameter(variable) ? variable : null;
}
Aggregations