use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable in project intellij-community by JetBrains.
the class GrAbstractInplaceIntroducer method createFieldToStartTemplateOn.
@Nullable
@Override
protected GrVariable createFieldToStartTemplateOn(boolean replaceAll, @NotNull String[] names) {
final Settings settings = getInitialSettingsForInplace(myContext, myReplaceChoice, names);
if (settings == null)
return null;
GrVariable var = runRefactoring(myContext, settings, false);
if (var != null) {
myVarMarker = myContext.getEditor().getDocument().createRangeMarker(var.getTextRange());
}
return var;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable in project intellij-community by JetBrains.
the class GrInplaceParameterIntroducer method createExpressionWrapper.
@NotNull
private static GrExpressionWrapper createExpressionWrapper(@NotNull GrIntroduceContext context) {
GrExpression expression = context.getExpression();
GrVariable var = context.getVar();
assert expression != null || var != null;
GrExpression initializer = expression != null ? expression : var.getInitializerGroovy();
return new GrExpressionWrapper(initializer);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable in project intellij-community by JetBrains.
the class GrIntroduceConstantProcessor method run.
@Nullable
public GrField run() {
final PsiClass targetClass = settings.getTargetClass();
if (targetClass == null)
return null;
if (checkErrors(targetClass)) {
return null;
}
final GrVariableDeclaration declaration = addDeclaration(targetClass);
final GrField field = (GrField) declaration.getVariables()[0];
GrVariable localVar = GrIntroduceHandlerBase.resolveLocalVar(context);
if (localVar != null) {
assert localVar.getInitializerGroovy() != null : "initializer should exist: " + localVar.getText();
GrIntroduceHandlerBase.deleteLocalVar(localVar);
if (settings.replaceAllOccurrences()) {
processOccurrences(field);
} else {
replaceOccurrence(field, localVar.getInitializerGroovy(), isEscalateVisibility());
}
} else if (context.getStringPart() != null) {
final GrExpression ref = context.getStringPart().replaceLiteralWithConcatenation(field.getName());
final PsiElement element = replaceOccurrence(field, ref, isEscalateVisibility());
updateCaretPosition(element);
} else if (context.getExpression() != null) {
if (settings.replaceAllOccurrences()) {
processOccurrences(field);
} else {
replaceOccurrence(field, context.getExpression(), isEscalateVisibility());
}
}
return field;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable in project intellij-community by JetBrains.
the class GrIntroduceConstantProcessor method getInitializer.
@NotNull
protected GrExpression getInitializer() {
GrVariable var = GrIntroduceHandlerBase.resolveLocalVar(context);
GrExpression expression = context.getExpression();
if (var != null) {
return var.getInitializerGroovy();
} else if (expression != null) {
return expression;
} else {
return context.getStringPart().createLiteralFromSelected();
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable in project intellij-community by JetBrains.
the class GrFieldNameSuggester method suggestNames.
@NotNull
public LinkedHashSet<String> suggestNames() {
final GrExpression expression = myContext.getExpression();
final GrVariable var = myContext.getVar();
final StringPartInfo stringPart = myContext.getStringPart();
if (expression != null) {
return new LinkedHashSet<>(Arrays.asList(GroovyNameSuggestionUtil.suggestVariableNames(expression, myValidator, myForStatic)));
} else if (stringPart != null) {
return new LinkedHashSet<>(Arrays.asList(GroovyNameSuggestionUtil.suggestVariableNames(stringPart.getLiteral(), myValidator, myForStatic)));
} else {
assert var != null;
return new LinkedHashSet<>(Arrays.asList(GroovyNameSuggestionUtil.suggestVariableNameByType(var.getType(), myValidator)));
}
}
Aggregations