use of org.jetbrains.annotations.Contract in project intellij-plugins by JetBrains.
the class DartAnnotator method canBeAnalyzedByServer.
@Contract("_, null -> false")
private static boolean canBeAnalyzedByServer(@NotNull final Project project, @Nullable final VirtualFile file) {
if (!DartAnalysisServerService.isLocalAnalyzableFile(file))
return false;
final DartSdk sdk = DartSdk.getDartSdk(project);
if (sdk == null || !DartAnalysisServerService.isDartSdkVersionSufficient(sdk))
return false;
// server can highlight files from Dart SDK, packages and from modules with enabled Dart support
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
if (fileIndex.isInLibraryClasses(file))
return true;
final Module module = fileIndex.getModuleForFile(file);
return module != null && DartSdkLibUtil.isDartSdkEnabled(module);
}
use of org.jetbrains.annotations.Contract in project intellij-plugins by JetBrains.
the class Reveal method getRevealLib.
@Contract("_, null -> null")
public static File getRevealLib(@NotNull File bundle, @Nullable AppleSdk sdk) {
if (sdk == null)
return null;
ApplePlatform platform = sdk.getPlatform();
String libraryPath = "/Contents/SharedSupport/";
if (platform.isIOS()) {
libraryPath += "iOS-Libraries/";
} else if (platform.isTv()) {
libraryPath += "tvOS-Libraries/";
}
if (isCompatibleWithRevealTwoOrHigher(bundle)) {
libraryPath += "RevealServer.framework/RevealServer";
} else if (platform.isTv()) {
libraryPath += "libReveal-tvOS.dylib";
} else {
libraryPath += "libReveal.dylib";
}
File result = new File(bundle, libraryPath);
return result.exists() ? result : null;
}
use of org.jetbrains.annotations.Contract in project android 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 PsiTestUtil method addRootsToJdk.
@NotNull
@Contract(pure = true)
public static Sdk addRootsToJdk(@NotNull Sdk sdk, @NotNull OrderRootType rootType, @NotNull VirtualFile... roots) {
Sdk clone;
try {
clone = (Sdk) sdk.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
SdkModificator sdkModificator = clone.getSdkModificator();
for (VirtualFile root : roots) {
sdkModificator.addRoot(root, rootType);
}
sdkModificator.commitChanges();
return clone;
}
use of org.jetbrains.annotations.Contract in project intellij-community by JetBrains.
the class ExpressionUtils method getReferenceExpressionFromNullComparison.
@Contract("null, _ -> null")
@Nullable
public static PsiReferenceExpression getReferenceExpressionFromNullComparison(PsiExpression expression, boolean equals) {
expression = ParenthesesUtils.stripParentheses(expression);
if (!(expression instanceof PsiPolyadicExpression)) {
return null;
}
final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression) expression;
final IElementType tokenType = polyadicExpression.getOperationTokenType();
if (equals) {
if (!JavaTokenType.EQEQ.equals(tokenType)) {
return null;
}
} else {
if (!JavaTokenType.NE.equals(tokenType)) {
return null;
}
}
final PsiExpression[] operands = polyadicExpression.getOperands();
if (operands.length != 2) {
return null;
}
PsiExpression comparedToNull = null;
if (PsiType.NULL.equals(operands[0].getType())) {
comparedToNull = operands[1];
} else if (PsiType.NULL.equals(operands[1].getType())) {
comparedToNull = operands[0];
}
comparedToNull = ParenthesesUtils.stripParentheses(comparedToNull);
return comparedToNull instanceof PsiReferenceExpression ? (PsiReferenceExpression) comparedToNull : null;
}
Aggregations