当前位置: 首页>>代码示例>>Java>>正文


Java PsiEquivalenceUtil.areElementsEquivalent方法代码示例

本文整理汇总了Java中com.intellij.codeInsight.PsiEquivalenceUtil.areElementsEquivalent方法的典型用法代码示例。如果您正苦于以下问题:Java PsiEquivalenceUtil.areElementsEquivalent方法的具体用法?Java PsiEquivalenceUtil.areElementsEquivalent怎么用?Java PsiEquivalenceUtil.areElementsEquivalent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.codeInsight.PsiEquivalenceUtil的用法示例。


在下文中一共展示了PsiEquivalenceUtil.areElementsEquivalent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例8: 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:lshain-android-source,项目名称:tools-idea,代码行数:18,代码来源:GroovyConditionalCanBeElvisInspection.java

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


注:本文中的com.intellij.codeInsight.PsiEquivalenceUtil.areElementsEquivalent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。