本文整理汇总了Java中com.intellij.codeInsight.PsiEquivalenceUtil类的典型用法代码示例。如果您正苦于以下问题:Java PsiEquivalenceUtil类的具体用法?Java PsiEquivalenceUtil怎么用?Java PsiEquivalenceUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PsiEquivalenceUtil类属于com.intellij.codeInsight包,在下文中一共展示了PsiEquivalenceUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: invoke
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return;
final PsiConditionalExpression conditionalExpression = PsiTreeUtil.getParentOfType(element, PsiConditionalExpression.class);
final PsiExpression thenExpression = (PsiExpression)conditionalExpression.getThenExpression().copy();
final PsiExpressionList thenArgsList = ((PsiCallExpression)thenExpression).getArgumentList();
final PsiExpression[] thenExpressions = thenArgsList.getExpressions();
final PsiExpression elseExpression = conditionalExpression.getElseExpression();
final PsiExpressionList elseArgsList = ((PsiCallExpression)elseExpression).getArgumentList();
final PsiExpression[] elseExpressions = elseArgsList.getExpressions();
for (int i = 0; i < thenExpressions.length; i++) {
PsiExpression lExpr = thenExpressions[i];
PsiExpression rExpr = elseExpressions[i];
if (!PsiEquivalenceUtil.areElementsEquivalent(lExpr, rExpr)) {
lExpr.replace(JavaPsiFacade.getElementFactory(project).createExpressionFromText(
conditionalExpression.getCondition().getText() + "?" + lExpr.getText() + ":" + rExpr.getText(), lExpr));
break;
}
}
CodeStyleManager.getInstance(project).reformat(conditionalExpression.replace(thenExpression));
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:PushConditionInCallAction.java
示例2: areExitStatementsTheSame
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
private void areExitStatementsTheSame() throws ExitStatementsNotSameException {
if (myExitStatements.isEmpty()) {
throw new ExitStatementsNotSameException();
}
PsiStatement first = null;
for (PsiStatement statement : myExitStatements) {
if (first == null) {
first = statement;
continue;
}
if (!PsiEquivalenceUtil.areElementsEquivalent(first, statement)) {
throw new ExitStatementsNotSameException();
}
}
myFirstExitStatementCopy = (PsiStatement)first.copy();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:ControlFlowWrapper.java
示例3: patchParams
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
public static List<ParameterInfoImpl> patchParams(Map<PsiVariable, PsiType> changedParams, final PsiMethod psiMethod) {
final ArrayList<ParameterInfoImpl> newParameters = new ArrayList<ParameterInfoImpl>();
final PsiParameter[] oldParameters = psiMethod.getParameterList().getParameters();
for (int i = 0; i < oldParameters.length; i++) {
final PsiParameter oldParameter = oldParameters[i];
PsiType type = oldParameter.getType();
for (PsiVariable variable : changedParams.keySet()) {
if (PsiEquivalenceUtil.areElementsEquivalent(variable, oldParameter)) {
type = changedParams.get(variable);
break;
}
}
newParameters.add(new ParameterInfoImpl(i, oldParameter.getName(), type));
}
return newParameters;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:MatchUtil.java
示例4: getInlinableStyleDataFromContext
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
@Nullable
static MyStyleData getInlinableStyleDataFromContext(@Nullable PsiElement context) {
if (context instanceof LazyValueResourceElementWrapper) {
context = ((LazyValueResourceElementWrapper)context).computeElement();
}
if (context == null || !context.getManager().isInProject(context)) {
return null;
}
final XmlAttributeValue attrValue = PsiTreeUtil.getParentOfType(context, XmlAttributeValue.class, false);
final XmlTag tag = attrValue != null ? PsiTreeUtil.getParentOfType(attrValue, XmlTag.class) : null;
if (tag == null) {
return null;
}
final MyStyleData data = getInlinableStyleData(tag);
return data != null && PsiEquivalenceUtil.areElementsEquivalent(data.myReferredElement, attrValue)
? data : null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:AndroidInlineUtil.java
示例5: checkForListIsEmpty
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
private static boolean checkForListIsEmpty(GrExpression condition, GrExpression elseBranch) {
if (condition instanceof GrMethodCall) condition = ((GrMethodCall)condition).getInvokedExpression();
if (!(condition instanceof GrReferenceExpression)) return false;
final GrExpression qualifier = ((GrReferenceExpression)condition).getQualifier();
if (qualifier == null) return false;
if (!PsiEquivalenceUtil.areElementsEquivalent(qualifier, elseBranch)) return false;
final PsiType type = qualifier.getType();
if (type == null) return false;
if (!InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_LIST)) return false;
final PsiElement resolved = ((GrReferenceExpression)condition).resolve();
return resolved instanceof PsiMethod &&
"isEmpty".equals(((PsiMethod)resolved).getName()) &&
((PsiMethod)resolved).getParameterList().getParametersCount() == 0;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:GroovyConditionalCanBeElvisInspection.java
示例6: checkForStringIsEmpty
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
/**
* checks for the case string.isEmpty() ? something_else : string
*/
private static boolean checkForStringIsEmpty(GrExpression condition, GrExpression elseBranch) {
if (condition instanceof GrMethodCall) condition = ((GrMethodCall)condition).getInvokedExpression();
if (!(condition instanceof GrReferenceExpression)) return false;
final GrExpression qualifier = ((GrReferenceExpression)condition).getQualifier();
if (qualifier == null) return false;
if (!PsiEquivalenceUtil.areElementsEquivalent(qualifier, elseBranch)) return false;
final PsiType type = qualifier.getType();
if (type == null) return false;
if (!type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) return false;
final PsiElement resolved = ((GrReferenceExpression)condition).resolve();
return resolved instanceof PsiMethod &&
"isEmpty".equals(((PsiMethod)resolved).getName()) &&
((PsiMethod)resolved).getParameterList().getParametersCount() == 0;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:GroovyConditionalCanBeElvisInspection.java
示例7: checkForNull
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
private static boolean checkForNull(GrExpression condition, GrExpression then) {
if (!(condition instanceof GrBinaryExpression)) return false;
GrBinaryExpression binaryExpression = (GrBinaryExpression)condition;
if (GroovyTokenTypes.mNOT_EQUAL != binaryExpression.getOperationTokenType()) return false;
GrExpression left = binaryExpression.getLeftOperand();
GrExpression right = binaryExpression.getRightOperand();
if (left instanceof GrLiteral && "null".equals(left.getText()) && right != null) {
return PsiEquivalenceUtil.areElementsEquivalent(right, then);
}
if (right instanceof GrLiteral && "null".equals(right.getText())) {
return PsiEquivalenceUtil.areElementsEquivalent(left, then);
}
return false;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GroovyConditionalCanBeElvisInspection.java
示例8: addVariantsWithSameQualifier
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
private void addVariantsWithSameQualifier(@NotNull PsiElement element, @NotNull Set<String> result) {
if (element instanceof GrReferenceExpression && element != myRefExpr && !PsiUtil.isLValue((GroovyPsiElement)element)) {
final GrReferenceExpression refExpr = (GrReferenceExpression)element;
final String refName = refExpr.getReferenceName();
if (refName != null && !result.contains(refName) && myMatcher.prefixMatches(refName)) {
final GrExpression hisQualifier = refExpr.getQualifierExpression();
if (hisQualifier != null && myQualifier != null) {
if (PsiEquivalenceUtil.areElementsEquivalent(hisQualifier, myQualifier)) {
if (refExpr.resolve() == null) {
result.add(refName);
}
}
}
else if (hisQualifier == null && myQualifier == null) {
if (refExpr.resolve() == null) {
result.add(refName);
}
}
}
}
for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
addVariantsWithSameQualifier(child, result);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:CompleteReferencesWithSameQualifier.java
示例9: matchPattern
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
private static boolean matchPattern(@Nullable final PsiElement pattern,
@Nullable final PsiElement candidate,
@NotNull final SimpleMatch match) {
ProgressManager.checkCanceled();
if (pattern == null || candidate == null) return pattern == candidate;
final PsiElement[] children1 = PsiEquivalenceUtil.getFilteredChildren(pattern, null, true);
final PsiElement[] children2 = PsiEquivalenceUtil.getFilteredChildren(candidate, null, true);
if (children1.length != children2.length) return false;
for (int i = 0; i < children1.length; i++) {
final PsiElement child1 = children1[i];
final PsiElement child2 = children2[i];
if (!matchPattern(child1, child2, match)) return false;
}
if (children1.length == 0) {
if (pattern.getUserData(PARAMETER) != null && pattern.getParent().getClass() == candidate.getParent().getClass()) {
match.changeParameter(pattern.getText(), candidate.getText());
return true;
}
if (!pattern.textMatches(candidate)) return false;
}
return true;
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:26,代码来源:SimpleDuplicatesFinder.java
示例10: getOccurrences
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
@NotNull
public static List<PsiElement> getOccurrences(@NotNull final PsiElement pattern, @Nullable final PsiElement context) {
if (context == null) {
return Collections.emptyList();
}
final List<PsiElement> occurrences = new ArrayList<PsiElement>();
final HaxeVisitor visitor = new HaxeVisitor() {
public void visitElement(@NotNull final PsiElement element) {
if (element instanceof HaxeParameter) {
return;
}
if (PsiEquivalenceUtil.areElementsEquivalent(element, pattern)) {
occurrences.add(element);
return;
}
element.acceptChildren(this);
}
};
context.acceptChildren(visitor);
return occurrences;
}
开发者ID:HaxeFoundation,项目名称:intellij-haxe,代码行数:22,代码来源:HaxeRefactoringUtil.java
示例11: addExpressionOccurrences
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
protected static void addExpressionOccurrences(JSExpression expr, List<JSExpression> array, PsiElement scope)
{
PsiElement[] children = scope.getChildren();
for(PsiElement child : children)
{
if(child instanceof JSExpression)
{
final JSExpression childExpression = unparenthesize((JSExpression) child);
if(childExpression != null &&
PsiEquivalenceUtil.areElementsEquivalent(childExpression, expr) &&
!JSResolveUtil.isSelfReference(scope, child))
{
array.add((JSExpression) child);
continue;
}
}
if(!(child instanceof JSFunction))
{
addExpressionOccurrences(expr, array, child);
}
}
}
开发者ID:consulo,项目名称:consulo-javascript,代码行数:25,代码来源:JSBaseIntroduceHandler.java
示例12: areExitStatementsTheSame
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
private void areExitStatementsTheSame() throws ExitStatementsNotSameException
{
if(myExitStatements.isEmpty())
{
throw new ExitStatementsNotSameException();
}
PsiStatement first = null;
for(PsiStatement statement : myExitStatements)
{
if(first == null)
{
first = statement;
continue;
}
if(!PsiEquivalenceUtil.areElementsEquivalent(first, statement))
{
throw new ExitStatementsNotSameException();
}
}
myFirstExitStatementCopy = (PsiStatement) first.copy();
}
开发者ID:consulo,项目名称:consulo-java,代码行数:23,代码来源:ControlFlowWrapper.java
示例13: collectOccurrences
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
private static void collectOccurrences(@NotNull PsiElement expr, @NotNull PsiElement scope, @NotNull ArrayList<PsiElement> acc, Comparator<PsiElement> comparator, boolean goIntoInner) {
if (scope.equals(expr)) {
acc.add(expr);
return;
}
for (PsiElement child : scope.getChildren()) {
// if (goIntoInner || !(scope instanceof LuaPsiFileBase)) {
if (PsiEquivalenceUtil.areElementsEquivalent(child, expr, comparator, false)) {
acc.add(child);
} else {
collectOccurrences(expr, child, acc, comparator, goIntoInner);
}
}
// }
}
开发者ID:internetisalie,项目名称:lua-for-idea,代码行数:16,代码来源:LuaRefactoringUtil.java
示例14: findEquivalent
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
@Nullable
private static PsiExpression findEquivalent(PsiExpression expr, PsiElement element) {
PsiElement expression = element;
while (expression != null) {
if (PsiEquivalenceUtil.areElementsEquivalent(expression, expr)) {
return (PsiExpression)expression;
}
expression = PsiTreeUtil.getParentOfType(expression, PsiExpression.class);
}
return null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:ParametersFolder.java
示例15: registerInstanceExpression
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
boolean registerInstanceExpression(PsiExpression instanceExpression, final PsiClass contextClass) {
if (myInstanceExpression == null) {
if (instanceExpression != null) {
final PsiType type = instanceExpression.getType();
if (!(type instanceof PsiClassType)) return false;
final PsiClass hisClass = ((PsiClassType) type).resolve();
if (hisClass == null || !InheritanceUtil.isInheritorOrSelf(hisClass, contextClass, true)) return false;
}
myInstanceExpression = Ref.create(instanceExpression);
return true;
}
else {
if (myInstanceExpression.get() == null) {
myInstanceExpression.set(instanceExpression);
return instanceExpression == null;
}
else {
if (instanceExpression != null) {
return PsiEquivalenceUtil.areElementsEquivalent(instanceExpression, myInstanceExpression.get());
}
else {
return myInstanceExpression.get() == null || myInstanceExpression.get() instanceof PsiThisExpression;
}
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:Match.java
示例16: getExpressionStatementInside
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
@Nullable
protected static PsiStatement getExpressionStatementInside(PsiFile file, Editor editor, @NotNull PsiExpression operand) {
PsiElement elementAt = file.findElementAt(editor.getCaretModel().getOffset());
PsiBlockStatement blockStatement = PsiTreeUtil.getParentOfType(elementAt, PsiBlockStatement.class);
if (blockStatement == null) {
final PsiIfStatement ifStm = PsiTreeUtil.getParentOfType(elementAt, PsiIfStatement.class);
if (ifStm != null) {
final PsiStatement thenBranch = ifStm.getThenBranch();
if (thenBranch instanceof PsiBlockStatement) {
blockStatement = (PsiBlockStatement)thenBranch;
}
} else {
final PsiWhileStatement whileStatement = PsiTreeUtil.getParentOfType(elementAt, PsiWhileStatement.class);
if (whileStatement != null) {
final PsiStatement body = whileStatement.getBody();
if (body instanceof PsiBlockStatement) {
blockStatement = (PsiBlockStatement)body;
}
}
}
}
if (blockStatement != null) {
final PsiStatement[] statements = blockStatement.getCodeBlock().getStatements();
if (statements.length == 1 &&
statements[0] instanceof PsiExpressionStatement &&
PsiEquivalenceUtil.areElementsEquivalent(((PsiExpressionStatement)statements[0]).getExpression(), operand)) {
return statements[0];
}
}
return null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:CreateLocalVarFromInstanceofAction.java
示例17: equals
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
@Override
public boolean equals(final PsiElement o1, final PsiElement o2) {
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return o1 != null && o2 != null && PsiEquivalenceUtil.areElementsEquivalent(o1, o2);
}
});
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:SliceLeafAnalyzer.java
示例18: matchPattern
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
private boolean matchPattern(@Nullable final PsiElement pattern,
@Nullable final PsiElement candidate,
@NotNull final SimpleMatch match) {
ProgressManager.checkCanceled();
if (pattern == null || candidate == null) return pattern == candidate;
final PsiElement[] children1 = PsiEquivalenceUtil.getFilteredChildren(pattern, null, true);
final PsiElement[] children2 = PsiEquivalenceUtil.getFilteredChildren(candidate, null, true);
final PsiElement patternParent = pattern.getParent();
final PsiElement candidateParent = candidate.getParent();
if (patternParent == null || candidateParent == null) return false;
if (pattern.getUserData(PARAMETER) != null && patternParent.getClass() == candidateParent.getClass()) {
match.changeParameter(pattern.getText(), candidate.getText());
return true;
}
if (children1.length != children2.length) return false;
for (int i = 0; i < children1.length; i++) {
final PsiElement child1 = children1[i];
final PsiElement child2 = children2[i];
if (!matchPattern(child1, child2, match)) return false;
}
if (children1.length == 0) {
if (pattern.getUserData(PARAMETER) != null && patternParent.getClass() == candidateParent.getClass()) {
match.changeParameter(pattern.getText(), candidate.getText());
return true;
}
if (myOutputVariables.contains(pattern.getText())) {
match.changeOutput(candidate.getText());
return true;
}
if (!pattern.textMatches(candidate)) {
return false;
}
}
return true;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:SimpleDuplicatesFinder.java
示例19: getOccurrences
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
@NotNull
public static List<PsiElement> getOccurrences(@NotNull final PsiElement pattern, @Nullable final PsiElement context) {
if (context == null) {
return Collections.emptyList();
}
final List<PsiElement> occurrences = new ArrayList<PsiElement>();
final PyElementVisitor visitor = new PyElementVisitor() {
public void visitElement(@NotNull final PsiElement element) {
if (element instanceof PyParameter) {
return;
}
if (PsiEquivalenceUtil.areElementsEquivalent(element, pattern)) {
occurrences.add(element);
return;
}
if (element instanceof PyStringLiteralExpression) {
final Pair<PsiElement, TextRange> selection = pattern.getUserData(PyReplaceExpressionUtil.SELECTION_BREAKS_AST_NODE);
if (selection != null) {
final String substring = selection.getSecond().substring(pattern.getText());
final PyStringLiteralExpression expr = (PyStringLiteralExpression)element;
final String text = element.getText();
if (text != null && expr.getStringNodes().size() == 1) {
final int start = text.indexOf(substring);
if (start >= 0) {
element.putUserData(PyReplaceExpressionUtil.SELECTION_BREAKS_AST_NODE, Pair.create(element, TextRange.from(start, substring.length())));
occurrences.add(element);
return;
}
}
}
}
element.acceptChildren(this);
}
};
context.acceptChildren(visitor);
return occurrences;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:PyRefactoringUtil.java
示例20: checkForEqualsNotElse
import com.intellij.codeInsight.PsiEquivalenceUtil; //导入依赖的package包/类
private static boolean checkForEqualsNotElse(GrExpression condition, GrExpression elseBranch) {
if (!(condition instanceof GrUnaryExpression)) return false;
if (((GrUnaryExpression)condition).getOperationTokenType() != GroovyTokenTypes.mLNOT) return false;
final GrExpression operand = ((GrUnaryExpression)condition).getOperand();
return operand != null && PsiEquivalenceUtil.areElementsEquivalent(operand, elseBranch);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:GroovyConditionalCanBeElvisInspection.java
注:本文中的com.intellij.codeInsight.PsiEquivalenceUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论