use of com.intellij.openapi.util.Ref in project intellij-community by JetBrains.
the class LiveProvider method getEarliestBunchInIntervalImpl.
private Fragment getEarliestBunchInIntervalImpl(long earliestRevision, final long oldestRevision, final int desirableSize, final boolean includeYoungest, final boolean includeOldest, final long earliestToTake) throws VcsException {
if ((myEarliestRevisionWasAccessed) || ((oldestRevision == myYoungestRevision) && ((!includeYoungest) || (!includeOldest)))) {
return null;
}
final SVNRevision youngRevision = (earliestRevision == -1) ? SVNRevision.HEAD : SVNRevision.create(earliestRevision);
final Ref<List<CommittedChangeList>> refToList = new Ref<>();
final Ref<VcsException> exceptionRef = new Ref<>();
final Runnable loader = () -> {
try {
refToList.set(myLoader.loadInterval(youngRevision, SVNRevision.create(oldestRevision), desirableSize, includeYoungest, includeOldest));
} catch (VcsException e) {
exceptionRef.set(e);
}
};
final Application application = ApplicationManager.getApplication();
if (application.isUnitTestMode() || !application.isDispatchThread()) {
loader.run();
} else {
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
final ProgressIndicator ind = ProgressManager.getInstance().getProgressIndicator();
if (ind != null) {
ind.setText(SvnBundle.message("progress.live.provider.loading.revisions.details.text"));
}
loader.run();
}, SvnBundle.message("progress.live.provider.loading.revisions.text"), false, myVcs.getProject());
}
if (!exceptionRef.isNull()) {
final VcsException e = exceptionRef.get();
if (isElementNotFound(e)) {
// occurs when target URL is deleted in repository
// try to find latest existent revision. expensive ...
final LatestExistentSearcher searcher = new LatestExistentSearcher(oldestRevision, myYoungestRevision, (oldestRevision != 0), myVcs, myLocation.toSvnUrl(), myRepositoryUrl);
final long existent = searcher.getLatestExistent();
if ((existent == -1) || (existent == earliestRevision)) {
myEarliestRevisionWasAccessed = true;
return null;
}
return getEarliestBunchInIntervalImpl(existent, oldestRevision, includeYoungest ? desirableSize : (desirableSize + 1), true, includeOldest, Math.min(existent, earliestRevision));
}
throw e;
}
final List<CommittedChangeList> list = refToList.get();
if (list.isEmpty()) {
myEarliestRevisionWasAccessed = (oldestRevision == 0);
return null;
}
if (earliestToTake > 0) {
for (Iterator<CommittedChangeList> iterator = list.iterator(); iterator.hasNext(); ) {
final CommittedChangeList changeList = iterator.next();
if (changeList.getNumber() > earliestToTake)
iterator.remove();
}
}
myEarliestRevisionWasAccessed = (oldestRevision == 0) && ((list.size() + ((!includeOldest) ? 1 : 0) + ((!includeYoungest) ? 1 : 0)) < desirableSize);
return new Fragment(Origin.LIVE, list, true, true, null);
}
use of com.intellij.openapi.util.Ref in project intellij-community by JetBrains.
the class CreateSnapShotAction method runSnapShooterSession.
private static void runSnapShooterSession(final SnapShotClient client, final Project project, final PsiDirectory dir, final IdeView view) {
try {
client.suspendSwing();
} catch (IOException e1) {
Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.connection.error"), UIDesignerBundle.message("snapshot.title"), Messages.getInformationIcon());
return;
}
final MyDialog dlg = new MyDialog(project, client, dir);
dlg.show();
if (dlg.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
final int id = dlg.getSelectedComponentId();
final Ref<Object> result = new Ref<>();
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
try {
result.set(client.createSnapshot(id));
} catch (Exception ex) {
result.set(ex);
}
}, UIDesignerBundle.message("progress.creating.snapshot"), false, project);
String snapshot = null;
if (result.get() instanceof String) {
snapshot = (String) result.get();
} else {
Exception ex = (Exception) result.get();
Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.create.error", ex.getMessage()), UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
}
if (snapshot != null) {
final String snapshot1 = snapshot;
ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().executeCommand(project, () -> {
try {
PsiFile formFile = PsiFileFactory.getInstance(dir.getProject()).createFileFromText(dlg.getFormName() + GuiFormFileType.DOT_DEFAULT_EXTENSION, snapshot1);
formFile = (PsiFile) dir.add(formFile);
formFile.getVirtualFile().setCharset(CharsetToolkit.UTF8_CHARSET);
formFile.getViewProvider().getDocument().setText(snapshot1);
view.selectElement(formFile);
} catch (IncorrectOperationException ex) {
Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.save.error", ex.getMessage()), UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
}
}, "", null));
}
}
try {
client.resumeSwing();
} catch (IOException ex) {
Messages.showErrorDialog(project, UIDesignerBundle.message("snapshot.connection.broken"), UIDesignerBundle.message("snapshot.title"));
}
client.dispose();
}
use of com.intellij.openapi.util.Ref in project intellij-community by JetBrains.
the class PyNamedParameterImpl method getParametersByCallArgument.
@NotNull
private List<PyNamedParameter> getParametersByCallArgument(@NotNull PsiElement element, @NotNull TypeEvalContext context) {
final PyArgumentList argumentList = PsiTreeUtil.getParentOfType(element, PyArgumentList.class);
if (argumentList != null) {
boolean elementIsArgument = false;
for (PyExpression argument : argumentList.getArgumentExpressions()) {
if (PyPsiUtils.flattenParens(argument) == element) {
elementIsArgument = true;
break;
}
}
final PyCallExpression callExpression = argumentList.getCallExpression();
if (elementIsArgument && callExpression != null) {
final PyExpression callee = callExpression.getCallee();
if (callee instanceof PyReferenceExpression) {
final PyReferenceExpression calleeReferenceExpr = (PyReferenceExpression) callee;
final PyExpression firstQualifier = PyPsiUtils.getFirstQualifier(calleeReferenceExpr);
if (firstQualifier != null) {
final PsiReference ref = firstQualifier.getReference();
if (ref != null && ref.isReferenceTo(this)) {
return Collections.emptyList();
}
}
}
final PyResolveContext resolveContext = PyResolveContext.noImplicits().withTypeEvalContext(context);
return callExpression.multiMapArguments(resolveContext).stream().flatMap(mapping -> mapping.getMappedParameters().entrySet().stream()).filter(entry -> entry.getKey() == element).map(Map.Entry::getValue).collect(Collectors.toList());
}
}
return Collections.emptyList();
}
use of com.intellij.openapi.util.Ref in project intellij-community by JetBrains.
the class PyNamedParameterImpl method collectUsedAttributes.
@NotNull
private Set<String> collectUsedAttributes(@NotNull final TypeEvalContext context) {
final Set<String> result = new LinkedHashSet<>();
final ScopeOwner owner = ScopeUtil.getScopeOwner(this);
final String name = getName();
if (owner != null && name != null) {
owner.accept(new PyRecursiveElementVisitor() {
@Override
public void visitPyElement(PyElement node) {
if (node instanceof ScopeOwner && node != owner) {
return;
}
if (node instanceof PyQualifiedExpression) {
final PyQualifiedExpression expr = (PyQualifiedExpression) node;
final PyExpression qualifier = expr.getQualifier();
if (qualifier != null) {
final String attributeName = expr.getReferencedName();
final PyExpression referencedExpr = node instanceof PyBinaryExpression && PyNames.isRightOperatorName(attributeName) ? ((PyBinaryExpression) node).getRightExpression() : qualifier;
if (referencedExpr != null) {
final PsiReference ref = referencedExpr.getReference();
if (ref != null && ref.isReferenceTo(PyNamedParameterImpl.this)) {
if (attributeName != null && !result.contains(attributeName)) {
result.add(attributeName);
}
}
}
} else {
final PsiReference ref = expr.getReference();
if (ref != null && ref.isReferenceTo(PyNamedParameterImpl.this)) {
StreamEx.of(getParametersByCallArgument(expr, context)).nonNull().map(context::getType).select(PyStructuralType.class).forEach(type -> result.addAll(type.getAttributeNames()));
}
}
}
super.visitPyElement(node);
}
@Override
public void visitPyIfStatement(PyIfStatement node) {
final PyExpression ifCondition = node.getIfPart().getCondition();
if (ifCondition != null) {
ifCondition.accept(this);
}
for (PyIfPart part : node.getElifParts()) {
final PyExpression elseIfCondition = part.getCondition();
if (elseIfCondition != null) {
elseIfCondition.accept(this);
}
}
}
@Override
public void visitPyCallExpression(PyCallExpression node) {
Optional.ofNullable(node.getCallee()).filter(callee -> "len".equals(callee.getName())).map(PyExpression::getReference).map(PsiReference::resolve).filter(element -> PyBuiltinCache.getInstance(element).isBuiltin(element)).ifPresent(callable -> {
final PyReferenceExpression argument = node.getArgument(0, PyReferenceExpression.class);
if (argument != null && argument.getReference().isReferenceTo(PyNamedParameterImpl.this)) {
result.add(PyNames.LEN);
}
});
super.visitPyCallExpression(node);
}
@Override
public void visitPyForStatement(PyForStatement node) {
Optional.of(node.getForPart()).map(PyForPart::getSource).map(PyExpression::getReference).filter(reference -> reference.isReferenceTo(PyNamedParameterImpl.this)).ifPresent(reference -> result.add(PyNames.ITER));
super.visitPyForStatement(node);
}
});
}
return result;
}
use of com.intellij.openapi.util.Ref in project intellij-community by JetBrains.
the class XmlBuilderDriver method processPrologNode.
private void processPrologNode(PsiBuilder psiBuilder, XmlBuilder builder, FlyweightCapableTreeStructure<LighterASTNode> structure, LighterASTNode prolog) {
final Ref<LighterASTNode[]> prologChildren = new Ref<>(null);
final int prologChildrenCount = structure.getChildren(structure.prepareForGetChildren(prolog), prologChildren);
for (int i = 0; i < prologChildrenCount; i++) {
LighterASTNode node = prologChildren.get()[i];
IElementType type = node.getTokenType();
if (type == XmlElementType.XML_DOCTYPE) {
processDoctypeNode(builder, structure, node);
break;
}
if (type == TokenType.ERROR_ELEMENT) {
processErrorNode(psiBuilder, node, builder);
}
}
}
Aggregations