String name = ctx.identifierToInline.getName();
PsiElement initializer = getInitializer(ctx.identifierToInline);
boolean shouldHaveInitializer = identifierShouldHaveInitializer(ctx.identifierToInline);
if (shouldHaveInitializer && initializer == null ||
usage.writeUsages.length == 0 && !shouldHaveInitializer) {
throw new GoRefactoringException(RefactoringBundle.message("variable.has.no.initializer", ctx.identifierToInline.getText()));
}
if (usage.readUsages.length == 0) {
String messsage = GoBundle.message("error.variable.is.never.used", name);
throw new GoRefactoringException(messsage);
}
if (usage.writeUsages.length == 1 && !shouldHaveInitializer) {
if (usage.readUsages[0].getTextOffset() > usage.writeUsages[0].getTextOffset()) {
String messsage = GoBundle.message("error.variable.is.used.before.modification", name);
throw new GoRefactoringException(messsage);
}
initializer = getInitializer((GoLiteralIdentifier) usage.writeUsages[0]);
if (initializer == null) {
throw new GoRefactoringException(RefactoringBundle.message("variable.has.no.initializer", ctx.identifierToInline.getText()));
}
}
if (usage.writeUsages.length >= 2 ||
usage.writeUsages.length == 1 && shouldHaveInitializer) {
throw new GoRefactoringException(RefactoringBundle.message("variable.is.accessed.for.writing", name));
}
while (initializer instanceof GoParenthesisedExpression) {
initializer = ((GoParenthesisedExpression) initializer).getInnerExpression();
}