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;
}
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;
}
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());
}
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);
}
}
}
}
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);
}
Aggregations