Search in sources :

Example 96 with Ref

use of com.intellij.openapi.util.Ref in project intellij-community by JetBrains.

the class GrUnresolvedAccessChecker method doCheckContainer.

private static boolean doCheckContainer(final PsiMethod patternMethod, PsiElement container, final String name) {
    final Ref<Boolean> result = new Ref<>(false);
    PsiScopeProcessor processor = new GrScopeProcessorWithHints(name, ClassHint.RESOLVE_KINDS_METHOD) {

        @Override
        public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
            if (element instanceof PsiMethod && name.equals(((PsiMethod) element).getName()) && patternMethod.getParameterList().getParametersCount() == ((PsiMethod) element).getParameterList().getParametersCount() && isNotFromGroovyObject((PsiMethod) element)) {
                result.set(true);
                return false;
            }
            return true;
        }
    };
    ResolveUtil.treeWalkUp(container, processor, true);
    return result.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) GrScopeProcessorWithHints(org.jetbrains.plugins.groovy.lang.resolve.processors.GrScopeProcessorWithHints) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) NotNull(org.jetbrains.annotations.NotNull) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GroovyDocPsiElement(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GroovyDocPsiElement)

Example 97 with Ref

use of com.intellij.openapi.util.Ref in project android by JetBrains.

the class Modules method getModule.

@NotNull
public Module getModule(@NotNull String name) {
    Ref<Module> moduleRef = new Ref<>();
    ApplicationManager.getApplication().runReadAction(() -> {
        Module module = ModuleManager.getInstance(myProject).findModuleByName(name);
        moduleRef.set(module);
    });
    Module module = moduleRef.get();
    assertNotNull("Unable to find module with name '" + name + "'", module);
    return module;
}
Also used : Ref(com.intellij.openapi.util.Ref) Module(com.intellij.openapi.module.Module) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 98 with Ref

use of com.intellij.openapi.util.Ref in project android by JetBrains.

the class ThemeEditorStyle method getValueTag.

/**
   * @param attribute The style attribute name.
   * @return the XmlTag that contains the value for a given attribute in the current style.
   */
@Nullable
private /*if the attribute does not exist in this theme*/
XmlTag getValueTag(@NotNull XmlTag sourceTag, @NotNull final String attribute) {
    if (!isProjectStyle()) {
        // Non project styles do not contain local values.
        return null;
    }
    final Ref<XmlTag> resultXmlTag = new Ref<XmlTag>();
    ApplicationManager.getApplication().assertReadAccessAllowed();
    sourceTag.acceptChildren(new PsiElementVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            super.visitElement(element);
            if (!(element instanceof XmlTag)) {
                return;
            }
            final XmlTag tag = (XmlTag) element;
            if (SdkConstants.TAG_ITEM.equals(tag.getName()) && attribute.equals(tag.getAttributeValue(SdkConstants.ATTR_NAME))) {
                resultXmlTag.set(tag);
            }
        }
    });
    return resultXmlTag.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 99 with Ref

use of com.intellij.openapi.util.Ref in project intellij-plugins by JetBrains.

the class DartAnalysisServerService method search_findElementReferences.

