use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class GroovyTypeCheckVisitor method visitVariable.
@Override
public void visitVariable(@NotNull GrVariable variable) {
super.visitVariable(variable);
final PsiType varType = variable.getType();
final PsiElement parent = variable.getParent();
if (variable instanceof GrParameter && ((GrParameter) variable).getDeclarationScope() instanceof GrMethod || parent instanceof GrForInClause) {
return;
} else if (parent instanceof GrVariableDeclaration && ((GrVariableDeclaration) parent).isTuple()) {
//check tuple assignment: def (int x, int y) = foo()
final GrVariableDeclaration tuple = (GrVariableDeclaration) parent;
final GrExpression initializer = tuple.getTupleInitializer();
if (initializer == null)
return;
if (!(initializer instanceof GrListOrMap)) {
PsiType type = initializer.getType();
if (type == null)
return;
PsiType valueType = extractIterableTypeParameter(type, false);
processAssignment(varType, valueType, tuple, variable.getNameIdentifierGroovy());
return;
}
}
GrExpression initializer = variable.getInitializerGroovy();
if (initializer == null)
return;
processAssignment(varType, initializer, variable.getNameIdentifierGroovy(), "cannot.assign", variable, ApplicableTo.ASSIGNMENT);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class GroovyFileImpl method getSyntheticArgsParameter.
private GrParameter getSyntheticArgsParameter() {
GrParameter parameter = mySyntheticArgsParameter;
if (parameter == null) {
final PsiType psiType = JavaPsiFacade.getElementFactory(getProject()).createTypeFromText("java.lang.String[]", this);
parameter = new GrLightParameter(SYNTHETIC_PARAMETER_NAME, psiType, this);
mySyntheticArgsParameter = parameter;
}
return parameter;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class ControlFlowBuilder method visitOpenBlock.
@Override
public void visitOpenBlock(@NotNull GrOpenBlock block) {
final PsiElement parent = block.getParent();
final PsiElement lbrace = block.getLBrace();
if (lbrace != null && parent instanceof GrMethod) {
for (GrParameter parameter : ((GrMethod) parent).getParameters()) {
if (myPolicy.isVariableInitialized(parameter)) {
addNode(new ReadWriteVariableInstruction(parameter.getName(), parameter, ReadWriteVariableInstruction.WRITE));
}
}
}
super.visitOpenBlock(block);
if (!(block.getParent() instanceof GrBlockStatement && block.getParent().getParent() instanceof GrLoopStatement)) {
final GrStatement[] statements = block.getStatements();
if (statements.length > 0) {
handlePossibleReturn(statements[statements.length - 1]);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class ControlFlowBuilder method visitTryStatement.
@Override
public void visitTryStatement(@NotNull GrTryCatchStatement tryCatchStatement) {
final GrOpenBlock tryBlock = tryCatchStatement.getTryBlock();
final GrCatchClause[] catchClauses = tryCatchStatement.getCatchClauses();
final GrFinallyClause finallyClause = tryCatchStatement.getFinallyClause();
for (int i = catchClauses.length - 1; i >= 0; i--) {
myCaughtExceptionInfos.push(new ExceptionInfo(catchClauses[i]));
}
if (finallyClause != null)
myFinallyCount++;
List<Pair<InstructionImpl, GroovyPsiElement>> oldPending = null;
if (finallyClause != null) {
oldPending = myPending;
myPending = new ArrayList<>();
}
InstructionImpl tryBegin = startNode(tryBlock);
tryBlock.accept(this);
InstructionImpl tryEnd = myHead;
finishNode(tryBegin);
Set<Pair<InstructionImpl, GroovyPsiElement>> pendingAfterTry = new LinkedHashSet<>(myPending);
@SuppressWarnings("unchecked") List<InstructionImpl>[] throwers = new List[catchClauses.length];
for (int i = 0; i < catchClauses.length; i++) {
throwers[i] = myCaughtExceptionInfos.pop().myThrowers;
}
InstructionImpl[] catches = new InstructionImpl[catchClauses.length];
for (int i = 0; i < catchClauses.length; i++) {
interruptFlow();
final InstructionImpl catchBeg = startNode(catchClauses[i]);
for (InstructionImpl thrower : throwers[i]) {
addEdge(thrower, catchBeg);
}
final GrParameter parameter = catchClauses[i].getParameter();
if (parameter != null && myPolicy.isVariableInitialized(parameter)) {
addNode(new ReadWriteVariableInstruction(parameter.getName(), parameter, ReadWriteVariableInstruction.WRITE));
}
catchClauses[i].accept(this);
catches[i] = myHead;
finishNode(catchBeg);
}
pendingAfterTry.addAll(myPending);
myPending = new ArrayList<>(pendingAfterTry);
if (finallyClause != null) {
myFinallyCount--;
interruptFlow();
final InstructionImpl finallyInstruction = startNode(finallyClause, false);
Set<AfterCallInstruction> postCalls = new LinkedHashSet<>();
final List<Pair<InstructionImpl, GroovyPsiElement>> copy = myPending;
myPending = new ArrayList<>();
for (Pair<InstructionImpl, GroovyPsiElement> pair : copy) {
postCalls.add(addCallNode(finallyInstruction, pair.getSecond(), pair.getFirst()));
}
if (tryEnd != null) {
postCalls.add(addCallNode(finallyInstruction, tryCatchStatement, tryEnd));
}
for (InstructionImpl catchEnd : catches) {
if (catchEnd != null) {
postCalls.add(addCallNode(finallyInstruction, tryCatchStatement, catchEnd));
}
}
//save added postcalls into separate list because we don't want returnInstruction grabbed their pending edges
List<Pair<InstructionImpl, GroovyPsiElement>> pendingPostCalls = myPending;
myPending = new ArrayList<>();
myHead = finallyInstruction;
finallyClause.accept(this);
final ReturnInstruction returnInstruction = new ReturnInstruction(finallyClause);
for (AfterCallInstruction postCall : postCalls) {
postCall.setReturnInstruction(returnInstruction);
addEdge(returnInstruction, postCall);
}
addNodeAndCheckPending(returnInstruction);
interruptFlow();
finishNode(finallyInstruction);
if (oldPending == null) {
error();
}
oldPending.addAll(pendingPostCalls);
myPending = oldPending;
} else {
if (tryEnd != null) {
addPendingEdge(tryCatchStatement, tryEnd);
}
for (InstructionImpl catchEnd : catches) {
addPendingEdge(tryBlock, catchEnd);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class GrModifierListImpl method addAnnotation.
@Override
@NotNull
public GrAnnotation addAnnotation(@NotNull @NonNls String qualifiedName) {
final PsiClass psiClass = JavaPsiFacade.getInstance(getProject()).findClass(qualifiedName, getResolveScope());
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(getProject());
GrAnnotation annotation;
if (psiClass != null && psiClass.isAnnotationType()) {
annotation = (GrAnnotation) addAfter(factory.createModifierFromText("@xxx"), null);
annotation.getClassReference().bindToElement(psiClass);
} else {
annotation = (GrAnnotation) addAfter(factory.createModifierFromText("@" + qualifiedName), null);
}
final PsiElement parent = getParent();
if (!(parent instanceof GrParameter)) {
final ASTNode node = annotation.getNode();
final ASTNode treeNext = node.getTreeNext();
if (treeNext != null) {
getNode().addLeaf(TokenType.WHITE_SPACE, "\n", treeNext);
} else {
parent.getNode().addLeaf(TokenType.WHITE_SPACE, "\n", getNode().getTreeNext());
}
}
return annotation;
}
Aggregations