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


Java Match类代码示例

本文整理汇总了Java中com.intellij.refactoring.util.duplicates.Match的典型用法代码示例。如果您正苦于以下问题:Java Match类的具体用法?Java Match怎么用?Java Match使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Match类属于com.intellij.refactoring.util.duplicates包,在下文中一共展示了Match类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDuplicates

import com.intellij.refactoring.util.duplicates.Match; //导入依赖的package包/类
public List<Match> getDuplicates(final PsiMethod method, final PsiMethodCallExpression methodCall, ParametersFolder folder) {
  final List<Match> duplicates = findDuplicatesSignature(method, folder);
  if (duplicates != null && !duplicates.isEmpty()) {
    if (ApplicationManager.getApplication().isUnitTestMode() || 
        new PreviewDialog(method, myExtractedMethod, methodCall, myMethodCall, duplicates.size()).showAndGet()) {
      PsiDocumentManager.getInstance(myProject).commitAllDocuments();
      WriteCommandAction.runWriteCommandAction(myProject, new Runnable() {
        @Override
        public void run() {
          myMethodCall = (PsiMethodCallExpression)methodCall.replace(myMethodCall);
          myExtractedMethod = (PsiMethod)method.replace(myExtractedMethod);
        }
      });

      final DuplicatesFinder finder = MethodDuplicatesHandler.createDuplicatesFinder(myExtractedMethod);
      if (finder != null) {
        final List<VariableData> datas = finder.getParameters().getInputVariables();
        myVariableData = datas.toArray(new VariableData[datas.size()]);
        return finder.findDuplicates(myExtractedMethod.getContainingClass());
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:ExtractMethodSignatureSuggester.java

示例2: collectParamValues

import com.intellij.refactoring.util.duplicates.Match; //导入依赖的package包/类
private static boolean collectParamValues(List<Match> duplicates, VariableData variableData, THashSet<PsiExpression> map) {
  for (Match duplicate : duplicates) {
    final List<PsiElement> values = duplicate.getParameterValues(variableData.variable);
    if (values == null || values.isEmpty()) {
      return false;
    }
    boolean found = false;
    for (PsiElement value : values) {
      if (value instanceof PsiExpression) {
        map.add((PsiExpression)value);
        found = true;
        break;
      }
    }
    if (!found) return false;
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ExtractMethodSignatureSuggester.java

示例3: filterChainedConstructorDuplicates

import com.intellij.refactoring.util.duplicates.Match; //导入依赖的package包/类
private static List<Match> filterChainedConstructorDuplicates(final List<Match> duplicates)
{
	List<Match> result = new ArrayList<Match>();
	for(Match duplicate : duplicates)
	{
		final PsiElement matchStart = duplicate.getMatchStart();
		final PsiMethod method = PsiTreeUtil.getParentOfType(matchStart, PsiMethod.class);
		if(method != null && method.isConstructor())
		{
			final PsiCodeBlock body = method.getBody();
			if(body != null)
			{
				final PsiStatement[] psiStatements = body.getStatements();
				if(psiStatements.length > 0 && matchStart == psiStatements[0])
				{
					result.add(duplicate);
				}
			}
		}
	}
	return result;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:23,代码来源:ExtractMethodProcessor.java

示例4: hasDuplicates

import com.intellij.refactoring.util.duplicates.Match; //导入依赖的package包/类
@Override
public Boolean hasDuplicates()
{
	List<Match> duplicates = getDuplicates();
	if(duplicates != null && !duplicates.isEmpty())
	{
		return true;
	}

	if(myExtractedMethod != null)
	{
		final ExtractMethodSignatureSuggester suggester = new ExtractMethodSignatureSuggester(myProject, myExtractedMethod, myMethodCall, myVariableDatum);
		duplicates = suggester.getDuplicates(myExtractedMethod, myMethodCall, myInputVariables.getFolding());
		if(duplicates != null && !duplicates.isEmpty())
		{
			myDuplicates = duplicates;
			myExtractedMethod = suggester.getExtractedMethod();
			myMethodCall = suggester.getMethodCall();
			myVariableDatum = suggester.getVariableData();
			return null;
		}
	}
	return false;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:25,代码来源:ExtractMethodProcessor.java

示例5: getConfirmDuplicatePrompt

import com.intellij.refactoring.util.duplicates.Match; //导入依赖的package包/类
@Override
@Nullable
public String getConfirmDuplicatePrompt(Match match)
{
	final boolean needToBeStatic = RefactoringUtil.isInStaticContext(match.getMatchStart(), myExtractedMethod.getContainingClass());
	final String changedSignature = MatchUtil.getChangedSignature(match, myExtractedMethod, needToBeStatic, VisibilityUtil.getVisibilityStringToDisplay(myExtractedMethod));
	if(changedSignature != null)
	{
		return RefactoringBundle.message("replace.this.code.fragment.and.change.signature", changedSignature);
	}
	if(needToBeStatic && !myExtractedMethod.hasModifierProperty(PsiModifier.STATIC))
	{
		return RefactoringBundle.message("replace.this.code.fragment.and.make.method.static");
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:17,代码来源:ExtractMethodProcessor.java

示例6: collectParamValues

import com.intellij.refactoring.util.duplicates.Match; //导入依赖的package包/类
private static boolean collectParamValues(List<Match> duplicates, VariableData variableData, THashSet<PsiExpression> map)
{
	for(Match duplicate : duplicates)
	{
		final List<PsiElement> values = duplicate.getParameterValues(variableData.variable);
		if(values == null || values.isEmpty())
		{
			return false;
		}
		boolean found = false;
		for(PsiElement value : values)
		{
			if(value instanceof PsiExpression)
			{
				map.add((PsiExpression) value);
				found = true;
				break;
			}
		}
		if(!found)
		{
			return false;
		}
	}
	return true;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:27,代码来源:ExtractMethodSignatureSuggester.java

示例7: findDuplicatesSignature

import com.intellij.refactoring.util.duplicates.Match; //导入依赖的package包/类
@Nullable
public List<Match> findDuplicatesSignature(final PsiMethod method, ParametersFolder folder) {
  final List<PsiExpression> copies = new ArrayList<PsiExpression>();
  final InputVariables variables = detectTopLevelExpressionsToReplaceWithParameters(copies);
  if (variables == null) {
    return null;
  }

  final DuplicatesFinder defaultFinder = MethodDuplicatesHandler.createDuplicatesFinder(myExtractedMethod);
  if (defaultFinder == null) {
    return null; 
  }

  final DuplicatesFinder finder = new DuplicatesFinder(defaultFinder.getPattern(), variables, defaultFinder.getReturnValue(), new ArrayList<PsiVariable>()) {
    @Override
    protected boolean isSelf(PsiElement candidate) {
      return PsiTreeUtil.isAncestor(method, candidate, true);
    }
  };
  List<Match> duplicates = finder.findDuplicates(method.getContainingClass());

  if (duplicates != null && !duplicates.isEmpty()) {
    restoreRenamedParams(copies, folder);
    if (!myMethodCall.isValid()) {
      return null;
    }
    myMethodCall = (PsiMethodCallExpression)myMethodCall.copy();
    inlineSameArguments(method, copies, variables, duplicates);
    for (PsiExpression expression : copies) {
      myMethodCall.getArgumentList().add(expression);
    }
    return duplicates;
  }
  else {
    return null;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:ExtractMethodSignatureSuggester.java

示例8: inlineSameArguments

import com.intellij.refactoring.util.duplicates.Match; //导入依赖的package包/类
private void inlineSameArguments(PsiMethod method, List<PsiExpression> copies, InputVariables variables, List<Match> duplicates) {
  final List<VariableData> variableDatum = variables.getInputVariables();
  final Map<PsiVariable, PsiExpression> toInline = new HashMap<PsiVariable, PsiExpression>();
  final int strongParamsCound = method.getParameterList().getParametersCount();
  for (int i = strongParamsCound; i < variableDatum.size(); i++) {
    VariableData variableData = variableDatum.get(i);
    final THashSet<PsiExpression> map = new THashSet<PsiExpression>(ourEquivalenceStrategy);
    if (!collectParamValues(duplicates, variableData, map)) {
      continue;
    }

    final PsiExpression currentExpression = copies.get(i - strongParamsCound);
    map.add(currentExpression);

    if (map.size() == 1) {
      toInline.put(variableData.variable, currentExpression);
    }
  }

  if (!toInline.isEmpty()) {
    copies.removeAll(toInline.values());
    inlineArgumentsInMethodBody(toInline);
    removeRedundantParametersFromMethodSignature(toInline);
  }

  removeUnusedStongParams(strongParamsCound);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:ExtractMethodSignatureSuggester.java

示例9: initDuplicates

import com.intellij.refactoring.util.duplicates.Match; //导入依赖的package包/类
@Nullable
private DuplicatesFinder initDuplicates()
{
	List<PsiElement> elements = new ArrayList<PsiElement>();
	for(PsiElement element : myElements)
	{
		if(!(element instanceof PsiWhiteSpace || element instanceof PsiComment))
		{
			elements.add(element);
		}
	}

	if(myExpression != null)
	{
		DuplicatesFinder finder = new DuplicatesFinder(PsiUtilCore.toPsiElementArray(elements), myInputVariables.copy(), new ArrayList<PsiVariable>());
		myDuplicates = finder.findDuplicates(myTargetClass);
		return finder;
	}
	else if(elements.size() > 0)
	{
		DuplicatesFinder myDuplicatesFinder = new DuplicatesFinder(PsiUtilCore.toPsiElementArray(elements), myInputVariables.copy(),
				myOutputVariable != null ? new VariableReturnValue(myOutputVariable) : null, Arrays.asList(myOutputVariables));
		myDuplicates = myDuplicatesFinder.findDuplicates(myTargetClass);
		return myDuplicatesFinder;
	}
	else
	{
		myDuplicates = new ArrayList<Match>();
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:32,代码来源:ExtractMethodProcessor.java

示例10: getDuplicates

import com.intellij.refactoring.util.duplicates.Match; //导入依赖的package包/类
@Override
public List<Match> getDuplicates()
{
	if(myIsChainedConstructor)
	{
		return filterChainedConstructorDuplicates(myDuplicates);
	}
	return myDuplicates;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:10,代码来源:ExtractMethodProcessor.java

示例11: getDuplicates

import com.intellij.refactoring.util.duplicates.Match; //导入依赖的package包/类
public List<Match> getDuplicates(final PsiMethod method, final PsiMethodCallExpression methodCall, ParametersFolder folder)
{
	final List<Match> duplicates = findDuplicatesSignature(method, folder);
	if(duplicates != null && !duplicates.isEmpty())
	{
		if(ApplicationManager.getApplication().isUnitTestMode() || new PreviewDialog(method, myExtractedMethod, methodCall, myMethodCall, duplicates.size()).showAndGet())
		{
			PsiDocumentManager.getInstance(myProject).commitAllDocuments();
			WriteCommandAction.runWriteCommandAction(myProject, new Runnable()
			{
				@Override
				public void run()
				{
					myMethodCall = (PsiMethodCallExpression) methodCall.replace(myMethodCall);
					myExtractedMethod = (PsiMethod) method.replace(myExtractedMethod);
				}
			});

			final DuplicatesFinder finder = MethodDuplicatesHandler.createDuplicatesFinder(myExtractedMethod);
			if(finder != null)
			{
				final List<VariableData> datas = finder.getParameters().getInputVariables();
				myVariableData = datas.toArray(new VariableData[datas.size()]);
				return finder.findDuplicates(myExtractedMethod.getContainingClass());
			}
		}
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:30,代码来源:ExtractMethodSignatureSuggester.java

示例12: inlineSameArguments

import com.intellij.refactoring.util.duplicates.Match; //导入依赖的package包/类
private void inlineSameArguments(PsiMethod method, List<PsiExpression> copies, InputVariables variables, List<Match> duplicates)
{
	final List<VariableData> variableDatum = variables.getInputVariables();
	final Map<PsiVariable, PsiExpression> toInline = new HashMap<PsiVariable, PsiExpression>();
	final int strongParamsCound = method.getParameterList().getParametersCount();
	for(int i = strongParamsCound; i < variableDatum.size(); i++)
	{
		VariableData variableData = variableDatum.get(i);
		final THashSet<PsiExpression> map = new THashSet<PsiExpression>(ourEquivalenceStrategy);
		if(!collectParamValues(duplicates, variableData, map))
		{
			continue;
		}

		final PsiExpression currentExpression = copies.get(i - strongParamsCound);
		map.add(currentExpression);

		if(map.size() == 1)
		{
			toInline.put(variableData.variable, currentExpression);
		}
	}

	if(!toInline.isEmpty())
	{
		copies.removeAll(toInline.values());
		inlineArgumentsInMethodBody(toInline);
		removeRedundantParametersFromMethodSignature(toInline);
	}

	removeUnusedStongParams(strongParamsCound);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:33,代码来源:ExtractMethodSignatureSuggester.java

示例13: performExtractMethod

import com.intellij.refactoring.util.duplicates.Match; //导入依赖的package包/类
public static boolean performExtractMethod(boolean doRefactor,
                                           boolean replaceAllDuplicates,
                                           Editor editor,
                                           PsiFile file,
                                           Project project,
                                           final boolean extractChainedConstructor,
                                           PsiType returnType,
                                           boolean makeStatic,
                                           String newNameOfFirstParam,
                                           int... disabledParams)
  throws PrepareFailedException, IncorrectOperationException {
  int startOffset = editor.getSelectionModel().getSelectionStart();
  int endOffset = editor.getSelectionModel().getSelectionEnd();

  PsiElement[] elements;
  PsiExpression expr = CodeInsightUtil.findExpressionInRange(file, startOffset, endOffset);
  if (expr != null) {
    elements = new PsiElement[]{expr};
  }
  else {
    elements = CodeInsightUtil.findStatementsInRange(file, startOffset, endOffset);
  }
  if (elements.length == 0) {
    final PsiExpression expression = IntroduceVariableBase.getSelectedExpression(project, file, startOffset, endOffset);
    if (expression != null) {
      elements = new PsiElement[]{expression};
    }
  }
  assertTrue(elements.length > 0);

  final ExtractMethodProcessor processor =
    new ExtractMethodProcessor(project, editor, elements, null, "Extract Method", "newMethod", null);
  processor.setShowErrorDialogs(false);
  processor.setChainedConstructor(extractChainedConstructor);

  if (!processor.prepare()) {
    return false;
  }

  if (doRefactor) {
    processor.testPrepare(returnType, makeStatic);
    processor.testNullness();
    if (disabledParams != null) {
      for (int param : disabledParams) {
        processor.doNotPassParameter(param);
      }
    }
    if (newNameOfFirstParam != null) {
      processor.changeParamName(0, newNameOfFirstParam);
    }
    ExtractMethodHandler.run(project, editor, processor);
  }

  if (replaceAllDuplicates) {
    final Boolean hasDuplicates = processor.hasDuplicates();
    if (hasDuplicates == null || hasDuplicates.booleanValue()) {
      final List<Match> duplicates = processor.getDuplicates();
      for (final Match match : duplicates) {
        if (!match.getMatchStart().isValid() || !match.getMatchEnd().isValid()) continue;
        PsiDocumentManager.getInstance(project).commitAllDocuments();
        processor.processMatch(match);
      }
    }
  }

  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:68,代码来源:ExtractMethodTest.java

示例14: visitTryStatement

import com.intellij.refactoring.util.duplicates.Match; //导入依赖的package包/类
@Override
public void visitTryStatement(PsiTryStatement statement) {
  super.visitTryStatement(statement);
  final PsiCatchSection[] catchSections = statement.getCatchSections();
  if (catchSections.length < 2) {
    return;
  }
  final PsiParameter[] parameters = statement.getCatchBlockParameters();
  if (catchSections.length != parameters.length) {
    return;
  }
  final boolean[] duplicates = new boolean[catchSections.length];
  for (int i = 0; i < catchSections.length - 1; i++) {
    final PsiCatchSection catchSection = catchSections[i];
    final PsiCodeBlock catchBlock = catchSection.getCatchBlock();
    if (catchBlock == null) {
      continue;
    }
    final PsiParameter parameter = catchSection.getParameter();
    if (parameter == null) {
      continue;
    }
    final InputVariables inputVariables = new InputVariables(Collections.singletonList(parameter),
                                                             statement.getProject(),
                                                             new LocalSearchScope(catchBlock),
                                                             false);
    final DuplicatesFinder finder = new DuplicatesFinder(new PsiElement[]{catchBlock},
                                                         inputVariables, null, Collections.<PsiVariable>emptyList());
    for (int j = i + 1; j < catchSections.length; j++) {
      if (duplicates[j]) {
        continue;
      }
      final PsiCatchSection otherSection = catchSections[j];
      final PsiCodeBlock otherCatchBlock = otherSection.getCatchBlock();
      if (otherCatchBlock == null) {
        continue;
      }
      final Match match = finder.isDuplicate(otherCatchBlock, true);
      if (match == null || match.getReturnValue() != null) {
        continue;
      }
      final List<PsiElement> parameterValues = match.getParameterValues(parameter);
      if (parameterValues != null && (parameterValues.size() != 1 || !(parameterValues.get(0) instanceof PsiReferenceExpression))) {
        continue;
      }
      if (j > i ? !canCollapse(parameters, i, j) : !canCollapse(parameters, j, i)) {
        continue;
      }
      final PsiJavaToken rParenth = otherSection.getRParenth();
      if (rParenth != null) {
        registerErrorAtOffset(otherSection, 0, rParenth.getStartOffsetInParent() + 1, parameter.getType(),
                              Integer.valueOf(i), Integer.valueOf(j));
      }
      duplicates[i] = true;
      duplicates[j] = true;
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:59,代码来源:TryWithIdenticalCatchesInspection.java

示例15: performExtractMethod

import com.intellij.refactoring.util.duplicates.Match; //导入依赖的package包/类
public static boolean performExtractMethod(boolean doRefactor,
                                           boolean replaceAllDuplicates,
                                           Editor editor,
                                           PsiFile file,
                                           Project project,
                                           final boolean extractChainedConstructor,
                                           int... disabledParams)
  throws PrepareFailedException, IncorrectOperationException {
  int startOffset = editor.getSelectionModel().getSelectionStart();
  int endOffset = editor.getSelectionModel().getSelectionEnd();

  PsiElement[] elements;
  PsiExpression expr = CodeInsightUtil.findExpressionInRange(file, startOffset, endOffset);
  if (expr != null) {
    elements = new PsiElement[]{expr};
  }
  else {
    elements = CodeInsightUtil.findStatementsInRange(file, startOffset, endOffset);
  }
  if (elements.length == 0) {
    final PsiExpression expression = IntroduceVariableBase.getSelectedExpression(project, file, startOffset, endOffset);
    if (expression != null) {
      elements = new PsiElement[]{expression};
    }
  }
  assertTrue(elements.length > 0);

  final ExtractMethodProcessor processor =
    new ExtractMethodProcessor(project, editor, elements, null, "Extract Method", "newMethod", null);
  processor.setShowErrorDialogs(false);
  processor.setChainedConstructor(extractChainedConstructor);

  if (!processor.prepare()) {
    return false;
  }

  if (doRefactor) {
    processor.testPrepare();
    if (disabledParams != null) {
      for (int param : disabledParams) {
        processor.doNotPassParameter(param);
      }
    }
    ExtractMethodHandler.run(project, editor, processor);
  }

  if (replaceAllDuplicates) {
    final List<Match> duplicates = processor.getDuplicates();
    for (final Match match : duplicates) {
      if (!match.getMatchStart().isValid() || !match.getMatchEnd().isValid()) continue;
      PsiDocumentManager.getInstance(project).commitAllDocuments();
      processor.processMatch(match);
    }
  }

  return true;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:58,代码来源:ExtractMethodTest.java


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