Search in sources :

Example 1 with JspFile

use of com.intellij.psi.jsp.JspFile in project intellij-community by JetBrains.

the class JspIndexPatternBuilder method getCommentTokenSet.

@Override
public TokenSet getCommentTokenSet(@NotNull final PsiFile file) {
    final JspFile jspFile = JspPsiUtil.getJspFile(file);
    TokenSet commentTokens = TokenSet.orSet(JavaIndexPatternBuilder.XML_COMMENT_BIT_SET, StdTokenSets.COMMENT_BIT_SET);
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(jspFile.getViewProvider().getTemplateDataLanguage());
    if (parserDefinition != null) {
        commentTokens = TokenSet.orSet(commentTokens, parserDefinition.getCommentTokens());
    }
    return commentTokens;
}
Also used : ParserDefinition(com.intellij.lang.ParserDefinition) JspFile(com.intellij.psi.jsp.JspFile) TokenSet(com.intellij.psi.tree.TokenSet)

Example 2 with JspFile

use of com.intellij.psi.jsp.JspFile in project intellij-community by JetBrains.

the class ImportHelper method collectNamesToImport.

@NotNull
private static // returns list of (name, isImportStatic) pairs
Collection<Pair<String, Boolean>> collectNamesToImport(@NotNull PsiJavaFile file, List<PsiElement> comments) {
    Set<Pair<String, Boolean>> names = new THashSet<>();
    final JspFile jspFile = JspPsiUtil.getJspFile(file);
    collectNamesToImport(names, comments, file, jspFile);
    if (jspFile != null) {
        PsiFile[] files = ArrayUtil.mergeArrays(JspSpiUtil.getIncludingFiles(jspFile), JspSpiUtil.getIncludedFiles(jspFile));
        for (PsiFile includingFile : files) {
            final PsiFile javaRoot = includingFile.getViewProvider().getPsi(JavaLanguage.INSTANCE);
            if (javaRoot instanceof PsiJavaFile && file != javaRoot) {
                collectNamesToImport(names, comments, (PsiJavaFile) javaRoot, jspFile);
            }
        }
    }
    addUnresolvedImportNames(names, file);
    return names;
}
Also used : JspFile(com.intellij.psi.jsp.JspFile) THashSet(gnu.trove.THashSet) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with JspFile

use of com.intellij.psi.jsp.JspFile in project intellij-community by JetBrains.

the class JavaTypedHandler method beforeCharTyped.

@Override
public Result beforeCharTyped(final char c, final Project project, final Editor editor, final PsiFile file, final FileType fileType) {
    if (!(file instanceof PsiJavaFile))
        return Result.CONTINUE;
    if (c == '@') {
        autoPopupJavadocLookup(project, editor);
    } else if (c == '#' || c == '.') {
        autoPopupMemberLookup(project, editor);
    }
    int offsetBefore = editor.getCaretModel().getOffset();
    //important to calculate before inserting charTyped
    myJavaLTTyped = '<' == c && !(file instanceof JspFile) && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET && PsiUtil.isLanguageLevel5OrHigher(file) && isAfterClassLikeIdentifierOrDot(offsetBefore, editor);
    if ('>' == c) {
        if (!(file instanceof JspFile) && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET && PsiUtil.isLanguageLevel5OrHigher(file)) {
            if (handleJavaGT(editor, JavaTokenType.LT, JavaTokenType.GT, INVALID_INSIDE_REFERENCE))
                return Result.STOP;
        }
    }
    if (c == ';') {
        if (handleSemicolon(editor, fileType))
            return Result.STOP;
    }
    if (fileType == StdFileTypes.JAVA && c == '{') {
        int offset = editor.getCaretModel().getOffset();
        if (offset == 0) {
            return Result.CONTINUE;
        }
        HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(offset - 1);
        while (!iterator.atEnd() && iterator.getTokenType() == TokenType.WHITE_SPACE) {
            iterator.retreat();
        }
        if (iterator.atEnd() || iterator.getTokenType() == JavaTokenType.RBRACKET || iterator.getTokenType() == JavaTokenType.EQ) {
            return Result.CONTINUE;
        }
        Document doc = editor.getDocument();
        PsiDocumentManager.getInstance(project).commitDocument(doc);
        final PsiElement leaf = file.findElementAt(offset);
        if (PsiTreeUtil.getParentOfType(leaf, PsiArrayInitializerExpression.class, false, PsiCodeBlock.class, PsiMember.class) != null) {
            return Result.CONTINUE;
        }
        PsiElement st = leaf != null ? leaf.getParent() : null;
        PsiElement prev = offset > 1 ? file.findElementAt(offset - 1) : null;
        if (CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET && isRparenth(leaf) && (st instanceof PsiWhileStatement || st instanceof PsiIfStatement) && shouldInsertStatementBody(st, doc, prev)) {
            CommandProcessor.getInstance().executeCommand(project, () -> new JavaSmartEnterProcessor().process(project, editor, file), "Insert block statement", null);
            return Result.STOP;
        }
        PsiElement prevLeaf = leaf == null ? null : PsiTreeUtil.prevVisibleLeaf(leaf);
        if (PsiUtil.isJavaToken(prevLeaf, JavaTokenType.ARROW) || PsiTreeUtil.getParentOfType(prevLeaf, PsiNewExpression.class, true, PsiCodeBlock.class, PsiMember.class) != null) {
            return Result.CONTINUE;
        }
        if (PsiTreeUtil.getParentOfType(leaf, PsiCodeBlock.class, false, PsiMember.class) != null) {
            EditorModificationUtil.insertStringAtCaret(editor, "{");
            TypedHandler.indentOpenedBrace(project, editor);
            // use case: manually wrapping part of method's code in 'if', 'while', etc
            return Result.STOP;
        }
    }
    return Result.CONTINUE;
}
Also used : JavaSmartEnterProcessor(com.intellij.codeInsight.editorActions.smartEnter.JavaSmartEnterProcessor) JspFile(com.intellij.psi.jsp.JspFile) Document(com.intellij.openapi.editor.Document) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator)

