protected String getFormattedArgumentsList(PatternCall call) { StringBuilder builder = new StringBuilder(); for (Iterator<ValueReference> iter = call.getParameters().iterator(); iter.hasNext();) { ValueReference parameter = iter.next(); builder.append(getConstantAsString(parameter)); if (iter.hasNext()) { builder.append(", "); } } return builder.toString(); }
@Check public void checkPatternCallParameters(PatternCall call) { if (call.getPatternRef() != null && call.getPatternRef().getName() != null && call.getParameters() != null) { final int definitionParameterSize = call.getPatternRef().getParameters().size(); final int callParameterSize = call.getParameters().size(); if (definitionParameterSize != callParameterSize) { error("The pattern " + getFormattedPattern(call.getPatternRef()) + " is not applicable for the arguments(" + getFormattedArgumentsList(call) + ")", PatternLanguagePackage.Literals.PATTERN_CALL__PATTERN_REF, IssueCodes.WRONG_NUMBER_PATTERNCALL_PARAMETER); } } }
/** * This validator checks if the literal or computational values match the pattern call's type. * * @param patternCall */ @Check public void checkForWrongLiteralAndComputationValuesInPatternCalls(PatternCall patternCall) { if (patternCall.getParameters().size() != patternCall.getPatternRef().getParameters().size()) { //This kind of error is detected in another place, however it throws an exception during literal checks return; } // Find and neg find (including count find as well) for (ValueReference valueReference : patternCall.getParameters()) { if (valueReference instanceof LiteralValueReference || valueReference instanceof ComputationValue) { Pattern pattern = patternCall.getPatternRef(); Variable variable = pattern.getParameters().get(patternCall.getParameters().indexOf(valueReference)); EClassifier typeClassifier = emfTypeProvider.getClassifierForVariable(variable); EClassifier inputClassifier = emfTypeProvider .getClassifierForLiteralComputationEnumValueReference(valueReference); if (!isCompatibleClassifiers(typeClassifier, inputClassifier)) { final String typeClassifierName = typeClassifier == null ? "(unknown)" : typeClassifier.getInstanceClassName(); error("The type inferred from the called pattern (" + typeClassifierName + ") is different from the input literal/computational value (" + inputClassifier.getInstanceClassName() + ").", patternCall, null, EMFIssueCodes.LITERAL_OR_COMPUTATION_TYPE_MISMATCH_IN_PATTERN_CALL); } } } }
/** * @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; }
for (ValueReference valueReferenceInner : aggregatedValue.getCall().getParameters()) { for (Variable variable : getUnnamedVariablesFromValueReference(valueReferenceInner, false)) { if (variable.getName().startsWith("_")) {
for (ValueReference valueReference : patternCompositionConstraint.getCall().getParameters()) { resultList.addAll(getUnnamedVariablesFromValueReference(valueReference, false));
private String aggregate(AggregatedValue reference, PatternModelAcceptor<?> acceptor) throws SpecificationBuilderException { String resultVariableName = acceptor.createVirtualVariable(); PatternCall call = reference.getCall(); Pattern patternRef = call.getPatternRef(); List<String> variableNames = getVariableNames(call.getParameters(), acceptor); AggregatorExpression aggregator = reference.getAggregator(); if (aggregator instanceof CountAggregator) { acceptor.acceptPatternMatchCounter(variableNames, patternRef, resultVariableName); } else { throw new SpecificationBuilderException("Unsupported aggregator expression type {1} in pattern {2}.", new String[] { aggregator.eClass().getName(), patternFQN }, "Unsupported aggregator expression", pattern); } return resultVariableName; }
private void gatherCompositionConstraint(PatternCompositionConstraint constraint, PatternModelAcceptor<?> acceptor) throws SpecificationBuilderException { PatternCall call = constraint.getCall(); Pattern patternRef = call.getPatternRef(); List<String> variableNames = getVariableNames(call.getParameters(), acceptor); if (!call.isTransitive()) { if (constraint.isNegative()) acceptor.acceptNegativePatternCall(variableNames, patternRef); else acceptor.acceptPositivePatternCall(variableNames, patternRef); } else { if (call.getParameters().size() != 2) throw new SpecificationBuilderException( "Transitive closure of {1} in pattern {2} is unsupported because called pattern is not binary.", new String[] { CorePatternLanguageHelper.getFullyQualifiedName(patternRef), patternFQN }, "Transitive closure only supported for binary patterns.", pattern); else if (constraint.isNegative()) throw new SpecificationBuilderException("Unsupported negated transitive closure of {1} in pattern {2}", new String[] { CorePatternLanguageHelper.getFullyQualifiedName(patternRef), patternFQN }, "Unsupported negated transitive closure", pattern); else acceptor.acceptBinaryTransitiveClosure(variableNames, patternRef); } }
if (!patternCompositionConstraint.isNegative()) { for (ValueReference valueReference : patternCompositionConstraint.getCall().getParameters()) { if (!isValueReferenceComputed(valueReference)) { positiveVariables.addAll(CorePatternLanguageHelper for (ValueReference valueReference : patternCompositionConstraint.getCall().getParameters()) { generalVariables.addAll(CorePatternLanguageHelper .getVariablesFromValueReference(valueReference)); if (!patternCompositionConstraint.isNegative()) { for (ValueReference valueReference : patternCompositionConstraint.getCall().getParameters()) { addPositiveVariablesFromValueReference(unnamedRunningVariables, justPositiveUnionFindForVariables, positiveVariables, valueReference);
PatternCall patternCall = patternCompositionConstraint.getCall(); int parameterIndex = 0; for (ValueReference valueReference : patternCall.getParameters()) { if (valueReference instanceof VariableValue) { VariableValue variableValue = (VariableValue) valueReference;