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; }
@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); } } }
@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 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; }
/** * @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); } }
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
final List<Variable> usedVariables = CorePatternLanguageHelper.getUsedVariables(eval.getExpression(), containerPatternBody(eval).getVariables()); if (!onlyFromAggregatedValues) { for (Variable variable : usedVariables) {
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Variable getVariable() { if (variable == null) { InternalEObject container = this.eContainer; while (container != null && !(container instanceof org.eclipse.incquery.patternlanguage.patternLanguage.PatternBody || container instanceof org.eclipse.incquery.patternlanguage.patternLanguage.Pattern)) { container = container.eInternalContainer(); } if (container instanceof org.eclipse.incquery.patternlanguage.patternLanguage.PatternBody) { //The side-effect of this call initializes the variable ((org.eclipse.incquery.patternlanguage.patternLanguage.PatternBody) container).getVariables(); } else if (container instanceof org.eclipse.incquery.patternlanguage.patternLanguage.Pattern) { org.eclipse.incquery.patternlanguage.patternLanguage.Pattern pattern = (org.eclipse.incquery.patternlanguage.patternLanguage.Pattern) container; for (org.eclipse.incquery.patternlanguage.patternLanguage.Variable var : pattern.getParameters()) { if (var.getName() != null && var.getName().equals(getVar())) { setVariable(var); } } } } return variable; }
for (Variable variable : patternBody.getVariables()) { Set<EClassifier> possibleClassifiers = emfTypeProvider.getIrreducibleClassifiersForVariableInBody( patternBody, variable);
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));
List<Variable> variables = patternBody.getVariables(); List<Variable> unnamedRunningVariables = CorePatternLanguageHelper.getUnnamedRunningVariables(patternBody); variables.removeAll(unnamedRunningVariables);
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; }