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();
}
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;
}
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();
}
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;
}
}
}
}
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();
}
Aggregations