use of com.intellij.util.ThreeState in project intellij-community by JetBrains.
the class PsiBuilderQuickTest method doTest.
private static void doTest(@NonNls final String text, final Parser parser, @NonNls final String expected) {
final PsiBuilder builder = createBuilder(text);
final PsiBuilder.Marker rootMarker = builder.mark();
parser.parse(builder);
rootMarker.done(ROOT);
// check light tree composition
final FlyweightCapableTreeStructure<LighterASTNode> lightTree = builder.getLightTree();
assertEquals(expected, DebugUtil.lightTreeToString(lightTree, false));
// verify that light tree can be taken multiple times
final FlyweightCapableTreeStructure<LighterASTNode> lightTree2 = builder.getLightTree();
assertEquals(expected, DebugUtil.lightTreeToString(lightTree2, false));
// check heavy tree composition
final ASTNode root = builder.getTreeBuilt();
assertEquals(expected, DebugUtil.nodeTreeToString(root, false));
// check heavy vs. light tree merging
final PsiBuilder builder2 = createBuilder(text);
final PsiBuilder.Marker rootMarker2 = builder2.mark();
parser.parse(builder2);
rootMarker2.done(ROOT);
DiffTree.diff(new ASTStructure(root), builder2.getLightTree(), new ShallowNodeComparator<ASTNode, LighterASTNode>() {
@NotNull
@Override
public ThreeState deepEqual(@NotNull ASTNode oldNode, @NotNull LighterASTNode newNode) {
return ThreeState.UNSURE;
}
@Override
public boolean typesEqual(@NotNull ASTNode oldNode, @NotNull LighterASTNode newNode) {
return true;
}
@Override
public boolean hashCodesEqual(@NotNull ASTNode oldNode, @NotNull LighterASTNode newNode) {
return true;
}
}, new DiffTreeChangeBuilder<ASTNode, LighterASTNode>() {
@Override
public void nodeReplaced(@NotNull ASTNode oldChild, @NotNull LighterASTNode newChild) {
fail("replaced(" + oldChild + "," + newChild.getTokenType() + ")");
}
@Override
public void nodeDeleted(@NotNull ASTNode oldParent, @NotNull ASTNode oldNode) {
fail("deleted(" + oldParent + "," + oldNode + ")");
}
@Override
public void nodeInserted(@NotNull ASTNode oldParent, @NotNull LighterASTNode newNode, int pos) {
fail("inserted(" + oldParent + "," + newNode.getTokenType() + ")");
}
}, root.getText());
}
use of com.intellij.util.ThreeState in project intellij-community by JetBrains.
the class CvsRootProvider method equals.
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof CvsRootProvider))
return false;
CvsRootProvider that = (CvsRootProvider) o;
if (myAdminRoot != null ? !myAdminRoot.equals(that.myAdminRoot) : that.myAdminRoot != null)
return false;
if (myLocalRoot != null ? !myLocalRoot.equals(that.myLocalRoot) : that.myLocalRoot != null)
return false;
final ThreeState checkEnv = checkNulls(myCvsEnvironment, that.myCvsEnvironment);
if (!ThreeState.UNSURE.equals(checkEnv))
return ThreeState.YES.equals(checkEnv);
final ThreeState checkRoot = checkNulls(myCvsEnvironment.getCvsRoot(), that.myCvsEnvironment.getCvsRoot());
if (!ThreeState.UNSURE.equals(checkRoot))
return ThreeState.YES.equals(checkRoot);
if (myCvsEnvironment.getCvsRoot().getRepositoryPath() != null ? !myCvsEnvironment.getCvsRoot().getRepositoryPath().equals(that.myCvsEnvironment.getCvsRoot().getRepositoryPath()) : that.myCvsEnvironment.getCvsRoot().getRepositoryPath() != null)
return false;
if (myCvsEnvironment.getCvsRoot().getCvsRoot() != null ? !myCvsEnvironment.getCvsRoot().getCvsRoot().equals(that.myCvsEnvironment.getCvsRoot().getCvsRoot()) : that.myCvsEnvironment.getCvsRoot().getCvsRoot() != null)
return false;
return true;
}
use of com.intellij.util.ThreeState in project intellij-community by JetBrains.
the class Cvs2SettingsEditPanel method testConnection.
private static void testConnection(final CvsRootConfiguration configuration, final Component component, Project project) {
final CvsLoginWorker loginWorker = configuration.getLoginWorker(project);
final Ref<Boolean> success = new Ref<>();
ProgressManager.getInstance().run(new Task.Modal(project, CvsBundle.message("message.connecting.to.cvs.server"), false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setText2(CvsBundle.message("message.current.global.timeout.setting", CvsApplicationLevelConfiguration.getInstance().TIMEOUT));
try {
final ThreeState result = LoginPerformer.checkLoginWorker(loginWorker, true);
if (ThreeState.NO == result) {
showConnectionFailedMessage(component, CvsBundle.message("test.connection.login.failed.text"));
} else if (ThreeState.UNSURE == result) {
showConnectionFailedMessage(component, CvsBundle.message("error.message.authentication.canceled"));
} else {
success.set(Boolean.TRUE);
}
} catch (ProcessCanceledException ignore) {
} catch (final Exception e) {
showConnectionFailedMessage(component, e.getLocalizedMessage());
}
}
});
if (success.get() != Boolean.TRUE)
return;
try {
configuration.testConnection(project);
showSuccessfulConnectionMessage(component);
} catch (ProcessCanceledException ignore) {
} catch (final Exception e) {
showConnectionFailedMessage(component, e.getLocalizedMessage());
}
}
use of com.intellij.util.ThreeState in project intellij-community by JetBrains.
the class SourceCodeChecker method check.
private static ThreeState check(Location location, SourcePosition position, Project project) {
Method method = DebuggerUtilsEx.getMethod(location);
// for now skip constructors, bridges, lambdas etc.
if (method == null || method.isConstructor() || method.isSynthetic() || method.isBridge() || method.isStaticInitializer() || (method.declaringType() instanceof ClassType && ((ClassType) method.declaringType()).isEnum()) || DebuggerUtilsEx.isLambda(method)) {
return ThreeState.UNSURE;
}
List<Location> locations = DebuggerUtilsEx.allLineLocations(method);
if (ContainerUtil.isEmpty(locations)) {
return ThreeState.UNSURE;
}
if (position != null) {
return ReadAction.compute(() -> {
PsiFile psiFile = position.getFile();
if (!psiFile.getLanguage().isKindOf(JavaLanguage.INSTANCE)) {
// only for java for now
return ThreeState.UNSURE;
}
Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
if (document == null) {
return ThreeState.UNSURE;
}
boolean res = false;
PsiElement psiMethod = DebuggerUtilsEx.getContainingMethod(position);
if (psiMethod != null) {
TextRange range = psiMethod.getTextRange();
if (psiMethod instanceof PsiDocCommentOwner) {
PsiDocComment comment = ((PsiDocCommentOwner) psiMethod).getDocComment();
if (comment != null) {
range = new TextRange(comment.getTextRange().getEndOffset() + 1, range.getEndOffset());
}
}
int startLine = document.getLineNumber(range.getStartOffset()) + 1;
int endLine = document.getLineNumber(range.getEndOffset()) + 1;
res = getLinesStream(locations, psiFile).allMatch(line -> startLine <= line && line <= endLine);
if (!res) {
LOG.debug("Source check failed: Method " + method.name() + ", source: " + ((NavigationItem) psiMethod).getName() + "\nLines: " + getLinesStream(locations, psiFile).joining(", ") + "\nExpected range: " + startLine + "-" + endLine);
}
} else {
LOG.debug("Source check failed: method " + method.name() + " not found in sources");
}
if (!res) {
FileEditor editor = FileEditorManager.getInstance(project).getSelectedEditor(position.getFile().getVirtualFile());
if (editor instanceof TextEditor) {
AppUIUtil.invokeOnEdt(() -> HintManager.getInstance().showErrorHint(((TextEditor) editor).getEditor(), DebuggerBundle.message("warning.source.code.not.match")));
} else {
XDebugSessionImpl.NOTIFICATION_GROUP.createNotification(DebuggerBundle.message("warning.source.code.not.match"), NotificationType.WARNING).notify(project);
}
return ThreeState.NO;
}
return ThreeState.YES;
});
}
return ThreeState.YES;
}
use of com.intellij.util.ThreeState in project intellij-community by JetBrains.
the class JsonSchemaMappingsConfigurable method updateWarningText.
private void updateWarningText() {
final MultiMap<String, JsonSchemaMappingsConfigurationBase.Item> patternsMap = new MultiMap<>();
final StringBuilder sb = new StringBuilder();
final List<JsonSchemaMappingsConfigurationBase.SchemaInfo> list;
try {
list = getUiList(false);
} catch (ConfigurationException e) {
// will not happen
return;
}
for (JsonSchemaMappingsConfigurationBase.SchemaInfo info : list) {
final JsonSchemaPatternComparator comparator = new JsonSchemaPatternComparator(myProject);
final List<JsonSchemaMappingsConfigurationBase.Item> patterns = info.getPatterns();
for (JsonSchemaMappingsConfigurationBase.Item pattern : patterns) {
for (Map.Entry<String, Collection<JsonSchemaMappingsConfigurationBase.Item>> entry : patternsMap.entrySet()) {
for (JsonSchemaMappingsConfigurationBase.Item item : entry.getValue()) {
final ThreeState similar = comparator.isSimilar(pattern, item);
if (ThreeState.NO.equals(similar))
continue;
if (sb.length() > 0)
sb.append('\n');
sb.append("'").append(pattern.getPresentation()).append("' for schema '").append(info.getName()).append("' and '").append(item.getPresentation()).append("' for schema '").append(entry.getKey()).append("'");
}
}
}
patternsMap.put(info.getName(), patterns);
}
if (sb.length() > 0) {
myError = "Conflicting mappings:\n" + sb.toString();
} else {
myError = null;
}
final Enumeration children = myRoot.children();
while (children.hasMoreElements()) {
Object o = children.nextElement();
if (o instanceof MyNode && ((MyNode) o).getConfigurable() instanceof JsonSchemaConfigurable) {
((JsonSchemaConfigurable) ((MyNode) o).getConfigurable()).setError(myError);
}
}
}
Aggregations