use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class ClashingGettersInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitTypeDefinition(@NotNull GrTypeDefinition typeDefinition) {
super.visitTypeDefinition(typeDefinition);
Map<String, PsiMethod> getters = new HashMap<>();
for (PsiMethod method : typeDefinition.getMethods()) {
final String methodName = method.getName();
if (!GroovyPropertyUtils.isSimplePropertyGetter(method))
continue;
final String propertyName = GroovyPropertyUtils.getPropertyNameByGetterName(methodName, true);
final PsiMethod otherGetter = getters.get(propertyName);
if (otherGetter != null && !methodName.equals(otherGetter.getName())) {
final Pair<PsiElement, String> description = getGetterDescription(method);
final Pair<PsiElement, String> otherDescription = getGetterDescription(otherGetter);
if (description.first != null) {
registerError(description.first, description.second, otherDescription.second);
}
if (otherDescription.first != null) {
registerError(otherDescription.first, otherDescription.second, description.second);
}
} else {
getters.put(propertyName, method);
}
}
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class BindableTransformationSupport method applyTransformation.
@Override
public void applyTransformation(@NotNull TransformationContext context) {
GrTypeDefinition clazz = context.getCodeClass();
if (!isApplicable(clazz))
return;
final PsiManager manager = clazz.getManager();
final GlobalSearchScope scope = clazz.getResolveScope();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(clazz.getProject());
final PsiType pclType = facade.getElementFactory().createTypeByFQClassName(PCL_FQN, scope);
final PsiArrayType pclArrayType = new PsiArrayType(pclType);
final PsiType stringType = PsiType.getJavaLangString(manager, scope);
final PsiType objectType = PsiType.getJavaLangObject(manager, scope);
final List<LightMethodBuilder> methods = ContainerUtil.newArrayList();
methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "addPropertyChangeListener").setMethodReturnType(PsiType.VOID).addParameter("listener", pclType));
methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "addPropertyChangeListener").setMethodReturnType(PsiType.VOID).addParameter("name", stringType).addParameter("listener", pclType));
methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "removePropertyChangeListener").setMethodReturnType(PsiType.VOID).addParameter("listener", pclType));
methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "removePropertyChangeListener").setMethodReturnType(PsiType.VOID).addParameter("name", stringType).addParameter("listener", pclType));
methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "firePropertyChange").setMethodReturnType(PsiType.VOID).addParameter("name", stringType).addParameter("oldValue", objectType).addParameter("newValue", objectType));
methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "getPropertyChangeListeners").setMethodReturnType(pclArrayType));
methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "getPropertyChangeListeners").setMethodReturnType(pclArrayType).addParameter("name", stringType));
for (LightMethodBuilder method : methods) {
method.addModifier(PsiModifier.PUBLIC);
method.setOriginInfo(ORIGIN_INFO);
method.putUserData(DOCUMENTATION_DELEGATE_FQN, PCS_FQN);
}
context.addMethods(methods);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyValidationUtil method validateVariableOccurrencesDown.
private static void validateVariableOccurrencesDown(PsiElement parent, PsiElement startChild, MultiMap<PsiElement, String> conflicts, @NotNull String varName) {
PsiElement child = parent.getLastChild();
while (child != null && child != startChild && !(child instanceof GrTypeDefinition)) {
validateVariableOccurrencesDownImpl(child, conflicts, varName);
child = child.getPrevSibling();
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyOverrideMethodsHandler method invoke.
@Override
public void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file) {
if (!EditorModificationUtil.checkModificationAllowed(editor))
return;
PsiClass aClass = OverrideImplementUtil.getContextClass(project, editor, file, true);
if (aClass instanceof GrTypeDefinition) {
GrTypeDefinition typeDefinition = (GrTypeDefinition) aClass;
if (GroovyOverrideImplementExploreUtil.getMethodSignaturesToOverride(typeDefinition).isEmpty()) {
HintManager.getInstance().showErrorHint(editor, "No methods to override have been found");
return;
}
GroovyOverrideImplementUtil.chooseAndOverrideMethods(project, editor, typeDefinition);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class TraitMethodImplementor method createImplementationPrototypes.
@NotNull
@Override
public PsiMethod[] createImplementationPrototypes(PsiClass inClass, PsiMethod method) throws IncorrectOperationException {
if (!(inClass instanceof GrTypeDefinition && method instanceof GrTraitMethod))
return PsiMethod.EMPTY_ARRAY;
final PsiClass containingClass = method.getContainingClass();
PsiSubstitutor substitutor = inClass.isInheritor(containingClass, true) ? TypeConversionUtil.getSuperClassSubstitutor(containingClass, inClass, PsiSubstitutor.EMPTY) : PsiSubstitutor.EMPTY;
return new GrMethod[] { GroovyOverrideImplementUtil.generateTraitMethodPrototype((GrTypeDefinition) inClass, (GrTraitMethod) method, substitutor) };
}
Aggregations