use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField in project intellij-community by JetBrains.
the class RenameGrFieldProcessor method findExistingNameConflicts.
@Override
public void findExistingNameConflicts(PsiElement element, String newName, MultiMap<PsiElement, String> conflicts) {
super.findExistingNameConflicts(element, newName, conflicts);
GrField field = (GrField) element;
final PsiClass containingClass = field.getContainingClass();
if (containingClass == null)
return;
final PsiMethod getter = GroovyPropertyUtils.findGetterForField(field);
if (getter instanceof GrAccessorMethod) {
final PsiMethod newGetter = PropertyUtil.findPropertyGetter(containingClass, newName, field.hasModifierProperty(PsiModifier.STATIC), true);
if (newGetter != null && !(newGetter instanceof GrAccessorMethod)) {
conflicts.putValue(newGetter, GroovyRefactoringBundle.message("implicit.getter.will.by.overriden.by.method", field.getName(), newGetter.getName()));
}
}
final PsiMethod setter = GroovyPropertyUtils.findSetterForField(field);
if (setter instanceof GrAccessorMethod) {
final PsiMethod newSetter = PropertyUtil.findPropertySetter(containingClass, newName, field.hasModifierProperty(PsiModifier.STATIC), true);
if (newSetter != null && !(newSetter instanceof GrAccessorMethod)) {
conflicts.putValue(newSetter, GroovyRefactoringBundle.message("implicit.setter.will.by.overriden.by.method", field.getName(), newSetter.getName()));
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField in project intellij-community by JetBrains.
the class RenameGroovyPropertyProcessor method prepareRenaming.
@Override
public void prepareRenaming(PsiElement element, String newName, Map<PsiElement, String> allRenames) {
LOG.assertTrue(element instanceof PropertyForRename);
final List<? extends PsiElement> elementsToRename = ((PropertyForRename) element).getElementsToRename();
for (PsiElement psiElement : elementsToRename) {
if (psiElement instanceof GrField) {
allRenames.put(psiElement, newName);
} else if (psiElement instanceof GrMethod) {
if (GroovyPropertyUtils.isSimplePropertyGetter((PsiMethod) psiElement)) {
allRenames.put(psiElement, RenamePropertyUtil.getGetterNameByOldName(newName, ((PsiMethod) psiElement).getName()));
} else {
allRenames.put(psiElement, GroovyPropertyUtils.getSetterName(newName));
}
}
}
allRenames.remove(element);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField in project intellij-community by JetBrains.
the class GrTraitUtil method doCollectCompiledTraitFields.
private static void doCollectCompiledTraitFields(ClsClassImpl trait, Collection<GrField> result) {
VirtualFile traitFile = trait.getContainingFile().getVirtualFile();
if (traitFile == null)
return;
VirtualFile helperFile = traitFile.getParent().findChild(trait.getName() + GroovyTraitFieldsFileIndex.HELPER_SUFFIX);
if (helperFile == null)
return;
int key = FileBasedIndex.getFileId(helperFile);
final List<Collection<TraitFieldDescriptor>> values = FileBasedIndex.getInstance().getValues(GroovyTraitFieldsFileIndex.INDEX_ID, key, trait.getResolveScope());
values.forEach(descriptors -> descriptors.forEach(descriptor -> result.add(createTraitField(descriptor, trait))));
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField in project intellij-community by JetBrains.
the class GroovyPropertyUtils method generateGetterPrototype.
public static GrMethod generateGetterPrototype(PsiField field) {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(field.getProject());
String name = field.getName();
String getName = getGetterNameNonBoolean(field.getName());
try {
PsiType type = field instanceof GrField ? ((GrField) field).getDeclaredType() : field.getType();
GrMethod getter = factory.createMethod(getName, type);
if (field.hasModifierProperty(PsiModifier.STATIC)) {
PsiUtil.setModifierProperty(getter, PsiModifier.STATIC, true);
}
annotateWithNullableStuff(field, getter);
GrCodeBlock body = factory.createMethodBodyFromText("\nreturn " + name + "\n");
getter.getBlock().replace(body);
return getter;
} catch (IncorrectOperationException e) {
LOG.error(e);
return null;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField in project intellij-community by JetBrains.
the class ExternalBuilderStrategySupport method applyTransformation.
@Override
public void applyTransformation(@NotNull TransformationContext context) {
PsiAnnotation annotation = PsiImplUtil.getAnnotation(context.getCodeClass(), BUILDER_FQN);
if (!isApplicable(annotation, EXTERNAL_STRATEGY_NAME))
return;
final PsiClass constructedClass = GrAnnotationUtil.inferClassAttribute(annotation, "forClass");
if (constructedClass == null || "groovy.transform.Undefined.CLASS".equals(constructedClass.getQualifiedName()))
return;
if (constructedClass instanceof GrTypeDefinition) {
for (GrField field : ((GrTypeDefinition) constructedClass).getCodeFields()) {
context.addMethod(DefaultBuilderStrategySupport.createFieldSetter(context.getCodeClass(), field, annotation));
}
} else {
for (PsiMethod setter : PropertyUtil.getAllProperties(constructedClass, true, false).values()) {
final PsiMethod builderSetter = createFieldSetter(context.getCodeClass(), setter, annotation);
if (builderSetter != null)
context.addMethod(builderSetter);
}
}
context.addMethod(createBuildMethod(annotation, createType(constructedClass)));
}
Aggregations