You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2014/02/07 19:27:08 UTC

svn commit: r1565751 - in /uima/ruta/trunk: ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/ ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/ ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/ ruta-ep-i...

Author: pkluegl
Date: Fri Feb  7 18:27:08 2014
New Revision: 1565751

URL: http://svn.apache.org/r1565751
Log:
UIMA-3533
- LanguageChecker* replaces VarRef- and TypeChecker
- implemented validator support for new import functionality

Added:
    uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java   (with props)
    uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaLanguageChecker.java   (with props)
Modified:
    uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaChecker.java
    uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerProblemFactory.java
    uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerUtils.java
    uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaTypeChecker.java
    uima/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g
    uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaSelectionEngine.java
    uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/RutaBlock.java
    uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/RutaSimpleStatement.java
    uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/StatementFactory.java

Added: uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java?rev=1565751&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java (added)
+++ uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java Fri Feb  7 18:27:08 2014
@@ -0,0 +1,1108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.validator;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+import java.util.Map.Entry;
+
+import org.antlr.runtime.Token;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.fit.factory.TypeSystemDescriptionFactory;
+import org.apache.uima.resource.ResourceManager;
+import org.apache.uima.resource.metadata.FeatureDescription;
+import org.apache.uima.resource.metadata.TypeDescription;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.ruta.UIMAConstants;
+import org.apache.uima.ruta.ide.RutaIdeUIPlugin;
+import org.apache.uima.ruta.ide.core.IRutaKeywords;
+import org.apache.uima.ruta.ide.core.RutaCorePreferences;
+import org.apache.uima.ruta.ide.core.RutaExtensionManager;
+import org.apache.uima.ruta.ide.core.RutaKeywordsManager;
+import org.apache.uima.ruta.ide.core.builder.RutaProjectUtils;
+import org.apache.uima.ruta.ide.core.extensions.IIDEActionExtension;
+import org.apache.uima.ruta.ide.core.extensions.IIDEBooleanFunctionExtension;
+import org.apache.uima.ruta.ide.core.extensions.IIDEConditionExtension;
+import org.apache.uima.ruta.ide.core.extensions.IIDENumberFunctionExtension;
+import org.apache.uima.ruta.ide.core.extensions.IIDEStringFunctionExtension;
+import org.apache.uima.ruta.ide.core.extensions.IIDETypeFunctionExtension;
+import org.apache.uima.ruta.ide.core.extensions.IRutaExtension;
+import org.apache.uima.ruta.ide.parser.ast.FeatureMatchExpression;
+import org.apache.uima.ruta.ide.parser.ast.RutaAction;
+import org.apache.uima.ruta.ide.parser.ast.RutaActionConstants;
+import org.apache.uima.ruta.ide.parser.ast.RutaBlock;
+import org.apache.uima.ruta.ide.parser.ast.RutaCondition;
+import org.apache.uima.ruta.ide.parser.ast.RutaDeclareDeclarationsStatement;
+import org.apache.uima.ruta.ide.parser.ast.RutaExpression;
+import org.apache.uima.ruta.ide.parser.ast.RutaFeatureDeclaration;
+import org.apache.uima.ruta.ide.parser.ast.RutaFunction;
+import org.apache.uima.ruta.ide.parser.ast.RutaImportStatement;
+import org.apache.uima.ruta.ide.parser.ast.RutaImportTypesStatement;
+import org.apache.uima.ruta.ide.parser.ast.RutaPackageDeclaration;
+import org.apache.uima.ruta.ide.parser.ast.RutaRegExpRule;
+import org.apache.uima.ruta.ide.parser.ast.RutaRuleElement;
+import org.apache.uima.ruta.ide.parser.ast.RutaStatementConstants;
+import org.apache.uima.ruta.ide.parser.ast.RutaStringExpression;
+import org.apache.uima.ruta.ide.parser.ast.RutaStructureAction;
+import org.apache.uima.ruta.ide.parser.ast.RutaTypeConstants;
+import org.apache.uima.ruta.ide.parser.ast.RutaTypeDeclaration;
+import org.apache.uima.ruta.ide.parser.ast.RutaVariableDeclaration;
+import org.apache.uima.ruta.ide.parser.ast.RutaVariableReference;
+import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.XMLInputSource;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.dltk.ast.ASTListNode;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.declarations.MethodDeclaration;
+import org.eclipse.dltk.ast.expressions.Expression;
+import org.eclipse.dltk.ast.expressions.NumericLiteral;
+import org.eclipse.dltk.ast.expressions.StringLiteral;
+import org.eclipse.dltk.ast.references.SimpleReference;
+import org.eclipse.dltk.ast.statements.Statement;
+import org.eclipse.dltk.compiler.problem.IProblem;
+import org.eclipse.dltk.compiler.problem.IProblemReporter;
+import org.eclipse.dltk.compiler.problem.ProblemSeverity;
+import org.eclipse.dltk.core.IModelElement;
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.core.builder.ISourceLineTracker;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+public class LanguageCheckerVisitor extends ASTVisitor {
+
+  private IProblemReporter pr;
+
+  private ISourceLineTracker linetracker;
+
+  private ISourceModule sourceModule;
+
+  private Map<String, IIDEConditionExtension> conditionExtensions;
+
+  private Map<String, IIDEActionExtension> actionExtensions;
+
+  private Map<String, IIDENumberFunctionExtension> numberFunctionExtensions;
+
+  private Map<String, IIDEBooleanFunctionExtension> booleanFunctionExtensions;
+
+  private Map<String, IIDEStringFunctionExtension> stringFunctionExtensions;
+
+  private Map<String, IIDETypeFunctionExtension> typeFunctionExtensions;
+
+  /**
+   * Mapping from short type name (e.g. {@code W}) to their disambiguated long type names (e.g.
+   * {@code org.apache.uima.ruta.type.W}).
+   */
+  private Map<String, String> namespaces;
+
+  /**
+   * Mapping from ambiguous short type names to all their possible long type names.
+   */
+  private Map<String, Set<String>> ambiguousTypeAlias;
+
+  /**
+   * Known variables for each block environment
+   */
+  private final Stack<Map<String, Integer>> knownLocalVariables;
+
+  /**
+   * Name of each block
+   */
+  private final Stack<String> blocks;
+
+  /**
+   * Caching the matched type of a rule element
+   */
+  private String matchedType;
+
+  /**
+   * Caching the declared package of the script
+   */
+  private String packageName = "";
+
+  /**
+   * Mapping all long type names of the type system to their type description
+   */
+  private Map<String, TypeDescription> typeDescriptionMap;
+
+  /**
+   * Mapping all long type names of all declared feature description
+   */
+  private Map<String, Set<FeatureDescription>> featureDescriptionMap;
+
+  /**
+   * The type system description of the script file
+   */
+  private TypeSystemDescription typeSystemDescription;
+
+  private final String implicitString = "Implicit";
+
+  private Set<String> finalTypes;
+
+  private boolean reportWarningOnShortNames;
+
+  private RutaCheckerProblemFactory problemFactory;
+
+  private ResourceManager resourceManager;
+
+  public LanguageCheckerVisitor(IProblemReporter problemReporter, ISourceLineTracker linetracker,
+          ISourceModule sourceModule) {
+    super();
+    this.pr = problemReporter;
+    this.linetracker = linetracker;
+    this.sourceModule = sourceModule;
+
+    this.problemFactory = new RutaCheckerProblemFactory(sourceModule.getElementName(), linetracker);
+
+    namespaces = new HashMap<String, String>();
+    ambiguousTypeAlias = new HashMap<String, Set<String>>();
+    knownLocalVariables = new Stack<Map<String, Integer>>();
+    knownLocalVariables.push(new HashMap<String, Integer>());
+    blocks = new Stack<String>();
+
+    initializePredefinedInformation();
+    initializeExtensionInformation();
+
+    IPreferenceStore store = RutaIdeUIPlugin.getDefault().getPreferenceStore();
+    reportWarningOnShortNames = !store
+            .getBoolean(RutaCorePreferences.BUILDER_IGNORE_DUPLICATE_SHORTNAMES);
+
+  }
+
+  @Override
+  public boolean visit(Statement s) throws Exception {
+    if (s instanceof RutaPackageDeclaration) {
+      this.packageName = ((RutaPackageDeclaration) s).getName();
+      return false;
+    }
+    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 {
+          IFile iFile = RutaCheckerUtils.checkScriptImport(localPath,
+                  sourceModule.getScriptProject());
+          if (iFile == null) {
+            pr.reportProblem(problemFactory.createFileNotFoundProblem(sRef, localPath));
+          }
+          IPath typeSystemDescriptorPath = RutaProjectUtils.getTypeSystemDescriptorPath(
+                  iFile.getLocation(), sourceModule.getScriptProject().getProject());
+          TypeSystemDescription tsDesc = importCompleteTypeSystem(typeSystemDescriptorPath);
+
+          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();
+        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();
+      if (features != null) {
+
+        for (RutaFeatureDeclaration each : features) {
+          String type = each.getType();
+          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);
+          }
+        }
+      }
+      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());
+          String string = namespaces.get(structure);
+          if(string != null) {
+            structure = string;
+          }
+        }
+        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);
+            }
+          }
+        }
+      }
+    }
+    return true;
+  }
+
+  private void processCompleteTypeSystemImport(SimpleReference sRef, String localPath)
+          throws CoreException {
+    processCompleteTypeSystemImport(sRef, localPath, null, null, null);
+  }
+
+  private void processCompleteTypeSystemImport(SimpleReference sRef, String localPath, Token typeToken,
+          Token pkgToken, Token aliasToken) throws CoreException {
+    try {
+      IFile ifile = RutaCheckerUtils.checkTypeSystemImport(localPath,
+              sourceModule.getScriptProject());
+      if (ifile == null) {
+        pr.reportProblem(problemFactory.createFileNotFoundProblem(sRef, localPath));
+      }
+      IPath location = ifile.getLocation();
+      TypeSystemDescription tsDesc = importTypeSystem(location, typeToken, pkgToken ,aliasToken);
+
+      if (reportWarningOnShortNames) {
+        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));
+    } catch (InvalidXMLException e) {
+      pr.reportProblem(problemFactory.createXMLProblem(sRef, localPath));
+    }
+  }
+
+  private List<String> checkOnAmbiguousShortNames(TypeSystemDescription tsDesc) {
+    List<String> checkDuplicateShortNames = new ArrayList<String>();
+    for (TypeDescription each : tsDesc.getTypes()) {
+      String longName = each.getName();
+      String shortName = getShortName(longName);
+      Set<String> set = ambiguousTypeAlias.get(shortName);
+      if (set != null && set.size() > 1) {
+        checkDuplicateShortNames.addAll(set);
+      }
+    }
+    return checkDuplicateShortNames;
+  }
+
+  private TypeSystemDescription importTypeSystem(IPath path, Token typeToken, Token pkgToken, Token aliasToken)
+          throws InvalidXMLException, IOException, MalformedURLException, CoreException {
+    File file = path.toFile();
+    TypeSystemDescription tsDesc = UIMAFramework.getXMLParser().parseTypeSystemDescription(
+            new XMLInputSource(file));
+    ResourceManager resMgr = getResourceManager();
+    tsDesc.resolveImports(resMgr);
+    for (TypeDescription each : tsDesc.getTypes()) {
+      String longName = each.getName();
+      String shortName = getShortName(longName);
+      if(pkgToken != null) {
+        String pkg = pkgToken.getText();
+        if(!longName.startsWith(pkg + ".")) {
+          continue;
+        }
+      }
+      if(typeToken != null) {
+        String type = typeToken.getText();
+        if(!longName.equals(type)) {
+          continue;
+        }
+      }
+      if (aliasToken != null) {
+        String alias = aliasToken.getText();
+        if(typeToken == null) {
+          shortName = alias + "." + shortName;
+        } else {
+          shortName = alias;
+        }
+      }
+      importType(longName, shortName);
+    }
+    return tsDesc;
+  }
+
+  private ResourceManager getResourceManager() throws MalformedURLException, CoreException {
+    if (resourceManager == null) {
+      resourceManager = UIMAFramework.newDefaultResourceManager();
+      List<IFolder> folders = RutaProjectUtils.getAllDescriptorFolders(sourceModule
+              .getScriptProject().getProject());
+      StringBuilder sb = new StringBuilder();
+      Iterator<IFolder> iterator = folders.iterator();
+      while (iterator.hasNext()) {
+        IFolder iFolder = (IFolder) iterator.next();
+        sb.append(iFolder.getLocationURI().toURL());
+        if (iterator.hasNext()) {
+          sb.append(System.getProperty("path.separator"));
+        }
+      }
+      resourceManager.setDataPath(sb.toString());
+    }
+    return resourceManager;
+  }
+
+  @Override
+  public boolean visit(Expression s) throws Exception {
+
+    if (s instanceof RutaRuleElement) {
+      RutaRuleElement re = (RutaRuleElement) s;
+      Expression head = re.getHead();
+      if (head instanceof FeatureMatchExpression) {
+        FeatureMatchExpression fme = (FeatureMatchExpression) head;
+        String text = fme.getFeature().getText();
+        int lastIndexOf = text.lastIndexOf('.');
+        String twf = text.substring(0, lastIndexOf);
+        matchedType = isFeatureMatch(twf);
+      } else if (head != null) {
+        matchedType = sourceModule.getSource().substring(head.sourceStart(), head.sourceEnd());
+      }
+      // cache long name
+      String string = namespaces.get(matchedType);
+      if (string != null) {
+        matchedType = string;
+      }
+    }
+    if (s instanceof FeatureMatchExpression) {
+      FeatureMatchExpression fme = (FeatureMatchExpression) s;
+      String featText = fme.getFeature().getText();
+      checkTypeOfFeatureMatch(featText, fme);
+      return true;
+    }
+    if (s instanceof RutaVariableReference) {
+      RutaVariableReference ref = (RutaVariableReference) s;
+      if ((ref.getType() & RutaTypeConstants.RUTA_TYPE_AT) != 0) {
+        // types
+        String name = ref.getName();
+        Set<String> set = ambiguousTypeAlias.get(name);
+        if (set != null && !set.isEmpty()) {
+          pr.reportProblem(problemFactory.createAmbiguousShortName(ref, set, ProblemSeverity.ERROR));
+          return false;
+        }
+        if (namespaces.keySet().contains(name) || namespaces.values().contains(name)) {
+          return false;
+        }
+        if (isFeatureMatch(ref.getName()) != null) {
+          return false;
+        }
+        pr.reportProblem(problemFactory.createTypeProblem(ref, sourceModule));
+        return false;
+      }
+      if (!isVariableDeclared(ref)) {
+        return false;
+      }
+      checkTypeOfVariable(ref);
+      return false;
+    }
+    // check assign types
+    if (s instanceof RutaAction) {
+      RutaAction tma = (RutaAction) s;
+
+      String actionName = sourceModule.getSource().substring(tma.getNameStart(), tma.getNameEnd());
+      String[] keywords = RutaKeywordsManager.getKeywords(IRutaKeywords.ACTION);
+      List<String> asList = Arrays.asList(keywords);
+      if (!StringUtils.isEmpty(actionName) && !"-".equals(actionName)
+              && !asList.contains(actionName) && !implicitString.equals(tma.getName())) {
+        IProblem problem = problemFactory.createUnknownActionProblem(tma);
+        pr.reportProblem(problem);
+      }
+
+      IRutaExtension extension = actionExtensions.get(actionName);
+      if (extension != null) {
+        extension.checkSyntax(tma, problemFactory, pr);
+      }
+
+      if (tma.getName().equals("GETFEATURE") || tma.getName().equals("SETFEATURE")) {
+        List<?> childs = tma.getChilds();
+        RutaStringExpression stringExpr = (RutaStringExpression) childs.get(0);
+        String feat = stringExpr.toString();
+        feat = getFeatureName(stringExpr, feat);
+        boolean featureFound = findFeature(matchedType, feat, -1);
+        if (!featureFound) {
+          IProblem problem = problemFactory.createUnknownFeatureProblem(stringExpr, matchedType);
+          pr.reportProblem(problem);
+        }
+      }
+
+      if (tma.getKind() == RutaActionConstants.A_ASSIGN) {
+        List<?> childs = tma.getChilds();
+        try {
+          RutaVariableReference ref = (RutaVariableReference) childs.get(0);
+          RutaExpression expr = (RutaExpression) childs.get(1);
+          int type = expr.getKind();
+          if (ref.getType() == RutaTypeConstants.RUTA_TYPE_G) {
+            ref.setType(type);
+          }
+        } catch (IndexOutOfBoundsException e) {
+          // exception should have been recognized and reported in
+          // parser
+          return false;
+        } catch (ClassCastException e) {
+          // exception should have been recognized and reported in
+          // parser
+          return false;
+        }
+      }
+
+      if (s instanceof RutaStructureAction) {
+        RutaStructureAction sa = (RutaStructureAction) s;
+        Expression struct = sa.getStructure();
+        String structure = null;
+        if (struct != null) {
+          structure = sourceModule.getSource().substring(struct.sourceStart(), struct.sourceEnd());
+          String string = namespaces.get(structure);
+          if(string != null) {
+            structure = string;
+          }
+        }
+        Map<Expression, Expression> assignments = sa.getAssignments();
+        // hotfix... correct name in ast
+        String action = sourceModule.getSource().substring(sa.getNameStart(), sa.getNameEnd());
+        if (assignments != null && !action.equals("TRIE")) {
+          for (Expression each : assignments.keySet()) {
+            // TODO refactor to visitor?
+            String feat = each.toString();
+            // List<?> childs = each.getChilds();
+            feat = getFeatureName(each, feat);
+            boolean featureFound = findFeature(structure, feat, -1);
+            if (!featureFound) {
+              IProblem problem = problemFactory.createUnknownFeatureProblem(each, structure);
+              pr.reportProblem(problem);
+            }
+          }
+        }
+      }
+    }
+    if (s instanceof RutaCondition) {
+      RutaCondition cond = (RutaCondition) s;
+      String conditionName = sourceModule.getSource().substring(cond.getNameStart(),
+              cond.getNameEnd());
+      String[] keywords = RutaKeywordsManager.getKeywords(IRutaKeywords.CONDITION);
+      List<String> asList = Arrays.asList(keywords);
+      if (!StringUtils.isEmpty(conditionName) && !"-".equals(conditionName)
+              && !asList.contains(conditionName) && !implicitString.equals(cond.getName())) {
+        IProblem problem = problemFactory.createUnknownConditionProblem(cond);
+        pr.reportProblem(problem);
+      }
+
+      IRutaExtension extension = conditionExtensions.get(conditionName);
+      if (extension != null) {
+        // boolean checkSyntax =
+        extension.checkSyntax(cond, problemFactory, pr);
+      }
+
+      if (conditionName.equals("FEATURE")) {
+        if (matchedType != null) {
+          List<?> args = cond.getChilds();
+          RutaStringExpression se = (RutaStringExpression) args.get(0);
+          String feat = se.toString();
+          feat = getFeatureName(se, feat);
+          boolean featureFound = findFeature(matchedType, feat, -1);
+          if (!featureFound) {
+            IProblem problem = problemFactory.createUnknownFeatureProblem(se, matchedType);
+            pr.reportProblem(problem);
+          }
+        }
+      }
+    }
+    if (s instanceof RutaFunction) {
+      RutaFunction f = (RutaFunction) s;
+      String name = f.getName();
+      if (s.getKind() == RutaTypeConstants.RUTA_TYPE_AT) {
+        IRutaExtension extension = typeFunctionExtensions.get(name);
+        if (extension != null) {
+          extension.checkSyntax(s, problemFactory, pr);
+        }
+      } else if (s.getKind() == RutaTypeConstants.RUTA_TYPE_B) {
+        IRutaExtension extension = booleanFunctionExtensions.get(name);
+        if (extension != null) {
+          extension.checkSyntax(s, problemFactory, pr);
+        }
+      } else if (s.getKind() == RutaTypeConstants.RUTA_TYPE_N) {
+        IRutaExtension extension = numberFunctionExtensions.get(name);
+        if (extension != null) {
+          extension.checkSyntax(s, problemFactory, pr);
+        }
+      } else if (s.getKind() == RutaTypeConstants.RUTA_TYPE_S) {
+        IRutaExtension extension = stringFunctionExtensions.get(name);
+        if (extension != null) {
+          extension.checkSyntax(s, problemFactory, pr);
+        }
+      }
+    }
+    return true;
+  }
+
+  private void checkTypeOfFeatureMatch(String featText, FeatureMatchExpression fme) {
+    int lastIndexOf = featText.lastIndexOf(".");
+    if (lastIndexOf == -1) {
+      return;
+    }
+    String aref = featText.substring(0, lastIndexOf);
+    String fref = featText.substring(lastIndexOf + 1, featText.length());
+    String match = isFeatureMatch(aref);
+    if (match != null) {
+      int kind = -1;
+      if (fme.getValue() != null) {
+        kind = fme.getValue().getKind();
+        if (fme.getValue() instanceof StringLiteral) {
+          kind = RutaTypeConstants.RUTA_TYPE_S;
+        } else if (fme.getValue() instanceof NumericLiteral) {
+          kind = RutaTypeConstants.RUTA_TYPE_N;
+        }
+      }
+      boolean findFeature = findFeature(match, fref, kind);
+      if (findFeature) {
+
+      } else {
+        pr.reportProblem(problemFactory.createUnknownFeatureProblem(fme, aref));
+      }
+    } else {
+      pr.reportProblem(problemFactory.createTypeProblem(fme, sourceModule));
+      pr.reportProblem(problemFactory.createUnknownFeatureProblem(fme, aref));
+    }
+  }
+
+  @Override
+  public boolean endvisit(Expression s) throws Exception {
+    if (s instanceof RutaRuleElement) {
+      matchedType = null;
+    }
+    return super.endvisit(s);
+  }
+
+  @Override
+  public boolean endvisit(MethodDeclaration s) throws Exception {
+    if (s instanceof RutaBlock) {
+      knownLocalVariables.pop();
+      blocks.pop();
+    }
+    return super.endvisit(s);
+  }
+
+  @Override
+  public boolean visit(MethodDeclaration s) throws Exception {
+    if (s instanceof RutaBlock) {
+      RutaBlock b = (RutaBlock) s;
+      knownLocalVariables.push(new HashMap<String, Integer>());
+      blocks.push(b.getName());
+    }
+    return true;
+  }
+
+  private boolean findFeature(String longTypeName, String featureName, int kind) {
+    if (longTypeName == null) {
+      return false;
+    }
+    if (longTypeName.equals("org.apache.uima.ruta.type.Document")
+            || longTypeName.equals("uima.tcas.DocumentAnnotation")) {
+      if (featureName.equals("language")) {
+        return true;
+      }
+    }
+    Set<FeatureDescription> set = featureDescriptionMap.get(longTypeName);
+    if (set != null) {
+      for (FeatureDescription featureDescription : set) {
+        String fName = featureDescription.getName();
+        if (fName.equals(featureName) && (kind == -1 || checkFeatureKind(featureDescription, kind))) {
+          return true;
+        }
+      }
+    }
+    return false;
+  }
+
+  private boolean checkFeatureKind(FeatureDescription f, int kind) {
+    if (kind == -1) {
+      return true;
+    }
+    String t = f.getRangeTypeName();
+    if (t.equals(UIMAConstants.TYPE_BOOLEAN) && RutaTypeConstants.RUTA_TYPE_B == kind) {
+      return true;
+    } else if (t.equals(UIMAConstants.TYPE_STRING) && RutaTypeConstants.RUTA_TYPE_S == kind) {
+      return true;
+    } else if ((t.equals(UIMAConstants.TYPE_BYTE) || t.equals(UIMAConstants.TYPE_DOUBLE)
+            || t.equals(UIMAConstants.TYPE_FLOAT) || t.equals(UIMAConstants.TYPE_INTEGER)
+            || t.equals(UIMAConstants.TYPE_LONG) || t.equals(UIMAConstants.TYPE_SHORT))
+            && RutaTypeConstants.RUTA_TYPE_N == kind) {
+      return true;
+    }
+    return false;
+  }
+
+  private void addDeclaredType(String shortName) {
+    String longName = getLongNameOfNewType(shortName);
+    importType(longName, shortName);
+  }
+
+  private String getLongNameOfNewType(String shortName) {
+    String moduleName = sourceModule.getElementName();
+    String packagePrefix = "";
+    if (!packageName.isEmpty()) {
+      packagePrefix = packageName + ".";
+    }
+    for (String each : blocks) {
+      packagePrefix += each + ".";
+    }
+    String longName = packagePrefix + moduleName + "." + shortName;
+    return longName;
+  }
+
+  /**
+   * Import a type in the current namespace.
+   * 
+   * @param longName
+   *          Complete type name.
+   * @param shortName
+   *          Short type name (without namespace).
+   */
+  private void importType(String longName, String shortName) {
+    Set<String> targets = ambiguousTypeAlias.get(shortName);
+    if (targets != null) {
+      // shortName is already ambiguous, add longName to its list of possible targets
+      targets.add(longName);
+    } else {
+      String existing = namespaces.put(shortName, longName);
+
+      if (existing != null && !existing.equals(longName)) {
+        // shortName can now be resolved to "existing" or "longName"
+        targets = new HashSet<String>(2);
+        targets.add(existing);
+        targets.add(longName);
+
+        // add existing mapping and longName to its list of possible targets
+        ambiguousTypeAlias.put(shortName, targets);
+
+        // remove shortName from the namespace because it is ambiguous
+        namespaces.remove(shortName);
+      }
+    }
+  }
+
+  private boolean knowsVariable(String name) {
+    for (Map<String, Integer> each : knownLocalVariables) {
+      if (each.containsKey(name)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  private int getVariableType(String name) {
+    for (Map<String, Integer> each : knownLocalVariables) {
+      Integer integer = each.get(name);
+      if (integer != null)
+        return integer;
+    }
+    return 0;
+  }
+
+  private String getFeatureName(Expression expression, String defaultValue) {
+    // TODO refactor AST. This is not a really straightforward!
+    String result = defaultValue;
+    List<?> childs = expression.getChilds();
+    if (childs != null && !childs.isEmpty()) {
+      Object object = childs.get(0);
+      if (object instanceof ASTListNode) {
+        List<?> childs2 = ((ASTListNode) object).getChilds();
+        if (childs2 != null && !childs2.isEmpty()) {
+          Object object2 = childs2.get(0);
+          if (object2 instanceof StringLiteral) {
+            StringLiteral sl = (StringLiteral) object2;
+            result = sl.getValue().replaceAll("\"", "");
+          }
+        }
+      }
+    }
+    return result;
+  }
+
+  private void initializePredefinedInformation() {
+
+    try {
+      typeSystemDescription = getTypeSystemOfScript();
+      IPath descriptorRootPath = RutaProjectUtils.getDescriptorRootPath(sourceModule
+              .getScriptProject().getProject());
+      IPath basicTSD = descriptorRootPath.append("BasicTypeSystem.xml");
+      importCompleteTypeSystem(basicTSD);
+    } catch (Exception e) {
+      RutaIdeUIPlugin.error(e);
+    }
+
+    typeDescriptionMap = new HashMap<String, TypeDescription>();
+    TypeDescription[] descriptions = typeSystemDescription.getTypes();
+    for (TypeDescription typeDescription : descriptions) {
+      String typeName = typeDescription.getName();
+      typeDescriptionMap.put(typeName, typeDescription);
+    }
+
+    featureDescriptionMap = new HashMap<String, Set<FeatureDescription>>();
+    for (TypeDescription typeDescription : descriptions) {
+      Set<FeatureDescription> allFeatures = getAllDeclaredFeatures(typeDescription,
+              typeDescriptionMap);
+      featureDescriptionMap.put(typeDescription.getName(), allFeatures);
+    }
+
+    List<String> uimaPredefTypes = Arrays.asList(new String[] { "uima.cas.Boolean",
+        "uima.cas.Byte", "uima.cas.Short", "uima.cas.Integer", "uima.cas.Long", "uima.cas.Float",
+        "uima.cas.Double", "uima.cas.String", "uima.cas.BooleanArray", "uima.cas.ByteArray",
+        "uima.cas.ShortArray", "uima.cas.IntegerArray", "uima.cas.LongArray",
+        "uima.cas.FloatArray", "uima.cas.DoubleArray", "uima.cas.StringArray", "uima.cas.FSArray",
+        "uima.cas.AnnotationBase", "uima.tcas.Annotation", "uima.tcas.DocumentAnnotation",
+        "uima.cas.FloatList", "uima.cas.IntegerList", "uima.cas.StringList", "uima.cas.FSList",
+        "uima.cas.EmptyFloatList", "uima.cas.EmptyIntegerList", "uima.cas.EmptyStringList",
+        "uima.cas.EmptyFSList", "uima.cas.NonEmptyFloatList", "uima.cas.NonEmptyIntegerList",
+        "uima.cas.NonEmptyStringList", "uima.cas.NonEmptyFSList" });
+    for (String longName : uimaPredefTypes) {
+      String shortName = getShortName(longName);
+      importType(longName, shortName);
+    }
+
+    this.finalTypes = new HashSet<String>();
+    Set<String> uimaFinalTypes = new HashSet<String>();
+    uimaFinalTypes.addAll(Arrays.asList(new String[] { "uima.cas.Boolean", "uima.cas.Byte",
+        "uima.cas.Short", "uima.cas.Integer", "uima.cas.Long", "uima.cas.Float", "uima.cas.Double",
+        "uima.cas.BooleanArray", "uima.cas.ByteArray", "uima.cas.ShortArray",
+        "uima.cas.IntegerArray", "uima.cas.LongArray", "uima.cas.FloatArray",
+        "uima.cas.DoubleArray", "uima.cas.StringArray", "uima.cas.FSArray" }));
+
+    for (String string : uimaFinalTypes) {
+      int indexOf = string.lastIndexOf('.');
+      finalTypes.add(string);
+      finalTypes.add(string.substring(indexOf + 1, string.length()));
+    }
+  }
+
+  private TypeSystemDescription importCompleteTypeSystem(IPath path) throws InvalidXMLException,
+          MalformedURLException, IOException, CoreException {
+    return importTypeSystem(path, null, null, null);
+  }
+
+  private void initializeExtensionInformation() {
+    conditionExtensions = new HashMap<String, IIDEConditionExtension>();
+    actionExtensions = new HashMap<String, IIDEActionExtension>();
+    numberFunctionExtensions = new HashMap<String, IIDENumberFunctionExtension>();
+    booleanFunctionExtensions = new HashMap<String, IIDEBooleanFunctionExtension>();
+    stringFunctionExtensions = new HashMap<String, IIDEStringFunctionExtension>();
+    typeFunctionExtensions = new HashMap<String, IIDETypeFunctionExtension>();
+    IIDEConditionExtension[] cextensions = RutaExtensionManager.getDefault()
+            .getIDEConditionExtensions();
+    for (IIDEConditionExtension each : cextensions) {
+      String[] knownExtensions = each.getKnownExtensions();
+      for (String string : knownExtensions) {
+        conditionExtensions.put(string, each);
+      }
+    }
+    IIDEActionExtension[] aextensions = RutaExtensionManager.getDefault().getIDEActionExtensions();
+    for (IIDEActionExtension each : aextensions) {
+      String[] knownExtensions = each.getKnownExtensions();
+      for (String string : knownExtensions) {
+        actionExtensions.put(string, each);
+      }
+    }
+    IIDENumberFunctionExtension[] nfextensions = RutaExtensionManager.getDefault()
+            .getIDENumberFunctionExtensions();
+    for (IIDENumberFunctionExtension each : nfextensions) {
+      String[] knownExtensions = each.getKnownExtensions();
+      for (String string : knownExtensions) {
+        numberFunctionExtensions.put(string, each);
+      }
+    }
+    IIDEBooleanFunctionExtension[] bfextensions = RutaExtensionManager.getDefault()
+            .getIDEBooleanFunctionExtensions();
+    for (IIDEBooleanFunctionExtension each : bfextensions) {
+      String[] knownExtensions = each.getKnownExtensions();
+      for (String string : knownExtensions) {
+        booleanFunctionExtensions.put(string, each);
+      }
+    }
+    IIDEStringFunctionExtension[] sfextensions = RutaExtensionManager.getDefault()
+            .getIDEStringFunctionExtensions();
+    for (IIDEStringFunctionExtension each : sfextensions) {
+      String[] knownExtensions = each.getKnownExtensions();
+      for (String string : knownExtensions) {
+        stringFunctionExtensions.put(string, each);
+      }
+    }
+    IIDETypeFunctionExtension[] tfextensions = RutaExtensionManager.getDefault()
+            .getIDETypeFunctionExtensions();
+    for (IIDETypeFunctionExtension each : tfextensions) {
+      String[] knownExtensions = each.getKnownExtensions();
+      for (String string : knownExtensions) {
+        typeFunctionExtensions.put(string, each);
+      }
+    }
+
+  }
+
+  private Set<FeatureDescription> getAllDeclaredFeatures(TypeDescription typeDescription,
+          Map<String, TypeDescription> typeMap) {
+    Set<FeatureDescription> result = new HashSet<FeatureDescription>();
+    if (typeDescription == null) {
+      return result;
+    }
+    FeatureDescription[] features = typeDescription.getFeatures();
+    if (features == null) {
+      return result;
+    }
+    result.addAll(Arrays.asList(features));
+    String supertypeName = typeDescription.getSupertypeName();
+    if (supertypeName != null) {
+      TypeDescription parent = typeMap.get(supertypeName);
+      result.addAll(getAllDeclaredFeatures(parent, typeMap));
+    }
+    return result;
+  }
+
+  private String isFeatureMatch(String text) {
+    for (String each : namespaces.keySet()) {
+      String t = checkFeatureMatch(text, each);
+      if (t != null) {
+        return t;
+      }
+    }
+    for (String each : namespaces.values()) {
+      String t = checkFeatureMatch(text, each);
+      if (t != null) {
+        return t;
+      }
+    }
+    return null;
+  }
+
+  private String checkFeatureMatch(String name, String type) {
+    if (name.startsWith(type)) {
+      boolean foundAll = true;
+      if (name.length() > type.length()) {
+        String tail = name.substring(type.length() + 1);
+        String[] split = tail.split("[.]");
+        String typeToCheck = type;
+        for (String feat : split) {
+          typeToCheck = checkFSFeatureOfType(feat, typeToCheck);
+          foundAll &= (typeToCheck != null);
+          if (!foundAll) {
+            return null;
+          }
+        }
+        return typeToCheck;
+      } else {
+        return type;
+      }
+    } else {
+      return null;
+    }
+  }
+
+  private String checkFSFeatureOfType(String featureName, String longTypeName) {
+    TypeDescription t = typeDescriptionMap.get(longTypeName);
+    if (t == null) {
+      return null;
+    }
+    FeatureDescription[] features = t.getFeatures();
+    for (FeatureDescription featureDescription : features) {
+      String name = featureDescription.getName();
+      String rangeTypeName = featureDescription.getRangeTypeName();
+      boolean isFS = isFeatureStructure(rangeTypeName);
+      if (name.equals(featureName) && isFS) {
+        return rangeTypeName;
+      }
+    }
+    return null;
+  }
+
+  private boolean isFeatureStructure(String rangeTypeName) {
+    if (rangeTypeName.equals("uima.tcas.Annotation") || rangeTypeName.equals("uima.cas.TOP")) {
+      return true;
+    }
+    TypeDescription type = typeDescriptionMap.get(rangeTypeName);
+    if (type == null) {
+      return false;
+    }
+    String supertypeName = type.getSupertypeName();
+    if (supertypeName != null) {
+      return isFeatureStructure(supertypeName);
+    }
+    return false;
+  }
+
+  private boolean checkTypeOfVariable(RutaVariableReference ref) {
+    Integer vt = getVariableType(ref.getName());
+    if (vt == null) {
+      IProblem problem = problemFactory.createUnknownVariableProblem(ref);
+      pr.reportProblem(problem);
+      return false;
+    } else {
+      int variableType = vt.intValue();
+      int requiredType = ref.getType();
+      // reject generic types
+      if ((requiredType & RutaTypeConstants.RUTA_TYPE_G) != 0) {
+        return true;
+      }
+      if ((variableType & requiredType) == 0) {
+        String errMsg = "Variable \"" + ref.getName() + "\" has type "
+                + RutaTypeConstants.typeStringOfInt.get(variableType) + ". But type "
+                + RutaTypeConstants.typeStringOfInt.get(requiredType) + " is required.";
+        IProblem problem = new RutaCheckerDefaultProblem(sourceModule.getElementName(), errMsg,
+                ref, linetracker.getLineNumberOfOffset(ref.sourceStart()));
+        pr.reportProblem(problem);
+        return false;
+      }
+    }
+    return true;
+  }
+
+  private boolean isVariableDeclared(RutaVariableReference ref) {
+    if (!knowsVariable(ref.getName())) {
+      // declared as type?
+      if (namespaces.keySet().contains(ref.getName())) {
+        String errMsg = "\"" + ref.getName() + "\" declared as a Type. Variable of type "
+                + RutaTypeConstants.typeStringOfInt.get(ref.getType()) + " required.";
+        IProblem problem = new RutaCheckerDefaultProblem(sourceModule.getElementName(), errMsg,
+                ref, linetracker.getLineNumberOfOffset(ref.sourceStart()));
+        pr.reportProblem(problem);
+        return false;
+      }
+      String errMsgHead = "Variable \"";
+      String errMsgTailDefault = " defined in this script or block!";
+
+      // not found
+      String errMsg = errMsgHead + ref.getName() + "\" not" + errMsgTailDefault;
+      IProblem problem = new RutaCheckerDefaultProblem(sourceModule.getElementName(), errMsg, ref,
+              linetracker.getLineNumberOfOffset(ref.sourceStart()));
+      pr.reportProblem(problem);
+      return false;
+    }
+    return true;
+  }
+
+  private String getShortName(String typeName) {
+    String[] nameSpace = typeName.split("[.]");
+    return nameSpace[nameSpace.length - 1];
+  }
+
+  private TypeSystemDescription getTypeSystemOfScript() throws InvalidXMLException, IOException,
+          CoreException {
+    IPath descriptorPath = RutaProjectUtils.getTypeSystemDescriptorPath(sourceModule.getResource()
+            .getLocation(), sourceModule.getScriptProject().getProject());
+    TypeSystemDescription typeSysDescr = null;
+    if (descriptorPath.toFile().exists()) {
+      typeSysDescr = UIMAFramework.getXMLParser().parseTypeSystemDescription(
+              new XMLInputSource(descriptorPath.toPortableString()));
+      ResourceManager resMgr = getResourceManager();
+      typeSysDescr.resolveImports(resMgr);
+    }
+    return typeSysDescr;
+  }
+
+}

Propchange: uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaChecker.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaChecker.java?rev=1565751&r1=1565750&r2=1565751&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaChecker.java (original)
+++ uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaChecker.java Fri Feb  7 18:27:08 2014
@@ -38,8 +38,9 @@ public class RutaChecker implements IBui
   public RutaChecker(IScriptProject project) {
     buildParticipants = new ArrayList<IBuildParticipant>();
     try {
-      buildParticipants.add(new RutaTypeChecker(project));
-      buildParticipants.add(new RutaVarRefChecker());
+      buildParticipants.add(new RutaLanguageChecker());
+//      buildParticipants.add(new RutaTypeChecker(project));
+//      buildParticipants.add(new RutaVarRefChecker());
       buildParticipants.add(new RutaEngineAndCallChecker(project));
       buildParticipants.add(new RutaRessourceChecker(project));
     } catch (CoreException e) {

Modified: uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerProblemFactory.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerProblemFactory.java?rev=1565751&r1=1565750&r2=1565751&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerProblemFactory.java (original)
+++ uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerProblemFactory.java Fri Feb  7 18:27:08 2014
@@ -19,6 +19,7 @@
 
 package org.apache.uima.ruta.ide.validator;
 
+import java.util.Collection;
 import java.util.List;
 
 import org.apache.commons.lang3.StringUtils;
@@ -191,6 +192,11 @@ public class RutaCheckerProblemFactory i
     return new RutaCheckerDefaultProblem(this.fileName, message, action, getLine(action));
   }
 
+  public IProblem createUnknownVariableProblem(RutaVariableReference ref) {
+    String message = "error: Variable \"" + ref.getName() + "\" is not defined.";
+    return new RutaCheckerDefaultProblem(this.fileName, message, ref, getLine(ref));
+  }
+  
   public IProblem createWrongNumberOfArgumentsProblem(String name, Expression element, int expected) {
     String message = "error: The element " + name + " expects " + expected + " arguments.";
     return new RutaCheckerDefaultProblem(this.fileName, message, element, getLine(element));
@@ -201,4 +207,13 @@ public class RutaCheckerProblemFactory i
     return new RutaCheckerDefaultProblem(this.fileName, message, f, getLine(f));
   }
 
+  public IProblem createAmbiguousShortName(RutaVariableReference ref, Collection<String> ambiguousTargets, ProblemSeverity error) {
+    StringBuilder message = new StringBuilder(ref.getName());
+    message.append(" is ambiguous, use one of the following instead : ");
+    for (String target : ambiguousTargets) {
+      message.append(target).append(' ');
+    }
+    return new RutaCheckerDefaultProblem(this.fileName, message.toString(), ref, getLine(ref));
+  }
+
 }

Modified: uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerUtils.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerUtils.java?rev=1565751&r1=1565750&r2=1565751&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerUtils.java (original)
+++ uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerUtils.java Fri Feb  7 18:27:08 2014
@@ -200,20 +200,21 @@ public class RutaCheckerUtils {
     return false;
   }
 
-  public static boolean checkScriptImport(String xmlFilePath, IScriptProject project) {
-    boolean result = false;
+  public static IFile checkScriptImport(String xmlFilePath, IScriptProject project) {
     List<IFolder> allDescriptorFolders;
     try {
       allDescriptorFolders = RutaProjectUtils.getAllScriptFolders(project);
     } catch (CoreException e) {
-      return false;
+      return null;
     }
     for (IFolder folder : allDescriptorFolders) {
       String fileExtended = xmlFilePath.replaceAll("[.]", "/") + RutaEngine.SCRIPT_FILE_EXTENSION;
       IFile iFile = RutaCheckerUtils.getFile(folder, fileExtended);
-      result |= iFile.exists();
+      if(iFile.exists()) {
+        return iFile;
+      }
     }
-    return result;
+    return null;
   }
 
   /**
@@ -267,19 +268,20 @@ public class RutaCheckerUtils {
     return getFile(folder, fileExtended);
   }
 
-  public static boolean checkTypeSystemImport(String localPath, IScriptProject project) {
-    boolean result = false;
+  public static IFile checkTypeSystemImport(String localPath, IScriptProject project) {
     List<IFolder> allDescriptorFolders;
     try {
       allDescriptorFolders = RutaProjectUtils.getAllDescriptorFolders(project.getProject());
     } catch (Exception e) {
-      return false;
+      return null;
     }
     for (IFolder folder : allDescriptorFolders) {
       String fileExtended = localPath.replaceAll("[.]", "/") + ".xml";
       IFile iFile = RutaCheckerUtils.getFile(folder, fileExtended);
-      result |= iFile.exists();
+      if(iFile.exists()) {
+        return iFile;
+      }
     }
-    return result;
+    return null;
   }
 }

Added: uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaLanguageChecker.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaLanguageChecker.java?rev=1565751&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaLanguageChecker.java (added)
+++ uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaLanguageChecker.java Fri Feb  7 18:27:08 2014
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.validator;
+
+import org.apache.uima.ruta.ide.RutaIdeUIPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.compiler.problem.IProblemReporter;
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.core.builder.IBuildContext;
+import org.eclipse.dltk.core.builder.IBuildParticipant;
+import org.eclipse.dltk.core.builder.IBuildParticipantExtension;
+import org.eclipse.dltk.core.builder.ISourceLineTracker;
+
+public class RutaLanguageChecker implements IBuildParticipant, IBuildParticipantExtension{
+  
+  public boolean beginBuild(int buildType) {
+    return true;
+  }
+
+  public void endBuild(IProgressMonitor monitor) {
+  }
+
+  public void build(IBuildContext context) throws CoreException {
+    Object mdObj = context.get(IBuildContext.ATTR_MODULE_DECLARATION);
+    if (!(mdObj instanceof ModuleDeclaration)) {
+      return;
+    }
+    ModuleDeclaration md = (ModuleDeclaration) mdObj;
+
+    IProblemReporter problemReporter = context.getProblemReporter();
+    ISourceModule smod = context.getSourceModule();
+    ISourceLineTracker linetracker = context.getLineTracker();
+    try {
+      ASTVisitor visitor = new LanguageCheckerVisitor(problemReporter, linetracker, smod);
+      md.traverse(visitor);
+    } catch (Exception e) {
+      RutaIdeUIPlugin.error(e);
+    }
+  }
+
+}

Propchange: uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaLanguageChecker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaTypeChecker.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaTypeChecker.java?rev=1565751&r1=1565750&r2=1565751&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaTypeChecker.java (original)
+++ uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaTypeChecker.java Fri Feb  7 18:27:08 2014
@@ -274,9 +274,9 @@ public class RutaTypeChecker implements 
           SimpleReference sRef = (SimpleReference) ((RutaImportStatement) s).getExpression();
           String localPath = sRef.getName();
           try {
-            boolean checkTypeSystemImport = RutaCheckerUtils.checkTypeSystemImport(localPath,
+            IFile checkTypeSystemImport = RutaCheckerUtils.checkTypeSystemImport(localPath,
                     project);
-            if (!checkTypeSystemImport) {
+            if (checkTypeSystemImport == null) {
               rep.reportProblem(problemFactory.createFileNotFoundProblem(sRef, localPath));
             }
             Set<String> importedTypes = importTypeSystem(localPath);
@@ -306,8 +306,8 @@ public class RutaTypeChecker implements 
 
           // HOTFIX Peter add also the imported types of the imported type system!
           try {
-            boolean checkScriptImport = RutaCheckerUtils.checkScriptImport(localpath, project);
-            if (!checkScriptImport) {
+            IFile checkScriptImport = RutaCheckerUtils.checkScriptImport(localpath, project);
+            if (checkScriptImport != null) {
               rep.reportProblem(problemFactory.createFileNotFoundProblem(sRef, localpath));
             }
             Set<String> importedTypes = importTypeSystem(localpath + "TypeSystem");

Modified: uima/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g?rev=1565751&r1=1565750&r2=1565751&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g (original)
+++ uima/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g Fri Feb  7 18:27:08 2014
@@ -330,13 +330,13 @@ importStatement returns [Statement stmt 
 	name = dottedComponentDeclaration 
 	{if(name != null) {stmt = StatementFactory.createImportEngine(name,im);addImportUimafitEngine(name);}}
 	 SEMI 
-	| ImportString type = dottedId2 (FromString ts = dottedComponentDeclaration)? (AsString alias = Identifier)? SEMI
+	| im = ImportString type = dottedId2 (FromString ts = dottedComponentDeclaration)? (AsString alias = Identifier)? SEMI
 	{stmt = StatementFactory.createImportType(im,type,ts,alias);addImportTypeSystem(ts);}
-	| ImportString STAR FromString ts = dottedComponentDeclaration SEMI
+	| im = ImportString STAR FromString ts = dottedComponentDeclaration SEMI
 	{stmt = StatementFactory.createImportTypeSystem(ts,im);addImportTypeSystem(ts);}
-	| ImportString PackageString pkg = dottedId2 (FromString ts = dottedComponentDeclaration)? (AsString alias = Identifier)? SEMI
+	| im = ImportString PackageString pkg = dottedId2 (FromString ts = dottedComponentDeclaration)? (AsString alias = Identifier)? SEMI
 	{stmt = StatementFactory.createImportPackage(im,pkg,ts,alias);addImportTypeSystem(ts);}
-	| ImportString PackageString STAR FromString ts = dottedComponentDeclaration (AsString alias = Identifier)? SEMI
+	| im = ImportString PackageString STAR FromString ts = dottedComponentDeclaration (AsString alias = Identifier)? SEMI
 	{stmt = StatementFactory.createImportAllPackagew(im,ts,alias);addImportTypeSystem(ts);}
 	
 	;

Modified: uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaSelectionEngine.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaSelectionEngine.java?rev=1565751&r1=1565750&r2=1565751&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaSelectionEngine.java (original)
+++ uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaSelectionEngine.java Fri Feb  7 18:27:08 2014
@@ -272,7 +272,6 @@ public class RutaSelectionEngine extends
 
     private void importTypesystem(Statement s) {
       SimpleReference sRef = (SimpleReference) ((RutaImportStatement) s).getExpression();
-      String sRefName = sRef.getName();
 
       // TODO not working yet
       // importTypesystem(sRefName);

Modified: uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/RutaBlock.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/RutaBlock.java?rev=1565751&r1=1565750&r2=1565751&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/RutaBlock.java (original)
+++ uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/RutaBlock.java Fri Feb  7 18:27:08 2014
@@ -19,12 +19,9 @@
 
 package org.apache.uima.ruta.ide.parser.ast;
 
-import java.util.List;
-
 import org.apache.commons.lang3.StringUtils;
 import org.eclipse.dltk.ast.ASTVisitor;
 import org.eclipse.dltk.ast.declarations.MethodDeclaration;
-import org.eclipse.dltk.ast.statements.Statement;
 
 public class RutaBlock extends MethodDeclaration {
 

Modified: uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/RutaSimpleStatement.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/RutaSimpleStatement.java?rev=1565751&r1=1565750&r2=1565751&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/RutaSimpleStatement.java (original)
+++ uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/RutaSimpleStatement.java Fri Feb  7 18:27:08 2014
@@ -46,7 +46,9 @@ public abstract class RutaSimpleStatemen
   @Override
   public void traverse(ASTVisitor visitor) throws Exception {
     if (visitor.visit(this)) {
-      expression.traverse(visitor);
+      if(expression != null) {
+        expression.traverse(visitor);
+      }
       visitor.endvisit(this);
     }
   }

Modified: uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/StatementFactory.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/StatementFactory.java?rev=1565751&r1=1565750&r2=1565751&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/StatementFactory.java (original)
+++ uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/StatementFactory.java Fri Feb  7 18:27:08 2014
@@ -20,7 +20,6 @@
 package org.apache.uima.ruta.ide.parser.ast;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
 import org.antlr.runtime.CommonToken;
@@ -74,7 +73,7 @@ public class StatementFactory extends Ab
     if(alias != null) {
       bounds = getBounds(importToken, alias);
     }
-    return new RutaImportTypesStatement(bounds[0], bounds[1], ts, null, alias, alias);
+    return new RutaImportTypesStatement(bounds[0], bounds[1], ts, null, null, alias);
   }
 
   public static Statement createImportPackage(Token importToken, Token pkg, ComponentDeclaration ts,