本文整理汇总了Java中com.intellij.codeInspection.AnonymousCanBeLambdaInspection类的典型用法代码示例。如果您正苦于以下问题:Java AnonymousCanBeLambdaInspection类的具体用法?Java AnonymousCanBeLambdaInspection怎么用?Java AnonymousCanBeLambdaInspection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AnonymousCanBeLambdaInspection类属于com.intellij.codeInspection包,在下文中一共展示了AnonymousCanBeLambdaInspection类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertFunctionOrPredicateParameter
import com.intellij.codeInspection.AnonymousCanBeLambdaInspection; //导入依赖的package包/类
@NotNull
public static String convertFunctionOrPredicateParameter(final @NotNull PsiExpression expression,
final boolean role) {
if (role) {
final String pattern = expression instanceof PsiMethodCallExpression || expression instanceof PsiReferenceExpression
? "%s::isInstance"
: "(%s)::isInstance";
return String.format(pattern, expression.getText());
}
if (expression instanceof PsiNewExpression) {
final PsiAnonymousClass anonymousClass = ((PsiNewExpression)expression).getAnonymousClass();
if (anonymousClass != null && AnonymousCanBeLambdaInspection.canBeConvertedToLambda(anonymousClass, true)) {
final PsiExpression lambdaExpression = AnonymousCanBeLambdaInspection.replacePsiElementWithLambda(expression, true);
LOG.assertTrue(lambdaExpression != null);
return lambdaExpression.getText();
}
}
String qualifierText = expression.getText();
if (!(expression instanceof PsiMethodCallExpression) && !(expression instanceof PsiReferenceExpression)) {
qualifierText = "(" + qualifierText + ")";
}
return qualifierText + "::apply";
}
示例2: doAction
import com.intellij.codeInspection.AnonymousCanBeLambdaInspection; //导入依赖的package包/类
protected void doAction() {
final JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance();
settings.INTRODUCE_PARAMETER_REPLACE_FIELDS_WITH_GETTERS =
myPanel.getReplaceFieldsWithGetters();
if (myCbDeclareFinal != null && myCbDeclareFinal.isEnabled()) {
settings.INTRODUCE_PARAMETER_CREATE_FINALS = Boolean.valueOf(myCbDeclareFinal.isSelected());
}
if (myCbCollapseToLambda.isVisible()) {
PropertiesComponent.getInstance(myProject).setValue(INTRODUCE_PARAMETER_LAMBDA, myCbCollapseToLambda.isSelected());
}
myPanel.saveSettings(settings);
myNameSuggestionsManager.nameSelected();
boolean isDeleteLocalVariable = false;
PsiExpression parameterInitializer = myExpression;
if (myLocalVar != null) {
if (myPanel.isUseInitializer()) {
parameterInitializer = myLocalVar.getInitializer();
}
isDeleteLocalVariable = myPanel.isDeleteLocalVariable();
}
final IntroduceParameterProcessor processor = new IntroduceParameterProcessor(
myProject, myMethodToReplaceIn, myMethodToSearchFor,
parameterInitializer, myExpression,
myLocalVar, isDeleteLocalVariable,
getParameterName(), myPanel.isReplaceAllOccurences(),
myPanel.getReplaceFieldsWithGetters(), isDeclareFinal(), myPanel.isGenerateDelegate(), getSelectedType(), myPanel.getParametersToRemove());
if (myCbCollapseToLambda.isVisible() && myCbCollapseToLambda.isSelected() && parameterInitializer != null) {
PsiExpression lambda = AnonymousCanBeLambdaInspection.replaceAnonymousWithLambda(parameterInitializer, getSelectedType());
if (lambda != null) {
processor.setParameterInitializer(lambda);
}
}
invokeRefactoring(processor);
}
示例3: configureLocalInspectionTools
import com.intellij.codeInspection.AnonymousCanBeLambdaInspection; //导入依赖的package包/类
@NotNull
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
return new LocalInspectionTool[]{
new AnonymousCanBeLambdaInspection(),
};
}
示例4: perform
import com.intellij.codeInspection.AnonymousCanBeLambdaInspection; //导入依赖的package包/类
private static boolean perform(boolean replaceAllOccurrences,
int replaceFieldsWithGetters,
@NonNls String parameterName,
boolean searchForSuper,
boolean declareFinal,
boolean removeUnusedParameters,
boolean generateDelegate,
int enclosingLevel,
final boolean replaceDuplicates) {
final ElementToWorkOn[] elementToWorkOn = new ElementToWorkOn[1];
ElementToWorkOn.processElementToWorkOn(myEditor, myFile, "INtr param", HelpID.INTRODUCE_PARAMETER, getProject(),
new ElementToWorkOn.ElementsProcessor<ElementToWorkOn>() {
@Override
public boolean accept(ElementToWorkOn el) {
return true;
}
@Override
public void pass(final ElementToWorkOn e) {
if (e != null) {
elementToWorkOn[0] = e;
}
}
});
final PsiExpression expr = elementToWorkOn[0].getExpression();
final PsiLocalVariable localVar = elementToWorkOn[0].getLocalVariable();
PsiElement context = expr == null ? localVar : expr;
PsiMethod method = Util.getContainingMethod(context);
if (method == null) return false;
final List<PsiMethod> methods = com.intellij.refactoring.introduceParameter.IntroduceParameterHandler.getEnclosingMethods(method);
assertTrue(methods.size() > enclosingLevel);
method = methods.get(enclosingLevel);
final PsiMethod methodToSearchFor;
if (searchForSuper) {
methodToSearchFor = method.findDeepestSuperMethods()[0];
}
else {
methodToSearchFor = method;
}
PsiExpression[] occurrences;
PsiExpression initializer;
if (expr == null) {
initializer = localVar.getInitializer();
assertNotNull(initializer);
occurrences = CodeInsightUtil.findReferenceExpressions(method, localVar);
}
else {
initializer = expr;
occurrences = new ExpressionOccurrenceManager(expr, method, null).findExpressionOccurrences();
}
TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, initializer, occurrences)
: new TIntArrayList();
IntroduceParameterProcessor processor = new IntroduceParameterProcessor(
getProject(), method, methodToSearchFor, initializer, expr, localVar, true, parameterName, replaceAllOccurrences,
replaceFieldsWithGetters, declareFinal, generateDelegate, null, parametersToRemove
) {
@Override
protected boolean isReplaceDuplicates() {
return replaceDuplicates;
}
};
PsiType initializerType = initializer.getType();
if (initializerType != null && initializerType != PsiType.NULL) {
PsiExpression lambda = AnonymousCanBeLambdaInspection.replaceAnonymousWithLambda(initializer, initializerType);
if (lambda != null) {
processor.setParameterInitializer(lambda);
}
}
processor.run();
myEditor.getSelectionModel().removeSelection();
return true;
}