mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
create method from usage: create type params for static methods created in generics classes as class type params won't be accessible (IDEA-87688)
This commit is contained in:
@@ -65,10 +65,10 @@ public class JavaTemplateUtil {
|
||||
if (!classes.isEmpty()) {
|
||||
for (PsiClass aClass : classes) {
|
||||
if (aClass instanceof PsiTypeParameter) {
|
||||
if (((PsiTypeParameter)aClass).getOwner() instanceof PsiMethod) {
|
||||
PsiElement element = file.findElementAt(segmentStart);
|
||||
PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
|
||||
if (method != null) {
|
||||
PsiElement element = file.findElementAt(segmentStart);
|
||||
PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
|
||||
if (method != null) {
|
||||
if (((PsiTypeParameter)aClass).getOwner() instanceof PsiMethod || method.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
PsiTypeParameterList paramList = method.getTypeParameterList();
|
||||
PsiTypeParameter[] params = paramList != null ? paramList.getTypeParameters() : PsiTypeParameter.EMPTY_ARRAY;
|
||||
for (PsiTypeParameter param : params) {
|
||||
@@ -76,7 +76,8 @@ public class JavaTemplateUtil {
|
||||
}
|
||||
try {
|
||||
if (paramList == null) {
|
||||
final PsiTypeParameterList newList = JVMElementFactories.getFactory(method.getLanguage(), project).createTypeParameterList();
|
||||
final PsiTypeParameterList newList =
|
||||
JVMElementFactories.getFactory(method.getLanguage(), project).createTypeParameterList();
|
||||
paramList = (PsiTypeParameterList)method.addAfter(newList, method.getModifierList());
|
||||
}
|
||||
paramList.add(aClass.copy());
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// "Create Method 'makeOp'" "true"
|
||||
class Base<T> {
|
||||
Base(Factory<T> factory, Operator<T> operator) {
|
||||
}
|
||||
}
|
||||
|
||||
interface MetaOperator<T> {
|
||||
}
|
||||
|
||||
interface Operator<T> {
|
||||
}
|
||||
|
||||
interface Factory<T> {
|
||||
}
|
||||
|
||||
class Sup<T> extends Base<T> {
|
||||
Sup(MetaOperator<T> mop) {
|
||||
super(null, makeOp(mop));
|
||||
}
|
||||
|
||||
private static <T> Operator<T> makeOp(MetaOperator<T> mop) {
|
||||
<selection>return null; //To change body of created methods use File | Settings | File Templates.</selection>
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Create Method 'makeOp'" "true"
|
||||
class Base<T> {
|
||||
Base(Factory<T> factory, Operator<T> operator) {
|
||||
}
|
||||
}
|
||||
|
||||
interface MetaOperator<T> {
|
||||
}
|
||||
|
||||
interface Operator<T> {
|
||||
}
|
||||
|
||||
interface Factory<T> {
|
||||
}
|
||||
|
||||
class Sup<T> extends Base<T> {
|
||||
Sup(MetaOperator<T> mop) {
|
||||
super(null, mak<caret>eOp(mop));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user