@Override public IInputKey getDeclaredType(Variable var) { final Type type = var.getType(); if (type != null) { return typeSystem.extractTypeDescriptor(type); } else { return null; } }
public VariableReferenceCount(Set<Variable> variables, boolean parameter) { this.variables = variables; this.parameter = parameter; for (ReferenceType type : ReferenceType.values()) { counters.put(type, 0); } for (Variable variable : variables) { if (variable instanceof ParameterRef && ((ParameterRef) variable).getReferredParam().getType() != null) { counters.put(ReferenceType.POSITIVE, 1); } } }
@Override public EClassifier getExplicitClassifierForPatternParameterVariable(Variable variable) { if (variable instanceof ParameterRef) { Variable referredParameter = ((ParameterRef) variable).getReferredParam(); return getClassifierForType(referredParameter.getType()); } else { return getClassifierForType(variable.getType()); } }
private void preprocessParameters(final PatternBody body, PatternModelAcceptor<?> acceptor) { EList<Variable> parameters = pattern.getParameters(); for (Variable variable : parameters) { if (variable.getType() != null && variable.getType() instanceof ClassType) { EClassifier classifier = ((ClassType) variable.getType()).getClassname(); IInputKey inputKey = classifierToInputKey(classifier); acceptor.acceptTypeConstraint(ImmutableList.of(variable.getName()), inputKey); } } acceptor.acceptExportedParameters(parameters); }
@Check public void checkMissingParameterTypes(Variable variable) { if (variable.eContainer() instanceof Pattern && variable.getType() == null) { Pattern pattern = (Pattern) variable.eContainer(); Set<EClassifier> possibleTypes = Sets.newHashSet(); for (PatternBody body : pattern.getBodies()) { possibleTypes.addAll(emfTypeProvider.getIrreducibleClassifiersForVariableInBody(body, variable)); } Iterable<String> typeNames = Iterables.transform(Iterables.filter(possibleTypes, EClass.class), new Function<EClassifier, String>() { @Override public String apply(EClassifier input) { final String name = input.getName(); return (Strings.isEmpty(name)) ? "" : name; } }); String[] issueData = Iterables.toArray(typeNames, String.class); if (issueData.length > 0) { warning("Type not defined for variable " + variable.getName(), PatternLanguagePackage.Literals.VARIABLE__NAME, EMFIssueCodes.MISSING_PARAMETER_TYPE, issueData); } } }
/** * The parameter's type must be the same or more specific than the type inferred from the pattern's body. This * warning usually arises when we have more pattern bodies, which contains different type definitions for the same * parameter. In a case like this the common parameter's type is the most specific common supertype of the * respective calculated types in the bodies. * * @param pattern */ @Check(/*CheckType.NORMAL*/) public void checkPatternParametersType(Pattern pattern) { for (Variable variable : pattern.getParameters()) { EClassifier classifierCorrect = emfTypeProvider.getClassifierForVariable(variable); EClassifier classifierDefined = emfTypeProvider.getClassifierForType(variable.getType()); if (classifierCorrect == null || classifierDefined == null || classifierDefined.equals(classifierCorrect)) { // Either correct - they are the same, or other validator returns the type error return; } else { if (classifierCorrect instanceof EClass && classifierDefined instanceof EClass) { if (((EClass) classifierDefined).getEAllSuperTypes().contains(classifierCorrect)) { // Correct the defined is more specific than what the pattern needs return; } } // OK, issue warning now warning(String.format( "Inconsistent parameter type definition, should be %s based on the pattern definition", classifierCorrect.getName()), variable, null, EMFIssueCodes.PARAMETER_TYPE_INVALID); } } }