Factory method for named constructor creation; unused class dropped

This commit is contained in:
Roman Shevchenko
2011-10-21 17:44:08 +02:00
parent 1bef31ed5c
commit da7ad14a48
2 changed files with 18 additions and 2 deletions
@@ -108,7 +108,17 @@ public interface PsiElementFactory extends PsiJavaParserFacade, JVMElementFactor
*
* @return the created constructor instance.
*/
@NotNull PsiMethod createConstructor();
@NotNull
PsiMethod createConstructor();
/**
* Creates an empty constructor with a given name.
*
* @param name the name of the constructor to create.
* @return the created constructor instance.
*/
@NotNull
PsiMethod createConstructor(@NotNull @NonNls String name);
/**
* Creates an empty class initializer block.
@@ -218,7 +218,13 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
@NotNull
@Override
public PsiMethod createConstructor() {
final PsiJavaFile aFile = createDummyJavaFile("class _Dummy_ { public _Dummy_() {} }");
return createConstructor("_Dummy_");
}
@NotNull
@Override
public PsiMethod createConstructor(@NotNull @NonNls final String name) {
final PsiJavaFile aFile = createDummyJavaFile(join("class ", name, " { public ", name, "() {} }"));
final PsiMethod method = aFile.getClasses()[0].getMethods()[0];
return (PsiMethod)CodeStyleManager.getInstance(myManager.getProject()).reformat(method);
}