use of org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceContextImpl in project intellij-community by JetBrains.
the class IntroduceVariableValidatorTest method processFile.
private String processFile(String fileText) throws IncorrectOperationException, InvalidDataException, IOException {
String result = "";
int startOffset = fileText.indexOf(TestUtils.BEGIN_MARKER);
if (startOffset < 0) {
startOffset = fileText.indexOf(ALL_MARKER);
replaceAllOccurences = true;
fileText = IntroduceVariableTest.removeAllMarker(fileText);
} else {
replaceAllOccurences = false;
fileText = TestUtils.removeBeginMarker(fileText);
}
int endOffset = fileText.indexOf(TestUtils.END_MARKER);
fileText = TestUtils.removeEndMarker(fileText);
myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, fileText);
Editor myEditor = myFixture.getEditor();
myEditor.getSelectionModel().setSelection(startOffset, endOffset);
GrExpression selectedExpr = PsiImplUtil.findElementInRange(myFixture.getFile(), startOffset, endOffset, GrExpression.class);
Assert.assertNotNull("Selected expression reference points to null", selectedExpr);
final PsiElement tempContainer = GrIntroduceHandlerBase.getEnclosingContainer(selectedExpr);
Assert.assertTrue(tempContainer instanceof GroovyPsiElement);
PsiElement[] occurences = GroovyRefactoringUtil.getExpressionOccurrences(PsiUtil.skipParentheses(selectedExpr, false), tempContainer);
String varName = "preved";
GroovyVariableValidator validator = new GroovyVariableValidator(new GrIntroduceContextImpl(getProject(), myEditor, selectedExpr, null, null, occurences, tempContainer));
result = validator.isOKTest(varName, replaceAllOccurences);
return result;
}
use of org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceContextImpl in project intellij-community by JetBrains.
the class GroovyIntroduceParameterUtil method suggestNames.
static LinkedHashSet<String> suggestNames(GrVariable var, GrExpression expr, StringPartInfo stringPart, GrParametersOwner scope, Project project) {
if (expr != null) {
final GrIntroduceContext introduceContext = new GrIntroduceContextImpl(project, null, expr, var, stringPart, PsiElement.EMPTY_ARRAY, scope);
final GroovyFieldValidator validator = new GroovyFieldValidator(introduceContext);
return new LinkedHashSet<>(Arrays.asList(GroovyNameSuggestionUtil.suggestVariableNames(expr, validator, true)));
} else if (var != null) {
final GrIntroduceContext introduceContext = new GrIntroduceContextImpl(project, null, expr, var, stringPart, PsiElement.EMPTY_ARRAY, scope);
final GroovyFieldValidator validator = new GroovyFieldValidator(introduceContext);
LinkedHashSet<String> names = new LinkedHashSet<>();
names.add(var.getName());
ContainerUtil.addAll(names, GroovyNameSuggestionUtil.suggestVariableNameByType(var.getType(), validator));
return names;
} else {
LinkedHashSet<String> names = new LinkedHashSet<>();
names.add("closure");
return names;
}
}
Aggregations