use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class CreateClassFix method createClassFromNewAction.
public static IntentionAction createClassFromNewAction(final GrNewExpression expression) {
return new CreateClassActionBase(GrCreateClassKind.CLASS, expression.getReferenceElement()) {
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final PsiFile file = element.getContainingFile();
if (!(file instanceof GroovyFileBase))
return;
GroovyFileBase groovyFile = (GroovyFileBase) file;
final PsiManager manager = myRefElement.getManager();
final String qualifier;
final String name;
final Module module;
final AccessToken accessToken = ReadAction.start();
try {
qualifier = groovyFile instanceof GroovyFile ? groovyFile.getPackageName() : "";
name = myRefElement.getReferenceName();
assert name != null;
module = ModuleUtilCore.findModuleForPsiElement(file);
} finally {
accessToken.finish();
}
PsiDirectory targetDirectory = getTargetDirectory(project, qualifier, name, module, getText());
if (targetDirectory == null)
return;
final GrTypeDefinition targetClass = createClassByType(targetDirectory, name, manager, myRefElement, GroovyTemplates.GROOVY_CLASS, true);
if (targetClass == null)
return;
PsiType[] argTypes = getArgTypes(myRefElement);
if (argTypes != null && argTypes.length > 0) {
generateConstructor(myRefElement, name, argTypes, targetClass, project);
bindRef(targetClass, myRefElement);
} else {
bindRef(targetClass, myRefElement);
IntentionUtils.positionCursor(project, targetClass.getContainingFile(), targetClass);
}
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyLineMarkerProvider method getGroovyCategory.
private static int getGroovyCategory(@NotNull PsiElement element, @NotNull CharSequence documentChars) {
if (element instanceof GrVariableDeclarationImpl) {
GrVariable[] variables = ((GrVariableDeclarationImpl) element).getVariables();
if (variables.length == 1 && variables[0] instanceof GrField && variables[0].getInitializerGroovy() instanceof GrClosableBlock) {
return 2;
}
}
if (element instanceof GrField || element instanceof GrTypeParameter)
return 1;
if (element instanceof GrTypeDefinition || element instanceof GrClassInitializer)
return 2;
if (element instanceof GrMethod) {
if (((GrMethod) element).hasModifierProperty(PsiModifier.ABSTRACT) && !(((GrMethod) element).getBlock() != null && GrTraitUtil.isTrait(((GrMethod) element).getContainingClass()))) {
return 1;
}
TextRange textRange = element.getTextRange();
int start = textRange.getStartOffset();
int end = Math.min(documentChars.length(), textRange.getEndOffset());
int crlf = StringUtil.getLineBreakCount(documentChars.subSequence(start, end));
return crlf == 0 ? 1 : 2;
}
return 0;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GrMemberInfo method extractClassMembers.
public static void extractClassMembers(PsiClass subclass, List<GrMemberInfo> result, Filter<GrMember> filter, final boolean extractInterfacesDeep) {
if (!(subclass instanceof GrTypeDefinition))
return;
if (extractInterfacesDeep) {
extractSuperInterfaces(subclass, filter, result, ContainerUtil.<PsiClass>newHashSet());
} else {
PsiClass[] interfaces = subclass.getInterfaces();
GrReferenceList sourceRefList = subclass.isInterface() ? ((GrTypeDefinition) subclass).getExtendsClause() : ((GrTypeDefinition) subclass).getImplementsClause();
for (PsiClass anInterface : interfaces) {
if (anInterface instanceof GrTypeDefinition && filter.includeMember((GrMember) anInterface)) {
result.add(new GrMemberInfo((GrMember) anInterface, true, sourceRefList));
}
}
}
PsiClass[] innerClasses = subclass.getInnerClasses();
for (PsiClass innerClass : innerClasses) {
if (innerClass instanceof GrTypeDefinition && filter.includeMember((GrMember) innerClass)) {
result.add(new GrMemberInfo((GrMember) innerClass));
}
}
GrMethod[] methods = ((GrTypeDefinition) subclass).getCodeMethods();
for (GrMethod method : methods) {
if (!method.isConstructor() && filter.includeMember(method)) {
result.add(new GrMemberInfo(method));
}
}
GrField[] fields = ((GrTypeDefinition) subclass).getCodeFields();
for (final GrField field : fields) {
if (filter.includeMember(field)) {
result.add(new GrMemberInfo(field));
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GrMemberInfoStorage method buildSubClassesMapForList.
private void buildSubClassesMapForList(final PsiClassType[] classesList, GrTypeDefinition aClass) {
for (int i = 0; i < classesList.length; i++) {
PsiClassType element = classesList[i];
PsiClass resolved = element.resolve();
if (resolved instanceof GrTypeDefinition) {
GrTypeDefinition superClass = (GrTypeDefinition) resolved;
getSubclasses(superClass).add(aClass);
buildSubClassesMap(superClass);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class ClassGenerator method writeMembers.
public void writeMembers(StringBuilder text, PsiClass typeDefinition) {
if (typeDefinition instanceof GrEnumTypeDefinition) {
final GrEnumConstant[] enumConstants = ((GrEnumTypeDefinition) typeDefinition).getEnumConstants();
for (GrEnumConstant constant : enumConstants) {
classItemGenerator.writeEnumConstant(text, constant);
text.append(',');
}
if (enumConstants.length > 0) {
//text.removeFromTheEnd(1).append(";\n");
text.delete(text.length() - 1, text.length());
}
text.append(";\n");
}
writeAllMethods(text, classItemGenerator.collectMethods(typeDefinition), typeDefinition);
if (typeDefinition instanceof GrTypeDefinition) {
for (GrMembersDeclaration declaration : ((GrTypeDefinition) typeDefinition).getMemberDeclarations()) {
if (declaration instanceof GrVariableDeclaration) {
classItemGenerator.writeVariableDeclarations(text, (GrVariableDeclaration) declaration);
}
}
for (PsiClass inner : typeDefinition.getInnerClasses()) {
writeTypeDefinition(text, inner, false, false);
text.append('\n');
}
}
classItemGenerator.writePostponed(text, typeDefinition);
}
Aggregations