in ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java [246:453]
public boolean visit(Statement s) throws Exception {
if (s instanceof RutaPackageDeclaration) {
packageName = ((RutaPackageDeclaration) s).getName();
checkPackage(s);
return false;
}
if (s instanceof RutaMacroDeclaration) {
RutaMacroDeclaration decl = (RutaMacroDeclaration) s;
Map<Token, Token> definition = decl.getDefinition();
String name = decl.getName();
int kind = decl.getKind();
if (kind == RutaTypeConstants.RUTA_TYPE_A) {
actionExtensions.put(name, null);
} else if (kind == RutaTypeConstants.RUTA_TYPE_C) {
conditionExtensions.put(name, null);
}
Set<Entry<Token, Token>> entrySet = definition.entrySet();
Map<String, Integer> map = new HashMap<>();
for (Entry<Token, Token> entry : entrySet) {
String varName = entry.getKey().getText();
String varType = entry.getValue().getText();
int vt = getType(varType);
map.put(varName, vt);
}
knownLocalVariables.push(map);
}
if (s instanceof RutaImportTypesStatement) {
RutaImportTypesStatement stmt = (RutaImportTypesStatement) s;
SimpleReference tsExpr = (SimpleReference) stmt.getExpression();
Token typeToken = stmt.getTypeToken();
Token pkgToken = stmt.getPkgToken();
Token aliasToken = stmt.getAliasToken();
if (tsExpr != null) {
String localPath = tsExpr.getName();
processCompleteTypeSystemImport(tsExpr, localPath, typeToken, pkgToken, aliasToken);
} else {
// TODO package import not supported in Workbench
}
} else if (s instanceof RutaImportStatement) {
// handle type system imports
if (((RutaImportStatement) s).getType() == RutaStatementConstants.S_IMPORT_TYPESYSTEM) {
SimpleReference sRef = (SimpleReference) ((RutaImportStatement) s).getExpression();
String localPath = sRef.getName();
processCompleteTypeSystemImport(sRef, localPath);
return false;
}
// handle script-imports
if (((RutaImportStatement) s).getType() == RutaStatementConstants.S_IMPORT_SCRIPT) {
SimpleReference sRef = (SimpleReference) ((RutaImportStatement) s).getExpression();
String localPath = sRef.getName();
// HOTFIX Peter add also the imported types of the imported type system!
try {
URL url = null;
IFile file = RutaCheckerUtils.checkScriptImport(localPath,
sourceModule.getScriptProject());
if (file == null) {
String typesystemSuffix = RutaProjectUtils
.getTypeSystemSuffix(sourceModule.getScriptProject().getProject());
url = RutaCheckerUtils.checkImportExistence(localPath + typesystemSuffix, "xml",
classLoader);
}
if (file == null && url == null) {
pr.reportProblem(problemFactory.createFileNotFoundProblem(sRef, localPath));
} else {
IProject referredProject = sourceModule.getScriptProject().getProject();
if (file != null) {
// script in other project? use that if the file was found in the workspace
referredProject = file.getProject();
IPath typeSystemDescriptorPath = RutaProjectUtils.getTypeSystemDescriptorPath(
file.getLocation(), referredProject, classLoader);
TypeSystemDescription tsDesc = importCompleteTypeSystem(typeSystemDescriptorPath,
url);
List<String> checkDuplicateShortNames = checkOnAmbiguousShortNames(tsDesc);
if (!checkDuplicateShortNames.isEmpty()) {
pr.reportProblem(problemFactory.createDuplicateShortNameInImported(sRef, localPath,
checkDuplicateShortNames, ProblemSeverity.WARNING));
}
}
}
} catch (IOException e) {
pr.reportProblem(problemFactory.createFileNotFoundProblem(sRef, localPath));
}
return false;
}
}
if (s instanceof RutaDeclareDeclarationsStatement) {
RutaDeclareDeclarationsStatement dds = (RutaDeclareDeclarationsStatement) s;
ASTNode parent = dds.getParent();
if (parent != null && parent instanceof RutaVariableReference) {
RutaVariableReference p = (RutaVariableReference) parent;
String name = p.getName();
name = expand(name);
parentTypeInDeclaration = name;
// TODO remember name for new types and their features!
if (finalTypes.contains(name)) {
IProblem problem = problemFactory.createInheritenceFinalProblem(p);
pr.reportProblem(problem);
}
}
return true;
}
if (s instanceof RutaTypeDeclaration) {
RutaTypeDeclaration newType = (RutaTypeDeclaration) s;
String shortName = newType.getName();
String longName = getLongNameOfNewType(shortName);
if (namespaces.values().contains(longName)) {
IProblem problem = problemFactory.createIdConflictsWithTypeProblem(newType);
pr.reportProblem(problem);
return false;
}
if (reportWarningOnShortNames && namespaces.containsKey(shortName)) {
IProblem problem = problemFactory.createDuplicateShortName(newType,
ProblemSeverity.WARNING);
pr.reportProblem(problem);
return false;
}
if (knowsVariable(shortName)) {
IProblem problem = problemFactory.createIdConflictsWithVariableProblem(newType);
pr.reportProblem(problem);
return false;
}
List<RutaFeatureDeclaration> features = newType.getFeatures();
Set<FeatureDescription> feats = new HashSet<>();
if (parentTypeInDeclaration != null) {
Set<FeatureDescription> set = featureDescriptionMap.get(parentTypeInDeclaration);
if (set != null) {
feats.addAll(set);
}
}
if (features != null) {
for (RutaFeatureDeclaration each : features) {
// TODO create correct feature description! Works right now because the type is not
// checked
String type = each.getType();
type = translate(type);
type = expand(type);
FeatureDescription f = new FeatureDescription_impl(each.getName(), "", type);
feats.add(f);
if (type.equals("INT") || type.equals("STRING") || type.equals("DOUBLE")
|| type.equals("FLOAT") || type.equals("BOOLEAN")) {
continue;
}
if (!namespaces.keySet().contains(type) && !namespaces.values().contains(type)) {
IProblem problem = problemFactory.createUnknownFeatureTypeProblem(each);
pr.reportProblem(problem);
}
}
featureDescriptionMap.put(longName, feats);
}
addDeclaredType(shortName);
return false;
}
if (s instanceof RutaVariableDeclaration) {
RutaVariableDeclaration newVar = (RutaVariableDeclaration) s;
if (knowsVariable(newVar.getName())) {
IProblem problem = problemFactory.createIdConflictsWithVariableProblem(newVar);
pr.reportProblem(problem);
return false;
}
if (namespaces.containsKey(newVar.getName())) {
IProblem problem = problemFactory.createIdConflictsWithTypeProblem(newVar);
pr.reportProblem(problem);
return false;
}
knownLocalVariables.peek().put(newVar.getName(), newVar.getKind());
return false;
}
if (s instanceof RutaRegExpRule) {
RutaRegExpRule rule = (RutaRegExpRule) s;
Map<Expression, Map<Expression, Expression>> faMap = rule.getFeats();
Set<Entry<Expression, Map<Expression, Expression>>> typeEntrySet = faMap.entrySet();
for (Entry<Expression, Map<Expression, Expression>> entry : typeEntrySet) {
Expression struct = entry.getKey();
String structure = "";
if (struct != null) {
structure = sourceModule.getSource().substring(struct.sourceStart(), struct.sourceEnd());
structure = expand(structure);
}
Map<Expression, Expression> fmap = entry.getValue();
Set<Expression> keySet = fmap.keySet();
for (Expression fkey : keySet) {
if (fkey instanceof RutaExpression && fkey.getKind() == RutaTypeConstants.RUTA_TYPE_S) {
String feat = fkey.toString();
feat = getFeatureName(fkey, feat);
boolean findFeature = findFeature(structure, feat, -1);
if (!findFeature) {
IProblem problem = problemFactory.createUnknownFeatureProblem(fkey, structure);
pr.reportProblem(problem);
}
}
}
}
}
if (s instanceof RutaRule) {
if (rules.isEmpty()) {
collectAllLabels((RutaRule) s);
}
rules.push((RutaRule) s);
}
return true;
}