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); } } } }
.getReferences().get(0), null, EMFIssueCodes.VARIABLE_TYPE_MULTIPLE_DECLARATION); } else { EClassifier explicitType = emfTypeProvider.getExplicitClassifierForPatternParameterVariable(variable); warning("Ambiguous variable type defintions: " + classifierNamesSet + ", the parameter type (" + explicitType.getName() + ") is used now.", variable .getReferences().get(0), null, EMFIssueCodes.VARIABLE_TYPE_INVALID_WARNING); } else { boolean isParameter = false; + ", type cannot be selected. Please specify the one to be used as the parameter type" + " by adding it to the parameter definition.", variable.getReferences().get(0), null, EMFIssueCodes.VARIABLE_TYPE_INVALID_ERROR); } else { error("Inconsistent variable type defintions: " + classifierNamesSet + ", type cannot be selected.", variable.getReferences().get(0), null, EMFIssueCodes.VARIABLE_TYPE_INVALID_ERROR);
warning(String.format( "Local variable '%s' is referenced only once. Is it mistyped? Start its name with '_' if intentional.", var.getName()), var.getReferences().get(0), PatternLanguagePackage.Literals.VARIABLE_REFERENCE__VAR, IssueCodes.LOCAL_VARIABLE_REFERENCED_ONCE); } else if (individualCounter.getReferenceCount() > 1 && isNamedSingleUse(var)) { for (VariableReference ref : var.getReferences()) { error(String.format("Named single-use variable %s used multiple times.", var.getName()), ref, PatternLanguagePackage.Literals.VARIABLE_REFERENCE__VAR, warning(String.format( "Local variable '%s' will be quantified because it is used only here. Acknowledge this by prefixing its name with '_'.", var.getName()), var.getReferences().get(0), PatternLanguagePackage.Literals.VARIABLE_REFERENCE__VAR, IssueCodes.LOCAL_VARIABLE_QUANTIFIED_REFERENCE); error(String.format( "Local variable '%s' has no positive reference, thus its value cannot be determined.", var.getName()), var.getReferences().get(0), PatternLanguagePackage.Literals.VARIABLE_REFERENCE__VAR, IssueCodes.LOCAL_VARIABLE_NO_POSITIVE_REFERENCE);