public void search_findElementReferences(@NotNull final VirtualFile file, final int _offset, @NotNull final Consumer<SearchResult> consumer) {
    final String filePath = FileUtil.toSystemDependentName(file.getPath());
    final Ref<String> searchIdRef = new Ref<>();
    final AnalysisServer server = myServer;
    if (server == null)
        return;
    final CountDownLatch latch = new CountDownLatch(1);
    final int offset = getOriginalOffset(file, _offset);
    server.search_findElementReferences(filePath, offset, true, new FindElementReferencesConsumer() {

        @Override
        public void computedElementReferences(String searchId, Element element) {
            searchIdRef.set(searchId);
            latch.countDown();
        }

        @Override
        public void onError(RequestError error) {
            LOG.info(getShortErrorMessage("search_findElementReferences()", filePath, error));
            latch.countDown();
        }
    });
    awaitForLatchCheckingCanceled(server, latch, FIND_ELEMENT_REFERENCES_TIMEOUT);
    if (latch.getCount() > 0) {
        LOG.info("search_findElementReferences() took too long for " + filePath + "@" + offset);
        return;
    }
    final String searchId = searchIdRef.get();
    if (searchId == null) {
        return;
    }
    while (true) {
        ProgressManager.checkCanceled();
        synchronized (mySearchResultSets) {
            SearchResultsSet resultSet;
            // process already received results
            while ((resultSet = mySearchResultSets.poll()) != null) {
                if (!resultSet.id.equals(searchId))
                    continue;
                for (final SearchResult searchResult : resultSet.results) {
                    consumer.consume(searchResult);
                }
                if (resultSet.isLast)
                    return;
            }
            // wait for more results
            try {
                mySearchResultSets.wait(CHECK_CANCELLED_PERIOD);
            } catch (InterruptedException e) {
                return;
            }
        }
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Ref(com.intellij.openapi.util.Ref) AnalysisServer(com.google.dart.server.generated.AnalysisServer)

Example 100 with Ref

use of com.intellij.openapi.util.Ref in project intellij-plugins by JetBrains.

the class DartAnalysisServerService method execution_mapUri.

@Nullable
public String execution_mapUri(@NotNull final String _id, @Nullable final String _filePath, @Nullable final String _uri) {
    // be generated. Similarly, if neither field is provided, then an error of type INVALID_PARAMETER will be generated.
    if ((_filePath == null && _uri == null) || (_filePath != null && _uri != null)) {
        LOG.error("One of _filePath and _uri must be non-null.");
        return null;
    }
    final String filePath = _filePath != null ? FileUtil.toSystemDependentName(_filePath) : null;
    final Ref<String> resultRef = new Ref<>();
    final AnalysisServer server = myServer;
    if (server == null)
        return null;
    final CountDownLatch latch = new CountDownLatch(1);
    server.execution_mapUri(_id, filePath, _uri, new MapUriConsumer() {

        @Override
        public void computedFileOrUri(final String file, final String uri) {
            if (uri != null) {
                resultRef.set(uri);
            } else {
                resultRef.set(file);
            }
            latch.countDown();
        }

        @Override
        public void onError(final RequestError error) {
            LOG.warn("execution_mapUri(" + _id + ", " + filePath + ", " + _uri + ") returned error " + error.getCode() + ": " + error.getMessage());
            latch.countDown();
        }
    });
    awaitForLatchCheckingCanceled(server, latch, EXECUTION_MAP_URI_TIMEOUT);
    if (latch.getCount() > 0) {
        LOG.info("execution_mapUri() took too long for contextID " + _id + " and file or uri " + (filePath != null ? filePath : _uri));
        return null;
    }
    if (_uri != null && !resultRef.isNull()) {
        return FileUtil.toSystemIndependentName(resultRef.get());
    }
    return resultRef.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) AnalysisServer(com.google.dart.server.generated.AnalysisServer) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Ref (com.intellij.openapi.util.Ref)253 Nullable (org.jetbrains.annotations.Nullable)82 NotNull (org.jetbrains.annotations.NotNull)70 VirtualFile (com.intellij.openapi.vfs.VirtualFile)48 Project (com.intellij.openapi.project.Project)38 List (java.util.List)30 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)26 PsiElement (com.intellij.psi.PsiElement)26 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)22 PsiFile (com.intellij.psi.PsiFile)20 Module (com.intellij.openapi.module.Module)18 Editor (com.intellij.openapi.editor.Editor)16 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)16 File (java.io.File)16 Task (com.intellij.openapi.progress.Task)15 Pair (com.intellij.openapi.util.Pair)14 VcsException (com.intellij.openapi.vcs.VcsException)14 IncorrectOperationException (com.intellij.util.IncorrectOperationException)14 Document (com.intellij.openapi.editor.Document)13