Search in sources :

Example 6 with CharTable

use of com.intellij.util.CharTable in project intellij-community by JetBrains.

the class NameValuePairElement method addInternal.

@Override
public TreeElement addInternal(TreeElement first, ASTNode last, ASTNode anchor, Boolean before) {
    final CharTable treeCharTab = SharedImplUtil.findCharTableByTree(this);
    final TreeElement treeElement = super.addInternal(first, last, anchor, before);
    if (first == last && first.getElementType() == JavaTokenType.IDENTIFIER) {
        LeafElement eq = Factory.createSingleLeafElement(JavaTokenType.EQ, "=", 0, 1, treeCharTab, getManager());
        super.addInternal(eq, eq, first, Boolean.FALSE);
    }
    return treeElement;
}
Also used : CharTable(com.intellij.util.CharTable)

Example 7 with CharTable

use of com.intellij.util.CharTable in project intellij-community by JetBrains.

the class TypeParameterListElement method addInternal.

@Override
public TreeElement addInternal(final TreeElement first, final ASTNode last, ASTNode anchor, Boolean before) {
    TreeElement lt = (TreeElement) findChildByRole(ChildRole.LT_IN_TYPE_LIST);
    final CharTable treeCharTab = SharedImplUtil.findCharTableByTree(this);
    if (lt == null) {
        lt = Factory.createSingleLeafElement(JavaTokenType.LT, "<", 0, 1, treeCharTab, getManager());
        super.addInternal(lt, lt, getFirstChildNode(), Boolean.TRUE);
    }
    TreeElement gt = (TreeElement) findChildByRole(ChildRole.GT_IN_TYPE_LIST);
    if (gt == null) {
        gt = Factory.createSingleLeafElement(JavaTokenType.GT, ">", 0, 1, treeCharTab, getManager());
        super.addInternal(gt, gt, getLastChildNode(), Boolean.FALSE);
    }
    if (anchor == null) {
        if (before == null || before.booleanValue()) {
            anchor = gt;
            before = Boolean.TRUE;
        } else {
            anchor = lt;
            before = Boolean.FALSE;
        }
    }
    TreeElement firstAdded = super.addInternal(first, last, anchor, before);
    if (first == last && first.getElementType() == JavaElementType.TYPE_PARAMETER) {
        JavaSourceUtil.addSeparatingComma(this, first, TYPE_PARAMETER_SET);
    }
    return firstAdded;
}
Also used : CharTable(com.intellij.util.CharTable)

Example 8 with CharTable

use of com.intellij.util.CharTable in project intellij-community by JetBrains.

the class JavaSharedImplUtil method setInitializer.

public static void setInitializer(PsiVariable variable, PsiExpression initializer) throws IncorrectOperationException {
    PsiExpression oldInitializer = variable.getInitializer();
    if (oldInitializer != null) {
        oldInitializer.delete();
    }
    if (initializer == null) {
        return;
    }
    CompositeElement variableElement = (CompositeElement) variable.getNode();
    ASTNode eq = variableElement.findChildByRole(ChildRole.INITIALIZER_EQ);
    if (eq == null) {
        final CharTable charTable = SharedImplUtil.findCharTableByTree(variableElement);
        eq = Factory.createSingleLeafElement(JavaTokenType.EQ, "=", 0, 1, charTable, variable.getManager());
        PsiElement identifier = variable.getNameIdentifier();
        assert identifier != null : variable;
        ASTNode node = PsiImplUtil.skipWhitespaceCommentsAndTokens(identifier.getNode().getTreeNext(), BRACKETS);
        variableElement.addInternal((TreeElement) eq, eq, node, Boolean.TRUE);
        eq = variableElement.findChildByRole(ChildRole.INITIALIZER_EQ);
        assert eq != null : variable;
    }
    variable.addAfter(initializer, eq.getPsi());
}
Also used : ASTNode(com.intellij.lang.ASTNode) CharTable(com.intellij.util.CharTable)

Example 9 with CharTable

use of com.intellij.util.CharTable in project intellij-community by JetBrains.

the class JavaSourceUtil method fullyQualifyReference.

