Search in sources :

Example 66 with Contract

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);
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module) Contract(org.jetbrains.annotations.Contract)

Example 67 with Contract

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;
}
Also used : ApplePlatform(com.jetbrains.cidr.xcode.frameworks.ApplePlatform) File(java.io.File) Contract(org.jetbrains.annotations.Contract)

Example 68 with Contract

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 69 with Contract

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;
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) NotNull(org.jetbrains.annotations.NotNull) Contract(org.jetbrains.annotations.Contract)

Example 70 with Contract

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;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Contract (org.jetbrains.annotations.Contract)111 NotNull (org.jetbrains.annotations.NotNull)48 Nullable (org.jetbrains.annotations.Nullable)40 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)29 PsiElement (com.intellij.psi.PsiElement)19 Call (org.elixir_lang.psi.call.Call)17 ASTNode (com.intellij.lang.ASTNode)14 CallDefinitionClause.enclosingModularMacroCall (org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall)9 PsiFile (com.intellij.psi.PsiFile)6 IElementType (com.intellij.psi.tree.IElementType)6 BigInteger (java.math.BigInteger)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Quotable (org.elixir_lang.psi.Quotable)5 Project (com.intellij.openapi.project.Project)4 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)3 Matcher (java.util.regex.Matcher)3 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)2 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)2 TextRange (com.intellij.openapi.util.TextRange)2 File (java.io.File)2