@Override public IInputKey getVariableReferenceType(VariableReference reference) { return getVariableType(reference.getVariable()); }
private void reportStrangeVariableRef(VariableReference ref, CompareConstraint constraint) { throw new IllegalStateException( // this should never come up "Strange reference to variable " + ref.getVar() + " in " + constraint.getClass().getName()); }
} else if (parameter.getValue() instanceof VariableValue) { VariableValue value = (VariableValue) parameter.getValue(); if (value.getValue().getVariable() == null) { error(String.format("Unknown variable %s", value.getValue().getVar()), parameter, PatternLanguagePackage.Literals.ANNOTATION_PARAMETER__VALUE, annotation.getParameters() .indexOf(parameter), IssueCodes.MISTYPED_ANNOTATION_PARAMETER);
if (obj instanceof VariableReference) { VariableReference varRef = (VariableReference) obj; String varName = varRef.getVar(); if ("_".equals(varName)) { varName = String.format("_<%d>", unnamedCounter); parameterMap.put(varName, var); varRef.setVariable(var);
private String getVariableName(VariableReference variable, PatternModelAcceptor<?> acceptor) { // Warning! variable.getVar() does not differentiate between // multiple anonymous variables ('_') return getVariableName(variable.getVariable(), acceptor); }
private String getConstantAsString(ValueReference ref) { if (ref instanceof IntValue) { return Integer.toString(((IntValue) ref).getValue()); } else if (ref instanceof DoubleValue) { return Double.toString(((DoubleValue) ref).getValue()); } else if (ref instanceof BoolValue) { return Boolean.toString(((BoolValue) ref).isValue()); } else if (ref instanceof StringValue) { return "\"" + ((StringValue) ref).getValue() + "\""; } else if (ref instanceof ListValue) { StringBuilder sb = new StringBuilder(); sb.append("{ "); for (Iterator<ValueReference> iter = ((ListValue) ref).getValues().iterator(); iter.hasNext();) { sb.append(getConstantAsString(iter.next())); if (iter.hasNext()) { sb.append(", "); } } sb.append("}"); return sb.toString(); } else if (ref instanceof VariableValue) { return ((VariableValue) ref).getValue().getVar(); } return "UNDEFINED"; }
private boolean isEqualVariables(Variable variable, VariableReference variableReference) { if (variable != null && variableReference != null) { final Variable variableReferenceVariable = variableReference.getVariable(); if (equal(variable, variableReferenceVariable) || equal(variable.getName(), variableReferenceVariable.getName())) { return true; } } return false; }
private static Object getValue(ValueReference ref) { Object value = null; if (ref instanceof BoolValue) { value = ((BoolValue)ref).isValue(); } else if (ref instanceof DoubleValue) { value = ((DoubleValue)ref).getValue(); } else if (ref instanceof IntValue) { value = ((IntValue)ref).getValue(); } else if (ref instanceof StringValue) { value = ((StringValue)ref).getValue(); } else if (ref instanceof VariableReference) { value = new ParameterReference(((VariableReference) ref).getVar()); } else if (ref instanceof VariableValue) { value = new ParameterReference(((VariableValue)ref).getValue().getVar()); } else if (ref instanceof ListValue) { value = Lists.transform(((ListValue) ref).getValues(), new Function<ValueReference, Object>() { @Override public Object apply(ValueReference ref) { return getValue(ref); } }); } else { throw new UnsupportedOperationException("Unknown attribute parameter type"); } return value; }
private EClassifier getClassifierForValueReference(ValueReference valueReference, PatternBody patternBody, Variable variable, int recursionCallingLevel, Variable injectiveVariablePair) { if (valueReference instanceof LiteralValueReference || valueReference instanceof ComputationValue || valueReference instanceof EnumValue) { return getClassifierForLiteralComputationEnumValueReference(valueReference); } else if (valueReference instanceof VariableValue) { VariableValue variableValue = (VariableValue) valueReference; Variable newPossibleInjectPair = variableValue.getValue().getVariable(); if (!newPossibleInjectPair.equals(injectiveVariablePair)) { return getClassifierForVariableWithPatternBody(patternBody, newPossibleInjectPair, recursionCallingLevel, variable); } } return null; }
/** * Contexts: * VariableReference returns VariableReference * * Constraint: * var=ID */ protected void sequence_VariableReference(ISerializationContext context, VariableReference semanticObject) { if (errorAcceptor != null) { if (transientValues.isValueTransient(semanticObject, PatternLanguagePackage.Literals.VARIABLE_REFERENCE__VAR) == ValueTransient.YES) errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, PatternLanguagePackage.Literals.VARIABLE_REFERENCE__VAR)); } SequenceFeeder feeder = createSequencerFeeder(context, semanticObject); feeder.accept(grammarAccess.getVariableReferenceAccess().getVarIDTerminalRuleCall_0(), semanticObject.getVar()); feeder.finish(); }
/** * @param valueReference * @return all variables from the ValueReference object. (Either referenced directly, or referenced throught an * AggregatedValue.) */ public static Set<Variable> getVariablesFromValueReference(ValueReference valueReference) { Set<Variable> resultSet = new HashSet<Variable>(); if (valueReference != null) { if (valueReference instanceof VariableValue) { resultSet.add(((VariableValue) valueReference).getValue().getVariable()); } else if (valueReference instanceof AggregatedValue) { AggregatedValue aggregatedValue = (AggregatedValue) valueReference; for (ValueReference valueReferenceInner : aggregatedValue.getCall().getParameters()) { for (Variable variable : getVariablesFromValueReference(valueReferenceInner)) { resultSet.add(variable); } } } else if (valueReference instanceof FunctionEvaluationValue) { FunctionEvaluationValue eval = (FunctionEvaluationValue) valueReference; final List<Variable> usedVariables = CorePatternLanguageHelper.getUsedVariables(eval.getExpression(), containerPatternBody(eval).getVariables()); resultSet.addAll(usedVariables); } } return resultSet; }
if (valueReference != null) { if (valueReference instanceof VariableValue) { Variable variable = ((VariableValue) valueReference).getValue().getVariable(); if (variable.getName().startsWith("_") && !onlyFromAggregatedValues) { resultSet.add(variable);
final Variable var = ref.getVariable(); final ReferenceType referenceClass = classifyReference(ref); individualRefCounters.get(var).incrementCounter(referenceClass);
private UnionFind<Variable> calculateEqualVariables(PatternBody body) { UnionFind<Variable> unions = new UnionFind<Variable>(body.getVariables()); TreeIterator<EObject> it = body.eAllContents(); while (it.hasNext()) { EObject obj = it.next(); if (obj instanceof CompareConstraint) { CompareConstraint constraint = (CompareConstraint) obj; if (constraint.getFeature() == CompareFeature.EQUALITY) { ValueReference left = constraint.getLeftOperand(); ValueReference right = constraint.getRightOperand(); if (left instanceof VariableValue && right instanceof VariableValue) { unions.union(((VariableValue) left).getValue().getVariable(), ((VariableValue) right).getValue().getVariable()); } } it.prune(); } else if (obj instanceof Constraint) { it.prune(); } } return unions; }
Variable pathExpressionHeadSourceVariable = null; if (pathExpressionHead.getSrc() != null) { pathExpressionHeadSourceVariable = pathExpressionHead.getSrc().getVariable(); Variable pathExpressionHeadSourceVariable = null; if (pathExpressionHead.getSrc() != null) { pathExpressionHeadSourceVariable = pathExpressionHead.getSrc().getVariable(); && rightValueReference instanceof VariableValue) { VariableValue variableValue = (VariableValue) rightValueReference; Variable variableToRemove = variableValue.getValue().getVariable(); generalUnionFindForVariables = copyAndRemove(generalUnionFindForVariables, variableToRemove); justPositiveUnionFindForVariables = copyAndRemove(justPositiveUnionFindForVariables, variableToRemove); && (rightValueReference instanceof LiteralValueReference || rightValueReference instanceof EnumValue)) { VariableValue variableValue = (VariableValue) leftValueReference; Variable variableToRemove = variableValue.getValue().getVariable(); generalUnionFindForVariables = copyAndRemove(generalUnionFindForVariables, variableToRemove); justPositiveUnionFindForVariables = copyAndRemove(justPositiveUnionFindForVariables, variableToRemove);