use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration in project intellij-community by JetBrains.
the class GrDocCommentUtil method findDocComment.
@Nullable
public static GrDocComment findDocComment(GrDocCommentOwner owner) {
if (owner.getFirstChild() instanceof GrDocComment) {
return ((GrDocComment) owner.getFirstChild());
}
PsiElement element = owner instanceof GrVariable && owner.getParent() instanceof GrVariableDeclaration ? owner.getParent() : owner;
element = skipWhiteSpacesAndStopOnDoc(element, false);
if (element instanceof GrDocComment)
return (GrDocComment) element;
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration in project intellij-community by JetBrains.
the class GrVariableBaseImpl method delete.
@Override
public void delete() throws IncorrectOperationException {
PsiElement parent = getParent();
PsiElement prev = PsiUtil.getPrevNonSpace(this);
PsiElement next = PsiUtil.getNextNonSpace(this);
ASTNode parentNode = parent.getNode();
assert parentNode != null;
super.delete();
if (prev != null && prev.getNode() != null && prev.getNode().getElementType() == GroovyTokenTypes.mCOMMA) {
prev.delete();
} else if (next instanceof LeafPsiElement && next.getNode() != null && next.getNode().getElementType() == GroovyTokenTypes.mCOMMA) {
next.delete();
}
if (parent instanceof GrVariableDeclaration && ((GrVariableDeclaration) parent).getVariables().length == 0) {
parent.delete();
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration in project intellij-community by JetBrains.
the class GrVariableBaseImpl method setType.
@Override
public void setType(@Nullable PsiType type) {
final GrVariableDeclaration variableDeclaration = getDeclaration();
if (variableDeclaration == null)
return;
final GrTypeElement typeElement = variableDeclaration.getTypeElementGroovyForVariable(this);
if (type == null) {
if (typeElement != null) {
if (!variableDeclaration.isTuple() && variableDeclaration.getModifierList().getModifiers().length == 0) {
variableDeclaration.getModifierList().setModifierProperty(GrModifier.DEF, true);
}
typeElement.delete();
}
return;
}
type = TypesUtil.unboxPrimitiveTypeWrapper(type);
GrTypeElement newTypeElement;
try {
newTypeElement = GroovyPsiElementFactory.getInstance(getProject()).createTypeElement(type);
} catch (IncorrectOperationException e) {
LOG.error(e);
return;
}
if (typeElement == null) {
newTypeElement = (GrTypeElement) getParent().addBefore(newTypeElement, this);
} else {
newTypeElement = (GrTypeElement) typeElement.replace(newTypeElement);
}
JavaCodeStyleManager.getInstance(getProject()).shortenClassReferences(newTypeElement);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration in project intellij-community by JetBrains.
the class GrVariableBaseImpl method getTypeElementGroovy.
@Override
@Nullable
public GrTypeElement getTypeElementGroovy() {
T stub = getStub();
if (stub != null) {
return stub.getTypeElement();
}
PsiElement parent = getParent();
if (parent instanceof GrVariableDeclaration) {
return ((GrVariableDeclaration) parent).getTypeElementGroovyForVariable(this);
}
return findChildByClass(GrTypeElement.class);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration in project intellij-community by JetBrains.
the class GrTypeDefinitionImpl method add.
@Override
public PsiElement add(@NotNull PsiElement psiElement) throws IncorrectOperationException {
final GrTypeDefinitionBody body = getBody();
if (body == null)
throw new IncorrectOperationException("Class must have body");
final PsiElement lBrace = body.getLBrace();
if (lBrace == null)
throw new IncorrectOperationException("No left brace");
PsiMember member = getAnyMember(psiElement);
PsiElement anchor = member != null ? getDefaultAnchor(body, member) : null;
if (anchor == null) {
anchor = lBrace.getNextSibling();
}
if (anchor != null) {
ASTNode node = anchor.getNode();
assert node != null;
if (GroovyTokenTypes.mSEMI.equals(node.getElementType())) {
anchor = anchor.getNextSibling();
}
if (psiElement instanceof GrField) {
//add field with modifiers which are in its parent
int i = ArrayUtilRt.find(((GrVariableDeclaration) psiElement.getParent()).getVariables(), psiElement);
psiElement = body.addBefore(psiElement.getParent(), anchor);
GrVariable[] vars = ((GrVariableDeclaration) psiElement).getVariables();
for (int j = 0; j < vars.length; j++) {
if (i != j)
vars[i].delete();
}
psiElement = vars[i];
} else {
psiElement = body.addBefore(psiElement, anchor);
}
} else {
psiElement = body.add(psiElement);
}
return psiElement;
}
Aggregations