mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
duplicate
This commit is contained in:
+14
-15
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 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.
|
||||
@@ -40,7 +40,6 @@ public class SimplifyTernaryOperatorIntention extends Intention {
|
||||
if (!(element instanceof GrConditionalExpression)) {
|
||||
throw new IncorrectOperationException("Not invoked on a conditional");
|
||||
}
|
||||
GroovyPsiElementFactory groovyPsiElementFactory = GroovyPsiElementFactory.getInstance(project);
|
||||
GrConditionalExpression condExp = (GrConditionalExpression)element;
|
||||
GrExpression thenBranch = condExp.getThenBranch();
|
||||
GrExpression elseBranch = condExp.getElseBranch();
|
||||
@@ -53,13 +52,7 @@ public class SimplifyTernaryOperatorIntention extends Intention {
|
||||
String conditionExpText = getStringToPutIntoOrExpression(conditionExp);
|
||||
String elseExpText = getStringToPutIntoOrExpression(elseBranch);
|
||||
String newExp = conditionExpText + "||" + elseExpText;
|
||||
int caretOffset = conditionExpText.length() + 2; // after "||"
|
||||
|
||||
GrExpression expressionFromText = groovyPsiElementFactory.createExpressionFromText(newExp, condExp.getContext());
|
||||
|
||||
expressionFromText = (GrExpression)condExp.replace(expressionFromText);
|
||||
|
||||
editor.getCaretModel().moveToOffset(expressionFromText.getTextOffset() + caretOffset); // just past "||"
|
||||
manageReplace(editor, condExp, conditionExpText, newExp);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -73,14 +66,20 @@ public class SimplifyTernaryOperatorIntention extends Intention {
|
||||
|
||||
|
||||
String newExp = conditionExpText + "&&" + thenExpText;
|
||||
int caretOffset = conditionExpText.length() + 2; // after "&&"
|
||||
GrExpression expressionFromText = groovyPsiElementFactory.createExpressionFromText(newExp, condExp.getContext());
|
||||
|
||||
expressionFromText = (GrExpression)condExp.replace(expressionFromText);
|
||||
|
||||
editor.getCaretModel().moveToOffset(expressionFromText.getTextOffset() + caretOffset); // just past "&&"
|
||||
manageReplace(editor, condExp, conditionExpText, newExp);
|
||||
}
|
||||
}
|
||||
|
||||
private static void manageReplace(Editor editor,
|
||||
GrConditionalExpression condExp,
|
||||
String conditionExpText, String newExp) {
|
||||
int caretOffset = conditionExpText.length() + 2; // after operation sign
|
||||
|
||||
GrExpression expressionFromText = GroovyPsiElementFactory.getInstance(editor.getProject()).createExpressionFromText(newExp, condExp .getContext());
|
||||
|
||||
expressionFromText = (GrExpression)condExp.replace(expressionFromText);
|
||||
|
||||
editor.getCaretModel().moveToOffset(expressionFromText.getTextOffset() + caretOffset); // just past operation sign
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user