Search in sources :

Example 56 with Contract

use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.

the class Variable method icon.

@Contract(pure = true)
@Nullable
private Icon icon(@NotNull PsiElement element) {
    Icon icon = null;
    Parameter parameter = new Parameter(element);
    Parameter.Type parameterType = Parameter.putParameterized(parameter).type;
    if (parameterType != null) {
        icon = Icons.PARAMETER;
    } else {
        icon = Icons.VARIABLE;
    }
    return icon;
}
Also used : Parameter(org.elixir_lang.annotator.Parameter) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 57 with Contract

use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.

the class Variable method enclosingMatch.

@Contract(pure = true)
@NotNull
private PsiElement enclosingMatch(@NotNull final PsiElement ancestor) {
    PsiElement enclosingMatch = ancestor;
    PsiElement parent = ancestor.getParent();
    if (parent instanceof InMatch || parent instanceof Match) {
        enclosingMatch = parent;
    } else {
        assert ancestor != null;
    }
    return enclosingMatch;
}
Also used : InMatch(org.elixir_lang.psi.operation.InMatch) PsiElement(com.intellij.psi.PsiElement) Match(org.elixir_lang.psi.operation.Match) InMatch(org.elixir_lang.psi.operation.InMatch) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 58 with Contract

use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.

the class Annotator method explanationToToolTip.

@Contract(pure = true)
@NotNull
private String explanationToToolTip(@NotNull Stream<String> explanation, @NotNull String workingDirectory) {
    List<String> headers = new ArrayList<>();
    Map<String, List<String>> contentsByHeader = new HashMap<>();
    Ref<String> headerRef = Ref.create();
    headers.add(headerRef.get());
    explanation.map(Annotator::stripEdge).forEachOrdered(content -> {
        Matcher headerMatcher = HEADER_PATTERN.matcher(content);
        if (headerMatcher.matches()) {
            String header = headerMatcher.group("header");
            headers.add(header);
            headerRef.set(header);
        } else {
            contentsByHeader.computeIfAbsent(headerRef.get(), k -> new ArrayList<>()).add(content);
        }
    });
    return headers.stream().flatMap(header -> sectionToHTML(header, contentsByHeader.getOrDefault(header, emptyList()), workingDirectory)).collect(Collectors.joining("\n"));
}
Also used : java.util(java.util) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) THashMap(gnu.trove.THashMap) Global(org.elixir_lang.credo.inspection_tool.Global) Mix(org.elixir_lang.Mix) Matcher(java.util.regex.Matcher) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) Type.mostSpecificSdk(org.elixir_lang.sdk.elixir.Type.mostSpecificSdk) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) StreamSupport(java.util.stream.StreamSupport) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) Collections.emptyMap(java.util.Collections.emptyMap) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) Collections.emptyList(java.util.Collections.emptyList) MissingSdk(org.elixir_lang.mix.MissingSdk) ExecUtil(com.intellij.execution.util.ExecUtil) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) TextRange(com.intellij.openapi.util.TextRange) com.intellij.lang.annotation(com.intellij.lang.annotation) Collectors(java.util.stream.Collectors) Sdk(com.intellij.openapi.projectRoots.Sdk) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) Stream(java.util.stream.Stream) StringEscapeUtils.escapeHtml(org.apache.commons.lang.StringEscapeUtils.escapeHtml) Paths(java.nio.file.Paths) ProcessOutput(com.intellij.execution.process.ProcessOutput) ConfigurationKt.ensureWorkingDirectory(org.elixir_lang.run.ConfigurationKt.ensureWorkingDirectory) FunctionWithIndex(org.elixir_lang.annotator.FunctionWithIndex) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) THashMap(gnu.trove.THashMap) Matcher(java.util.regex.Matcher) Collections.emptyList(java.util.Collections.emptyList) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 59 with Contract

use of org.jetbrains.annotations.Contract in project midpoint by Evolveum.

the class ExtItemDictionary method createOrFindItemByDefinitionInternal.

@Contract("_, _, true -> !null")
private RExtItem createOrFindItemByDefinitionInternal(@NotNull ItemDefinition<?> definition, boolean create, boolean throwExceptionAfterCreate) {
    boolean fetchedNow = fetchItemsIfNeeded();
    RExtItem.Key key = RExtItem.createKeyFromDefinition(definition);
    RExtItem item = itemsByKey.get(key);
    if (item == null && !fetchedNow) {
        LOGGER.debug("Ext item for {} not found, fetching all items.", key);
        fetchItems();
        item = itemsByKey.get(key);
    }
    if (item == null && create) {
        LOGGER.debug("Ext item for {} not found even in current items; creating it.", key);
        item = RExtItem.createFromDefinition(definition);
        addExtItemAttempt(item);
        if (throwExceptionAfterCreate) {
            throw new RestartOperationRequestedException("Restarting parent operation because an extension item was created");
        }
    }
    return item;
}
Also used : RExtItem(com.evolveum.midpoint.repo.sql.data.common.any.RExtItem) RestartOperationRequestedException(com.evolveum.midpoint.repo.sql.RestartOperationRequestedException) Contract(org.jetbrains.annotations.Contract)

Example 60 with Contract

use of org.jetbrains.annotations.Contract in project midpoint by Evolveum.

the class QueryHelper method applyMatchingRules.

/**
 * Visit the query and normalize values (or set matching rules) as needed
 */
@Contract("null, _ -> null; !null, _ -> !null")
ObjectQuery applyMatchingRules(ObjectQuery originalQuery, ResourceObjectDefinition objectDef) {
    if (originalQuery == null) {
        return null;
    }
    ObjectQuery processedQuery = originalQuery.clone();
    ObjectFilter filter = processedQuery.getFilter();
    Visitor visitor = f -> {
        try {
            if (f instanceof EqualFilter) {
                applyMatchingRuleToEqFilter((EqualFilter<?>) f, objectDef);
            }
        } catch (SchemaException e) {
            throw new SystemException(e);
        }
    };
    filter.accept(visitor);
    return processedQuery;
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Trace(com.evolveum.midpoint.util.logging.Trace) MatchingRuleRegistry(com.evolveum.midpoint.prism.match.MatchingRuleRegistry) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ArrayList(java.util.ArrayList) List(java.util.List) Contract(org.jetbrains.annotations.Contract) Component(org.springframework.stereotype.Component) MatchingRule(com.evolveum.midpoint.prism.match.MatchingRule) Visitor(com.evolveum.midpoint.prism.query.Visitor) SystemException(com.evolveum.midpoint.util.exception.SystemException) QName(javax.xml.namespace.QName) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) NotNull(org.jetbrains.annotations.NotNull) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Visitor(com.evolveum.midpoint.prism.query.Visitor) SystemException(com.evolveum.midpoint.util.exception.SystemException) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Contract(org.jetbrains.annotations.Contract)

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