mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] @ListenerList: fix empty custom name processing, add tests
This commit is contained in:
+3
-1
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.transformations.listenerList
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.psi.PsiClassType
|
||||
import com.intellij.psi.PsiModifier
|
||||
import com.intellij.psi.PsiType
|
||||
@@ -34,7 +35,8 @@ class ListenerListTransformationSupport : AstTransformationSupport {
|
||||
val annotation = PsiImplUtil.getAnnotation(field, listenerListFqn) ?: continue
|
||||
val listenerType = field.getListenerType() as? PsiClassType ?: continue
|
||||
val listenerClass = listenerType.resolve() ?: continue
|
||||
val name = GrAnnotationUtil.getString(annotation.findDeclaredDetachedValue("name")) ?: listenerClass.name ?: continue
|
||||
val declaredName = GrAnnotationUtil.getString(annotation.findDeclaredDetachedValue("name"))
|
||||
val name = StringUtil.nullize(declaredName) ?: listenerClass.name ?: continue
|
||||
context += context.memberBuilder.method("add${name.capitalize()}") {
|
||||
addModifier(GrModifierFlags.PUBLIC_MASK)
|
||||
returnType = PsiType.VOID
|
||||
|
||||
+103
-2
@@ -44,7 +44,7 @@ def bean = new Bean()
|
||||
bean.addMyCoolListener {}
|
||||
bean.removeMyCoolListener() {}
|
||||
bean.getMyCoolListeners()
|
||||
bean.fireSomeCoolStuffHappened(null)
|
||||
bean.fireSomeCoolStuffHappened(new WowEvent())
|
||||
'''
|
||||
enableInspections(GrUnresolvedAccessInspection)
|
||||
checkHighlighting()
|
||||
@@ -56,7 +56,7 @@ class Main {
|
||||
bean.addMyCoolListener(e -> {});
|
||||
bean.removeMyCoolListener(e -> {});
|
||||
MyCoolListener[] actionListeners = bean.getMyCoolListeners();
|
||||
bean.fireSomeCoolStuffHappened(null);
|
||||
bean.fireSomeCoolStuffHappened(new WowEvent());
|
||||
}
|
||||
}
|
||||
'''
|
||||
@@ -64,6 +64,107 @@ class Main {
|
||||
}
|
||||
}
|
||||
|
||||
void 'test with empty custom name'() {
|
||||
fixture.with {
|
||||
addFileToProject 'Bean.groovy', '''\
|
||||
class WowEvent {}
|
||||
interface MyCoolListener {
|
||||
void someCoolStuffHappened(WowEvent e)
|
||||
}
|
||||
class Bean {
|
||||
@groovy.beans.ListenerList(name = "")
|
||||
List<MyCoolListener> listeners
|
||||
}
|
||||
'''
|
||||
|
||||
configureByText '_.groovy', '''\
|
||||
def bean = new Bean()
|
||||
bean.addMyCoolListener {}
|
||||
bean.removeMyCoolListener() {}
|
||||
bean.getMyCoolListeners()
|
||||
bean.fireSomeCoolStuffHappened(new WowEvent())
|
||||
'''
|
||||
enableInspections(GrUnresolvedAccessInspection)
|
||||
checkHighlighting()
|
||||
|
||||
configureByText 'Main.java', '''\
|
||||
class Main {
|
||||
void foo() {
|
||||
Bean bean = new Bean();
|
||||
bean.addMyCoolListener(e -> {});
|
||||
bean.removeMyCoolListener(e -> {});
|
||||
MyCoolListener[] actionListeners = bean.getMyCoolListeners();
|
||||
bean.fireSomeCoolStuffHappened(new WowEvent());
|
||||
}
|
||||
}
|
||||
'''
|
||||
checkHighlighting()
|
||||
}
|
||||
}
|
||||
|
||||
void 'test with custom name'() {
|
||||
fixture.with {
|
||||
addFileToProject 'Bean.groovy', '''\
|
||||
class WowEvent {}
|
||||
interface MyCoolListener {
|
||||
void someCoolStuffHappened(WowEvent e)
|
||||
}
|
||||
class Bean {
|
||||
@groovy.beans.ListenerList(name = "awesomeListener")
|
||||
List<MyCoolListener> listeners
|
||||
}
|
||||
'''
|
||||
|
||||
configureByText '_.groovy', '''\
|
||||
def bean = new Bean()
|
||||
bean.addAwesomeListener {}
|
||||
bean.removeAwesomeListener() {}
|
||||
bean.getAwesomeListeners()
|
||||
bean.fireSomeCoolStuffHappened(new WowEvent())
|
||||
'''
|
||||
enableInspections(GrUnresolvedAccessInspection)
|
||||
checkHighlighting()
|
||||
|
||||
configureByText 'Main.java', '''\
|
||||
class Main {
|
||||
void foo() {
|
||||
Bean bean = new Bean();
|
||||
bean.addAwesomeListener(e -> {});
|
||||
bean.removeAwesomeListener(e -> {});
|
||||
MyCoolListener[] actionListeners = bean.getAwesomeListeners();
|
||||
bean.fireSomeCoolStuffHappened(new WowEvent());
|
||||
}
|
||||
}
|
||||
'''
|
||||
checkHighlighting()
|
||||
}
|
||||
}
|
||||
|
||||
void 'test with spaces custom name'() {
|
||||
fixture.with {
|
||||
addFileToProject 'Bean.groovy', '''\
|
||||
class WowEvent {}
|
||||
interface MyCoolListener {
|
||||
void someCoolStuffHappened(WowEvent e)
|
||||
}
|
||||
class Bean {
|
||||
@groovy.beans.ListenerList(name = " ")
|
||||
List<MyCoolListener> listeners
|
||||
}
|
||||
'''
|
||||
|
||||
configureByText '_.groovy', '''\
|
||||
def bean = new Bean()
|
||||
bean.'add ' {}
|
||||
bean.'remove '() {}
|
||||
bean.'get s'()
|
||||
bean.fireSomeCoolStuffHappened(new WowEvent())
|
||||
'''
|
||||
enableInspections(GrUnresolvedAccessInspection)
|
||||
checkHighlighting()
|
||||
}
|
||||
}
|
||||
|
||||
void 'test errors highlighting'() {
|
||||
fixture.with {
|
||||
configureByText '_.groovy', '''\
|
||||
|
||||
Reference in New Issue
Block a user