use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class SuppressForMemberFix method getContainer.
@Override
@Nullable
public GrDocCommentOwner getContainer(final PsiElement context) {
if (context == null || context instanceof PsiFile) {
return null;
}
GrDocCommentOwner container = null;
GrDocComment docComment = PsiTreeUtil.getParentOfType(context, GrDocComment.class);
if (docComment != null) {
container = docComment.getOwner();
}
if (container == null) {
container = PsiTreeUtil.getParentOfType(context, GrDocCommentOwner.class);
}
while (container instanceof GrAnonymousClassDefinition || container instanceof GrTypeParameter) {
container = PsiTreeUtil.getParentOfType(container, GrDocCommentOwner.class);
if (container == null)
return null;
}
if (myForClass) {
while (container != null) {
final GrTypeDefinition parentClass = PsiTreeUtil.getParentOfType(container, GrTypeDefinition.class);
if (parentClass == null && container instanceof GrTypeDefinition) {
return container;
}
container = parentClass;
}
}
return container;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class ChangeExtendsImplementsQuickFix method addNewClause.
private void addNewClause(Collection<String> elements, Collection<String> additional, Project project, boolean isExtends) throws IncorrectOperationException {
if (elements.isEmpty() && additional.isEmpty())
return;
StringBuilder classText = new StringBuilder();
classText.append("class A ");
classText.append(isExtends ? "extends " : "implements ");
for (String str : elements) {
classText.append(str);
classText.append(", ");
}
for (String str : additional) {
classText.append(str);
classText.append(", ");
}
classText.delete(classText.length() - 2, classText.length());
classText.append(" {}");
final GrTypeDefinition definition = GroovyPsiElementFactory.getInstance(project).createTypeDefinition(classText.toString());
GroovyPsiElement clause = isExtends ? definition.getExtendsClause() : definition.getImplementsClause();
assert clause != null;
PsiElement addedClause = myClass.addBefore(clause, myClass.getBody());
JavaCodeStyleManager.getInstance(project).shortenClassReferences(addedClause);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GrTypeDefinitionBodyBase method addInternal.
@Override
public ASTNode addInternal(ASTNode first, ASTNode last, ASTNode anchor, Boolean before) {
ASTNode afterLast = last.getTreeNext();
ASTNode next;
for (ASTNode child = first; child != afterLast; child = next) {
next = child.getTreeNext();
if (child.getElementType() == GroovyElementTypes.CONSTRUCTOR_DEFINITION) {
ASTNode oldIdentifier = child.findChildByType(GroovyTokenTypes.mIDENT);
ASTNode newIdentifier = ((GrTypeDefinition) getParent()).getNameIdentifierGroovy().getNode().copyElement();
child.replaceChild(oldIdentifier, newIdentifier);
}
}
return super.addInternal(first, last, anchor, before);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GriffonPropertyListenerAnnotationChecker method checkArgumentList.
@Override
public boolean checkArgumentList(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
if (!"griffon.transform.PropertyListener".equals(annotation.getQualifiedName()))
return false;
final GrAnnotationNameValuePair[] attributes = annotation.getParameterList().getAttributes();
if (attributes.length != 1)
return false;
final GrAnnotationNameValuePair attribute = attributes[0];
final GrAnnotationMemberValue value = attribute.getValue();
final PsiAnnotationOwner owner = annotation.getOwner();
if (owner instanceof GrField) {
if (value instanceof GrClosableBlock) {
return true;
}
} else if (owner instanceof GrTypeDefinition) {
if (value instanceof GrReferenceExpression) {
final PsiElement resolved = ((GrReferenceExpression) value).resolve();
if (resolved instanceof GrField) {
final PsiClass containingClass = ((GrField) resolved).getContainingClass();
if (annotation.getManager().areElementsEquivalent((PsiElement) owner, containingClass)) {
return true;
}
}
}
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class CreateParameterForFieldIntention method findCandidates.
private static List<GrField> findCandidates(PsiMethod constructor, final GrTypeDefinition clazz) {
final List<GrField> usedFields = new ArrayList<>();
final GrOpenBlock block = constructor instanceof GrMethod ? ((GrMethod) constructor).getBlock() : null;
if (block == null) {
return usedFields;
}
final PsiManager manager = clazz.getManager();
block.accept(new GroovyRecursiveElementVisitor() {
@Override
public void visitReferenceExpression(@NotNull GrReferenceExpression referenceExpression) {
super.visitReferenceExpression(referenceExpression);
final PsiElement resolved = referenceExpression.resolve();
if (resolved instanceof GrField && manager.areElementsEquivalent(((GrField) resolved).getContainingClass(), clazz) && PsiUtil.isAccessedForWriting(referenceExpression)) {
usedFields.add((GrField) resolved);
}
}
@Override
public void visitTypeDefinition(@NotNull GrTypeDefinition typeDefinition) {
}
@Override
public void visitClosure(@NotNull GrClosableBlock closure) {
}
});
List<GrField> fields = new ArrayList<>();
for (final GrField field : clazz.getFields()) {
if (field.getInitializerGroovy() != null)
continue;
if (ContainerUtil.find(usedFields, new Condition<PsiField>() {
@Override
public boolean value(PsiField o) {
return manager.areElementsEquivalent(o, field);
}
}) == null) {
fields.add(field);
}
}
return fields;
}
Aggregations