Search in sources :

Example 16 with ThreeState

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());
}
Also used : ThreeState(com.intellij.util.ThreeState) ASTStructure(com.intellij.psi.impl.source.tree.ASTStructure) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with ThreeState

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;
}
Also used : ThreeState(com.intellij.util.ThreeState)

Example 18 with ThreeState

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());
    }
}
Also used : ThreeState(com.intellij.util.ThreeState) Ref(com.intellij.openapi.util.Ref) Task(com.intellij.openapi.progress.Task) CvsLoginWorker(com.intellij.cvsSupport2.connections.login.CvsLoginWorker) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) InputException(com.intellij.openapi.ui.InputException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 19 with ThreeState

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;
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) NavigationItem(com.intellij.navigation.NavigationItem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) ContainerUtil(com.intellij.util.containers.ContainerUtil) XDebugSessionImpl(com.intellij.xdebugger.impl.XDebugSessionImpl) ReadAction(com.intellij.openapi.application.ReadAction) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) PositionManagerImpl(com.intellij.debugger.engine.PositionManagerImpl) SuspendContextImpl(com.intellij.debugger.engine.SuspendContextImpl) Project(com.intellij.openapi.project.Project) DebuggerBundle(com.intellij.debugger.DebuggerBundle) Logger(com.intellij.openapi.diagnostic.Logger) JavaLanguage(com.intellij.lang.java.JavaLanguage) TextEditor(com.intellij.openapi.fileEditor.TextEditor) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) NoDataException(com.intellij.debugger.NoDataException) AppUIUtil(com.intellij.ui.AppUIUtil) ThreeState(com.intellij.util.ThreeState) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) TextRange(com.intellij.openapi.util.TextRange) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NotificationType(com.intellij.notification.NotificationType) TestOnly(org.jetbrains.annotations.TestOnly) PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) List(java.util.List) LineNumbersMapping(com.intellij.execution.filters.LineNumbersMapping) StreamEx(one.util.streamex.StreamEx) Registry(com.intellij.openapi.util.registry.Registry) com.sun.jdi(com.sun.jdi) IntStreamEx(one.util.streamex.IntStreamEx) com.intellij.psi(com.intellij.psi) HintManager(com.intellij.codeInsight.hint.HintManager) SourcePosition(com.intellij.debugger.SourcePosition) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) NavigationItem(com.intellij.navigation.NavigationItem) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

Example 20 with ThreeState

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);
        }
    }
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ThreeState(com.intellij.util.ThreeState) ConfigurationException(com.intellij.openapi.options.ConfigurationException) MultiMap(com.intellij.util.containers.MultiMap)

Aggregations

ThreeState (com.intellij.util.ThreeState)21 PsiElement (com.intellij.psi.PsiElement)4 NotNull (org.jetbrains.annotations.NotNull)4 StackFrameProxyImpl (com.intellij.debugger.jdi.StackFrameProxyImpl)3 Project (com.intellij.openapi.project.Project)3 Ref (com.intellij.openapi.util.Ref)3 SourcePosition (com.intellij.debugger.SourcePosition)2 SuspendContextImpl (com.intellij.debugger.engine.SuspendContextImpl)2 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)2 ExpressionEvaluator (com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)2 JavaLanguage (com.intellij.lang.java.JavaLanguage)2 Logger (com.intellij.openapi.diagnostic.Logger)2 Document (com.intellij.openapi.editor.Document)2 TextEditor (com.intellij.openapi.fileEditor.TextEditor)2 TextRange (com.intellij.openapi.util.TextRange)2 Registry (com.intellij.openapi.util.registry.Registry)2 Client (com.android.ddmlib.Client)1 ClientData (com.android.ddmlib.ClientData)1 IDevice (com.android.ddmlib.IDevice)1 GoBuildTargetSettings (com.goide.project.GoBuildTargetSettings)1