Example 4 with JspFile

use of com.intellij.psi.jsp.JspFile in project intellij-plugins by JetBrains.

the class OgnlStruts2JspVariableReferencesContributor method process.

@Override
public boolean process(@NotNull PsiElement element, @NotNull PsiFile containingFile, @NotNull Processor<OgnlVariableReference> processor) {
    final PsiFile topLevelFile = InjectedLanguageManager.getInstance(containingFile.getProject()).getTopLevelFile(element);
    if (!(topLevelFile instanceof JspFile)) {
        return true;
    }
    if (StrutsFacet.getInstance(element) == null) {
        return true;
    }
    final PsiElement selfNavigation = element.getOriginalElement();
    for (String name : VAR_NAMES) {
        if (!processor.process(new OgnlVariableReference(name, "java.util.Map<String,Object>", ORIGIN_INFO, selfNavigation))) {
            return false;
        }
    }
    return true;
}
Also used : JspFile(com.intellij.psi.jsp.JspFile) OgnlVariableReference(com.intellij.lang.ognl.psi.resolve.variable.OgnlVariableReference) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 5 with JspFile

use of com.intellij.psi.jsp.JspFile in project intellij-plugins by JetBrains.

the class Struts2GraphFileEditorProvider method accept.

public boolean accept(@NotNull final Project project, @NotNull final VirtualFile file) {
    if (!file.isValid()) {
        return false;
    }
    final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if (!(psiFile instanceof XmlFile)) {
        return false;
    }
    if (psiFile instanceof JspFile) {
        return false;
    }
    if (!StrutsManager.getInstance(project).isStruts2ConfigFile((XmlFile) psiFile)) {
        return false;
    }
    final Module module = ModuleUtilCore.findModuleForFile(file, project);
    if (module == null) {
        return false;
    }
    final Set<StrutsFileSet> fileSets = StrutsManager.getInstance(project).getAllConfigFileSets(module);
    for (final StrutsFileSet fileSet : fileSets) {
        if (fileSet.hasFile(file)) {
            return true;
        }
    }
    return false;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) JspFile(com.intellij.psi.jsp.JspFile) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) StrutsFileSet(com.intellij.struts2.facet.ui.StrutsFileSet)

Aggregations

JspFile (com.intellij.psi.jsp.JspFile)6 PsiFile (com.intellij.psi.PsiFile)3 Module (com.intellij.openapi.module.Module)2 XmlFile (com.intellij.psi.xml.XmlFile)2 StrutsFileSet (com.intellij.struts2.facet.ui.StrutsFileSet)2 NotNull (org.jetbrains.annotations.NotNull)2 JavaSmartEnterProcessor (com.intellij.codeInsight.editorActions.smartEnter.JavaSmartEnterProcessor)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 BaseIntentionAction (com.intellij.codeInsight.intention.impl.BaseIntentionAction)1 ParserDefinition (com.intellij.lang.ParserDefinition)1 Annotation (com.intellij.lang.annotation.Annotation)1 OgnlVariableReference (com.intellij.lang.ognl.psi.resolve.variable.OgnlVariableReference)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)1 Project (com.intellij.openapi.project.Project)1 Pair (com.intellij.openapi.util.Pair)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 TokenSet (com.intellij.psi.tree.TokenSet)1