@Check public void checkPatternBody(PatternBody body) { if (body.getConstraints().isEmpty()) { String bodyName = getName(body); if (bodyName == null) { Pattern pattern = ((Pattern) body.eContainer()); String patternName = pattern.getName(); error("A patternbody of " + patternName + " is empty", body, PatternLanguagePackage.Literals.PATTERN_BODY__CONSTRAINTS, IssueCodes.PATTERN_BODY_EMPTY); } else { error("The patternbody " + bodyName + " cannot be empty", body, PatternLanguagePackage.Literals.PATTERN_BODY__NAME, IssueCodes.PATTERN_BODY_EMPTY); } } }
private void preprocessVariables(PatternBody body, PatternModelAcceptor<?> acceptor) { for (Variable variable : body.getVariables()) { acceptor.acceptVariable(variable); } }
public IScope scope_Variable(PatternBody ctx, EReference ref) { if (ctx != null && !ctx.eIsProxy()) { return Scopes.scopeFor(ctx.getVariables()); } return null; }
private String getPatternBodyName(PatternBody patternBody) { return (patternBody.getName() != null) ? patternBody.getName() : String.format("#%d", ((Pattern) patternBody.eContainer()).getBodies().indexOf(patternBody) + 1); }
for (Variable variable : patternBody.getVariables()) { Set<EClassifier> possibleClassifiers = emfTypeProvider.getIrreducibleClassifiersForVariableInBody( patternBody, variable); } else { EClassifier explicitType = emfTypeProvider.getExplicitClassifierForPatternParameterVariable(variable); PatternModel patternModel = (PatternModel) patternBody.eContainer().eContainer(); if (explicitType != null && possibleClassifiers.contains(explicitType) && hasCommonSubType(patternModel, possibleClassifiers)) {
private void calculateUsageCounts(PatternBody body, UnionFind<Variable> variableUnions, Map<Variable, VariableReferenceCount> individualRefCounters, Map<Set<Variable>, VariableReferenceCount> unifiedRefCounters) { for (Variable var : body.getVariables()) { boolean isParameter = var instanceof ParameterRef; individualRefCounters.put(var, new VariableReferenceCount(Collections.singleton(var), isParameter)); TreeIterator<EObject> it = body.eAllContents(); while (it.hasNext()) { EObject obj = it.next();
List<Variable> variables = patternBody.getVariables(); List<Variable> unnamedRunningVariables = CorePatternLanguageHelper.getUnnamedRunningVariables(patternBody); variables.removeAll(unnamedRunningVariables); for (Constraint constraint : patternBody.getConstraints()) { Set<Variable> positiveVariables = new HashSet<Variable>(); Set<Variable> generalVariables = new HashSet<Variable>(); for (Constraint constraint : patternBody.getConstraints()) { Set<Variable> positiveVariables = new HashSet<Variable>(); if (constraint instanceof CompareConstraint) { for (Constraint constraint : patternBody.getConstraints()) { if (constraint instanceof CompareConstraint) {
private void gatherBodyConstraints(PatternBody body, PatternModelAcceptor<?> acceptor) throws SpecificationBuilderException { EList<Constraint> constraints = body.getConstraints(); for (Constraint constraint : constraints) { acceptor.acceptConstraint(constraint); gatherConstraint(constraint, acceptor); } }
@Override public QualifiedName getFullyQualifiedName(EObject obj) { if (obj instanceof Pattern) { Pattern pattern = (Pattern) obj; return nameConverter.toQualifiedName(CorePatternLanguageHelper.getFullyQualifiedName(pattern)); } else if (obj instanceof PatternBody) { PatternBody patternBody = (PatternBody) obj; Pattern pattern = (Pattern) patternBody.eContainer(); return getFullyQualifiedName(pattern).append(Integer.toString(pattern.getBodies().indexOf(patternBody))); } return super.getFullyQualifiedName(obj); }
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; }
for (Constraint constraint : patternBody.getConstraints()) { if (constraint instanceof CompareConstraint) {
@Check(CheckType.NORMAL) public void checkVariableUsageCounters(PatternBody body) { UnionFind<Variable> variableUnions = calculateEqualVariables(body); Map<Set<Variable>, VariableReferenceCount> unifiedRefCounters = new HashMap<Set<Variable>, VariableReferenceCount>(); Map<Variable, VariableReferenceCount> individualRefCounters = new HashMap<Variable, VariableReferenceCount>(); calculateUsageCounts(body, variableUnions, individualRefCounters, unifiedRefCounters); for (Variable var : body.getVariables()) { if (var instanceof ParameterRef) { checkParameterUsageCounter((ParameterRef) var, individualRefCounters, unifiedRefCounters, variableUnions, body); } else { checkLocalVariableUsageCounter(var, individualRefCounters, unifiedRefCounters, variableUnions); } } }
EList<Variable> parameters = ((Pattern) body.eContainer()).getParameters(); for (Variable var : variables) { parameterMap.put(var.getName(), var); for (Constraint constraint : body.getConstraints()) { Iterator<EObject> it = constraint.eAllContents(); while (it.hasNext()) {
for (Constraint constraint : patternBody.getConstraints()) { if (constraint instanceof EClassifierConstraint) { EClassifierConstraint eClassifierConstraint = (EClassifierConstraint) constraint;
@Check(CheckType.NORMAL) public void checkVariableNames(PatternBody body) { for (Variable var1 : body.getVariables()) { Variable otherVar = null; for (Variable var2 : body.getVariables()) { if (isNamedSingleUse(var1) && var1.getSimpleName().substring(1).equals(var2.getName())) { otherVar = var2; } } if (otherVar != null) { if (var1.eContainer() instanceof PatternBody && !var1.getReferences().isEmpty()) { // Local variables do not have source location warning(String.format( "Dubius variable naming: Single use variable %s shares its name with the variable %s", var1.getSimpleName(), otherVar.getSimpleName()), var1.getReferences().get(0), PatternLanguagePackage.Literals.VARIABLE_REFERENCE__VARIABLE, IssueCodes.DUBIUS_VARIABLE_NAME); } else { warning(String.format( "Dubius variable naming: Single use variable %s shares its name with the variable %s", var1.getSimpleName(), otherVar.getSimpleName()), var1, PatternLanguagePackage.Literals.VARIABLE__NAME, IssueCodes.DUBIUS_VARIABLE_NAME); } } } }
/** * @param xExpression * the expression to evaluate * @param pattern */ public XBaseEvaluator(XExpression xExpression, Pattern pattern) throws SpecificationBuilderException{ super(); try { XtextInjectorProvider.INSTANCE.getInjector().injectMembers(this); this.xExpression = xExpression; this.pattern = pattern; ClassLoader classLoader = classLoaderProvider.getClassLoader(pattern); if (classLoader != null) { interpreter.setClassLoader(classLoader); } PatternBody body = EcoreUtil2.getContainerOfType(xExpression, PatternBody.class); List<Variable> usedVariables = CorePatternLanguageHelper.getUsedVariables(xExpression, body.getVariables()); usedNames = Iterables.transform(usedVariables, new Function<Variable, String>() { @Override public String apply(Variable var) { return var.getName(); } }); } catch (IncQueryException e) { logger.error("XBase Java evaluator extension point initialization failed.", e); throw new SpecificationBuilderException("XBase interpreter initialization failed", new String[0], "Failed Xbase interpreter initialization", pattern, e); } }
/** * @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; }
final List<Variable> usedVariables = CorePatternLanguageHelper.getUsedVariables(eval.getExpression(), containerPatternBody(eval).getVariables()); if (!onlyFromAggregatedValues) { for (Variable variable : usedVariables) {
Iterator<String> _map = IteratorExtensions.<XFeatureCall, String>map(_filter, _function); final List<String> valNames = IteratorExtensions.<String>toList(_map); EList<Variable> _variables = body.getVariables(); final Function1<Variable, Boolean> _function_1 = new Function1<Variable, Boolean>() { @Override