use of org.jetbrains.plugins.groovy.refactoring.GrRefactoringError in project intellij-community by JetBrains.
the class GroovyExtractMethodHandler method invokeImpl.
private void invokeImpl(Project project, Editor editor, PsiFile file, final int startOffset, final int endOffset) {
try {
final InitialInfo initialInfo = GroovyExtractChooser.invoke(project, editor, file, startOffset, endOffset, true);
if (findConflicts(initialInfo))
return;
performRefactoring(initialInfo, editor);
} catch (GrRefactoringError e) {
CommonRefactoringUtil.showErrorHint(project, editor, e.getMessage(), REFACTORING_NAME, HelpID.EXTRACT_METHOD);
}
}
use of org.jetbrains.plugins.groovy.refactoring.GrRefactoringError in project intellij-community by JetBrains.
the class GrIntroduceConstantHandler method checkVariable.
@Override
protected void checkVariable(@NotNull GrVariable variable) throws GrRefactoringError {
final GrExpression initializer = variable.getInitializerGroovy();
if (initializer == null) {
throw new GrRefactoringError(RefactoringBundle.message("variable.does.not.have.an.initializer", variable.getName()));
}
checkExpression(initializer);
}
use of org.jetbrains.plugins.groovy.refactoring.GrRefactoringError in project intellij-community by JetBrains.
the class GroovyExtractChooser method invoke.
public static InitialInfo invoke(Project project, Editor editor, PsiFile file, int start, int end, boolean forceStatements) throws GrRefactoringError {
PsiDocumentManager.getInstance(project).commitAllDocuments();
if (!(file instanceof GroovyFileBase)) {
throw new GrRefactoringError(GroovyRefactoringBundle.message("only.in.groovy.files"));
}
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, file)) {
throw new GrRefactoringError(RefactoringBundle.message("readonly.occurences.found"));
}
PsiDocumentManager.getInstance(project).commitAllDocuments();
final StringPartInfo stringPart = StringPartInfo.findStringPart(file, start, end);
if (stringPart != null) {
return new InitialInfo(new VariableInfo[0], new VariableInfo[0], PsiElement.EMPTY_ARRAY, GrStatement.EMPTY_ARRAY, new ArrayList<>(), stringPart, project, null);
}
final SelectionModel selectionModel = editor.getSelectionModel();
if (!forceStatements) {
GrVariable variable = GrIntroduceHandlerBase.findVariable(file, start, end);
if (variable != null) {
GrExpression initializer = variable.getInitializerGroovy();
if (initializer != null) {
TextRange range = initializer.getTextRange();
return buildInfo(project, file, range.getStartOffset(), range.getEndOffset(), forceStatements, selectionModel, variable);
}
}
}
return buildInfo(project, file, start, end, forceStatements, selectionModel, null);
}
use of org.jetbrains.plugins.groovy.refactoring.GrRefactoringError in project intellij-community by JetBrains.
the class GroovyIntroduceParameterUtil method getOccurrences.
static PsiElement[] getOccurrences(GrIntroduceParameterSettings settings) {
final GrParametersOwner scope = settings.getToReplaceIn();
final GrExpression expression = settings.getExpression();
if (expression != null) {
final PsiElement expr = PsiUtil.skipParentheses(expression, false);
if (expr == null)
return PsiElement.EMPTY_ARRAY;
final PsiElement[] occurrences = GroovyRefactoringUtil.getExpressionOccurrences(expr, scope);
if (occurrences == null || occurrences.length == 0) {
throw new GrRefactoringError(GroovyRefactoringBundle.message("no.occurrences.found"));
}
return occurrences;
} else {
final GrVariable var = settings.getVar();
LOG.assertTrue(var != null);
final List<PsiElement> list = Collections.synchronizedList(new ArrayList<PsiElement>());
ReferencesSearch.search(var, new LocalSearchScope(scope)).forEach(psiReference -> {
final PsiElement element = psiReference.getElement();
if (element != null) {
list.add(element);
}
return true;
});
return list.toArray(new PsiElement[list.size()]);
}
}
use of org.jetbrains.plugins.groovy.refactoring.GrRefactoringError in project intellij-community by JetBrains.
the class GrIntroduceParameterHandler method invoke.
private void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file, int startOffset, int endOffset) {
try {
final InitialInfo initialInfo = GroovyExtractChooser.invoke(project, editor, file, startOffset, endOffset, false);
chooseScopeAndRun(initialInfo, editor);
} catch (GrRefactoringError e) {
if (ApplicationManager.getApplication().isUnitTestMode())
throw e;
CommonRefactoringUtil.showErrorHint(project, editor, e.getMessage(), RefactoringBundle.message("introduce.parameter.title"), HelpID.GROOVY_INTRODUCE_PARAMETER);
}
}
Aggregations