use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable in project intellij-community by JetBrains.
the class InvalidWriteAccessSearcher method findInvalidWriteAccess.
@Nullable
public static List<ReadWriteVariableInstruction> findInvalidWriteAccess(@NotNull Instruction[] flow, @NotNull Map<String, GrVariable> variables, @NotNull Set<GrVariable> alreadyInitialized) {
DFAEngine<MyData> engine = new DFAEngine<>(flow, new MyDFAInstance(), new MySemilattice());
final List<MyData> dfaResult = engine.performDFAWithTimeout();
if (dfaResult == null)
return null;
List<ReadWriteVariableInstruction> result = ContainerUtil.newArrayList();
for (int i = 0; i < flow.length; i++) {
Instruction instruction = flow[i];
if (instruction instanceof ReadWriteVariableInstruction && ((ReadWriteVariableInstruction) instruction).isWrite()) {
final MyData initialized = dfaResult.get(i);
final GrVariable var = variables.get(((ReadWriteVariableInstruction) instruction).getVariableName());
if (alreadyInitialized.contains(var)) {
if (initialized.isInitialized(((ReadWriteVariableInstruction) instruction).getVariableName())) {
result.add((ReadWriteVariableInstruction) instruction);
}
} else {
if (initialized.isOverInitialized(((ReadWriteVariableInstruction) instruction).getVariableName())) {
result.add((ReadWriteVariableInstruction) instruction);
}
}
}
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable in project intellij-community by JetBrains.
the class WritesCounterDFAInstance method fun.
@Override
public void fun(@NotNull TObjectIntHashMap<GrVariable> map, @NotNull Instruction instruction) {
if (!(instruction instanceof ReadWriteVariableInstruction))
return;
final ReadWriteVariableInstruction rwInstruction = (ReadWriteVariableInstruction) instruction;
if (!rwInstruction.isWrite())
return;
final GrVariable variable = getVariable(instruction.getElement());
if (variable == null)
return;
int currentVal = map.get(variable);
if (currentVal == 2)
return;
if (currentVal == 0 || currentVal == 1 && !(variable.getParent() instanceof GrForInClause))
currentVal++;
map.put(variable, currentVal);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable in project intellij-community by JetBrains.
the class GroovyTypeCheckVisitor method visitForInClause.
@Override
public void visitForInClause(@NotNull GrForInClause forInClause) {
super.visitForInClause(forInClause);
final GrVariable variable = forInClause.getDeclaredVariable();
final GrExpression iterated = forInClause.getIteratedExpression();
if (variable == null || iterated == null)
return;
final PsiType iteratedType = ClosureParameterEnhancer.findTypeForIteration(iterated, forInClause);
if (iteratedType == null)
return;
final PsiType targetType = variable.getType();
processAssignment(targetType, iteratedType, forInClause, variable.getNameIdentifierGroovy());
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable in project intellij-community by JetBrains.
the class GrConcatenationInjector method findLanguageParams.
private static BaseInjection findLanguageParams(PsiElement place) {
PsiElement parent = place.getParent();
if (parent instanceof GrAssignmentExpression && ((GrAssignmentExpression) parent).getRValue() == place) {
final GrExpression lvalue = ((GrAssignmentExpression) parent).getLValue();
if (lvalue instanceof GrReferenceExpression) {
final PsiElement resolved = ((GrReferenceExpression) lvalue).resolve();
if (resolved instanceof PsiModifierListOwner) {
return getLanguageParams((PsiModifierListOwner) resolved);
}
}
} else if (parent instanceof GrVariable) {
return getLanguageParams((PsiModifierListOwner) parent);
} else if (parent instanceof GrArgumentList) {
final PsiElement pparent = parent.getParent();
if (pparent instanceof GrCall) {
final GrCall call = (GrCall) pparent;
final GroovyResolveResult result = call.advancedResolve();
if (result.getElement() != null) {
final Map<GrExpression, Pair<PsiParameter, PsiType>> map = GrClosureSignatureUtil.mapArgumentsToParameters(result, place, false, false, call.getNamedArguments(), call.getExpressionArguments(), call.getClosureArguments());
if (map != null) {
final Pair<PsiParameter, PsiType> pair = map.get(place);
return getLanguageParams(pair.first);
}
}
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable in project intellij-community by JetBrains.
the class GrCastFix method findExpressionToCast.
private static GrExpression findExpressionToCast(ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
final PsiElement parent = element.getParent();
if (parent instanceof GrVariable) {
return ((GrVariable) parent).getInitializerGroovy();
} else if (parent instanceof GrAssignmentExpression) {
return ((GrAssignmentExpression) parent).getRValue();
} else if (parent instanceof GrThrowStatement) {
return ((GrThrowStatement) parent).getException();
} else if (parent instanceof GrReturnStatement) {
return ((GrReturnStatement) parent).getReturnValue();
} else if (element instanceof GrExpression) {
return (GrExpression) element;
}
PsiFile file = element.getContainingFile();
VirtualFile virtualFile = file.getVirtualFile();
String url = virtualFile == null ? "" : virtualFile.getPresentableUrl();
LOG.error("can't find expression to cast at position " + element.getTextRange(), new Attachment(url, file.getText()));
return null;
}
Aggregations