@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); } } }
@Override public EClassifier getClassifierForVariable(Variable variable) { if (!variable.eIsProxy()) { EObject container = variable.eContainer(); if (container instanceof Pattern) { return getClassifierForParameterVariable((Pattern) container, variable, 0); } else if (container instanceof PatternBody) { return getClassifierForVariableWithPatternBody((PatternBody) container, variable, 0, null); } } return null; }
private JvmTypeReference getTypeReferenceForTypeName(String typeName, EObject context) { JvmTypeReference typeRef = typeReferences.getTypeForName(typeName, context); JvmTypeReference typeReference = primitives.asWrapperTypeIfPrimitive(typeRef); if (typeReference == null) { EObject errorContext = context; String contextName = context.toString(); if (context instanceof Variable && ((Variable)context).eContainer() instanceof PatternBody && ((Variable)context).getReferences().size() > 0) { contextName = ((Variable)context).getName(); errorContext = ((Variable)context).getReferences().get(0); } errorFeedback.reportError( errorContext, String.format( "Cannot resolve corresponding Java type for variable %s. Are the required bundle dependencies set?", contextName), EMFPatternLanguageJvmModelInferrer.INVALID_TYPEREF_CODE, Severity.WARNING, IErrorFeedback.JVMINFERENCE_ERROR_TYPE); } return typeReference; }
@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); } } } }