mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
+3
-3
@@ -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.
|
||||
@@ -24,7 +24,7 @@ import com.intellij.psi.impl.java.stubs.impl.PsiImportStatementStubImpl;
|
||||
import com.intellij.psi.impl.source.PsiImportStatementImpl;
|
||||
import com.intellij.psi.impl.source.PsiImportStaticStatementImpl;
|
||||
import com.intellij.psi.impl.source.tree.JavaElementType;
|
||||
import com.intellij.psi.impl.source.tree.SourceUtil;
|
||||
import com.intellij.psi.impl.source.tree.JavaSourceUtil;
|
||||
import com.intellij.psi.impl.source.tree.java.ImportStaticStatementElement;
|
||||
import com.intellij.psi.stubs.IndexSink;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
@@ -68,7 +68,7 @@ public abstract class JavaImportStatementElementType extends JavaStubElementType
|
||||
for (LighterASTNode child : tree.getChildren(node)) {
|
||||
IElementType type = child.getTokenType();
|
||||
if (type == JavaElementType.JAVA_CODE_REFERENCE || type == JavaElementType.IMPORT_STATIC_REFERENCE) {
|
||||
refText = SourceUtil.getReferenceText(tree, child);
|
||||
refText = JavaSourceUtil.getReferenceText(tree, child);
|
||||
}
|
||||
else if (type == JavaTokenType.ASTERISK) {
|
||||
isOnDemand = true;
|
||||
|
||||
@@ -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.
|
||||
@@ -44,7 +44,7 @@ public class JavaLightStubBuilder extends LightStubBuilder {
|
||||
if (pkg != null) {
|
||||
LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, pkg, JavaElementType.JAVA_CODE_REFERENCE);
|
||||
if (ref != null) {
|
||||
refText = SourceUtil.getReferenceText(tree, ref);
|
||||
refText = JavaSourceUtil.getReferenceText(tree, ref);
|
||||
}
|
||||
}
|
||||
return new PsiJavaFileStubImpl((PsiJavaFile)file, StringRef.fromString(refText), false);
|
||||
|
||||
+1
-1
@@ -751,7 +751,7 @@ public class PsiJavaCodeReferenceElementImpl extends CompositePsiElement impleme
|
||||
private String getNormalizedText() {
|
||||
String whiteSpaceAndComments = myCachedNormalizedText;
|
||||
if (whiteSpaceAndComments == null) {
|
||||
myCachedNormalizedText = whiteSpaceAndComments = SourceUtil.getReferenceText(this);
|
||||
myCachedNormalizedText = whiteSpaceAndComments = JavaSourceUtil.getReferenceText(this);
|
||||
}
|
||||
return whiteSpaceAndComments;
|
||||
}
|
||||
|
||||
@@ -84,8 +84,8 @@ public interface JavaElementType {
|
||||
IElementType PARAMETER_LIST = JavaStubElementTypes.PARAMETER_LIST;
|
||||
IElementType EXTENDS_BOUND_LIST = JavaStubElementTypes.EXTENDS_BOUND_LIST;
|
||||
IElementType THROWS_LIST = JavaStubElementTypes.THROWS_LIST;
|
||||
IElementType LITERAL_EXPRESSION = new JavaCompositeElementType("LITERAL_EXPRESSION", PsiLiteralExpressionImpl.class);
|
||||
|
||||
IElementType LITERAL_EXPRESSION = new JavaCompositeElementType("LITERAL_EXPRESSION", PsiLiteralExpressionImpl.class);
|
||||
IElementType IMPORT_STATIC_REFERENCE = new JavaCompositeElementType("IMPORT_STATIC_REFERENCE", PsiImportStaticReferenceElementImpl.class);
|
||||
IElementType TYPE = new JavaCompositeElementType("TYPE", PsiTypeElementImpl.class);
|
||||
IElementType DIAMOND_TYPE = new JavaCompositeElementType("DIAMOND_TYPE", PsiDiamondTypeElementImpl.class);
|
||||
|
||||
@@ -15,13 +15,28 @@
|
||||
*/
|
||||
package com.intellij.psi.impl.source.tree;
|
||||
|
||||
import com.intellij.lang.ASTFactory;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.LighterAST;
|
||||
import com.intellij.lang.LighterASTNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.impl.source.DummyHolder;
|
||||
import com.intellij.psi.impl.source.SourceJavaCodeReference;
|
||||
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;
|
||||
|
||||
public class JavaSourceUtil {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.JavaSourceUtil");
|
||||
|
||||
private static final TokenSet REF_FILTER = TokenSet.orSet(
|
||||
ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET, TokenSet.create(JavaElementType.ANNOTATION));
|
||||
|
||||
private JavaSourceUtil() { }
|
||||
|
||||
public static void fullyQualifyReference(@NotNull CompositeElement reference, @NotNull PsiClass targetClass) {
|
||||
@@ -61,4 +76,70 @@ public class JavaSourceUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getReferenceText(@NotNull LighterAST tree, @NotNull LighterASTNode node) {
|
||||
return LightTreeUtil.toFilteredString(tree, node, REF_FILTER);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-11
@@ -13,10 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @author max
|
||||
*/
|
||||
package com.intellij.psi.impl.source.tree.java;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
@@ -24,13 +20,11 @@ import com.intellij.psi.impl.source.tree.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class ExpressionPsiElement extends CompositePsiElement {
|
||||
private final int myHC = CompositePsiElement.ourHC++;
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return myHC;
|
||||
}
|
||||
@SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod") private final int myHC = CompositePsiElement.ourHC++;
|
||||
|
||||
public ExpressionPsiElement(final IElementType type) {
|
||||
super(type);
|
||||
@@ -42,9 +36,14 @@ public class ExpressionPsiElement extends CompositePsiElement {
|
||||
ElementType.EXPRESSION_BIT_SET.contains(newElement.getElementType())) {
|
||||
boolean needParenth = ReplaceExpressionUtil.isNeedParenthesis(child, newElement);
|
||||
if (needParenth) {
|
||||
newElement = SourceUtil.addParenthToReplacedChild(JavaElementType.PARENTH_EXPRESSION, newElement, getManager());
|
||||
newElement = JavaSourceUtil.addParenthToReplacedChild(JavaElementType.PARENTH_EXPRESSION, newElement, getManager());
|
||||
}
|
||||
}
|
||||
super.replaceChildInternal(child, newElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return myHC;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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.
|
||||
@@ -38,7 +38,7 @@ public class PsiPackageStatementImpl extends CompositePsiElement implements PsiP
|
||||
@Override
|
||||
public String getPackageName() {
|
||||
PsiJavaCodeReferenceElement ref = getPackageReference();
|
||||
return ref == null ? null : SourceUtil.getReferenceText(ref);
|
||||
return ref == null ? null : JavaSourceUtil.getReferenceText(ref);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -761,7 +761,7 @@ public class PsiReferenceExpressionImpl extends PsiReferenceExpressionBase imple
|
||||
private String getCachedNormalizedText() {
|
||||
String whiteSpaceAndComments = myCachedNormalizedText;
|
||||
if (whiteSpaceAndComments == null) {
|
||||
myCachedNormalizedText = whiteSpaceAndComments = SourceUtil.getReferenceText(this);
|
||||
myCachedNormalizedText = whiteSpaceAndComments = JavaSourceUtil.getReferenceText(this);
|
||||
}
|
||||
return whiteSpaceAndComments;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user