diff options
Diffstat (limited to 'java/java-psi-impl/src/com/intellij/psi/impl/source/tree/SourceUtil.java')
-rw-r--r-- | java/java-psi-impl/src/com/intellij/psi/impl/source/tree/SourceUtil.java | 79 |
1 files changed, 7 insertions, 72 deletions
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/SourceUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/SourceUtil.java index 93e9f60c890e..554580828c0b 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/SourceUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/SourceUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,94 +15,29 @@ */ package com.intellij.psi.impl.source.tree; -import com.intellij.lang.ASTFactory; import com.intellij.lang.LighterAST; import com.intellij.lang.LighterASTNode; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.psi.JavaTokenType; -import com.intellij.psi.PsiElement; import com.intellij.psi.PsiJavaCodeReferenceElement; import com.intellij.psi.PsiManager; -import com.intellij.psi.codeStyle.CodeStyleManager; -import com.intellij.psi.impl.source.DummyHolder; -import com.intellij.psi.impl.source.SourceTreeToPsiMap; import com.intellij.psi.tree.IElementType; -import com.intellij.psi.tree.TokenSet; -import com.intellij.util.CharTable; -import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; +/** @deprecated use {@link JavaSourceUtil} (to be removed in IDEA 15) */ +@SuppressWarnings("UnusedDeclaration") public class SourceUtil { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.SourceUtil"); - - private static final TokenSet REF_FILTER = TokenSet.orSet( - ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET, TokenSet.create(JavaElementType.ANNOTATION)); - private SourceUtil() { } @NotNull public static String getReferenceText(@NotNull PsiJavaCodeReferenceElement ref) { - final StringBuilder buffer = new StringBuilder(); - - ((TreeElement)ref.getNode()).acceptTree(new RecursiveTreeElementWalkingVisitor() { - @Override - public void visitLeaf(LeafElement leaf) { - if (!REF_FILTER.contains(leaf.getElementType())) { - String leafText = leaf.getText(); - if (buffer.length() > 0 && !leafText.isEmpty() && Character.isJavaIdentifierPart(leafText.charAt(0))) { - char lastInBuffer = buffer.charAt(buffer.length() - 1); - if (lastInBuffer == '?' || Character.isJavaIdentifierPart(lastInBuffer)) { - buffer.append(" "); - } - } - - buffer.append(leafText); - } - } - - @Override - public void visitComposite(CompositeElement composite) { - if (!REF_FILTER.contains(composite.getElementType())) { - super.visitComposite(composite); - } - } - }); - - return buffer.toString(); + return JavaSourceUtil.getReferenceText(ref); } @NotNull public static String getReferenceText(@NotNull LighterAST tree, @NotNull LighterASTNode node) { - return LightTreeUtil.toFilteredString(tree, node, REF_FILTER); + return JavaSourceUtil.getReferenceText(tree, node); } - public static TreeElement addParenthToReplacedChild(@NotNull IElementType parenthType, - @NotNull TreeElement newChild, - @NotNull PsiManager manager) { - CompositeElement parenthExpr = ASTFactory.composite(parenthType); - - TreeElement dummyExpr = (TreeElement)newChild.clone(); - final CharTable charTableByTree = SharedImplUtil.findCharTableByTree(newChild); - new DummyHolder(manager, parenthExpr, null, charTableByTree); - parenthExpr.putUserData(CharTable.CHAR_TABLE_KEY, charTableByTree); - parenthExpr.rawAddChildren(ASTFactory.leaf(JavaTokenType.LPARENTH, "(")); - parenthExpr.rawAddChildren(dummyExpr); - parenthExpr.rawAddChildren(ASTFactory.leaf(JavaTokenType.RPARENTH, ")")); - - try { - CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); - PsiElement formatted = codeStyleManager.reformat(SourceTreeToPsiMap.treeToPsiNotNull(parenthExpr)); - parenthExpr = (CompositeElement)SourceTreeToPsiMap.psiToTreeNotNull(formatted); - } - catch (IncorrectOperationException e) { - LOG.error(e); // should not happen - } - - newChild.putUserData(CharTable.CHAR_TABLE_KEY, SharedImplUtil.findCharTableByTree(newChild)); - dummyExpr.getTreeParent().replaceChild(dummyExpr, newChild); - - // TODO remove explicit caches drop since this should be ok if we will use ChangeUtil for the modification - TreeUtil.clearCaches(TreeUtil.getFileElement(parenthExpr)); - return parenthExpr; + public static TreeElement addParenthToReplacedChild(@NotNull IElementType parenthType, @NotNull TreeElement newChild, @NotNull PsiManager manager) { + return JavaSourceUtil.addParenthToReplacedChild(parenthType, newChild, manager); } } |