public static void fullyQualifyReference(@NotNull CompositeElement reference, @NotNull PsiClass targetClass) {
    if (((SourceJavaCodeReference) reference).isQualified()) {
        // qualified reference
        final PsiClass parentClass = targetClass.getContainingClass();
        if (parentClass == null)
            return;
        final ASTNode qualifier = reference.findChildByRole(ChildRole.QUALIFIER);
        if (qualifier instanceof SourceJavaCodeReference) {
            ((SourceJavaCodeReference) qualifier).fullyQualify(parentClass);
        }
    } else {
        // unqualified reference, need to qualify with package name
        final String qName = targetClass.getQualifiedName();
        if (qName == null) {
            // todo: local classes?
            return;
        }
        final int i = qName.lastIndexOf('.');
        if (i > 0) {
            final String prefix = qName.substring(0, i);
            final PsiManager manager = reference.getManager();
            final PsiJavaParserFacade parserFacade = JavaPsiFacade.getInstance(manager.getProject()).getParserFacade();
            final TreeElement qualifier;
            if (reference instanceof PsiReferenceExpression) {
                qualifier = (TreeElement) parserFacade.createExpressionFromText(prefix, null).getNode();
            } else {
                qualifier = (TreeElement) parserFacade.createReferenceFromText(prefix, null).getNode();
            }
            if (qualifier != null) {
                final CharTable systemCharTab = SharedImplUtil.findCharTableByTree(qualifier);
                final LeafElement dot = Factory.createSingleLeafElement(JavaTokenType.DOT, ".", 0, 1, systemCharTab, manager);
                qualifier.rawInsertAfterMe(dot);
                reference.addInternal(qualifier, dot, null, Boolean.FALSE);
            }
        }
    }
}
Also used : SourceJavaCodeReference(com.intellij.psi.impl.source.SourceJavaCodeReference) ASTNode(com.intellij.lang.ASTNode) LighterASTNode(com.intellij.lang.LighterASTNode) CharTable(com.intellij.util.CharTable)

Example 10 with CharTable

use of com.intellij.util.CharTable in project intellij-community by JetBrains.

the class PsiDocCommentImpl method addNewLineToTag.

private static void addNewLineToTag(CompositeElement tag, Project project) {
    LOG.assertTrue(tag != null && tag.getElementType() == DOC_TAG);
    ASTNode current = tag.getLastChildNode();
    while (current != null && current.getElementType() == DOC_COMMENT_DATA && isWhitespaceCommentData(current)) {
        current = current.getTreePrev();
    }
    if (current != null && current.getElementType() == DOC_COMMENT_LEADING_ASTERISKS)
        return;
    final CharTable treeCharTab = SharedImplUtil.findCharTableByTree(tag);
    final ASTNode newLine = Factory.createSingleLeafElement(DOC_COMMENT_DATA, "\n", 0, 1, treeCharTab, SharedImplUtil.getManagerByTree(tag));
    tag.addChild(newLine, null);
    ASTNode leadingWhitespaceAnchor = null;
    if (JavaCodeStyleSettingsFacade.getInstance(project).isJavaDocLeadingAsterisksEnabled()) {
        final TreeElement leadingAsterisk = Factory.createSingleLeafElement(DOC_COMMENT_LEADING_ASTERISKS, "*", 0, 1, treeCharTab, SharedImplUtil.getManagerByTree(tag));
        leadingWhitespaceAnchor = tag.addInternal(leadingAsterisk, leadingAsterisk, null, Boolean.TRUE);
    }
    final TreeElement commentData = Factory.createSingleLeafElement(DOC_COMMENT_DATA, " ", 0, 1, treeCharTab, SharedImplUtil.getManagerByTree(tag));
    tag.addInternal(commentData, commentData, leadingWhitespaceAnchor, Boolean.TRUE);
}
Also used : ASTNode(com.intellij.lang.ASTNode) CharTable(com.intellij.util.CharTable)

Aggregations

CharTable (com.intellij.util.CharTable)35 ASTNode (com.intellij.lang.ASTNode)22 IElementType (com.intellij.psi.tree.IElementType)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4 PsiElement (com.intellij.psi.PsiElement)3 PsiFile (com.intellij.psi.PsiFile)3 FileElement (com.intellij.psi.impl.source.tree.FileElement)3 FileASTNode (com.intellij.lang.FileASTNode)2 Language (com.intellij.lang.Language)2 LighterASTNode (com.intellij.lang.LighterASTNode)2 TextRange (com.intellij.openapi.util.TextRange)2 PsiClass (com.intellij.psi.PsiClass)2 DummyHolder (com.intellij.psi.impl.source.DummyHolder)2 LeafElement (com.intellij.psi.impl.source.tree.LeafElement)2 TreeElement (com.intellij.psi.impl.source.tree.TreeElement)2 NotNull (org.jetbrains.annotations.NotNull)2 PlainTextLanguage (com.intellij.openapi.fileTypes.PlainTextLanguage)1 Project (com.intellij.openapi.project.Project)1 Pair (com.intellij.openapi.util.Pair)1 PomModel (com.intellij.pom.PomModel)1