use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class GrHighlightUtil method collectReassignedNames.
private static Set<String> collectReassignedNames(PsiElement scope) {
final Set<String> result = ContainerUtil.newHashSet();
PsiTreeUtil.processElements(scope, new PsiElementProcessor() {
@Override
public boolean execute(@NotNull PsiElement element) {
if (!(element instanceof GrReferenceExpression) || !((GrReferenceExpression) element).isQualified()) {
return true;
}
GrReferenceExpression ref = (GrReferenceExpression) element;
if (isWriteAccess(ref)) {
String varName = ref.getReferenceName();
if (!result.contains(varName)) {
PsiElement target = ref.resolve();
if (target instanceof GrVariable && ((GrVariable) target).getInitializerGroovy() != null || target instanceof GrParameter) {
result.add(varName);
}
}
}
return true;
}
});
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class GroovyAnnotator method visitTryStatement.
@Override
public void visitTryStatement(@NotNull GrTryCatchStatement statement) {
final GrCatchClause[] clauses = statement.getCatchClauses();
List<PsiType> usedExceptions = new ArrayList<>();
for (GrCatchClause clause : clauses) {
final GrParameter parameter = clause.getParameter();
if (parameter == null)
continue;
final GrTypeElement typeElement = parameter.getTypeElementGroovy();
PsiType type = typeElement != null ? typeElement.getType() : TypesUtil.createType(CommonClassNames.JAVA_LANG_EXCEPTION, statement);
if (typeElement instanceof GrDisjunctionTypeElement) {
final GrTypeElement[] elements = ((GrDisjunctionTypeElement) typeElement).getTypeElements();
PsiType[] types = PsiType.createArray(elements.length);
for (int i = 0; i < elements.length; i++) {
types[i] = elements[i].getType();
}
List<PsiType> usedInsideDisjunction = new ArrayList<>();
for (int i = 0; i < types.length; i++) {
if (checkExceptionUsed(usedExceptions, parameter, elements[i], types[i])) {
usedInsideDisjunction.add(types[i]);
for (int j = 0; j < types.length; j++) {
if (i != j && types[j].isAssignableFrom(types[i])) {
myHolder.createWarningAnnotation(elements[i], GroovyBundle.message("unnecessary.type", types[i].getCanonicalText(), types[j].getCanonicalText())).registerFix(new GrRemoveExceptionFix(true));
}
}
}
}
usedExceptions.addAll(usedInsideDisjunction);
} else {
if (checkExceptionUsed(usedExceptions, parameter, typeElement, type)) {
usedExceptions.add(type);
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class GrParameterListImpl method addInternal.
/*@Override
public PsiElement addAfter(@NotNull PsiElement element, PsiElement anchor) throws IncorrectOperationException {
GrParameter[] params = getParameters();
if (params.length == 0) {
element = add(element);
}
else {
element = super.addAfter(element, anchor);
final ASTNode astNode = getNode();
if (anchor != null) {
astNode.addLeaf(mCOMMA, ",", element.getNode());
}
else {
astNode.addLeaf(mCOMMA, ",", element.getNextSibling().getNode());
}
CodeStyleManager.getInstance(getManager().getProject()).reformat(this);
}
return element;
}
@Override
public PsiElement addBefore(@NotNull PsiElement element, PsiElement anchor) throws IncorrectOperationException {
GrParameter[] params = getParameters();
if (params.length == 0) {
element = add(element);
}
else {
element = super.addBefore(element, anchor);
final ASTNode astNode = getNode();
if (anchor != null) {
astNode.addLeaf(mCOMMA, ",", anchor.getNode());
}
else {
astNode.addLeaf(mCOMMA, ",", element.getNode());
}
CodeStyleManager.getInstance(getManager().getProject()).reformat(this);
}
return element;
}*/
@Override
public ASTNode addInternal(ASTNode first, ASTNode last, ASTNode anchor, Boolean before) {
GrParameter[] params = getParameters();
ASTNode result = super.addInternal(first, last, anchor, before);
if (first == last && first.getPsi() instanceof GrParameter && params.length > 0) {
if (before.booleanValue() && anchor != null) {
getNode().addLeaf(GroovyTokenTypes.mCOMMA, ",", anchor);
} else if (before.booleanValue() && anchor == null) {
getNode().addLeaf(GroovyTokenTypes.mCOMMA, ",", result);
} else if (!before.booleanValue() && anchor != null) {
getNode().addLeaf(GroovyTokenTypes.mCOMMA, ",", result);
} else if (!before.booleanValue() && anchor == null) {
getNode().addLeaf(GroovyTokenTypes.mCOMMA, ",", result.getTreeNext());
}
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class ClosureSyntheticParameter method setName.
@Override
public PsiElement setName(@NotNull String newName) throws IncorrectOperationException {
if (!newName.equals(getName())) {
GrParameter parameter = GroovyPsiElementFactory.getInstance(getProject()).createParameter(newName, (String) null, null);
myClosure.addParameter(parameter);
}
return this;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class GrLightMethodBuilder method copyData.
protected void copyData(GrLightMethodBuilder dst) {
dst.setMethodKind(getMethodKind());
dst.setData(getData());
dst.setNamedParameters(getNamedParameters());
if (getNavigationElement() != this) {
dst.setNavigationElement(getNavigationElement());
}
dst.setBaseIcon(myBaseIcon);
dst.setReturnType(getReturnType());
dst.setContainingClass(getContainingClass());
dst.getModifierList().copyModifiers(this);
dst.getParameterList().clear();
for (GrParameter parameter : getParameterList().getParameters()) {
dst.addParameter(parameter);
}
}
Aggregations