use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class ClassNameDiffersFromFileNamePredicate method satisfiedBy.
@Override
public boolean satisfiedBy(PsiElement element) {
final PsiElement parent = element.getParent();
if (!(parent instanceof GrTypeDefinition))
return false;
if (((GrTypeDefinition) parent).getNameIdentifierGroovy() != element)
return false;
final String name = ((GrTypeDefinition) parent).getName();
if (name == null || name.isEmpty())
return false;
if (myClassConsumer != null)
myClassConsumer.consume(((GrTypeDefinition) parent));
final PsiFile file = element.getContainingFile();
if (!(file instanceof GroovyFile))
return false;
if (!file.isPhysical())
return false;
if (name.equals(FileUtil.getNameWithoutExtension(file.getName())))
return false;
if (mySearchForClassInMultiClassFile) {
return ((GroovyFile) file).getClasses().length > 1;
} else {
return !((GroovyFile) file).isScript();
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyShellLanguageConsoleView method processCode.
protected void processCode() {
GroovyShellCodeFragment groovyFile = getGroovyFile();
for (GrTopStatement statement : groovyFile.getTopStatements()) {
if (statement instanceof GrImportStatement) {
groovyFile.addImportsFromString(importToString((GrImportStatement) statement));
} else if (statement instanceof GrMethod) {
groovyFile.addVariable(((GrMethod) statement).getName(), generateClosure((GrMethod) statement));
} else if (statement instanceof GrAssignmentExpression) {
GrAssignmentExpression assignment = (GrAssignmentExpression) statement;
GrExpression left = assignment.getLValue();
if (left instanceof GrReferenceExpression && !((GrReferenceExpression) left).isQualified()) {
groovyFile.addVariable(((GrReferenceExpression) left).getReferenceName(), assignment.getRValue());
}
} else if (statement instanceof GrTypeDefinition) {
groovyFile.addTypeDefinition(prepareTypeDefinition((GrTypeDefinition) statement));
}
}
PsiType scriptType = groovyFile.getInferredScriptReturnType();
if (scriptType != null) {
groovyFile.addVariable("_", scriptType);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GrPullUpHandler method invokeImpl.
private void invokeImpl(Project project, DataContext dataContext, GrTypeDefinition aClass, PsiElement aMember) {
final Editor editor = dataContext != null ? CommonDataKeys.EDITOR.getData(dataContext) : null;
if (aClass == null) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("is.not.supported.in.the.current.context", REFACTORING_NAME));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MEMBERS_PULL_UP);
return;
}
ArrayList<PsiClass> bases = RefactoringHierarchyUtil.createBasesList(aClass, false, true);
if (bases.isEmpty()) {
final GrTypeDefinition containingClass = DefaultGroovyMethods.asType(aClass.getContainingClass(), GrTypeDefinition.class);
if (containingClass != null) {
invokeImpl(project, dataContext, containingClass, aClass);
return;
}
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("class.does.not.have.base.classes.interfaces.in.current.project", aClass.getQualifiedName()));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MEMBERS_PULL_UP);
return;
}
mySubclass = aClass;
GrMemberInfoStorage memberInfoStorage = new GrMemberInfoStorage((GrTypeDefinition) mySubclass, new MemberInfoBase.Filter<GrMember>() {
@Override
public boolean includeMember(GrMember element) {
return true;
}
});
List<GrMemberInfo> members = memberInfoStorage.getClassMemberInfos(mySubclass);
PsiManager manager = mySubclass.getManager();
for (GrMemberInfo member : members) {
if (manager.areElementsEquivalent(member.getMember(), aMember)) {
member.setChecked(true);
break;
}
}
final GrPullUpDialog dialog = new GrPullUpDialog(project, aClass, bases, memberInfoStorage, this);
dialog.show();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyMoveClassToInnerHandler method moveClass.
@Override
public PsiClass moveClass(@NotNull PsiClass aClass, @NotNull PsiClass targetClass) {
if (!(aClass instanceof GrTypeDefinition))
return null;
GroovyChangeContextUtil.encodeContextInfo(aClass);
PsiDocComment doc = aClass.getDocComment();
PsiElement brace = targetClass.getRBrace();
PsiClass newClass = (PsiClass) targetClass.addBefore(aClass, brace);
PsiElement sibling = newClass.getPrevSibling();
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(targetClass.getProject());
if (!org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isNewLine(sibling)) {
targetClass.addBefore(factory.createLineTerminator("\n "), newClass);
} else if (doc != null) {
LOG.assertTrue(sibling != null);
sibling.replace(factory.createLineTerminator(sibling.getText() + " "));
}
if (doc != null) {
targetClass.addBefore(doc, newClass);
targetClass.addBefore(factory.createLineTerminator("\n"), newClass);
}
if (targetClass.isInterface()) {
PsiUtil.setModifierProperty(newClass, PsiModifier.PUBLIC, true);
} else {
PsiUtil.setModifierProperty(newClass, PsiModifier.STATIC, true);
}
GroovyChangeContextUtil.decodeContextInfo(newClass, null, null);
return newClass;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyPsiManager method getArrayClass.
@Nullable
public GrTypeDefinition getArrayClass(@NotNull PsiType type) {
final String typeText = type.getCanonicalText();
GrTypeDefinition definition = myArrayClass.get(typeText);
if (definition == null) {
try {
definition = GroovyPsiElementFactory.getInstance(myProject).createTypeDefinition("class __ARRAY__ { public int length; public " + typeText + "[] clone(){} }");
myArrayClass.put(typeText, definition);
} catch (IncorrectOperationException e) {
LOG.error(e);
return null;
}
}
return definition;
}
Aggregations