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 [5/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/codeassist/TextMarkerSelectionEngine.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/TextMarkerSelectionEngine.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/TextMarkerSelectionEngine.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerSelectionEngine.java Mon Aug 1 14:06:27 2011
@@ -0,0 +1,459 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.resource.metadata.TypeDescription;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.tm.dltk.internal.core.builder.TextMarkerProjectUtils;
+import org.apache.uima.tm.dltk.internal.core.parser.TextMarkerParseUtils;
+import org.apache.uima.tm.dltk.parser.ast.TMActionConstants;
+import org.apache.uima.tm.dltk.parser.ast.TMStatementConstants;
+import org.apache.uima.tm.dltk.parser.ast.TextMarkerImportStatement;
+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.IPath;
+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.references.SimpleReference;
+import org.eclipse.dltk.ast.references.VariableReference;
+import org.eclipse.dltk.ast.statements.Statement;
+import org.eclipse.dltk.codeassist.IAssistParser;
+import org.eclipse.dltk.codeassist.ScriptSelectionEngine;
+import org.eclipse.dltk.compiler.env.ISourceModule;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.IDLTKLanguageToolkit;
+import org.eclipse.dltk.core.IField;
+import org.eclipse.dltk.core.IMethod;
+import org.eclipse.dltk.core.IModelElement;
+import org.eclipse.dltk.core.IModelElementVisitor;
+import org.eclipse.dltk.core.IOpenable;
+import org.eclipse.dltk.core.IScriptFolder;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.core.ModelException;
+
+
+public class TextMarkerSelectionEngine extends ScriptSelectionEngine {
+ /**
+ * @author Martin Toepfer
+ *
+ */
+ private class ModelElementFinder extends ASTVisitor {
+ private int offset;
+
+ private List results;
+
+ private Set<String> engines;
+
+ private Set<String> typesystems;
+
+ private Map<String, org.eclipse.dltk.core.ISourceModule> scripts;
+
+ private Map<String, IField> impFields;
+
+ private String curFileName;
+
+ public ModelElementFinder(int offset, List results, String curFileName) {
+ super();
+ this.offset = offset;
+ this.results = results;
+ this.engines = new HashSet<String>();
+ this.typesystems = new HashSet<String>();
+ this.scripts = new HashMap<String, org.eclipse.dltk.core.ISourceModule>();
+ this.impFields = new HashMap<String, IField>();
+ this.curFileName = curFileName;
+ try {
+ importScript(parseFileName(curFileName));
+ } catch (Exception e) {
+ }
+ }
+
+ private String parseFileName(String curFileName2) {
+ int i = curFileName2.indexOf("script");
+ String s = curFileName2.substring(i + "scripts".length() - 1);
+ s = s.replace('/', '.');
+ if (s.endsWith(".tm")) {
+ s = s.substring(1, s.length() - 3);
+ }
+ return s;
+ }
+
+ @Override
+ public boolean visit(Statement s) throws Exception {
+ if (s instanceof TextMarkerImportStatement) {
+ // handle engine imports
+ if (((TextMarkerImportStatement) s).getType() == TMStatementConstants.S_IMPORT_ENGINE) {
+ SimpleReference sRef = (SimpleReference) ((TextMarkerImportStatement) s).getExpression();
+ importEngine(sRef.getName());
+ }
+ // handle script imports
+ if (((TextMarkerImportStatement) s).getType() == TMStatementConstants.S_IMPORT_SCRIPT) {
+ importScript(s);
+ }
+ // handle type system imports
+ if (((TextMarkerImportStatement) s).getType() == TMStatementConstants.S_IMPORT_TYPESYSTEM) {
+ importTypesystem(s);
+ }
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean visit(Expression s) throws Exception {
+ if (s.sourceStart() <= offset && offset <= s.sourceEnd()) {
+ if (s instanceof VariableReference) {
+ VariableReference ref = (VariableReference) s;
+ // TODO refactor: extern declaration always checked, even if
+ // local decl found
+ String name = ((VariableReference) s).getName();
+ findLocalDeclaration(name, results, IField.class);
+ if (impFields.containsKey(name)) {
+ results.add(impFields.get(name));
+ }
+ }
+ if (s.getKind() == TMActionConstants.A_CALL) {
+ SimpleReference sr = (SimpleReference) s.getChilds().get(0);
+ if (sr != null) {
+ String name = sr.getName();
+ if (engines.contains(name)) {
+ // referenceEngineCall(name);
+ } else if (scripts.containsKey(name)) {
+ findImportedDeclaration(name, results, IMethod.class);
+ } else {
+ checkInnerBlockRef(name, "");
+ name = name.substring(name.lastIndexOf('.') + 1);
+ findLocalDeclaration(name, results, IMethod.class);
+ }
+ }
+ }
+ }
+ return super.visit(s);
+ }
+
+ @Override
+ public boolean visit(MethodDeclaration s) throws Exception {
+ if (s.getNameStart() <= offset && offset <= s.getNameEnd()) {
+ findLocalDeclaration(s.getName(), results, IMethod.class);
+ }
+ return super.visit(s);
+ }
+
+ @Override
+ public boolean visit(TypeDeclaration s) throws Exception {
+ if (s.getNameStart() <= offset && offset <= s.getNameEnd()) {
+ findLocalDeclaration(s.getName(), results, IField.class);
+ // TODO ??
+ }
+ return super.visit(s);
+ }
+
+ private void checkInnerBlockRef(String head, String tail) {
+ int li = head.lastIndexOf('.');
+ if (li > 0) {
+ String frontPart = head.substring(0, li);
+ if (tail.equals("")) {
+ tail = head.substring(li + 1);
+ }
+ if (scripts.containsKey(frontPart)) {
+ findDeclaration(scripts.get(frontPart), tail, results, IMethod.class);
+ } else {
+ checkInnerBlockRef(frontPart, tail);
+ }
+ }
+ }
+
+ private void importEngine(String name) {
+ engines.add(name);
+ int i = name.lastIndexOf('.');
+ if (i > 1) {
+ String lastPart = name.substring(i + 1);
+ if (lastPart != null && lastPart.length() != 0) {
+ engines.add(lastPart);
+ }
+ }
+ }
+
+ private void referenceEngineCall(String name) {
+ // name = "";
+ IScriptProject scriptProject = sourceModule.getScriptProject();
+ IFile engine = getEngine(name, scriptProject);
+ if (engine == null) {
+ return;
+ }
+ results.add(engine);
+ // IScriptProject scriptProject = sourceModule.getScriptProject();
+ // IPath path = scriptProject.g;
+ // path = path.append(name);
+ // IModelElement element;
+ // try {
+ // element = scriptProject.findElement(path);
+ // System.out.println(element.exists() + "bla");
+ // } catch (ModelException e) {
+ // e.printStackTrace();
+ // }
+ // sourceModule.
+ // scriptProject.findType(packageName, name);
+ }
+
+ public 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);
+ }
+
+ /**
+ * @param xmlFilePath
+ * absolute full path. i.e.: "de.uniwue.myengine" ".xml" will be added.
+ * @return file.exists
+ */
+ public IFile getEngine(String xmlFilePath, IScriptProject project) {
+ IFolder folder = project.getProject().getFolder(
+ TextMarkerProjectUtils.getDefaultDescriptorLocation());
+ IFolder f = folder.getFolder("de.martin");
+ boolean b = f.exists();
+ // xmlFilePath = xmlFilePath.replace('.', '/');
+ String fileExtended = xmlFilePath + ".xml";
+ IFile file = getFile(folder, fileExtended);
+ if (file.exists()) {
+ IOpenable opena = (IOpenable) file.getAdapter(IOpenable.class);
+ return file;
+ }
+ return null;
+ }
+
+ /**
+ * @param s
+ * @throws ModelException
+ */
+ private void importScript(Statement s) throws ModelException {
+ SimpleReference sRef = (SimpleReference) ((TextMarkerImportStatement) s).getExpression();
+ String sRefName = sRef.getName();
+ importScript(sRefName);
+ }
+
+ private void importTypesystem(Statement s) {
+ SimpleReference sRef = (SimpleReference) ((TextMarkerImportStatement) s).getExpression();
+ String sRefName = sRef.getName();
+
+ // TODO not working yet
+ // importTypesystem(sRefName);
+
+ }
+
+ private void importTypesystem(String sRefName) {
+ typesystems.add(sRefName);
+ IFolder folder = sourceModule.getScriptProject().getProject().getFolder(
+ TextMarkerProjectUtils.getDefaultDescriptorLocation());
+ if (folder != null) {
+ int lastDot = sRefName.lastIndexOf('.');
+ String fileNameShort = sRefName.substring(lastDot + 1);
+ String folderName = sRefName.substring(0, lastDot);
+ String fileName = fileNameShort + ".xml";
+ IFolder tsFolder = folder.getFolder(folderName);
+ if (tsFolder != null) {
+ IFile file = tsFolder.getFile(fileName);
+ if (file != null) {
+ File tsFile = file.getLocation().toFile();
+ try {
+ TypeSystemDescription typeSystemDescription = UIMAFramework.getXMLParser()
+ .parseTypeSystemDescription(new XMLInputSource(tsFile));
+ TypeDescription[] types = typeSystemDescription.getTypes();
+ for (TypeDescription each : types) {
+ impFields.put(each.getName(), null);
+ }
+ } catch (InvalidXMLException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * @param sRefName
+ * @throws ModelException
+ */
+ private void importScript(String sRefName) throws ModelException {
+ int lastDot = sRefName.lastIndexOf('.');
+ String fileNameShort = sRefName.substring(lastDot + 1);
+ String fileName = fileNameShort + ".tm";
+
+ org.eclipse.dltk.core.ISourceModule sm = null;
+ IScriptFolder[] scriptFolders = sourceModule.getScriptProject().getScriptFolders();
+ for (int i = 0; i < scriptFolders.length; i++) {
+ sm = scriptFolders[i].getSourceModule(fileName);
+ if (sm.exists() && sm.getResource() != null && sm.getResource().exists()) {
+ scripts.put(sRefName, sm);
+ scripts.put(fileNameShort, sm);
+ importFields(sm.getFields());
+ break;
+ }
+ }
+ }
+
+ private void importFields(IField[] fields) {
+ if (fields == null) {
+ return;
+ }
+ for (int i = 0; i < fields.length; i++) {
+ if (fields[i] == null) {
+ continue;
+ }
+ IField iField = fields[i];
+ IPath path = iField.getPath();
+ String fullyQualifiedName = parseFileName(path.toString());
+ impFields.put(iField.getElementName(), iField);
+ impFields.put(fullyQualifiedName + "." + iField.getElementName(), iField);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void findImportedDeclaration(final String name, final List results, final Class type) {
+ org.eclipse.dltk.core.ISourceModule module = this.scripts.get(name);
+ if (module != null && module.exists()) {
+ results.add(module);
+ // findDeclaration(module, name, results, type);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void findDeclaration(org.eclipse.dltk.core.ISourceModule sm, final String name,
+ final List results, final Class type) {
+ try {
+ sm.accept(new IModelElementVisitor() {
+ public boolean visit(IModelElement element) {
+ Class e = element.getClass();
+ boolean classCheck = type.isAssignableFrom(e);
+ if (element.getElementName().equals(name) && classCheck) {
+ results.add(element);
+ return false;
+ }
+ return true;
+ }
+ });
+ } catch (ModelException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void findLocalDeclaration(final String name, final List results, final Class type) {
+ try {
+ sourceModule.accept(new IModelElementVisitor() {
+ public boolean visit(IModelElement element) {
+ Class e = element.getClass();
+ boolean classCheck = type.isAssignableFrom(e);
+ if (element.getElementName().equals(name) && classCheck) {
+ results.add(element);
+ }
+ return true;
+ }
+ });
+ } catch (ModelException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public static boolean DEBUG = DLTKCore.DEBUG_SELECTION;
+
+ protected int actualSelectionStart;
+
+ protected int actualSelectionEnd;
+
+ protected List selectionElements = new ArrayList();
+
+ protected TextMarkerSelectionParser parser = new TextMarkerSelectionParser();
+
+ protected org.eclipse.dltk.core.ISourceModule sourceModule;
+
+ protected IDLTKLanguageToolkit toolkit;
+
+ @Override
+ public IAssistParser getParser() {
+ return parser;
+ }
+
+ public IModelElement[] select(ISourceModule module, final int offset, int i) {
+ sourceModule = (org.eclipse.dltk.core.ISourceModule) module.getModelElement();
+ ModuleDeclaration moduleDeclaration = this.parser.parse(module);
+
+ final List results = new ArrayList();
+ try {
+ moduleDeclaration.traverse(new ModelElementFinder(offset, results, String.copyValueOf(module
+ .getFileName())));
+ } catch (Exception e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ return (IModelElement[]) results.toArray(new IModelElement[results.size()]);
+ }
+
+ protected boolean checkSelection(String source, int selectionSourceStart, int selectionSourceEnd) {
+
+ boolean cheat = false;
+ if (selectionSourceEnd < selectionSourceStart) {
+ selectionSourceEnd = selectionSourceStart;
+ cheat = true;
+ }
+
+ int start = TextMarkerParseUtils.startLineOrNoSymbol(selectionSourceStart, source);
+ int end = TextMarkerParseUtils.endLineOrNoSymbol(selectionSourceEnd, source);
+ if (end <= start) {
+ if (cheat)
+ return checkSelection(source, selectionSourceEnd - 1, selectionSourceEnd - 1);
+ return false;
+ }
+ if (start > source.length() || end > source.length()) {
+ if (cheat)
+ return checkSelection(source, selectionSourceEnd - 1, selectionSourceEnd - 1);
+ return false;
+ }
+
+ String sub = source.substring(start, end);
+
+ // If contain tabs or spaces, then from start.
+ if ((sub.indexOf(' ') != -1 || sub.indexOf('\t') != -1 || sub.indexOf('\n') != -1)) {
+ if (cheat)
+ return checkSelection(source, selectionSourceEnd - 1, selectionSourceEnd - 1);
+ return false;
+ }
+ this.actualSelectionStart = start;
+ this.actualSelectionEnd = end;
+ return true;
+ }
+
+ @Override
+ protected ASTNode parseBlockStatements(ModuleDeclaration unit, int position) {
+ // TODO Auto-generated method stub
+ return super.parseBlockStatements(unit, position);
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerSelectionEngine.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/TextMarkerSelectionEngine.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/TextMarkerSelectionParser.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/TextMarkerSelectionParser.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/TextMarkerSelectionParser.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerSelectionParser.java Mon Aug 1 14:06:27 2011
@@ -0,0 +1,17 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist;
+
+import org.eclipse.dltk.ast.ASTNode;
+
+public class TextMarkerSelectionParser extends TextMarkerAssistParser {
+
+ public void handleNotInElement(ASTNode unit, int position) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void parseBlockStatements(ASTNode node, ASTNode unit, int position) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/TextMarkerSelectionParser.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/TextMarkerSelectionParser.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/completion/CompletionOnKeywordArgumentOrFunctionArgument.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/completion/CompletionOnKeywordArgumentOrFunctionArgument.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/completion/CompletionOnKeywordArgumentOrFunctionArgument.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/completion/CompletionOnKeywordArgumentOrFunctionArgument.java Mon Aug 1 14:06:27 2011
@@ -0,0 +1,85 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist.completion;
+
+import org.apache.uima.tm.dltk.parser.ast.TextMarkerStatement;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.references.SimpleReference;
+import org.eclipse.dltk.codeassist.complete.ICompletionOnKeyword;
+import org.eclipse.dltk.utils.CorePrinter;
+
+
+public class CompletionOnKeywordArgumentOrFunctionArgument extends SimpleReference implements
+ ICompletionOnKeyword {
+
+ private String[] possibleKeywords;
+
+ private TextMarkerStatement statement;
+
+ private ASTNode completionNode;
+
+ public CompletionOnKeywordArgumentOrFunctionArgument(String token, ASTNode completionNode,
+ TextMarkerStatement node, String[] KeywordspossibleKeywords) {
+ super(completionNode.sourceStart(), completionNode.sourceEnd(), token);
+ this.possibleKeywords = KeywordspossibleKeywords;
+ this.statement = node;
+ this.completionNode = completionNode;
+ }
+
+ public CompletionOnKeywordArgumentOrFunctionArgument(String token, TextMarkerStatement node,
+ String[] possibleKeywords, int position) {
+ super(position, position, token);
+ this.possibleKeywords = possibleKeywords;
+ this.statement = node;
+ this.completionNode = null;
+ }
+
+ public char[] getToken() {
+ if (getName() != null) {
+ return getName().toCharArray();
+ }
+ return "".toCharArray();
+ }
+
+ public String[] getPossibleKeywords() {
+ return this.possibleKeywords;
+ }
+
+ @Override
+ public void printNode(CorePrinter output) {
+ }
+
+ @Override
+ public void traverse(ASTVisitor pVisitor) throws Exception {
+ }
+
+ public boolean canCompleteEmptyToken() {
+ return true;
+ }
+
+ public TextMarkerStatement getStatement() {
+ return this.statement;
+ }
+
+ public int argumentIndex() {
+ if (this.completionNode == null) {
+ if (this.statement.getCount() == 1) {
+ return 1;
+ }
+ if (statement.getCount() > 2 && statement.getAt(0).sourceEnd() <= sourceStart()
+ && sourceEnd() <= statement.getAt(1).sourceStart()) {
+ return 1;
+ }
+ return -1;
+ }
+ for (int i = 0; i < this.statement.getCount(); ++i) {
+ if (this.statement.getAt(i).equals(this.completionNode)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ public ASTNode getCompletionNode() {
+ return this.completionNode;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/completion/CompletionOnKeywordArgumentOrFunctionArgument.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/completion/CompletionOnKeywordArgumentOrFunctionArgument.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/completion/CompletionOnKeywordOrFunction.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/completion/CompletionOnKeywordOrFunction.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/completion/CompletionOnKeywordOrFunction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/completion/CompletionOnKeywordOrFunction.java Mon Aug 1 14:06:27 2011
@@ -0,0 +1,38 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist.completion;
+
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.references.SimpleReference;
+import org.eclipse.dltk.codeassist.complete.ICompletionOnKeyword;
+import org.eclipse.dltk.utils.CorePrinter;
+
+public class CompletionOnKeywordOrFunction extends SimpleReference implements ICompletionOnKeyword {
+
+ private String[] possibleKeywords;
+
+ public CompletionOnKeywordOrFunction(String token, ASTNode completionNode, ASTNode node,
+ String[] possibleKeywords) {
+ super(completionNode.sourceStart(), completionNode.sourceEnd(), token);
+ this.possibleKeywords = possibleKeywords;
+ }
+
+ public char[] getToken() {
+ return getName().toCharArray();
+ }
+
+ public String[] getPossibleKeywords() {
+ return this.possibleKeywords;
+ }
+
+ @Override
+ public void printNode(CorePrinter output) {
+ }
+
+ @Override
+ public void traverse(ASTVisitor pVisitor) throws Exception {
+ }
+
+ public boolean canCompleteEmptyToken() {
+ return true;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/completion/CompletionOnKeywordOrFunction.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/completion/CompletionOnKeywordOrFunction.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/completion/CompletionOnVariable.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/completion/CompletionOnVariable.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/completion/CompletionOnVariable.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/completion/CompletionOnVariable.java Mon Aug 1 14:06:27 2011
@@ -0,0 +1,55 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist.completion;
+
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.references.SimpleReference;
+
+public class CompletionOnVariable extends SimpleReference {
+ private ASTNode parentNode;
+
+ private ASTNode inNode;
+
+ private ASTNode completionNode;
+
+ private boolean canHandleEmpty;
+
+ private boolean provideDollar = true;
+
+ public CompletionOnVariable(String completionToken, ASTNode completionNode, ASTNode node,
+ ASTNode inNode, boolean canHandleEmpty) {
+ super(completionNode.sourceStart(), completionNode.sourceEnd(), completionToken);
+ this.parentNode = node;
+ this.completionNode = completionNode;
+ this.inNode = inNode;
+ this.canHandleEmpty = canHandleEmpty;
+ }
+
+ public CompletionOnVariable(String completionToken, ASTNode completionNode, ASTNode node,
+ ASTNode inNode, boolean canHandleEmpty, boolean provideDollar) {
+ this(completionToken, completionNode, node, inNode, canHandleEmpty);
+ this.provideDollar = provideDollar;
+ }
+
+ public ASTNode getParentNode() {
+ return this.parentNode;
+ }
+
+ public ASTNode getInNode() {
+ return this.inNode;
+ }
+
+ public ASTNode getCompletionNode() {
+ return this.completionNode;
+ }
+
+ public char[] getToken() {
+ return this.getName().toCharArray();
+ }
+
+ public boolean canHandleEmpty() {
+ return this.canHandleEmpty;
+ }
+
+ public boolean getProvideDollar() {
+ return this.provideDollar;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/completion/CompletionOnVariable.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/completion/CompletionOnVariable.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/completion/TextMarkerCompletionParser.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/completion/TextMarkerCompletionParser.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/completion/TextMarkerCompletionParser.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/completion/TextMarkerCompletionParser.java Mon Aug 1 14:06:27 2011
@@ -0,0 +1,371 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist.completion;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.tm.dltk.core.extensions.ICompletionExtension;
+import org.apache.uima.tm.dltk.internal.core.codeassist.TextMarkerAssistParser;
+import org.apache.uima.tm.dltk.internal.core.parser.TextMarkerParseUtils;
+import org.apache.uima.tm.dltk.parser.ast.TextMarkerStatement;
+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.references.SimpleReference;
+import org.eclipse.dltk.ast.statements.Block;
+import org.eclipse.dltk.ast.statements.Statement;
+import org.eclipse.dltk.codeassist.complete.CompletionNodeFound;
+
+
+public class TextMarkerCompletionParser extends TextMarkerAssistParser {
+ private static class TextMarkerEmptyCompleteStatement extends TextMarkerStatement {
+ public TextMarkerEmptyCompleteStatement(List expressions) {
+ super(expressions);
+ }
+ }
+
+ private ICompletionExtension[] extensions;
+
+ public TextMarkerCompletionParser(ICompletionExtension[] extensions) {
+ this.extensions = extensions;
+ }
+
+ /**
+ * Called then element could not be found.
+ */
+ public void handleNotInElement(ASTNode node, int position) {
+ if (node != null && node.sourceStart() <= position && position <= node.sourceEnd()) {
+ // this is empty module case
+ if (node instanceof ModuleDeclaration) {
+ ModuleDeclaration unit = (ModuleDeclaration) node;
+ List exprs = new ArrayList();
+ exprs.add(new SimpleReference(position, position, ""));
+ TextMarkerEmptyCompleteStatement statement = new TextMarkerEmptyCompleteStatement(exprs);
+ unit.addStatement(statement);
+ this.parseBlockStatements(statement, unit, position);
+ } else if (node instanceof MethodDeclaration) {
+ // empty keyword like completion.
+ MethodDeclaration method = (MethodDeclaration) node;
+ List exprs = new ArrayList();
+ exprs.add(new SimpleReference(position, position, ""));
+ TextMarkerEmptyCompleteStatement statement = new TextMarkerEmptyCompleteStatement(exprs);
+ method.getStatements().add(statement);
+ this.parseBlockStatements(statement, method, position);
+ } else if (node instanceof TypeDeclaration) {
+ // empty keyword like completion.
+ TypeDeclaration type = (TypeDeclaration) node;
+ List exprs = new ArrayList();
+ exprs.add(new SimpleReference(position, position, ""));
+ TextMarkerEmptyCompleteStatement statement = new TextMarkerEmptyCompleteStatement(exprs);
+ type.getStatements().add(statement);
+ // this.assistNodeParent = node;
+ this.parseBlockStatements(statement, type, position);
+ // } else if (node instanceof TextMarkerExecuteExpression) {
+ // // empty keyword like completion.
+ // List exprs = new ArrayList();
+ // exprs.add(new SimpleReference(position, position, ""));
+ // TextMarkerEmptyCompleteStatement statement = new
+ // TextMarkerEmptyCompleteStatement(
+ // exprs);
+ // this.parseBlockStatements(statement, node, position);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.dltk.codeassist.IAssistParser#parseBlockStatements(org.eclipse.dltk.ast.ASTNode,
+ * org.eclipse.dltk.ast.ASTNode, int)
+ */
+ public void parseBlockStatements(ASTNode node, ASTNode inNode, int position) {
+ // if (node instanceof TextMarkerStatement) {
+ // TextMarkerStatement statement = (TextMarkerStatement) node;
+ // List expressions = statement.getExpressions();
+ // int len = expressions.size();
+ // boolean first = false;
+ // String completionToken = null;
+ // ASTNode completionNode = null;
+ // for (int i = 0; i < len; ++i) {
+ // ASTNode n = (ASTNode) expressions.get(i);
+ // if (n.sourceStart() <= position && n.sourceEnd() >= position
+ // || (node instanceof TextMarkerEmptyCompleteStatement)) {
+ // if (i == 0) {
+ // first = true;
+ // }
+ // completionNode = n;
+ // }
+ // }
+ // if (completionNode == null) {
+ // // TODO: Add inner completion here.
+ // if (len > 0) {
+ // // ASTNode firstNode = (ASTNode) expressions.get(0);
+ // // if (position > firstNode.sourceEnd()) {
+ // // // This could be variable completion.
+ // // boolean provideDollar =
+ // // !checkVariableWithoutDollarCompletion(
+ // // statement, position);
+ // // this.assistNodeParent = inNode;
+ // // SimpleReference ref = new SimpleReference(position,
+ // // position, "");
+ // // ASTNode nde = new CompletionOnVariable("", ref, node,
+ // // inNode, true, provideDollar);
+ // // throw new CompletionNodeFound(nde, null);
+ // // }
+ // String[] keywords = checkKeywords(completionToken, MODULE);
+ // ASTNode nde = new CompletionOnKeywordArgumentOrFunctionArgument("",
+ // (TextMarkerStatement) node, keywords, position);
+ // this.assistNodeParent = inNode;
+ // throw new CompletionNodeFound(nde, null/* ((TypeDeclaration)inNode).scope */);
+ //
+ // } else {
+ // completionToken = "";
+ // }
+ // } else if (completionNode instanceof SimpleReference) {
+ // int maxLen = position - completionNode.sourceStart();
+ // completionToken = ((SimpleReference) completionNode).getName();
+ // // We need to cut some sumbols if node is begger then position.
+ // if (completionToken.length() > maxLen && maxLen > 0) {
+ // completionToken = completionToken.substring(0, maxLen);
+ // }
+ // } /*
+ // * else if (completionNode instanceof TextMarkerBlockExpression) { TextMarkerBlockExpression
+ // * block = (TextMarkerBlockExpression) completionNode;
+ // *
+ // * List s = block.parseBlock(); if (s != null) { int slen = s.size(); for (int u = 0; u <
+ // * slen; ++u) { ASTNode n = (ASTNode) s.get(u); n.setStart(n.sourceStart() -
+ // * block.sourceStart()); n.setEnd(n.sourceEnd() - block.sourceStart());
+ // * TextMarkerASTUtil.extendStatement(n, block.getBlock()); n.setStart(n.sourceStart() +
+ // * block.sourceStart()); n.setEnd(n.sourceEnd() + block.sourceStart()); if (n != null &&
+ // * n.sourceStart() <= position && n.sourceEnd() >= position) { parseBlockStatements(n,
+ // * inNode, position); } } } handleNotInElement(inNode, position); }
+ // */
+ // if (completionNode instanceof StringLiteral) {
+ // int maxLen = position - completionNode.sourceStart();
+ // int pos = maxLen;
+ // SimpleReference tok = TextMarkerParseUtils.extractVariableFromString(
+ // (StringLiteral) completionNode, pos);
+ // if (tok != null) {
+ // this.assistNodeParent = inNode;
+ // ASTNode nde = new CompletionOnVariable(tok.getName(), tok, node, inNode, false);
+ // throw new CompletionNodeFound(nde, null);
+ // } else {
+ // this.assistNodeParent = inNode;
+ // SimpleReference ref = new SimpleReference(position, position, "");
+ // ASTNode nde = new CompletionOnVariable("", ref, node, inNode, true);
+ // throw new CompletionNodeFound(nde, null);
+ // }
+ // }
+ // // if (completionNode instanceof TextMarkerExecuteExpression) {
+ // // TextMarkerExecuteExpression expr = (TextMarkerExecuteExpression)
+ // // completionNode;
+ // // List exprs = expr.parseExpression();
+ // // for (int i = 0; i < exprs.size(); ++i) {
+ // // ASTNode n = (ASTNode) exprs.get(i);
+ // // if (n.sourceStart() <= position
+ // // && n.sourceEnd() >= position) {
+ // // parseBlockStatements(n, expr, position);
+ // // }
+ // // }
+ // // handleNotInElement(expr, position);
+ // // }
+ // if (completionToken != null && completionToken.startsWith("$")) {
+ // // Argument name completion...
+ // this.assistNodeParent = inNode;
+ // ASTNode nde = new CompletionOnVariable(completionToken, completionNode, node, inNode, false);
+ // throw new CompletionNodeFound(nde, null);
+ // } else {
+ // // This is keyword or function completion.
+ // if (inNode instanceof ModuleDeclaration && completionNode != null && first) {
+ // String[] keywords = checkKeywords(completionToken, MODULE);
+ // ASTNode nde = new CompletionOnKeywordOrFunction(completionToken, completionNode, node,
+ // keywords);
+ // this.assistNodeParent = inNode;
+ // throw new CompletionNodeFound(nde, ((ModuleDeclaration) inNode).scope);
+ // } else if (inNode instanceof MethodDeclaration && completionNode != null && first) {
+ // String[] keywords = checkKeywords(completionToken, FUNCTION);
+ // ASTNode nde = new CompletionOnKeywordOrFunction(completionToken, completionNode, node,
+ // keywords);
+ // this.assistNodeParent = inNode;
+ // throw new CompletionNodeFound(nde, ((MethodDeclaration) inNode).scope);
+ // } else if (inNode instanceof TypeDeclaration && completionNode != null && first) {
+ // String[] keywords = checkKeywords(completionToken, NAMESPACE);
+ // ASTNode nde = new CompletionOnKeywordOrFunction(completionToken, completionNode, node,
+ // keywords);
+ // this.assistNodeParent = inNode;
+ // throw new CompletionNodeFound(nde, null/* ((TypeDeclaration)inNode).scope */);
+ // // } else if (inNode instanceof TextMarkerExecuteExpression
+ // // && completionNode != null && first) {
+ // // String[] keywords = checkKeywords(completionToken,
+ // // EXEC_EXPRESSION);
+ // // ASTNode nde = new CompletionOnKeywordOrFunction(
+ // // completionToken, completionNode, node, keywords);
+ // // this.assistNodeParent = inNode;
+ // // throw new CompletionNodeFound(nde, null/*
+ // // ((TypeDeclaration)inNode).scope */);
+ // } else {
+ // if (completionNode != null) {
+ // String[] keywords = checkKeywords(completionToken, MODULE);
+ //
+ // ASTNode nde = new CompletionOnKeywordArgumentOrFunctionArgument(completionToken,
+ // completionNode, (TextMarkerStatement) node, keywords);
+ // this.assistNodeParent = inNode;
+ // throw new CompletionNodeFound(nde, null/* ((TypeDeclaration)inNode).scope */);
+ // } else {
+ // String[] keywords = checkKeywords(completionToken, MODULE);
+ // if (completionToken == null) {
+ // completionToken = "";
+ // }
+ // ASTNode nde = new CompletionOnKeywordArgumentOrFunctionArgument(completionToken,
+ // (TextMarkerStatement) node, keywords, position);
+ // this.assistNodeParent = inNode;
+ // throw new CompletionNodeFound(nde, null/* ((TypeDeclaration)inNode).scope */);
+ // }
+ // }
+ // }
+ // // if (checkVariableWithoutDollarCompletion(statement, position)
+ // // && completionToken != null) {
+ // // this.assistNodeParent = inNode;
+ // // SimpleReference ref = new SimpleReference(completionNode
+ // // .sourceStart(), completionNode.sourceEnd(),
+ // // completionToken);
+ // // ASTNode nde = new CompletionOnVariable(completionToken, ref,
+ // // node, inNode, true);
+ // // throw new CompletionNodeFound(nde, null);
+ // // }
+ //
+ // } else if (node instanceof MethodDeclaration) {
+ // MethodDeclaration method = (MethodDeclaration) node;
+ // List statements = method.getStatements();
+ // boolean inStatement = false;
+ // if (statements != null) {
+ // int length = statements.size();
+ // for (int i = 0; i < length; i++) {
+ // ASTNode nde = (ASTNode) statements.get(i);
+ // if (nde.sourceStart() <= position && nde.sourceEnd() >= position) {
+ // inStatement = true;
+ // parseBlockStatements(nde, method, position);
+ // }
+ // }
+ // }
+ // if (!inStatement) {
+ // this.handleNotInElement(method, position);
+ // }
+ // } else {
+ // visitElements(node, position);
+ // }
+ }
+
+ public class CompletionVisitor extends ASTVisitor {
+ protected int position;
+
+ protected ModuleDeclaration module;
+
+ public CompletionVisitor(int position, ModuleDeclaration module) {
+ this.position = position;
+ this.module = module;
+ }
+
+ @Override
+ public boolean visit(Statement s) throws Exception {
+ // if (s.sourceStart() <= position && s.sourceEnd() >= position) {
+ // for (int i = 0; i < extensions.length; i++) {
+ // extensions[i].visit(s, TextMarkerCompletionParser.this,
+ // position);
+ // }
+ // if (s instanceof TextMarkerStatement) {
+ // ASTNode inNode = TextMarkerParseUtil.getScopeParent(module, s);
+ // TextMarkerCompletionParser.this.parseBlockStatements(s, inNode,
+ // position);
+ // }
+ // if (s instanceof TextMarkerPackageDeclaration) {
+ // TextMarkerPackageDeclaration decl =
+ // (TextMarkerPackageDeclaration) s;
+ // if (decl.getNameStart() <= position
+ // && position <= decl.getNameEnd()) {
+ // ASTNode inNode = TextMarkerParseUtil.getScopeParent(module, s);
+ // assistNodeParent = inNode;
+ // throw new CompletionNodeFound(decl, null/*
+ // ((TypeDeclaration)inNode).scope */);
+ // }
+ // }
+ // }
+ return super.visit(s);
+ }
+
+ @Override
+ public boolean visit(Expression s) throws Exception {
+ if (s.sourceStart() <= position && s.sourceEnd() >= position) {
+ for (int i = 0; i < extensions.length; i++) {
+ extensions[i].visit(s, TextMarkerCompletionParser.this, position);
+ }
+ }
+ return super.visit(s);
+ }
+
+ @Override
+ public boolean endvisit(Expression s) throws Exception {
+ if (s instanceof Block && s.sourceStart() <= position && s.sourceEnd() >= position) {
+ // We are in block, and no in node completion are done.
+ String[] keywords = checkKeywords("", MODULE);
+ ASTNode inNode = TextMarkerParseUtils.getScopeParent(module, s);
+ ASTNode nde = new CompletionOnKeywordOrFunction("", inNode, s, keywords);
+ assistNodeParent = inNode;
+ throw new CompletionNodeFound(nde, null);
+ }
+ return super.endvisit(s);
+ }
+ };
+
+ protected CompletionVisitor createCompletionVisitor(int position) {
+ return new CompletionVisitor(position, this.getModule());
+ }
+
+ private void visitElements(ASTNode node, int position) {
+ if (!(node instanceof TextMarkerStatement)) {
+ CompletionVisitor visitor = createCompletionVisitor(position);
+ try {
+ node.traverse(visitor);
+ } catch (CompletionNodeFound e) {
+ throw e;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private boolean checkVariableWithoutDollarCompletion(TextMarkerStatement statement, int position) {
+ // TODO: Add more compecated check.
+ Expression e = statement.getAt(0);
+ if (e instanceof SimpleReference) {
+ SimpleReference ref = (SimpleReference) e;
+ String name = ref.getName();
+ if (name.equals("set")) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public String[] checkKeywords(String completionToken, int type) {
+ // String[] keywords = TextMarkerKeywordsManager.getKeywords(type);
+ // // TODO: Possible require cases.
+ // if (type == MODULE || type == FUNCTION || type == NAMESPACE
+ // || type == EXEC_EXPRESSION) {
+ // // Suppose we can handle all keywords.
+ // String[] kw = new String[keywords.length];
+ // for (int i = 0; i < keywords.length; ++i) {
+ // kw[i] = keywords[i];
+ // }
+ // return kw;
+ // }
+ return null;
+ }
+
+ public void setAssistNodeParent(ASTNode prevParent) {
+ this.assistNodeParent = prevParent;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/completion/TextMarkerCompletionParser.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/completion/TextMarkerCompletionParser.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/selection/SelectionOnAST.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/selection/SelectionOnAST.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/selection/SelectionOnAST.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/selection/SelectionOnAST.java Mon Aug 1 14:06:27 2011
@@ -0,0 +1,18 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist.selection;
+
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.references.SimpleReference;
+
+public class SelectionOnAST extends SimpleReference {
+
+ private ASTNode method;
+
+ public SelectionOnAST(ASTNode token) {
+ super(token.sourceStart(), token.sourceEnd(), "");
+ this.method = token;
+ }
+
+ public ASTNode getNode() {
+ return method;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/selection/SelectionOnAST.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/selection/SelectionOnAST.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/selection/SelectionOnKeywordOrFunction.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/selection/SelectionOnKeywordOrFunction.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/selection/SelectionOnKeywordOrFunction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/selection/SelectionOnKeywordOrFunction.java Mon Aug 1 14:06:27 2011
@@ -0,0 +1,17 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist.selection;
+
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.references.SimpleReference;
+
+public class SelectionOnKeywordOrFunction extends SimpleReference {
+ private ASTNode originalNode;
+
+ public SelectionOnKeywordOrFunction(String completionToken, ASTNode completionNode, ASTNode node) {
+ super(completionNode.sourceStart(), completionNode.sourceEnd(), completionToken);
+ this.originalNode = node;
+ }
+
+ public ASTNode getOriginalNode() {
+ return this.originalNode;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/selection/SelectionOnKeywordOrFunction.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/selection/SelectionOnKeywordOrFunction.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/selection/SelectionOnNode.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/selection/SelectionOnNode.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/selection/SelectionOnNode.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/selection/SelectionOnNode.java Mon Aug 1 14:06:27 2011
@@ -0,0 +1,27 @@
+package org.apache.uima.tm.dltk.internal.core.codeassist.selection;
+
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.references.SimpleReference;
+
+public class SelectionOnNode extends SimpleReference {
+ private ASTNode node;
+
+ private int position;
+
+ public SelectionOnNode(ASTNode token) {
+ super(token.sourceStart(), token.sourceEnd(), "");
+ this.node = token;
+ }
+
+ public ASTNode getNode() {
+ return this.node;
+ }
+
+ public void setPosition(int position) {
+ this.position = position;
+ }
+
+ public int getPosition() {
+ return this.position;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/codeassist/selection/SelectionOnNode.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/selection/SelectionOnNode.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/packages/DLTKTextMarkerHelper.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/packages/DLTKTextMarkerHelper.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/packages/DLTKTextMarkerHelper.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/packages/DLTKTextMarkerHelper.java Mon Aug 1 14:06:27 2011
@@ -0,0 +1,397 @@
+package org.apache.uima.tm.dltk.internal.core.packages;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+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 javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.uima.tm.dltk.core.TextMarkerPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.environment.IDeployment;
+import org.eclipse.dltk.core.environment.IExecutionEnvironment;
+import org.eclipse.dltk.core.environment.IFileHandle;
+import org.eclipse.dltk.launching.EnvironmentVariable;
+import org.eclipse.dltk.launching.IInterpreterInstall;
+import org.eclipse.dltk.launching.InterpreterConfig;
+import org.eclipse.dltk.launching.ScriptLaunchUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+
+public class DLTKTextMarkerHelper {
+
+ private static final String DLTK_TM = "scripts/dltk.tm"; //$NON-NLS-1$
+
+ public static List getScriptOutput(InputStream stream) {
+ final List elements = new ArrayList();
+ final BufferedReader input = new BufferedReader(new InputStreamReader(stream));
+ Thread t = new Thread(new Runnable() {
+ public void run() {
+ try {
+ while (true) {
+ String line;
+ line = input.readLine();
+ if (line == null) {
+ break;
+ }
+ elements.add(line);
+ }
+ } catch (IOException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ }
+ });
+ t.start();
+ try {
+ t.join(50000);// No more then 50 seconds
+ } catch (InterruptedException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ return elements;
+ }
+
+ private static List deployExecute(IExecutionEnvironment exeEnv, String installLocation,
+ String[] arguments, EnvironmentVariable[] env) {
+ IDeployment deployment = exeEnv.createDeployment();
+ IFileHandle script = deploy(deployment);
+ if (script == null) {
+ return null;
+ }
+
+ IFileHandle workingDir = script.getParent();
+ InterpreterConfig config = ScriptLaunchUtil.createInterpreterConfig(exeEnv, script, workingDir,
+ env);
+ // For wish
+ config.removeEnvVar("DISPLAY"); //$NON-NLS-1$
+
+ if (arguments != null) {
+ config.addScriptArgs(arguments);
+ }
+
+ Process process = null;
+ try {
+ process = ScriptLaunchUtil.runScriptWithInterpreter(exeEnv, installLocation, config);
+ } catch (CoreException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ if (process == null) {
+ return new ArrayList();
+ }
+ List output = getScriptOutput(process.getInputStream());
+ getScriptOutput(process.getErrorStream());
+ process.destroy();
+ deployment.dispose();
+ return output;
+ }
+
+ private static IFileHandle deploy(IDeployment deployment) {
+ IFileHandle script;
+ try {
+ IPath path = deployment.add(TextMarkerPlugin.getDefault().getBundle(), DLTK_TM);
+ script = deployment.getFile(path);
+ } catch (IOException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+ return script;
+ }
+
+ public static String[] getDefaultPath(IFileHandle installLocation,
+ EnvironmentVariable[] environment) {
+ // Process process = deployExecute(installLocation.getAbsolutePath(),
+ // new String[] { "get-paths" }, environment);
+ // List content = getScriptOutput(process);
+ // String[] autoPath = getAutoPath(content);
+ // for (int i = 0; i < autoPath.length; i++) {
+ // Path p = new Path(autoPath[i]);
+ // if (p.lastSegment().startsWith("tcl8.")) {
+ // return new String[] { autoPath[i] };
+ // }
+ // }
+ // process.destroy();
+ return new String[0];
+ // return autoPath;
+ }
+
+ public static TextMarkerPackage[] getSrcs(IExecutionEnvironment exeEnv,
+ IFileHandle installLocation, EnvironmentVariable[] environment, String packageName) {
+ IDeployment deployment = exeEnv.createDeployment();
+ IFileHandle script = deploy(deployment);
+ if (script == null) {
+ return null;
+ }
+
+ IFileHandle workingDir = script.getParent();
+ InterpreterConfig config = ScriptLaunchUtil.createInterpreterConfig(exeEnv, script, workingDir,
+ environment);
+ String names = packageName;
+ ByteArrayInputStream bais = new ByteArrayInputStream(names.getBytes());
+ IPath packagesPath = null;
+ try {
+ packagesPath = deployment.add(bais, "packages.txt"); //$NON-NLS-1$
+ } catch (IOException e1) {
+ if (DLTKCore.DEBUG) {
+ e1.printStackTrace();
+ }
+ return null;
+ }
+ IFileHandle file = deployment.getFile(packagesPath);
+ // For wish
+ config.removeEnvVar("DISPLAY"); //$NON-NLS-1$
+ String[] arguments = new String[] { "get-srcs", "-fpkgs", //$NON-NLS-1$ //$NON-NLS-2$
+ file.toOSString() };
+
+ config.addScriptArgs(arguments);
+
+ Process process = null;
+ try {
+ process = ScriptLaunchUtil.runScriptWithInterpreter(exeEnv, installLocation.toOSString(),
+ config);
+ } catch (CoreException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ if (process == null) {
+ return null;
+ }
+ List output = getScriptOutput(process.getInputStream());
+ getScriptOutput(process.getErrorStream());
+ process.destroy();
+ deployment.dispose();
+ return getPackagePath(output);
+ }
+
+ private static boolean isElementName(Node nde, String name) {
+ if (nde != null) {
+ if (nde.getNodeType() == Node.ELEMENT_NODE) {
+ if (name.equalsIgnoreCase(nde.getNodeName())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static String[] getAutoPath(List content) {
+ String text = getXMLContent(content);
+ Document document = getDocument(text);
+
+ Set paths = new HashSet();
+ if (document != null) {
+ Element element = document.getDocumentElement();
+ NodeList childNodes = element.getChildNodes();
+ int len = childNodes.getLength();
+ for (int i = 0; i < len; i++) {
+ Node nde = childNodes.item(i);
+ if (isElementName(nde, "path")) { //$NON-NLS-1$
+ Element el = (Element) nde;
+ String path = el.getAttribute("name"); //$NON-NLS-1$
+ if (path.length() > 0) {
+ paths.add(path);
+ }
+ }
+ }
+ }
+ return (String[]) paths.toArray(new String[paths.size()]);
+ }
+
+ public static class TextMarkerPackage {
+ private String name;
+
+ private Set paths = new HashSet();
+
+ private Set dependencies = new HashSet();
+
+ public TextMarkerPackage(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ TextMarkerPackage other = (TextMarkerPackage) obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ return true;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set getPaths() {
+ return paths;
+ }
+
+ public void setPaths(Set paths) {
+ this.paths = paths;
+ }
+
+ public Set getDependencies() {
+ return dependencies;
+ }
+
+ public void setDependencies(Set dependencies) {
+ this.dependencies = dependencies;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer(128);
+ sb.append("TextMarkerPackage"); //$NON-NLS-1$
+ sb.append('{');
+ sb.append("name=").append(name); //$NON-NLS-1$
+ sb.append(' ');
+ sb.append("paths=").append(paths); //$NON-NLS-1$
+ sb.append(' ');
+ sb.append("dependencies=").append(dependencies); //$NON-NLS-1$
+ sb.append('}');
+ return sb.toString();
+ }
+ };
+
+ public static TextMarkerPackage[] getPackagePath(List content) {
+ String text = getXMLContent(content);
+ Document document = getDocument(text);
+
+ Map packages = new HashMap();
+ if (document != null) {
+ Element element = document.getDocumentElement();
+ NodeList childNodes = element.getChildNodes();
+ int len = childNodes.getLength();
+ for (int i = 0; i < len; i++) {
+ Node nde = childNodes.item(i);
+ if (isElementName(nde, "path")) { //$NON-NLS-1$
+ Element el = (Element) nde;
+ NodeList elChilds = el.getChildNodes();
+ for (int j = 0; j < elChilds.getLength(); j++) {
+ Node pkgNde = elChilds.item(j);
+ if (isElementName(pkgNde, "package")) { //$NON-NLS-1$
+ populatePackage(packages, pkgNde);
+ }
+ }
+ }
+ }
+ }
+ return (TextMarkerPackage[]) packages.values().toArray(new TextMarkerPackage[packages.size()]);
+ }
+
+ private static void populatePackage(Map packages, Node pkgNde) {
+ Element pkg = (Element) pkgNde;
+ String pkgName = pkg.getAttribute("name"); //$NON-NLS-1$
+ TextMarkerPackage tclPackage = new TextMarkerPackage(pkgName);
+ if (packages.containsKey(tclPackage)) {
+ tclPackage = (TextMarkerPackage) packages.get(tclPackage);
+ } else {
+ packages.put(tclPackage, tclPackage);
+ }
+ NodeList childs = pkg.getChildNodes();
+ for (int i = 0; i < childs.getLength(); i++) {
+ Node nde = childs.item(i);
+ if (isElementName(nde, "source")) { //$NON-NLS-1$
+ Element el = (Element) nde;
+ String name = el.getAttribute("name"); //$NON-NLS-1$
+ IPath path = new Path(name).removeLastSegments(1);
+ tclPackage.getPaths().add(path);
+ } else if (isElementName(nde, "require")) { //$NON-NLS-1$
+ Element el = (Element) nde;
+ String name = el.getAttribute("name"); //$NON-NLS-1$
+ tclPackage.getDependencies().add(name);
+ }
+ }
+ }
+
+ private static Document getDocument(String text) {
+ try {
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ parser.setErrorHandler(new DefaultHandler());
+ Document document = parser.parse(new ByteArrayInputStream(text.getBytes()));
+ return document;
+ } catch (IOException e) {
+
+ } catch (ParserConfigurationException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ } catch (SAXException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+
+ private static String getXMLContent(List content) {
+ StringBuffer newList = new StringBuffer();
+ if (content != null) {
+ for (Iterator iterator = content.iterator(); iterator.hasNext();) {
+ String line = (String) iterator.next();
+ if (line.trim().startsWith("<")) { //$NON-NLS-1$
+ newList.append(line).append("\n"); //$NON-NLS-1$
+ }
+ }
+ }
+ return newList.toString();
+ }
+
+ public static Set getPackages(IInterpreterInstall install) {
+ IExecutionEnvironment exeEnv = install.getExecEnvironment();
+ List content = deployExecute(exeEnv, install.getInstallLocation().toOSString(),
+ new String[] { "get-pkgs" }, install //$NON-NLS-1$
+ .getEnvironmentVariables());
+ Set packages = new HashSet();
+ TextMarkerPackage[] packagePath = getPackagePath(content);
+ for (int i = 0; i < packagePath.length; i++) {
+ packages.add(packagePath[i].getName());
+ }
+ return packages;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/packages/DLTKTextMarkerHelper.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/packages/DLTKTextMarkerHelper.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/packages/Messages.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/packages/Messages.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/packages/Messages.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/packages/Messages.java Mon Aug 1 14:06:27 2011
@@ -0,0 +1,24 @@
+package org.apache.uima.tm.dltk.internal.core.packages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.apache.uima.tm.dltk.internal.core.packages.messages"; //$NON-NLS-1$
+
+ public static String TextMarkerCheckBuilder_interpreterNotFound;
+
+ public static String TextMarkerCheckBuilder_processing;
+
+ public static String TextMarkerCheckBuilder_retrievePackages;
+
+ public static String TextMarkerCheckBuilder_unknownPackage;
+
+ public static String TextMarkerCheckBuilder_unresolvedDependencies;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/packages/Messages.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.dltk.core/src/main/java/org/apache/uima/tm/dltk/internal/core/packages/Messages.java
------------------------------------------------------------------------------
svn:mime-type = text/plain