use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList in project intellij-community by JetBrains.
the class GrClosableBlockImpl method addParameter.
@Override
public GrParameter addParameter(GrParameter parameter) {
GrParameterList parameterList = getParameterList();
if (getArrow() == null) {
final GrParameterList newParamList = (GrParameterList) addAfter(parameterList, getLBrace());
parameterList.delete();
ASTNode next = newParamList.getNode().getTreeNext();
getNode().addLeaf(GroovyTokenTypes.mCLOSABLE_BLOCK_OP, "->", next);
return (GrParameter) newParamList.add(parameter);
}
return (GrParameter) parameterList.add(parameter);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList in project intellij-community by JetBrains.
the class GrMethodBaseImpl method getParameterList.
@Override
@NotNull
public GrParameterList getParameterList() {
final GrParameterList parameterList = getStubOrPsiChild(GroovyElementTypes.PARAMETERS_LIST);
LOG.assertTrue(parameterList != null);
return parameterList;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList in project intellij-community by JetBrains.
the class DelegatesToInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitAnnotation(@NotNull GrAnnotation annotation) {
checkTarget(annotation);
checkDelegatesTo(annotation);
}
private void checkTarget(GrAnnotation annotation) {
if (!GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO_TARGET.equals(annotation.getQualifiedName()))
return;
final PsiElement owner = annotation.getParent().getParent();
if (!(owner instanceof GrParameter))
return;
final boolean isTargetDeclared = annotation.findDeclaredAttributeValue("value") != null;
String targetName = GrAnnotationUtil.inferStringAttribute(annotation, "value");
final GrParameterList parameterList = DefaultGroovyMethods.asType(owner.getParent(), GrParameterList.class);
for (GrParameter parameter : parameterList.getParameters()) {
final PsiAnnotation delegatesTo = parameter.getModifierList().findAnnotation(GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO);
if (delegatesTo != null) {
if (isTargetDeclared) {
final String curTarget = GrAnnotationUtil.inferStringAttribute(delegatesTo, "target");
if (curTarget != null && curTarget.equals(targetName)) {
//target is used
return;
}
} else {
if (delegatesTo.findDeclaredAttributeValue("target") == null && delegatesTo.findDeclaredAttributeValue("value") == null) {
// target is used
return;
}
}
}
}
registerError(annotation.getClassReference(), GroovyInspectionBundle.message("target.annotation.is.unused"), LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
private void checkDelegatesTo(GrAnnotation annotation) {
if (!GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO.equals(annotation.getQualifiedName()))
return;
final PsiElement owner = annotation.getParent().getParent();
if (!(owner instanceof GrParameter))
return;
final PsiAnnotationMemberValue targetPair = annotation.findDeclaredAttributeValue("target");
if (targetPair == null)
return;
String targetName = GrAnnotationUtil.inferStringAttribute(annotation, "target");
final GrParameterList parameterList = DefaultGroovyMethods.asType(owner.getParent(), GrParameterList.class);
for (GrParameter parameter : parameterList.getParameters()) {
final PsiAnnotation target = parameter.getModifierList().findAnnotation(GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO_TARGET);
if (target != null) {
final String curTarget = GrAnnotationUtil.inferStringAttribute(target, "value");
if (curTarget != null && curTarget.equals(targetName)) {
//target is used
return;
}
}
}
registerError(targetPair, GroovyInspectionBundle.message("target.0.does.not.exist", targetName != null ? targetName : "?"), LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList in project intellij-community by JetBrains.
the class GroovyValidationUtil method validateNewParameterName.
public static boolean validateNewParameterName(GrParameter variable, MultiMap<PsiElement, String> conflicts, @NotNull String varName) {
GrParameterList list = PsiTreeUtil.getParentOfType(variable, GrParameterList.class);
GrParametersOwner owner = PsiTreeUtil.getParentOfType(variable, GrParametersOwner.class);
assert owner != null;
for (GrParameter parameter : list.getParameters()) {
if (parameter.equals(variable))
continue;
validateVariableOccurrencesDownImpl(parameter, conflicts, varName);
}
validateVariableOccurrencesDown(owner, list, conflicts, varName);
PsiElement parent = owner.getParent();
validateVariableOccurrencesUp(parent, owner, conflicts, varName, parent instanceof GroovyFile);
return conflicts.isEmpty();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList in project intellij-community by JetBrains.
the class GrBlockImpl method addStatementBefore.
@Override
@NotNull
public GrStatement addStatementBefore(@NotNull GrStatement element, @Nullable GrStatement anchor) throws IncorrectOperationException {
if (anchor == null && getRBrace() == null) {
throw new IncorrectOperationException();
}
if (anchor != null && !this.equals(anchor.getParent())) {
throw new IncorrectOperationException();
}
final LeafElement nls = Factory.createSingleLeafElement(GroovyTokenTypes.mNLS, "\n", 0, 1, null, getManager());
PsiElement actualAnchor = anchor == null ? getRBrace() : anchor;
if (mayUseNewLinesAsSeparators()) {
PsiElement prev = actualAnchor.getPrevSibling();
if (prev instanceof GrParameterList && prev.getTextLength() == 0 && prev.getPrevSibling() != null) {
prev = prev.getPrevSibling();
}
if (!PsiUtil.isLineFeed(prev)) {
addBefore(nls.getPsi(), actualAnchor);
}
}
element = (GrStatement) addBefore(element, actualAnchor);
if (mayUseNewLinesAsSeparators()) {
addBefore(nls.getPsi(), actualAnchor);
} else {
addBefore(Factory.createSingleLeafElement(GroovyTokenTypes.mNLS, "\n", 0, 1, null, getManager()).getPsi(), actualAnchor);
}
return element;
}
Aggregations