use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyShellCodeFragment method processTypeDefinitions.
private boolean processTypeDefinitions(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state) {
ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
if (!ResolveUtil.shouldProcessClasses(classHint)) {
return true;
}
NameHint nameHint = processor.getHint(NameHint.KEY);
String name = nameHint != null ? nameHint.getName(state) : null;
if (name != null) {
final GrTypeDefinition definition = myTypeDefinitions.get(name);
if (definition != null) {
if (processor.execute(definition, state)) {
return false;
}
}
} else {
for (GrTypeDefinition definition : myTypeDefinitions.values()) {
if (!processor.execute(definition, state)) {
return false;
}
}
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class OverridingTester method doTest.
public void doTest() throws Throwable {
final String testFile = getTestName(true) + ".test";
final List<String> strings = TestUtils.readInput(getTestDataPath() + "/" + testFile);
GroovyFileBase psiFile = (GroovyFileBase) myFixture.addFileToProject("foo.groovy", strings.get(0));
StringBuilder buffer = new StringBuilder();
GrTypeDefinition[] grTypeDefinitions = psiFile.getTypeDefinitions();
GrTypeDefinition lastTypeDefinition = psiFile.getTypeDefinitions()[grTypeDefinitions.length - 1];
PsiMethod[] psiMethods = lastTypeDefinition.getMethods();
for (PsiMethod method : psiMethods) {
PsiMethod[] superMethods = findMethod(method);
String[] classes = sortUseContainingClass(superMethods);
for (String classAsString : classes) {
buffer.append(classAsString);
//between different super methods
buffer.append("\n");
}
//between different methods
buffer.append("\n");
}
//between class definitions
buffer.append("\n");
assertEquals(strings.get(1), buffer.toString().trim());
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GrCreateSubclassAction method createSubclassGroovy.
@Nullable
public static PsiClass createSubclassGroovy(final GrTypeDefinition psiClass, final PsiDirectory targetDirectory, final String className) {
final Project project = psiClass.getProject();
final Ref<GrTypeDefinition> targetClass = new Ref<>();
new WriteCommandAction(project, getTitle(psiClass), getTitle(psiClass)) {
@Override
protected void run(@NotNull Result result) throws Throwable {
IdeDocumentHistory.getInstance(project).includeCurrentPlaceAsChangePlace();
final GrTypeParameterList oldTypeParameterList = psiClass.getTypeParameterList();
try {
targetClass.set(CreateClassActionBase.createClassByType(targetDirectory, className, PsiManager.getInstance(project), psiClass, GroovyTemplates.GROOVY_CLASS, true));
} catch (final IncorrectOperationException e) {
ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(project, CodeInsightBundle.message("intention.error.cannot.create.class.message", className) + "\n" + e.getLocalizedMessage(), CodeInsightBundle.message("intention.error.cannot.create.class.title")));
return;
}
startTemplate(oldTypeParameterList, project, psiClass, targetClass.get(), false);
}
}.execute();
if (targetClass.get() == null)
return null;
if (!ApplicationManager.getApplication().isUnitTestMode() && !psiClass.hasTypeParameters()) {
final Editor editor = CodeInsightUtil.positionCursorAtLBrace(project, targetClass.get().getContainingFile(), targetClass.get());
if (editor == null)
return targetClass.get();
chooseAndImplement(psiClass, project, targetClass.get(), editor);
}
return targetClass.get();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GrPullUpHandler method invoke.
@Override
public void invoke(@NotNull final Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
if (elements.length != 1)
return;
myProject = project;
PsiElement element = elements[0];
GrTypeDefinition aClass;
PsiElement aMember = null;
if (element instanceof GrTypeDefinition) {
aClass = (GrTypeDefinition) element;
} else if (element instanceof GrMethod) {
aClass = DefaultGroovyMethods.asType(((GrMethod) element).getContainingClass(), GrTypeDefinition.class);
aMember = element;
} else if (element instanceof GrField) {
aClass = DefaultGroovyMethods.asType(((GrField) element).getContainingClass(), GrTypeDefinition.class);
aMember = element;
} else {
return;
}
invokeImpl(project, dataContext, aClass, aMember);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GrPullUpHelper method doMoveClass.
private void doMoveClass(PsiSubstitutor substitutor, MemberInfo info) {
if (Boolean.FALSE.equals(info.getOverrides())) {
PsiClass aClass = (PsiClass) info.getMember();
if (myTargetSuperClass instanceof GrTypeDefinition) {
addClassToSupers(info, aClass, substitutor, (GrTypeDefinition) myTargetSuperClass);
}
} else {
GrTypeDefinition aClass = (GrTypeDefinition) info.getMember();
GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(myProject);
replaceMovedMemberTypeParameters(aClass, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);
fixReferencesToStatic(aClass);
PsiMember movedElement = (PsiMember) myTargetSuperClass.addAfter(convertClassToLanguage(aClass, myTargetSuperClass.getLanguage()), null);
myMembersAfterMove.add(movedElement);
deleteMemberWithDocComment(aClass);
}
}
Aggregations