use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationArgumentList in project intellij-community by JetBrains.
the class GroovyBlock method getChildAttributes.
@Override
@NotNull
public ChildAttributes getChildAttributes(final int newChildIndex) {
ASTNode astNode = getNode();
final PsiElement psiParent = astNode.getPsi();
if (psiParent instanceof GroovyFileBase) {
return new ChildAttributes(Indent.getNoneIndent(), null);
}
if (psiParent instanceof GrSwitchStatement) {
List<Block> subBlocks = getSubBlocks();
if (newChildIndex > 0) {
Block block = subBlocks.get(newChildIndex - 1);
if (block instanceof GroovyBlock) {
PsiElement anchorPsi = ((GroovyBlock) block).getNode().getPsi();
if (anchorPsi instanceof GrCaseSection) {
for (GrStatement statement : ((GrCaseSection) anchorPsi).getStatements()) {
if (statement instanceof GrBreakStatement || statement instanceof GrContinueStatement || statement instanceof GrReturnStatement || statement instanceof GrThrowStatement) {
final Indent indent = GroovyIndentProcessor.getSwitchCaseIndent(myContext.getSettings());
return new ChildAttributes(indent, null);
}
}
int indentSize = myContext.getSettings().getIndentOptions().INDENT_SIZE;
final int spaces = myContext.getSettings().INDENT_CASE_FROM_SWITCH ? 2 * indentSize : indentSize;
return new ChildAttributes(Indent.getSpaceIndent(spaces), null);
}
}
}
}
if (psiParent instanceof GrCaseLabel) {
return new ChildAttributes(GroovyIndentProcessor.getSwitchCaseIndent(getContext().getSettings()), null);
}
if (psiParent instanceof GrCaseSection) {
return getSwitchIndent((GrCaseSection) psiParent, newChildIndex);
}
if (TokenSets.BLOCK_SET.contains(astNode.getElementType()) || GroovyElementTypes.SWITCH_STATEMENT.equals(astNode.getElementType())) {
return new ChildAttributes(Indent.getNormalIndent(), null);
}
if (GroovyElementTypes.CASE_SECTION.equals(astNode.getElementType())) {
return new ChildAttributes(Indent.getNormalIndent(), null);
}
if (psiParent instanceof GrBinaryExpression || psiParent instanceof GrConditionalExpression || psiParent instanceof GrCommandArgumentList || psiParent instanceof GrArgumentList || psiParent instanceof GrParameterList || psiParent instanceof GrListOrMap || psiParent instanceof GrAnnotationArgumentList || psiParent instanceof GrVariable || psiParent instanceof GrAssignmentExpression) {
return new ChildAttributes(Indent.getContinuationWithoutFirstIndent(), null);
}
if (psiParent instanceof GrDocComment || psiParent instanceof GrDocTag) {
return new ChildAttributes(Indent.getSpaceIndent(GroovyIndentProcessor.GDOC_COMMENT_INDENT), null);
}
if (psiParent instanceof GrIfStatement || psiParent instanceof GrLoopStatement) {
return new ChildAttributes(Indent.getNormalIndent(), null);
}
if (psiParent instanceof GrLabeledStatement && newChildIndex == 2) {
final Indent indent = getContext().getGroovySettings().INDENT_LABEL_BLOCKS ? Indent.getLabelIndent() : Indent.getNoneIndent();
return new ChildAttributes(indent, null);
}
return new ChildAttributes(Indent.getNoneIndent(), null);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationArgumentList in project intellij-community by JetBrains.
the class SpockUnrollReferenceProvider method getReferencesByElement.
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
GrAnnotationNameValuePair nvp = (GrAnnotationNameValuePair) element.getParent();
String name = nvp.getName();
if (name != null && !name.equals("value"))
return PsiReference.EMPTY_ARRAY;
PsiElement argumentList = nvp.getParent();
if (!(argumentList instanceof GrAnnotationArgumentList))
return PsiReference.EMPTY_ARRAY;
PsiElement eAnnotation = argumentList.getParent();
if (!(eAnnotation instanceof GrAnnotation))
return PsiReference.EMPTY_ARRAY;
GrAnnotation annotation = (GrAnnotation) eAnnotation;
String shortName = annotation.getShortName();
if (!shortName.equals("Unroll") && !shortName.equals("spock.lang.Unroll"))
return PsiReference.EMPTY_ARRAY;
PsiElement modifierList = annotation.getParent();
if (!(modifierList instanceof GrModifierList))
return PsiReference.EMPTY_ARRAY;
PsiElement eMethod = modifierList.getParent();
if (!(eMethod instanceof GrMethod))
return PsiReference.EMPTY_ARRAY;
final GrMethod method = (GrMethod) eMethod;
ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(element);
TextRange rangeInElement = manipulator.getRangeInElement(element);
String text = rangeInElement.substring(element.getText());
final List<SpockVariableReference> references = new ArrayList<>();
Matcher matcher = PATTERN.matcher(text);
while (matcher.find()) {
TextRange range = new TextRange(rangeInElement.getStartOffset() + matcher.start(1), rangeInElement.getStartOffset() + matcher.end(1));
references.add(new SpockVariableReference(element, range, references, method));
}
return references.toArray(new PsiReference[references.size()]);
}
Aggregations