You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by jo...@apache.org on 2011/08/01 16:07:12 UTC

svn commit: r1152783 [4/12] - in /uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core: ./ META-INF/ bin/ schema/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/uima/ src/main/java/org/apache/u...

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/builder/TextMarkerSimpleBuilder.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/builder/TextMarkerSimpleBuilder.java?rev=1152783&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/builder/TextMarkerSimpleBuilder.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/builder/TextMarkerSimpleBuilder.java Mon Aug  1 14:06:27 2011
@@ -0,0 +1,427 @@
+package org.apache.uima.tm.dltk.internal.core.builder;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+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 org.apache.uima.ResourceSpecifierFactory;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.metadata.Capability;
+import org.apache.uima.resource.metadata.ConfigurationParameterSettings;
+import org.apache.uima.resource.metadata.FsIndexDescription;
+import org.apache.uima.resource.metadata.Import;
+import org.apache.uima.resource.metadata.TypeDescription;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.resource.metadata.impl.Import_impl;
+import org.apache.uima.tm.textmarker.engine.TextMarkerEngine;
+import org.apache.uima.util.CasCreationUtils;
+import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.XMLInputSource;
+import org.apache.uima.util.XMLSerializer;
+import org.apache.uima.util.XMLizable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+
+public class TextMarkerSimpleBuilder {
+
+  private static ResourceSpecifierFactory uimaFactory = UIMAFramework.getResourceSpecifierFactory();
+
+  private TypeSystemDescription typeSystemDescription;
+
+  private AnalysisEngineDescription analysisEngineDescription;
+
+  private final String defaultTypeSystem;
+
+  public TextMarkerSimpleBuilder(String defaultTypeSystem, String defaultEngine)
+          throws InvalidXMLException, IOException {
+    super();
+    this.defaultTypeSystem = defaultTypeSystem;
+    initialize(defaultEngine);
+  }
+
+  private void initialize(String defaultEngine) throws InvalidXMLException, IOException {
+    typeSystemDescription = uimaFactory.createTypeSystemDescription();
+    analysisEngineDescription = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(
+            new XMLInputSource(new File(defaultEngine)));
+  }
+
+  public void build(DescriptorManager desc, String typeSystemOutput, String engineOutput,
+          TextMarkerBuildOptions option, String mainScript, String[] scriptPaths,
+          String[] enginePaths) throws SAXException, TextMarkerBuildException, InvalidXMLException,
+          IOException, ResourceInitializationException {
+    Map<String, String> typeNameMap = new HashMap<String, String>();
+    Capability capability = uimaFactory.createCapability();
+    // String defaultTypeSystem2 = defaultTypeSystem.replaceAll("/", "\\\\");
+    File defaultTypeSystemFile = new File(defaultTypeSystem);
+    if (!defaultTypeSystemFile.exists()) {
+      System.out.println("Does not exist: " + defaultTypeSystemFile.getName());
+    }
+    TypeSystemDescription initialTypeSystem = UIMAFramework.getXMLParser()
+            .parseTypeSystemDescription(new XMLInputSource(defaultTypeSystemFile));
+    CAS cas = CasCreationUtils.createCas(initialTypeSystem, null, new FsIndexDescription[0]);
+    fillTypeNameMap(typeNameMap, cas.getTypeSystem());
+    cas.release();
+    List<Import> importList = new ArrayList<Import>();
+    Import_impl import_impl = new Import_impl();
+    if (option.isImportByName()) {
+      String name = initialTypeSystem.getName();
+      import_impl.setName(name);
+    } else if (option.isResolveImports()) {
+      String absoluteLocation = initialTypeSystem.getSourceUrlString();
+      import_impl.setLocation(absoluteLocation);
+    } else {
+      String relativeLocation = getRelativeLocation(defaultTypeSystemFile.getAbsolutePath(),
+              typeSystemOutput);
+      import_impl.setLocation(relativeLocation);
+    }
+    importList.add(import_impl);
+    for (String eachName : desc.getImportedTypeSystems()) {
+      String locate = TextMarkerEngine.locate(eachName, enginePaths, ".xml");
+      File file = new File(locate);
+      TypeSystemDescription each = getTypeSystemDescriptor(file, option);
+      if (each != null) {
+        fillTypeNameMap(typeNameMap, each);
+        import_impl = new Import_impl();
+        if (option.isImportByName()) {
+          import_impl.setName(eachName);
+        } else if (option.isResolveImports()) {
+          String absoluteLocation = each.getSourceUrlString();
+          import_impl.setLocation(absoluteLocation);
+        } else {
+          String relativeLocation = getRelativeLocation(file.getAbsolutePath(), typeSystemOutput);
+          import_impl.setLocation(relativeLocation);
+        }
+        importList.add(import_impl);
+      } else {
+        throw new FileNotFoundException("Build process can't find " + eachName + " in "
+                + mainScript);
+      }
+    }
+    for (String eachName : desc.getImportedScripts()) {
+      String locate = TextMarkerEngine.locate(eachName, enginePaths, "TypeSystem.xml");
+      File file = new File(locate);
+      TypeSystemDescription each = getTypeSystemDescriptor(file, option);
+      if (each != null) {
+        fillTypeNameMap(typeNameMap, each);
+        import_impl = new Import_impl();
+        if (option.isImportByName()) {
+          import_impl.setName(eachName + "TypeSystem");
+        } else if (option.isResolveImports()) {
+          String absoluteLocation = each.getSourceUrlString();
+          import_impl.setLocation(absoluteLocation);
+        } else {
+          String relativeLocation = getRelativeLocation(file.getAbsolutePath(), typeSystemOutput);
+          import_impl.setLocation(relativeLocation);
+        }
+        importList.add(import_impl);
+      } else {
+        throw new FileNotFoundException("Build process can't find " + eachName + " in "
+                + mainScript);
+      }
+    }
+
+    Import[] newImports = importList.toArray(new Import[0]);
+    typeSystemDescription.setImports(newImports);
+    if (option.isResolveImports()) {
+      try {
+        typeSystemDescription.resolveImports();
+      } catch (InvalidXMLException e) {
+        throw new TextMarkerBuildException("Failed to resolve imported Type Systems", e);
+      }
+    }
+
+    // TODO hotfixes: where do I get the final types??
+    Set<String> finalTypes = new HashSet<String>();
+    finalTypes.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" }));
+
+    int typeIndex = 0;
+    for (String eachType : desc.getTypeShortNames()) {
+      StringTriple typeTriple = desc.getTypeTriples().get(typeIndex);
+      typeTriple = resolveType(typeTriple, typeNameMap, mainScript);
+      if (typeSystemDescription.getType(typeTriple.getName()) != null) {
+        continue;
+      }
+      if (!finalTypes.contains(typeTriple.getParent())) {
+        TypeDescription newType = typeSystemDescription.addType(typeTriple.getName(), typeTriple
+                .getDescription(), typeTriple.getParent());
+        capability.addInputType(typeTriple.getName(), false);
+        capability.addOutputType(typeTriple.getName(), false);
+        Collection<StringTriple> collection = desc.getFeatures().get(eachType);
+        if (collection != null) {
+          for (StringTriple eachFeature : collection) {
+            eachFeature = resolveFeature(eachFeature, typeNameMap);
+            newType.addFeature(eachFeature.getName(), eachFeature.getDescription(), eachFeature
+                    .getParent());
+            // capability.addInputFeature(eachFeature.getName());
+            // capability.addOutputFeature(eachFeature.getName());
+          }
+        }
+      }
+      typeIndex++;
+    }
+
+    Set<String> names = new HashSet<String>();
+    List<TypeDescription> types = new ArrayList<TypeDescription>();
+    for (TypeDescription each : typeSystemDescription.getTypes()) {
+      String name = each.getName();
+      if (!names.contains(name)) {
+        names.add(name);
+        types.add(each);
+      }
+    }
+
+    typeSystemDescription.setTypes(types.toArray(new TypeDescription[0]));
+    File typeSystemFile = getFile(typeSystemOutput);
+    typeSystemDescription.setName(mainScript + "TypeSystem");
+    typeSystemDescription.setSourceUrl(typeSystemFile.toURI().toURL());
+    TypeSystemDescription aets = uimaFactory.createTypeSystemDescription();
+    import_impl = new Import_impl();
+    if (option.isImportByName()) {
+      import_impl.setName(typeSystemDescription.getName());
+    } else {
+      String relativeLocation = getRelativeLocation(engineOutput, typeSystemOutput);
+      import_impl.setLocation(relativeLocation);
+    }
+
+    File engineFile = configureEngine(desc, engineOutput, option, mainScript, scriptPaths,
+            enginePaths, capability, import_impl, aets);
+
+    toFile(typeSystemDescription, typeSystemFile);
+    toFile(analysisEngineDescription, engineFile);
+  }
+
+  private void fillTypeNameMap(Map<String, String> typeNameMap, TypeSystem typeSystem) {
+    Iterator<Type> typeIterator = typeSystem.getTypeIterator();
+    while (typeIterator.hasNext()) {
+      Type type = (Type) typeIterator.next();
+      String shortName = type.getShortName();
+      String name = type.getName();
+      typeNameMap.put(shortName, name);
+    }
+  }
+
+  private boolean fillTypeNameMap(Map<String, String> typeNameMap, TypeSystemDescription desc) {
+    boolean contained = false;
+    for (TypeDescription each : desc.getTypes()) {
+      String name = each.getName();
+      int lastIndexOf = name.lastIndexOf(".");
+      String shortName = name.substring(lastIndexOf + 1, name.length());
+      typeNameMap.put(shortName, name);
+    }
+    return contained;
+  }
+
+  private StringTriple resolveFeature(StringTriple eachFeature, Map<String, String> types) {
+    String parent = eachFeature.getParent();
+    String name = eachFeature.getName();
+    parent = translate(parent);
+    if (parent.indexOf(".") == -1 && types.containsKey(parent)) {
+      parent = types.get(parent);
+    }
+    return new StringTriple(name, eachFeature.getDescription(), parent);
+  }
+
+  private StringTriple resolveType(StringTriple typeTriple, Map<String, String> types,
+          String packageName) {
+    String parent = typeTriple.getParent();
+    String name = typeTriple.getName();
+    if (parent == null) {
+      parent = "uima.tcas.Annotation";
+    }
+    parent = translate(parent);
+    name = translate(name);
+    if (parent.indexOf(".") == -1 && types.containsKey(parent)) {
+      parent = types.get(parent);
+    }
+    if (name.indexOf(".") == -1) {
+      if (types.containsKey(name)) {
+        name = types.get(name);
+      } else {
+        name = packageName + "." + name;
+      }
+    }
+    int lastIndexOf = name.lastIndexOf(".");
+    String shortName = name.substring(lastIndexOf + 1, name.length());
+    types.put(shortName, name);
+    return new StringTriple(name, typeTriple.getDescription(), parent);
+  }
+
+  private String translate(String name) {
+    if (name == null) {
+      return null;
+    }
+    if (name.equals("Annotation")) {
+      return "uima.tcas.Annotation";
+    } else if (name.equals("STRING")) {
+      return "uima.cas.String";
+    } else if (name.equals("INT")) {
+      return "uima.cas.Integer";
+    } else if (name.equals("DOUBLE")) {
+      return "uima.cas.Double";
+    } else if (name.equals("BOOLEAN")) {
+      return "uima.cas.Boolean";
+    } else if (name.equals("TYPE")) {
+      return "uima.cas.String";
+    }
+    return name;
+  }
+
+  private File configureEngine(DescriptorManager desc, String engineOutput,
+          TextMarkerBuildOptions option, String mainScript, String[] scriptPaths,
+          String[] descriptorPaths, Capability capability, Import_impl import_impl,
+          TypeSystemDescription aets) throws MalformedURLException {
+    aets.setImports(new Import[] { import_impl });
+    analysisEngineDescription.getAnalysisEngineMetaData().setTypeSystem(aets);
+    File file = getFile(engineOutput);
+    analysisEngineDescription.setSourceUrl(file.toURI().toURL());
+
+    if (!desc.getTypeShortNames().isEmpty()) {
+      Capability[] capabilities = analysisEngineDescription.getAnalysisEngineMetaData()
+              .getCapabilities();
+      Capability[] newArray = new Capability[capabilities.length + 1];
+      System.arraycopy(capabilities, 0, newArray, 0, capabilities.length);
+      newArray[capabilities.length] = capability;
+      analysisEngineDescription.getAnalysisEngineMetaData().setCapabilities(newArray);
+    }
+
+    analysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings()
+            .setParameterValue(TextMarkerEngine.MAIN_SCRIPT, mainScript);
+    analysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings()
+            .setParameterValue(TextMarkerEngine.SCRIPT_PATHS, scriptPaths);
+    analysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings()
+            .setParameterValue(TextMarkerEngine.DESCRIPTOR_PATHS, descriptorPaths);
+    String[] parameterValue = (String[]) analysisEngineDescription.getAnalysisEngineMetaData()
+            .getConfigurationParameterSettings().getParameterValue(TextMarkerEngine.RESOURCE_PATHS);
+    Set<String> resourceLocations = new HashSet<String>();
+
+    if (parameterValue != null && parameterValue.length != 0) {
+      resourceLocations.addAll(Arrays.asList(parameterValue));
+    }
+    for (String string : descriptorPaths) {
+      File descDir = new File(string);
+      File defaultResourceDir = new File(descDir.getParent(), TextMarkerProjectUtils
+              .getDefaultResourcesLocation());
+      resourceLocations.add(defaultResourceDir.getAbsolutePath());
+    }
+    analysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings()
+            .setParameterValue(TextMarkerEngine.RESOURCE_PATHS,
+                    resourceLocations.toArray(new String[0]));
+
+    String[] additionalScriptsArray = desc.getImportedScripts().toArray(new String[] {});
+    analysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings()
+            .setParameterValue(TextMarkerEngine.ADDITIONAL_SCRIPTS, additionalScriptsArray);
+
+    String[] additionalEnginesArray = desc.getImportedEngines().toArray(new String[] {});
+    analysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings()
+            .setParameterValue(TextMarkerEngine.ADDITIONAL_ENGINES, additionalEnginesArray);
+
+    String styleMapLocation = getStyleMapLocation(mainScript, engineOutput);
+    analysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings()
+            .setParameterValue(TextMarkerEngine.STYLE_MAP, styleMapLocation);
+    analysisEngineDescription.getAnalysisEngineMetaData().setTypeSystem(typeSystemDescription);
+
+    configureExtensions(option);
+    return file;
+  }
+
+  private String getRelativeLocation(String target, String base) {
+    IPath targetPath = Path.fromOSString(target);
+    IPath basePath = Path.fromPortableString(base);
+    IPath result = targetPath.makeRelativeTo(basePath);
+    // TODO remove the first part! Should be correct in first place!
+    result = result.removeFirstSegments(1);
+    return result.toPortableString();
+  }
+
+  private void configureExtensions(TextMarkerBuildOptions options) {
+    ConfigurationParameterSettings configurationParameterSettings = analysisEngineDescription
+            .getAnalysisEngineMetaData().getConfigurationParameterSettings();
+
+    List<String> languageExtensions = options.getLanguage();
+
+    configurationParameterSettings.setParameterValue(TextMarkerEngine.ADDITIONAL_EXTENSIONS,
+            languageExtensions.toArray(new String[0]));
+    configurationParameterSettings.setParameterValue(TextMarkerEngine.ADDITIONAL_ENGINE_LOADERS,
+            options.getEngines().toArray(new String[0]));
+  }
+
+  private String getPackage(String eachName) {
+    if (eachName.endsWith(".tm")) {
+      int indexOf = eachName.lastIndexOf(".tm");
+      eachName = eachName.substring(0, indexOf);
+    }
+    int lastIndexOf = eachName.lastIndexOf(".");
+    if (lastIndexOf != -1) {
+      eachName = eachName.substring(0, lastIndexOf);
+      return eachName;
+    }
+    return "";
+  }
+
+  private String getModuleName(String eachName) {
+    if (eachName.endsWith(".tm")) {
+      int indexOf = eachName.lastIndexOf(".tm");
+      eachName = eachName.substring(0, indexOf);
+    }
+    int lastIndexOf = eachName.lastIndexOf(".");
+    if (lastIndexOf != -1) {
+      eachName = eachName.substring(lastIndexOf + 1, eachName.length());
+    }
+    return eachName;
+  }
+
+  private TypeSystemDescription getTypeSystemDescriptor(File file, TextMarkerBuildOptions option)
+          throws InvalidXMLException, IOException {
+    TypeSystemDescription tsdesc = UIMAFramework.getXMLParser().parseTypeSystemDescription(
+            new XMLInputSource(file));
+    if (option.isResolveImports()) {
+      tsdesc.resolveImports();
+    }
+    return tsdesc;
+  }
+
+  private String getStyleMapLocation(String scriptLocation, String engineDescriptorOutputLocation) {
+    String module = getModuleName(scriptLocation);
+    String pack = getPackage(scriptLocation);
+    return pack + "." + module + "StyleMap";
+  }
+
+  private File getFile(String location) {
+    return new File(location);
+  }
+
+  private void toFile(XMLizable desc, File destination) throws SAXException, FileNotFoundException {
+    destination.getParentFile().mkdirs();
+    OutputStream out = new FileOutputStream(destination);
+    XMLSerializer sax = new XMLSerializer(out);
+    ContentHandler ch = sax.getContentHandler();
+    ch.startDocument();
+    desc.toXML(ch);
+    ch.endDocument();
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/builder/TextMarkerSimpleBuilder.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/builder/TextMarkerSimpleBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TMAutoCompletionToolkit.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TMAutoCompletionToolkit.java?rev=1152783&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TMAutoCompletionToolkit.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TMAutoCompletionToolkit.java Mon Aug  1 14:06:27 2011
@@ -0,0 +1,81 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist;
+
+public class TMAutoCompletionToolkit {
+
+  private int wordOffset;
+
+  private int currentOffset;
+
+  private int relativeReplacementStart;
+
+  private String wordPrefix;
+
+  public TMAutoCompletionToolkit(String text, int offset) {
+    this.currentOffset = offset;
+    wordOffset = getWordOffset(text, offset) + 1;
+    wordPrefix = text.substring(wordOffset, offset);
+    relativeReplacementStart = offset - wordOffset;
+
+  }
+
+  private int getWordOffset(String text, int offset) {
+    for (int i = offset - 1; i > 0; i--) {
+      switch (text.charAt(i)) {
+        case ' ': {
+          return i;
+        }
+        case '\n': {
+          return i;
+        }
+        case '\r': {
+          return i;
+        }
+        case '\t': {
+          return i;
+        }
+        case '[': {
+          return i;
+        }
+        case ']': {
+          return i;
+        }
+        case '(': {
+          return i;
+        }
+        case ')': {
+          return i;
+        }
+        case '{': {
+          return i;
+        }
+        case '}': {
+          return i;
+        }
+        case ',': {
+          return i;
+        }
+        case ';': {
+          return i;
+        }
+      }
+    }
+    return -1;
+  }
+
+  public int getWordOffset() {
+    return this.wordOffset;
+  }
+
+  public int getCurrentOffset() {
+    return this.currentOffset;
+  }
+
+  public int getRelativeReplacementStart() {
+    return relativeReplacementStart;
+  }
+
+  public String getWordPrefix() {
+    return wordPrefix;
+  }
+
+}
\ No newline at end of file

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TMAutoCompletionToolkit.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TMAutoCompletionToolkit.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerASTUtil.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerASTUtil.java?rev=1152783&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerASTUtil.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerASTUtil.java Mon Aug  1 14:06:27 2011
@@ -0,0 +1,97 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.tm.dltk.internal.core.parser.TextMarkerParseUtils;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.declarations.MethodDeclaration;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.ast.declarations.TypeDeclaration;
+import org.eclipse.dltk.ast.expressions.Expression;
+import org.eclipse.dltk.ast.statements.Block;
+import org.eclipse.dltk.core.DLTKCore;
+
+
+public class TextMarkerASTUtil {
+  public static List getStatements(ASTNode node) {
+    if (node instanceof ModuleDeclaration) {
+      return ((ModuleDeclaration) node).getStatements();
+    } else if (node instanceof TypeDeclaration) {
+      return ((TypeDeclaration) node).getStatements();
+    } else if (node instanceof MethodDeclaration) {
+      return ((MethodDeclaration) node).getStatements();
+    } else if (node instanceof Block) {
+      return ((Block) node).getStatements();
+    } else {
+      final List innerBlockStatements = new ArrayList();
+      // Lets traverse to see inner blocks.
+      ASTVisitor visitor = new ASTVisitor() {
+        @Override
+        public boolean visit(Expression s) throws Exception {
+          if (s instanceof Block) {
+            List tStatements = ((Block) s).getStatements();
+            innerBlockStatements.addAll(tStatements);
+          }
+          return false;
+        }
+
+        @Override
+        public boolean visit(MethodDeclaration s) throws Exception {
+          return false;
+        }
+
+        @Override
+        public boolean visit(TypeDeclaration s) throws Exception {
+          return false;
+        }
+      };
+      try {
+        node.traverse(visitor);
+      } catch (Exception e) {
+        e.printStackTrace();
+      }
+      return innerBlockStatements;
+    }
+    // return null;
+  }
+
+  /**
+   * We need to extend all statements to end of lines or to begining of next statement. This is
+   * needed to for correct completion in statements. Such as variable completion and so on.
+   */
+  public static void extendStatements(ASTNode node, String content) {
+    List statements = getStatements(node);
+
+    if (statements != null) {
+      int len = statements.size();
+      for (int i = 0; i < len; ++i) {
+        ASTNode nde = (ASTNode) statements.get(i);
+
+        extendStatement(nde, content);
+        extendStatements(nde, content);
+      }
+    }
+  }
+
+  public static void extendStatement(ASTNode node, String content) {
+    int newValueStart = startLineOrSymbol(node, content);
+    int newValueEnd = endLineOrSymbol(node, content);
+    if (DLTKCore.DEBUG_COMPLETION) {
+      if (node.sourceEnd() != newValueEnd || node.sourceStart() != newValueStart) {
+        // TODO
+      }
+    }
+    node.setStart(newValueStart);
+    node.setEnd(newValueEnd);
+  }
+
+  public static int endLineOrSymbol(ASTNode node, String content) {
+    return TextMarkerParseUtils.endLineOrSymbol(node.sourceEnd(), content);
+  }
+
+  public static int startLineOrSymbol(ASTNode node, String content) {
+    return TextMarkerParseUtils.startLineOrSymbol(node.sourceStart(), content);
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerASTUtil.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerASTUtil.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerAssistParser.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerAssistParser.java?rev=1152783&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerAssistParser.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerAssistParser.java Mon Aug  1 14:06:27 2011
@@ -0,0 +1,95 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.tm.dltk.core.TextMarkerNature;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.ast.parser.ISourceParser;
+import org.eclipse.dltk.codeassist.IAssistParser;
+import org.eclipse.dltk.compiler.env.ISourceModule;
+import org.eclipse.dltk.core.DLTKLanguageManager;
+
+
+public abstract class TextMarkerAssistParser implements IAssistParser {
+  public static final int MODULE = 0;// ITextMarkerKeywords.MODULE;
+
+  public static final int NAMESPACE = 1;// ITextMarkerKeywords.NAMESPACE;
+
+  public static final int FUNCTION = 2;// ITextMarkerKeywords.FUNCTION;
+
+  public static final int EXEC_EXPRESSION = 3;// ITextMarkerKeywords.EXEC_EXPRESSION;
+
+  protected ISourceParser parser = null;
+
+  protected ModuleDeclaration module;
+
+  protected ASTNode assistNodeParent = null;
+
+  public TextMarkerAssistParser() {
+    // try {
+    this.parser = DLTKLanguageManager.getSourceParser(TextMarkerNature.NATURE_ID);
+    // } catch (CoreException e) {
+    // if (DLTKCore.DEBUG) {
+    // e.printStackTrace();
+    // }
+    // }
+  }
+
+  public ASTNode getAssistNodeParent() {
+    return assistNodeParent;
+  }
+
+  protected void findElementsTo(List statements, ASTNode node, List elements) {
+    if (statements == null) {
+      return;
+    }
+    Iterator i = statements.iterator();
+    while (i.hasNext()) {
+      ASTNode n = (ASTNode) i.next();
+      if (n.equals(node)) {
+        elements.add(n);
+        return;
+      }
+      if (n.sourceStart() <= node.sourceStart() && node.sourceEnd() <= n.sourceEnd()) {
+        elements.add(n);
+        findElementsTo(TextMarkerASTUtil.getStatements(n), node, elements);
+        return;
+      }
+    }
+
+  }
+
+  protected List findLevelsTo(ASTNode astNodeParent) {
+    List elements = new ArrayList();
+    if (this.module != null || astNodeParent instanceof ModuleDeclaration) {
+      if (this.module == null) {
+        this.module = (ModuleDeclaration) astNodeParent;
+      }
+      elements.add(this.module);
+      findElementsTo(TextMarkerASTUtil.getStatements(this.module), astNodeParent, elements);
+    }
+    return elements;
+  }
+
+  public void setSource(ModuleDeclaration unit) {
+    this.module = unit;
+  }
+
+  public ModuleDeclaration parse(ISourceModule sourceUnit) {
+    module = this.parser.parse(sourceUnit.getFileName(), sourceUnit.getSourceContents()
+            .toCharArray(), null);
+    module.rebuild();
+
+    // TextMarkerASTUtil.extendStatements(module, sourceUnit
+    // .getSourceContents());
+
+    return module;
+  }
+
+  public ModuleDeclaration getModule() {
+    return this.module;
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerAssistParser.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerAssistParser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerCompletionEngine.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerCompletionEngine.java?rev=1152783&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerCompletionEngine.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerCompletionEngine.java Mon Aug  1 14:06:27 2011
@@ -0,0 +1,612 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.resource.ResourceManager;
+import org.apache.uima.resource.metadata.TypeDescription;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.tm.dltk.core.ITextMarkerKeywords;
+import org.apache.uima.tm.dltk.core.TextMarkerKeywordsManager;
+import org.apache.uima.tm.dltk.core.extensions.ICompletionExtension;
+import org.apache.uima.tm.dltk.internal.core.TextMarkerExtensionManager;
+import org.apache.uima.tm.dltk.internal.core.builder.TextMarkerProjectUtils;
+import org.apache.uima.tm.dltk.internal.core.codeassist.completion.TextMarkerCompletionParser;
+import org.apache.uima.tm.dltk.internal.core.parser.TextMarkerParseUtils;
+import org.apache.uima.tm.dltk.parser.ast.ComponentDeclaration;
+import org.apache.uima.tm.dltk.parser.ast.ComponentReference;
+import org.apache.uima.tm.dltk.parser.ast.TMTypeConstants;
+import org.apache.uima.tm.dltk.parser.ast.TextMarkerModuleDeclaration;
+import org.apache.uima.tm.dltk.parser.ast.actions.TextMarkerAction;
+import org.apache.uima.tm.dltk.parser.ast.conditions.TextMarkerCondition;
+import org.apache.uima.tm.dltk.parser.ast.expressions.TextMarkerVariableReference;
+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.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.codeassist.IAssistParser;
+import org.eclipse.dltk.codeassist.RelevanceConstants;
+import org.eclipse.dltk.codeassist.ScriptCompletionEngine;
+import org.eclipse.dltk.compiler.CharOperation;
+import org.eclipse.dltk.compiler.env.ISourceModule;
+import org.eclipse.dltk.core.CompletionProposal;
+import org.eclipse.dltk.core.IField;
+import org.eclipse.dltk.core.IMethod;
+import org.eclipse.dltk.core.IModelElement;
+import org.eclipse.dltk.core.IType;
+import org.eclipse.dltk.core.ModelException;
+import org.eclipse.dltk.internal.core.SourceField;
+import org.eclipse.dltk.internal.core.SourceMethod;
+
+
+public class TextMarkerCompletionEngine extends ScriptCompletionEngine {
+
+  protected TextMarkerCompletionParser parser;
+
+  protected org.eclipse.dltk.core.ISourceModule sourceModule;
+
+  protected final static boolean TRACE_COMPLETION_TIME = false;
+
+  private ICompletionExtension[] extensions;
+
+  public TextMarkerCompletionEngine() {
+    extensions = TextMarkerExtensionManager.getDefault().getCompletionExtensions();
+    this.parser = new TextMarkerCompletionParser(extensions);
+  }
+
+  @Override
+  protected int getEndOfEmptyToken() {
+    return actualCompletionPosition;
+  }
+
+  @Override
+  protected String processFieldName(IField field, String token) {
+    return TextMarkerParseUtils.processFieldName(field, token);
+  }
+
+  @Override
+  protected String processMethodName(IMethod method, String token) {
+    return TextMarkerParseUtils.processMethodName(method, token);
+  }
+
+  @Override
+  protected String processTypeName(IType type, String token) {
+    return TextMarkerParseUtils.processTypeName(type, token);
+  }
+
+  @Override
+  public IAssistParser getParser() {
+    return parser;
+  }
+
+  public void complete(ISourceModule cu, int position, int i) {
+    this.sourceModule = (org.eclipse.dltk.core.ISourceModule) cu.getModelElement();
+    this.actualCompletionPosition = position;
+    this.offset = i;
+    this.requestor.beginReporting();
+    String content = cu.getSourceContents();
+    if (position < 0 || position > content.length()) {
+      return;
+    }
+
+    TMAutoCompletionToolkit tk = new TMAutoCompletionToolkit(content, position);
+
+    String startPart = tk.getWordPrefix();
+    this.setSourceRange(position - startPart.length(), position);
+
+    // 090813:
+    TextMarkerModuleDeclaration parsed = (TextMarkerModuleDeclaration) this.parser.parse(cu);
+
+    // types = getShortNames(types);
+
+    ASTNode node;
+    if (parsed != null) {
+      try {
+        TextMarkerReferenceVisitor referenceVisitor = new TextMarkerReferenceVisitor(
+                actualCompletionPosition);
+        parsed.traverse(referenceVisitor);
+        node = referenceVisitor.getResult();
+        if (node == null) {
+          doCompletionOnEmptyStatement(cu, position, i);
+          doCompletionOnDeclaration(cu, startPart);
+        } else if (node instanceof TextMarkerVariableReference) {
+          int type = ((TextMarkerVariableReference) node).getType();
+          doCompletionOnVarRef(cu, parsed, startPart, type, ((TextMarkerVariableReference) node)
+                  .getName());
+          // TODO: only if first rule element
+          doCompletionOnDeclaration(cu, startPart);
+        } else if (node instanceof ComponentDeclaration) {
+          doCompletionOnComponentDeclaration(cu, parsed, startPart, ((ComponentDeclaration) node)
+                  .getType(), startPart);
+        } else if (node instanceof ComponentReference) {
+          doCompletionOnComponentReference(cu, parsed, startPart, ((ComponentReference) node)
+                  .getType(), startPart);
+        } else if (node instanceof TextMarkerAction) {
+          doCompletionOnAction(cu, parsed, startPart, TMTypeConstants.TM_TYPE_A, startPart);
+        } else if (node instanceof TextMarkerCondition) {
+          doCompletionOnCondition(cu, parsed, startPart, TMTypeConstants.TM_TYPE_C, startPart);
+        }
+        // if(requestor.)
+        // doCompletionOnKeyword(position, i, startPart);
+
+        // }
+      } catch (Exception e) {
+        System.out.println("no completion node found");
+        System.out.println("");
+      } finally {
+        this.requestor.endReporting();
+      }
+    }
+  }
+
+  private void doCompletionOnComponentReference(ISourceModule cu,
+          TextMarkerModuleDeclaration parsed, String startPart, int type, String complString) {
+    Collection<String> importedEngines = parsed.descriptorInfo.getImportedEngines();
+    for (String string : importedEngines) {
+      if (string.startsWith(complString) || removeLowerCase(string).startsWith(complString)) {
+        addProposal(complString, string, CompletionProposal.PACKAGE_REF);
+      }
+    }
+    Collection<String> importedScripts = parsed.descriptorInfo.getImportedScripts();
+    for (String each : importedScripts) {
+      String[] split = each.split("\\.");
+      String string = split[split.length - 1];
+      if (string.startsWith(complString) || removeLowerCase(string).startsWith(complString)) {
+        addProposal(complString, string, CompletionProposal.PACKAGE_REF);
+      }
+    }
+    List<IMethod> blocks = new ArrayList<IMethod>();
+    try {
+      IModelElement[] children = sourceModule.getChildren();
+      for (IModelElement iModelElement : children) {
+        if (iModelElement instanceof SourceMethod) {
+          collectBlocks((SourceMethod) iModelElement, blocks);
+        }
+      }
+    } catch (ModelException e) {
+    }
+    for (IMethod m : blocks) {
+      String string = m.getElementName();
+      if (string.startsWith(complString) || removeLowerCase(string).startsWith(complString)) {
+        addProposal(complString, string, CompletionProposal.PACKAGE_REF);
+      }
+    }
+  }
+
+  private void doCompletionOnComponentDeclaration(ISourceModule cu,
+          TextMarkerModuleDeclaration parsed, String startPart, int type, String complString)
+          throws CoreException {
+    if (type == ComponentDeclaration.SCRIPT) {
+      List<IFolder> scriptFolders = TextMarkerProjectUtils.getAllScriptFolders(sourceModule
+              .getScriptProject());
+
+      List<String> scripts = new ArrayList<String>();
+      for (IFolder folder : scriptFolders) {
+        try {
+          scripts.addAll(collectScripts(folder, ""));
+        } catch (CoreException e) {
+        }
+      }
+      for (String string : scripts) {
+        if (string.startsWith(complString) || removeLowerCase(string).startsWith(complString)) {
+          addProposal(complString, string, CompletionProposal.PACKAGE_REF);
+        }
+      }
+    } else if (type == ComponentDeclaration.ENGINE) {
+      List<IFolder> descriptorFolders = TextMarkerProjectUtils.getAllDescriptorFolders(sourceModule
+              .getScriptProject().getProject());
+      List<String> engines = new ArrayList<String>();
+      for (IFolder folder : descriptorFolders) {
+        try {
+          engines.addAll(collectEngines(folder, ""));
+        } catch (CoreException e) {
+        }
+      }
+      for (String string : engines) {
+        if (string.startsWith(complString) || removeLowerCase(string).startsWith(complString)) {
+          addProposal(complString, string, CompletionProposal.PACKAGE_REF);
+        }
+      }
+    } else {
+      List<IFolder> descriptorFolders = TextMarkerProjectUtils.getAllDescriptorFolders(sourceModule
+              .getScriptProject().getProject());
+      List<String> tss = new ArrayList<String>();
+      for (IFolder folder : descriptorFolders) {
+        try {
+          tss.addAll(collectTypeSystems(folder, ""));
+        } catch (CoreException e) {
+        }
+      }
+      for (String string : tss) {
+        if (string.startsWith(complString) || removeLowerCase(string).startsWith(complString)) {
+          addProposal(complString, string, CompletionProposal.PACKAGE_REF);
+        }
+      }
+    }
+  }
+
+  private List<String> collectEngines(IFolder folder, String prefix) throws CoreException {
+    List<String> result = new ArrayList<String>();
+    IResource[] members = folder.members();
+    for (IResource iResource : members) {
+      if (iResource instanceof IFolder) {
+        IFolder folder2 = (IFolder) iResource;
+        String newPrefix = prefix + folder2.getProjectRelativePath().lastSegment() + ".";
+        result.addAll(collectEngines(folder2, newPrefix));
+      } else if (iResource instanceof IFile) {
+        IFile file = (IFile) iResource;
+        if (file.getFileExtension().equals("xml")) {
+          File f = new File(file.getLocation().toPortableString());
+          if (f.exists()) {
+            try {
+              UIMAFramework.getXMLParser().parseAnalysisEngineDescription(new XMLInputSource(f));
+              result.add(prefix + file.getName().substring(0, file.getName().length() - 4));
+            } catch (Exception e) {
+            }
+          }
+        }
+      }
+    }
+    return result;
+  }
+
+  private List<String> collectTypeSystems(IFolder folder, String prefix) throws CoreException {
+    List<String> result = new ArrayList<String>();
+    IResource[] members = folder.members();
+    for (IResource iResource : members) {
+      if (iResource instanceof IFolder) {
+        IFolder folder2 = (IFolder) iResource;
+        String newPrefix = prefix + folder2.getProjectRelativePath().lastSegment() + ".";
+        result.addAll(collectTypeSystems(folder2, newPrefix));
+      } else if (iResource instanceof IFile) {
+        IFile file = (IFile) iResource;
+        if (file.getFileExtension().equals("xml")) {
+          File f = new File(file.getLocation().toPortableString());
+          if (f.exists()) {
+            try {
+              UIMAFramework.getXMLParser().parseTypeSystemDescription(new XMLInputSource(f));
+              result.add(prefix + file.getName().substring(0, file.getName().length() - 4));
+            } catch (Exception e) {
+            }
+          }
+        }
+      }
+    }
+    return result;
+  }
+
+  private List<String> collectScripts(IFolder folder, String prefix) throws CoreException {
+    List<String> result = new ArrayList<String>();
+    IResource[] members = folder.members();
+    for (IResource iResource : members) {
+      if (iResource instanceof IFolder) {
+        IFolder folder2 = (IFolder) iResource;
+        String newPrefix = prefix + folder2.getProjectRelativePath().lastSegment() + ".";
+        result.addAll(collectScripts(folder2, newPrefix));
+      } else if (iResource instanceof IFile) {
+        IFile file = (IFile) iResource;
+        if (file.getFileExtension().equals("tm")) {
+          result.add(prefix + file.getName().substring(0, file.getName().length() - 3));
+        }
+      }
+    }
+    return result;
+  }
+
+  private void doCompletionOnDeclaration(ISourceModule cu, String startPart) {
+    String[] keywords = TextMarkerKeywordsManager.getKeywords(ITextMarkerKeywords.DECLARATION);
+    for (String string : keywords) {
+      if (string.startsWith(startPart) || removeLowerCase(string).startsWith(startPart)) {
+        addProposal(startPart, string, CompletionProposal.KEYWORD);
+      }
+    }
+  }
+
+  private Set<String> importTypeSystem(String xmlFilePath, IProject project)
+          throws InvalidXMLException, IOException {
+    IFolder folder = project.getProject().getFolder(
+            TextMarkerProjectUtils.getDefaultDescriptorLocation());
+    xmlFilePath = xmlFilePath.substring(0, xmlFilePath.length() - 3) + "TypeSystem.xml";
+    return getTypes(folder, xmlFilePath);
+  }
+
+  private Set<String> getTypes(IFolder folder, String filePath) throws InvalidXMLException,
+          IOException {
+    Set<String> types = new HashSet<String>();
+    IFile iFile = getFile(folder, filePath);
+    URL url;
+    try {
+      url = iFile.getLocationURI().toURL();
+      ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();
+      resMgr.setDataPath(folder.getLocation().toPortableString());
+      types = getTypes(url, resMgr);
+    } catch (MalformedURLException e) {
+      e.printStackTrace();
+    }
+    return types;
+  }
+
+  private Set<String> getTypes(URL resource, ResourceManager resMgr) throws IOException,
+          InvalidXMLException {
+    Set<String> types = new HashSet<String>();
+    TypeSystemDescription typeSysDescr = null;
+    typeSysDescr = UIMAFramework.getXMLParser().parseTypeSystemDescription(
+            new XMLInputSource(resource));
+    typeSysDescr.resolveImports(resMgr);
+    for (TypeDescription each : typeSysDescr.getTypes()) {
+      String name = each.getName();
+      String[] nameSpace = name.split("[.]");
+      types.add(nameSpace[nameSpace.length - 1]);
+      StringBuffer fullName = new StringBuffer();
+      if (nameSpace.length > 0) {
+        fullName.append(nameSpace[0]);
+      }
+      for (int i = 1; i < nameSpace.length; i++) {
+        // TODO fix workaround
+        if (!nameSpace[i].equals("type")) {
+          fullName.append('.');
+          fullName.append(nameSpace[i]);
+        }
+      }
+      types.add(fullName.toString());
+    }
+    return types;
+  }
+
+  private IFile getFile(IFolder folder, String filePath) {
+    int lastDot = filePath.lastIndexOf('.');
+    int sndLastDot = filePath.lastIndexOf('.', lastDot - 1);
+    String fName = filePath;
+    if (sndLastDot >= 0) {
+      String subFolder = filePath.substring(0, sndLastDot);
+      folder = folder.getFolder(subFolder);
+      fName = filePath.substring(sndLastDot + 1);
+    }
+    return folder.getFile(fName);
+  }
+
+  private void doCompletionOnAction(ISourceModule cu, TextMarkerModuleDeclaration parsed,
+          String startPart, int type, String complString) {
+    String[] keywords = TextMarkerKeywordsManager.getKeywords(ITextMarkerKeywords.ACTION);
+    for (String string : keywords) {
+      if (string.startsWith(complString) || removeLowerCase(string).startsWith(complString)) {
+        addProposal(complString, string, CompletionProposal.METHOD_NAME_REFERENCE);
+      }
+    }
+  }
+
+  private void doCompletionOnCondition(ISourceModule cu, TextMarkerModuleDeclaration parsed,
+          String startPart, int type, String complString) {
+    if (complString.startsWith("-")) {
+      complString = complString.substring(1, complString.length());
+    }
+    String[] keywords = TextMarkerKeywordsManager.getKeywords(ITextMarkerKeywords.CONDITION);
+    for (String string : keywords) {
+      if (string.startsWith(complString) || removeLowerCase(string).startsWith(complString)) {
+        addProposal(complString, string, CompletionProposal.METHOD_NAME_REFERENCE);
+      }
+    }
+  }
+
+  /**
+   * @param cu
+   * @param startPart
+   * @param type
+   * 
+   * @author Martin Toepfer
+   * @param complString
+   */
+  private void doCompletionOnVarRef(ISourceModule cu, TextMarkerModuleDeclaration parsed,
+          String startPart, int type, String complString) {
+    Collection<String> types = new HashSet<String>();
+    try {
+      IPath path = sourceModule.getPath();
+      path = path.removeFirstSegments(2);
+      types = importTypeSystem(path.toPortableString(), sourceModule.getScriptProject()
+              .getProject());
+    } catch (Exception e) {
+    }
+    for (String string : types) {
+      if (string.startsWith(complString) || removeLowerCase(string).startsWith(complString)) {
+        addProposal(complString, string, CompletionProposal.TYPE_REF);
+      }
+    }
+    try {
+      if (cu != null) {
+        IField[] fieldsArray = sourceModule.getFields();
+        for (IField field : fieldsArray) {
+          // if (type != TMTypeConstants.TM_TYPE_AT && Flags.isPrivate(field.getFlags())
+          // || (type & TMTypeConstants.TM_TYPE_AT) != 0 && Flags.isPublic(field.getFlags())) {
+          if ((type & TextMarkerParseUtils.getTypeOfIModelElement(field)) != 0) {
+            addProposal(complString, new ArrayList<String>(), field);
+          }
+        }
+        List<IField> fields = new ArrayList<IField>();
+        IModelElement[] children = sourceModule.getChildren();
+        for (IModelElement iModelElement : children) {
+          if (iModelElement instanceof SourceMethod) {
+            collectFields((SourceMethod) iModelElement, fields);
+          }
+        }
+        for (IField field : fields) {
+          // if (type != TMTypeConstants.TM_TYPE_AT && Flags.isPrivate(field.getFlags())
+          // || (type & TMTypeConstants.TM_TYPE_AT) != 0 && Flags.isPublic(field.getFlags())) {
+          // if ((type & TextMarkerParseUtils.getTypeOfIModelElement(field)) != 0) {
+          if (!types.contains(field.getElementName())) {
+            addProposal(complString, new ArrayList<String>(), field);
+          }
+          // }
+        }
+      }
+    } catch (ModelException e) {
+    }
+  }
+
+  private void collectFields(SourceMethod sm, List<IField> fields) throws ModelException {
+    IModelElement[] children = sm.getChildren();
+    for (IModelElement me : children) {
+      if (me instanceof SourceMethod) {
+        collectFields((SourceMethod) me, fields);
+      } else if (me instanceof SourceField) {
+        fields.add((IField) me);
+      }
+    }
+  }
+
+  private void collectBlocks(SourceMethod sm, List<IMethod> blocks) throws ModelException {
+    blocks.add(sm);
+    IModelElement[] children = sm.getChildren();
+    for (IModelElement me : children) {
+      if (me instanceof SourceMethod) {
+        collectBlocks((SourceMethod) me, blocks);
+      }
+    }
+  }
+
+  private String removeLowerCase(String string) {
+    String replaceAll = string.replaceAll("\\p{Lower}|[.]", "");
+    return replaceAll;
+  }
+
+  @SuppressWarnings( { "unchecked" })
+  private void doCompletionOnEmptyStatement(ISourceModule cu, int position, int i) {
+    int kind = CompletionProposal.LOCAL_VARIABLE_REF;
+    // doCompletionOnKeyword(position, i, "");
+    if (!super.requestor.isIgnored(kind)) {
+      suggestFields(cu);
+    }
+  }
+
+  /**
+   * @param cu
+   */
+  private void suggestFields(ISourceModule cu) {
+    List names = new ArrayList();
+    try {
+      if (cu != null) {
+        IField[] fieldsArray = sourceModule.getFields();
+        for (IField field : fieldsArray) {
+          int relevance = RelevanceConstants.R_EXACT_EXPECTED_TYPE;
+          // accept result
+          super.noProposal = false;
+          int kind = CompletionProposal.LOCAL_VARIABLE_REF;
+          if (!super.requestor.isIgnored(kind)) {
+            CompletionProposal proposal = super.createProposal(kind, actualCompletionPosition);
+            proposal.setRelevance(relevance);
+            proposal.setModelElement(field);
+            char[] fieldName = field.getElementName().toCharArray();
+            proposal.setName(fieldName);
+            proposal.setCompletion(fieldName);
+            proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition
+                    - this.offset);
+            try {
+              proposal.setFlags(field.getFlags());
+            } catch (ModelException e) {
+            }
+            this.requestor.accept(proposal);
+            if (DEBUG) {
+              this.printDebug(proposal);
+            }
+          }
+        }
+      }
+    } catch (ModelException e) {
+    }
+  }
+
+  /**
+   * @param complString
+   * @param names
+   * @param field
+   */
+  private void addProposal(String complString, List names, IField field) {
+    char[] fieldName = field.getElementName().toCharArray();
+    char[] complFragment = complString.toCharArray();
+
+    if (CharOperation.camelCaseMatch(complString.toCharArray(), fieldName)) {
+
+      int relevance = RelevanceConstants.R_DEFAULT;
+      relevance += computeRelevanceForCaseMatching(complFragment, fieldName);
+
+      // accept result
+      super.noProposal = false;
+      int kind = CompletionProposal.LOCAL_VARIABLE_REF;
+      if (!super.requestor.isIgnored(kind)) {
+        CompletionProposal proposal = super.createProposal(kind, actualCompletionPosition);
+        proposal.setRelevance(relevance);
+        proposal.setModelElement(field);
+        proposal.setName(fieldName);
+        proposal.setCompletion(fieldName);
+        proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset);
+        try {
+          proposal.setFlags(field.getFlags());
+        } catch (ModelException e) {
+        }
+        this.requestor.accept(proposal);
+        if (DEBUG) {
+          this.printDebug(proposal);
+        }
+      }
+    }
+  }
+
+  private void addProposal(String complString, String string, int kind) {
+    char[] fieldName = string.toCharArray();
+    char[] complFragment = complString.toCharArray();
+
+    char[] pattern = null;
+    if (complString.length() > 0) {
+      pattern = complString.toCharArray();
+    }
+    if (CharOperation.camelCaseMatch(pattern, fieldName)) {
+
+      int relevance = RelevanceConstants.R_DEFAULT;
+      relevance += computeRelevanceForCaseMatching(complFragment, fieldName);
+
+      // accept result
+      super.noProposal = false;
+      if (!super.requestor.isIgnored(kind)) {
+        CompletionProposal proposal = super.createProposal(kind, actualCompletionPosition);
+        proposal.setRelevance(relevance);
+        proposal.setName(fieldName);
+        proposal.setCompletion(fieldName);
+        proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset);
+        // try {
+        // proposal.setFlags(field.getFlags());
+        // } catch (ModelException e) {
+        // }
+        this.requestor.accept(proposal);
+        if (DEBUG) {
+          this.printDebug(proposal);
+        }
+      }
+    }
+  }
+
+  private void doCompletionOnKeyword(int position, int pos, String startPart) {
+    List<String> keywords = new ArrayList<String>();
+    for (int i = 0; i < ITextMarkerKeywords.END_INDEX; i++) {
+      keywords.addAll(Arrays.asList(TextMarkerKeywordsManager.getKeywords(i)));
+    }
+    char[][] keyWordsArray = new char[keywords.size()][];
+    for (int a = 0; a < keywords.size(); a++) {
+      keyWordsArray[a] = keywords.get(a).toCharArray();
+    }
+    findKeywords(startPart.toCharArray(), keyWordsArray, true);
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerCompletionEngine.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerCompletionEngine.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerModelElementView.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerModelElementView.java?rev=1152783&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerModelElementView.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerModelElementView.java Mon Aug  1 14:06:27 2011
@@ -0,0 +1,7 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist;
+
+public interface TextMarkerModelElementView {
+
+  void setModelElement(Object element);
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerModelElementView.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerModelElementView.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerReferenceDeclarationVisitor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerReferenceDeclarationVisitor.java?rev=1152783&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerReferenceDeclarationVisitor.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerReferenceDeclarationVisitor.java Mon Aug  1 14:06:27 2011
@@ -0,0 +1,55 @@
+/**
+ * 
+ */
+package org.apache.uima.tm.dltk.internal.core.codeassist;
+
+import org.apache.uima.tm.dltk.parser.ast.declarations.TextMarkerDeclarationsStatement;
+import org.apache.uima.tm.dltk.parser.ast.expressions.TextMarkerVariableReference;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.declarations.FieldDeclaration;
+import org.eclipse.dltk.ast.expressions.Expression;
+import org.eclipse.dltk.ast.statements.Statement;
+
+
+/**
+ * @author Martin Toepfer
+ * 
+ */
+public class TextMarkerReferenceDeclarationVisitor extends ASTVisitor {
+  private ASTNode result = null;
+
+  private int start = 0;
+
+  public TextMarkerReferenceDeclarationVisitor(int start) {
+    this.start = start;
+  }
+
+  @Override
+  public boolean visitGeneral(ASTNode node) throws Exception {
+    if (node.sourceStart() <= start && start <= node.sourceEnd()) {
+      return true;
+    }
+    return false;
+  }
+
+  @Override
+  public boolean visit(Statement s) throws Exception {
+    if (s instanceof TextMarkerDeclarationsStatement || s instanceof FieldDeclaration) {
+      return true && super.visit(s);
+    }
+    return false;
+  }
+
+  @Override
+  public boolean visit(Expression s) throws Exception {
+    if (s instanceof TextMarkerVariableReference) {
+      result = s;
+    }
+    return super.visit(s);
+  }
+
+  public ASTNode getResult() {
+    return result;
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerReferenceDeclarationVisitor.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerReferenceDeclarationVisitor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerReferenceVisitor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerReferenceVisitor.java?rev=1152783&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerReferenceVisitor.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerReferenceVisitor.java Mon Aug  1 14:06:27 2011
@@ -0,0 +1,52 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist;
+
+import org.apache.uima.tm.dltk.parser.ast.ComponentDeclaration;
+import org.apache.uima.tm.dltk.parser.ast.ComponentReference;
+import org.apache.uima.tm.dltk.parser.ast.actions.TextMarkerAction;
+import org.apache.uima.tm.dltk.parser.ast.conditions.TextMarkerCondition;
+import org.apache.uima.tm.dltk.parser.ast.expressions.TextMarkerVariableReference;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.expressions.Expression;
+
+
+public class TextMarkerReferenceVisitor extends ASTVisitor {
+  private ASTNode result = null;
+
+  private int start = 0;
+
+  public TextMarkerReferenceVisitor(int start) {
+    this.start = start;
+  }
+
+  @Override
+  public boolean visitGeneral(ASTNode node) throws Exception {
+    if (result == null && node.sourceStart() <= start && start <= node.sourceEnd()) {
+      return true;
+    }
+    return false;
+  }
+
+  @Override
+  public boolean visit(Expression s) throws Exception {
+    if (result != null) {
+      return false;
+    }
+    if (s instanceof TextMarkerVariableReference || s instanceof ComponentDeclaration
+            || s instanceof ComponentReference) {
+      result = s;
+    } else if (s instanceof TextMarkerAction && ((TextMarkerAction) s).getNameStart() <= start
+            && start <= ((TextMarkerAction) s).getNameEnd()) {
+      result = s;
+    } else if (s instanceof TextMarkerCondition
+            && ((TextMarkerCondition) s).getNameStart() <= start
+            && start <= ((TextMarkerCondition) s).getNameEnd()) {
+      result = s;
+    }
+    return super.visit(s);
+  }
+
+  public ASTNode getResult() {
+    return result;
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerReferenceVisitor.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerReferenceVisitor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerResolver.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerResolver.java?rev=1152783&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerResolver.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerResolver.java Mon Aug  1 14:06:27 2011
@@ -0,0 +1,308 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.tm.dltk.internal.core.parser.TextMarkerParseUtils;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.Modifiers;
+import org.eclipse.dltk.ast.declarations.FieldDeclaration;
+import org.eclipse.dltk.ast.declarations.MethodDeclaration;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.ast.declarations.TypeDeclaration;
+import org.eclipse.dltk.ast.expressions.Expression;
+import org.eclipse.dltk.ast.statements.Block;
+import org.eclipse.dltk.ast.statements.Statement;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.IField;
+import org.eclipse.dltk.core.IModelElement;
+import org.eclipse.dltk.core.IParent;
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.core.IType;
+import org.eclipse.dltk.core.ModelException;
+
+
+public class TextMarkerResolver {
+  private IResolveElementParent resolver;
+
+  private ModuleDeclaration moduleDeclaration;
+
+  private ISourceModule sourceModule;
+
+  public TextMarkerResolver(ISourceModule sourceModule, ModuleDeclaration moduleDeclaration,
+          IResolveElementParent resolver) {
+    this(sourceModule, moduleDeclaration);
+    this.resolver = resolver;
+  }
+
+  public TextMarkerResolver(ISourceModule sourceModule, ModuleDeclaration moduleDeclaration) {
+    this.sourceModule = sourceModule;
+    this.moduleDeclaration = moduleDeclaration;
+  }
+
+  public IModelElement findModelElementFrom(ASTNode node) {
+    List statements = moduleDeclaration.getStatements();
+    List elements = new ArrayList();
+    searchAddElementsTo(statements, node, sourceModule, elements);
+    if (elements.size() == 1) {
+      return (IModelElement) elements.get(0);
+    }
+    return null;
+  }
+
+  public interface IResolveElementParent {
+    IModelElement findElementParent(ASTNode node, String name, IParent parent);
+  }
+
+  public void searchAddElementsTo(List statements, final ASTNode node, IParent element,
+          List selectionElements) {
+    if (statements == null || element == null) {
+      return;
+    }
+    Iterator i = statements.iterator();
+    while (i.hasNext()) {
+      ASTNode nde = (ASTNode) i.next();
+      if (nde.equals(node)) {
+        if (node instanceof MethodDeclaration) {
+          String oName = ((MethodDeclaration) node).getName();
+          if (oName.indexOf("::") != -1) {
+            String pName = oName.substring(0, oName.lastIndexOf("::"));
+            pName = pName.replaceAll("::", "\\$");
+
+            if (pName.startsWith("$")) {
+              if (pName.equals("$")) {
+                element = sourceModule;
+              } else {
+                try {
+                  element = findTypeFrom(sourceModule.getChildren(), "", pName, '$');
+                } catch (ModelException e) {
+                  if (DLTKCore.DEBUG) {
+                    e.printStackTrace();
+                  }
+                }
+              }
+            } else {
+              pName = "$" + pName;
+              try {
+                element = findTypeFrom(element.getChildren(), "", pName, '$');
+                if (element == null) {
+                  return;
+                }
+              } catch (ModelException e) {
+                e.printStackTrace();
+                return;
+              }
+            }
+          }
+        }
+        String nodeName = getNodeChildName(node);
+        if (nodeName != null) {
+          IModelElement e = null;
+          if (nodeName.startsWith("::")) {
+            nodeName = nodeName.substring(2);
+            e = findChildrenByName(nodeName, sourceModule);
+          } else {
+            e = findChildrenByName(nodeName, element);
+          }
+          if (e == null && resolver != null) {
+            e = resolver.findElementParent(node, nodeName, element);
+
+          }
+          if (e != null) {
+            List toRemove = new ArrayList();
+            for (int k = 0; k < selectionElements.size(); ++k) {
+              IModelElement ke = (IModelElement) selectionElements.get(k);
+              String keName = ke.getElementName();
+              if (keName.equals(nodeName)) {
+                toRemove.add(ke);
+              }
+            }
+            for (int k = 0; k < toRemove.size(); ++k) {
+              selectionElements.remove(toRemove.get(k));
+            }
+            selectionElements.add(e);
+          }
+        }
+        return;
+      }
+      if (nde.sourceStart() <= node.sourceStart() && node.sourceEnd() <= nde.sourceEnd()) {
+        if (element instanceof IParent) {
+          if (nde instanceof TypeDeclaration) {
+            TypeDeclaration type = (TypeDeclaration) nde;
+            String typeName = getNodeChildName(type);
+            IModelElement e = findChildrenByName(typeName, element);
+            if (e == null && type.getName().startsWith("::")) {
+              try {
+                e = (IModelElement) findTypeFrom(sourceModule.getChildren(), "", type.getName()
+                        .replaceAll("::", "\\$"), '$');
+              } catch (ModelException e1) {
+                // TODO Auto-generated catch block
+                e1.printStackTrace();
+              }
+            }
+            if (e instanceof IParent) {
+              // was: if (e != null || e instanceof IParent)
+              List stats = ((TypeDeclaration) nde).getStatements();
+              searchAddElementsTo(stats, node, (IParent) e, selectionElements);
+            }
+          } else if (nde instanceof MethodDeclaration) {
+            searchInMethod(node, element, nde, selectionElements);
+          } /*
+             * else if (nde instanceof TextMarkerStatement) { TextMarkerStatement s =
+             * (TextMarkerStatement) nde; Expression commandId = s.getAt(0); final IParent e =
+             * element; if (commandId != null && commandId instanceof SimpleReference) { String
+             * qname = ((SimpleReference) commandId) .getName(); } }
+             */
+          else {
+            final IParent e = element;
+            List statements2 = findExtractBlocks(nde);
+            if (statements2.size() > 0) {
+              searchAddElementsTo(statements2, node, e, selectionElements);
+            }
+          }
+        }
+        return;
+      }
+    }
+  }
+
+  public static IModelElement findChildrenByName(String childName, IParent element) {
+    try {
+      if (element == null) {
+        return null;
+      }
+      String nextName = null;
+      int pos;
+      if ((pos = childName.indexOf("::")) != -1) {
+        nextName = childName.substring(pos + 2);
+        childName = childName.split("::")[0];
+      }
+      IModelElement[] children = element.getChildren();
+      if (children != null) {
+        for (int i = 0; i < children.length; ++i) {
+          String name = children[i].getElementName();
+          if (children[i] instanceof IField && name.indexOf('(') != -1) {
+            name = name.substring(0, name.indexOf('('));
+          }
+          if (name.equals(childName)) {
+            if (nextName == null) {
+              return children[i];
+            } else if (children[i] instanceof IParent) {
+              return findChildrenByName(nextName, (IParent) children[i]);
+            }
+          }
+        }
+      }
+    } catch (ModelException e) {
+      if (DLTKCore.DEBUG) {
+        e.printStackTrace();
+      }
+    }
+    return null;
+  }
+
+  public static IParent findTypeFrom(IModelElement[] childs, String name, String parentName,
+          char delimiter) {
+    try {
+      for (int i = 0; i < childs.length; ++i) {
+        if (childs[i] instanceof IType) {
+          if ((((IType) childs[i]).getFlags() & Modifiers.AccNameSpace) == 0) {
+            continue;
+          }
+          IType type = (IType) childs[i];
+          String qname = name + delimiter + type.getElementName();
+          if (qname.equals(parentName)) {
+            return type;
+          }
+          IParent val = findTypeFrom(type.getChildren(), qname, parentName, delimiter);
+          if (val != null) {
+            return val;
+          }
+        }
+      }
+    } catch (ModelException e) {
+      if (DLTKCore.DEBUG) {
+        e.printStackTrace();
+      }
+    }
+    return null;
+  }
+
+  public static String getNodeChildName(ASTNode node) {
+    if (node instanceof MethodDeclaration) {
+      MethodDeclaration method = (MethodDeclaration) node;
+      String name = method.getName();
+      if (name.indexOf("::") != -1) {
+        return name.substring(name.lastIndexOf("::") + 2);
+      }
+      return name;
+    } else if (node instanceof TypeDeclaration) {
+      TypeDeclaration type = (TypeDeclaration) node;
+      String name = type.getName();
+      /*
+       * if (name.startsWith("::")) { return name.substring(2); }
+       */
+      return name;
+    } else if (node instanceof Statement) {
+      String[] var = TextMarkerParseUtils.returnVariable((Statement) node);
+      if (var != null) {
+        return var[0];
+      }
+    } else if (node instanceof FieldDeclaration) {
+      return ((FieldDeclaration) node).getName();
+    }
+    return null;
+  }
+
+  public void searchInMethod(final ASTNode node, IParent element, ASTNode nde,
+          List selectionElements) {
+    MethodDeclaration method = (MethodDeclaration) nde;
+    String methodName = method.getName();
+    if (methodName.indexOf("::") != -1) {
+      String pName = methodName.substring(0, methodName.lastIndexOf("::"));
+      pName = pName.replaceAll("::", "\\$");
+      if (pName.equals("$")) {
+        element = sourceModule;
+      } else {
+        try {
+          element = TextMarkerResolver.findTypeFrom(sourceModule.getChildren(), "", pName, '$');
+          if (element == null) {
+            return;
+          }
+        } catch (ModelException e) {
+          e.printStackTrace();
+          return;
+        }
+      }
+      methodName = TextMarkerResolver.getNodeChildName(nde);
+    }
+    IModelElement e = TextMarkerResolver.findChildrenByName(methodName, element);
+    if (e != null && e instanceof IParent) {
+      List stats = ((MethodDeclaration) nde).getStatements();
+      searchAddElementsTo(stats, node, (IParent) e, selectionElements);
+    }
+  }
+
+  public static List findExtractBlocks(ASTNode node) {
+    final List statements2 = new ArrayList();
+    ASTVisitor visitor = new ASTVisitor() {
+      @Override
+      public boolean visit(Expression s) throws Exception {
+        if (s instanceof Block) {
+          statements2.addAll(((Block) s).getStatements());
+        }
+        return super.visit(s);
+      }
+    };
+    try {
+      node.traverse(visitor);
+    } catch (Exception e) {
+      if (DLTKCore.DEBUG) {
+        e.printStackTrace();
+      }
+    }
+    return statements2;
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerResolver.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain