use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable in project intellij-community by JetBrains.
the class GroovyBlockGenerator method alignVariableDeclarations.
private void alignVariableDeclarations(List<GrStatement> group, boolean classLevel) {
AlignmentProvider.Aligner typeElement = myAlignmentProvider.createAligner(true);
AlignmentProvider.Aligner varName = myAlignmentProvider.createAligner(true);
AlignmentProvider.Aligner eq = myAlignmentProvider.createAligner(true);
for (GrStatement statement : group) {
GrVariableDeclaration varDeclaration = (GrVariableDeclaration) statement;
GrVariable[] variables = varDeclaration.getVariables();
for (GrVariable variable : variables) {
varName.append(variable.getNameIdentifierGroovy());
}
if (classLevel && myContext.getSettings().ALIGN_GROUP_FIELD_DECLARATIONS) {
typeElement.append(varDeclaration.getTypeElementGroovy());
ASTNode current_eq = variables[variables.length - 1].getNode().findChildByType(GroovyTokenTypes.mASSIGN);
if (current_eq != null) {
eq.append(current_eq.getPsi());
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable in project intellij-community by JetBrains.
the class GrIntroduceValidatorEngine method validateOccurrencesDown.
/**
* @param startElement Container to start checking conflicts from
* @param conflicts Conflict accumulator
* @param varName Variable name
* @param startOffset
*/
private void validateOccurrencesDown(@NotNull PsiElement startElement, @NotNull MultiMap<PsiElement, String> conflicts, @NotNull String varName, double startOffset) {
PsiElement child = startElement.getFirstChild();
while (child != null) {
// Do not check defined classes, methods, closures and blocks before
if (child instanceof GrTypeDefinition || child instanceof GrMethod || GroovyRefactoringUtil.isAppropriateContainerForIntroduceVariable(child) && child.getTextRange().getEndOffset() < startOffset) {
myReporter.check(child, conflicts, varName);
child = child.getNextSibling();
continue;
}
if (child instanceof GrVariable) {
myReporter.check(child, conflicts, varName);
validateOccurrencesDown(child, conflicts, varName, startOffset);
} else {
validateOccurrencesDown(child, conflicts, varName, startOffset);
}
child = child.getNextSibling();
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable in project intellij-community by JetBrains.
the class GrInplaceConstantIntroducer method getInitialSettingsForInplace.
@Nullable
@Override
protected GrIntroduceConstantSettings getInitialSettingsForInplace(@NotNull final GrIntroduceContext context, @NotNull final OccurrencesChooser.ReplaceChoice choice, final String[] names) {
return new GrIntroduceConstantSettings() {
@Override
public String getVisibilityModifier() {
return PsiModifier.PUBLIC;
}
@Nullable
@Override
public PsiClass getTargetClass() {
return (PsiClass) context.getScope();
}
@Nullable
@Override
public String getName() {
return names[0];
}
@Override
public boolean replaceAllOccurrences() {
return isReplaceAllOccurrences();
}
@Nullable
@Override
public PsiType getSelectedType() {
GrExpression expression = context.getExpression();
GrVariable var = context.getVar();
StringPartInfo stringPart = context.getStringPart();
return var != null ? var.getDeclaredType() : expression != null ? expression.getType() : stringPart != null ? stringPart.getLiteral().getType() : null;
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable in project intellij-community by JetBrains.
the class GrIntroduceConstantDialog method createUIComponents.
private void createUIComponents() {
myJavaVisibilityPanel = new JavaVisibilityPanel(false, true);
final GrVariable var = myContext.getVar();
final GrExpression expression = myContext.getExpression();
final StringPartInfo stringPart = myContext.getStringPart();
if (expression != null) {
myTypeCombo = GrTypeComboBox.createTypeComboBoxFromExpression(expression);
} else if (stringPart != null) {
myTypeCombo = GrTypeComboBox.createTypeComboBoxFromExpression(stringPart.getLiteral());
} else {
assert var != null;
myTypeCombo = GrTypeComboBox.createTypeComboBoxWithDefType(var.getDeclaredType(), var);
}
List<String> names = new ArrayList<>();
if (var != null) {
names.add(var.getName());
}
if (expression != null) {
ContainerUtil.addAll(names, suggestNames());
}
myNameField = new NameSuggestionsField(ArrayUtil.toStringArray(names), myContext.getProject(), GroovyFileType.GROOVY_FILE_TYPE);
GrTypeComboBox.registerUpDownHint(myNameField, myTypeCombo);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable in project intellij-community by JetBrains.
the class GrIntroduceConstantHandler method getOccurrenceOptions.
@NotNull
@Override
protected Map<OccurrencesChooser.ReplaceChoice, List<Object>> getOccurrenceOptions(@NotNull GrIntroduceContext context) {
HashMap<OccurrencesChooser.ReplaceChoice, List<Object>> map = ContainerUtil.newLinkedHashMap();
GrVariable localVar = resolveLocalVar(context);
if (localVar != null) {
map.put(OccurrencesChooser.ReplaceChoice.ALL, Arrays.<Object>asList(context.getOccurrences()));
return map;
}
if (context.getExpression() != null) {
map.put(OccurrencesChooser.ReplaceChoice.NO, Collections.<Object>singletonList(context.getExpression()));
} else if (context.getStringPart() != null) {
map.put(OccurrencesChooser.ReplaceChoice.NO, Collections.<Object>singletonList(context.getStringPart()));
}
PsiElement[] occurrences = context.getOccurrences();
if (occurrences.length > 1) {
map.put(OccurrencesChooser.ReplaceChoice.ALL, Arrays.<Object>asList(occurrences));
}
return map;
}
Aggregations