Search in sources :

Example 56 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class YAMLBreadcrumbsInfoProvider method getElementInfo.

@NotNull
@Override
public String getElementInfo(@NotNull PsiElement e) {
    if (e instanceof YAMLDocument) {
        final YAMLFile file = (YAMLFile) e.getContainingFile();
        if (file == null) {
            return "Document";
        }
        final List<YAMLDocument> documents = file.getDocuments();
        return "Document " + getIndexOf(documents, e);
    }
    if (e instanceof YAMLKeyValue) {
        return ((YAMLKeyValue) e).getKeyText() + ':';
    }
    if (e instanceof YAMLSequenceItem) {
        final PsiElement parent = e.getParent();
        if (!(parent instanceof YAMLSequence)) {
            return "Item";
        }
        final List<YAMLSequenceItem> items = ((YAMLSequence) parent).getItems();
        return "Item " + getIndexOf(items, e);
    }
    if (e instanceof YAMLScalar) {
        return StringUtil.first(((YAMLScalar) e).getTextValue(), SCALAR_MAX_LENGTH, true);
    }
    throw new IllegalArgumentException("This element should not pass #acceptElement");
}
Also used : PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 57 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class YAMLKeyValueImpl method getKeyText.

@NotNull
public String getKeyText() {
    final PsiElement keyElement = getKey();
    if (keyElement == null) {
        return "";
    }
    if (keyElement instanceof YAMLCompoundValue) {
        return ((YAMLCompoundValue) keyElement).getTextValue();
    }
    final String text = keyElement.getText();
    return StringUtil.unquoteString(text.substring(0, text.length() - 1));
}
Also used : PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 58 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class YAMLQuotedTextImpl method getContentRanges.

@NotNull
@Override
public List<TextRange> getContentRanges() {
    final ASTNode firstContentNode = getFirstContentNode();
    if (firstContentNode == null) {
        return Collections.emptyList();
    }
    List<TextRange> result = new ArrayList<>();
    TextRange contentRange = TextRange.create(firstContentNode.getStartOffset(), getTextRange().getEndOffset()).shiftRight(-getTextRange().getStartOffset());
    final List<String> lines = StringUtil.split(contentRange.substring(getText()), "\n", true, false);
    // First line has opening quote
    int cumulativeOffset = contentRange.getStartOffset();
    for (int i = 0; i < lines.size(); ++i) {
        final String line = lines.get(i);
        int lineStart = 0;
        int lineEnd = line.length();
        if (i == 0) {
            lineStart++;
        } else {
            while (lineStart < line.length() && YAMLGrammarCharUtil.isSpaceLike(line.charAt(lineStart))) {
                lineStart++;
            }
        }
        if (i == lines.size() - 1) {
            // Last line has closing quote
            lineEnd--;
        } else {
            while (lineEnd > lineStart && YAMLGrammarCharUtil.isSpaceLike(line.charAt(lineEnd - 1))) {
                lineEnd--;
            }
        }
        result.add(TextRange.create(lineStart, lineEnd).shiftRight(cumulativeOffset));
        cumulativeOffset += line.length() + 1;
    }
    return result;
}
Also used : ASTNode(com.intellij.lang.ASTNode) ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull)

Example 59 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class XsltDebuggerEditorsProvider method createDocument.

@NotNull
@Override
public Document createDocument(@NotNull Project project, @NotNull String text, @Nullable XSourcePosition sourcePosition, @NotNull EvaluationMode mode) {
    final PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText("XPathExpr." + myFileType.getDefaultExtension(), myFileType, text, LocalTimeCounter.currentTime(), true);
    if (sourcePosition instanceof XsltSourcePosition && ((XsltSourcePosition) sourcePosition).getLocation() instanceof Debugger.StyleFrame) {
        final Debugger.Locatable location = ((XsltSourcePosition) sourcePosition).getLocation();
        final EvalContextProvider context = new EvalContextProvider(((Debugger.StyleFrame) location).getVariables());
        context.attachTo(psiFile);
    } else {
        final PsiElement contextElement = XsltBreakpointHandler.findContextElement(project, sourcePosition);
        if (contextElement != null) {
            final BreakpointContext context = new BreakpointContext(contextElement);
            context.attachTo(psiFile);
        }
    }
    final Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
    assert document != null;
    return document;
}
Also used : Debugger(org.intellij.plugins.xsltDebugger.rt.engine.Debugger) BreakpointContext(org.intellij.plugins.xsltDebugger.BreakpointContext) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 60 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class YAMLCodeStyleSettingsProvider method createSettingsPage.

@NotNull
@Override
public Configurable createSettingsPage(final CodeStyleSettings settings, final CodeStyleSettings originalSettings) {
    return new CodeStyleAbstractConfigurable(settings, originalSettings, YAMLLanguage.INSTANCE.getDisplayName()) {

        @Override
        protected CodeStyleAbstractPanel createPanel(final CodeStyleSettings settings) {
            final CodeStyleSettings currentSettings = getCurrentSettings();
            final CodeStyleSettings settings1 = settings;
            return new TabbedLanguageCodeStylePanel(YAMLLanguage.INSTANCE, currentSettings, settings1) {

                @Override
                protected void initTabs(final CodeStyleSettings settings) {
                    addIndentOptionsTab(settings);
                }
            };
        }

        @Override
        public String getHelpTopic() {
            return "reference.settingsdialog.codestyle.yaml";
        }
    };
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) CodeStyleAbstractConfigurable(com.intellij.application.options.CodeStyleAbstractConfigurable) TabbedLanguageCodeStylePanel(com.intellij.application.options.TabbedLanguageCodeStylePanel) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)8141 VirtualFile (com.intellij.openapi.vfs.VirtualFile)888 ArrayList (java.util.ArrayList)809 PsiElement (com.intellij.psi.PsiElement)764 Project (com.intellij.openapi.project.Project)647 File (java.io.File)627 Nullable (org.jetbrains.annotations.Nullable)518 List (java.util.List)400 PsiFile (com.intellij.psi.PsiFile)358 Module (com.intellij.openapi.module.Module)336 IOException (java.io.IOException)325 TextRange (com.intellij.openapi.util.TextRange)260 Document (com.intellij.openapi.editor.Document)173 ContainerUtil (com.intellij.util.containers.ContainerUtil)173 BasePhpElementVisitor (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor)169 ASTNode (com.intellij.lang.ASTNode)167 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)167 Map (java.util.Map)156 java.util (java.util)154 IElementType (com.intellij.psi.tree.IElementType)146