You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2013/04/29 16:51:06 UTC
svn commit: r1477113 [4/18] - in
/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide:
./ core/ core/builder/ core/codeassist/ core/extensions/ core/packages/
core/parser/ core/search/ debug/ debug/ui/ debug/ui/handlers/ debug/ui...
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaResolver.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaResolver.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaResolver.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaResolver.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,327 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.ruta.ide.core.codeassist;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.ruta.ide.core.parser.RutaParseUtils;
+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 RutaResolver {
+ private IResolveElementParent resolver;
+
+ private ModuleDeclaration moduleDeclaration;
+
+ private ISourceModule sourceModule;
+
+ public RutaResolver(ISourceModule sourceModule, ModuleDeclaration moduleDeclaration,
+ IResolveElementParent resolver) {
+ this(sourceModule, moduleDeclaration);
+ this.resolver = resolver;
+ }
+
+ public RutaResolver(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 RutaStatement) { RutaStatement s =
+ * (RutaStatement) 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 = RutaParseUtils.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 = RutaResolver.findTypeFrom(sourceModule.getChildren(), "", pName, '$');
+ if (element == null) {
+ return;
+ }
+ } catch (ModelException e) {
+ e.printStackTrace();
+ return;
+ }
+ }
+ methodName = RutaResolver.getNodeChildName(nde);
+ }
+ IModelElement e = RutaResolver.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;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaRuleIdVisitor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaRuleIdVisitor.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaRuleIdVisitor.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaRuleIdVisitor.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.uima.ruta.ide.core.codeassist;
+
+import org.apache.uima.ruta.ide.parser.ast.RutaRule;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.statements.Statement;
+
+public class RutaRuleIdVisitor extends ASTVisitor {
+
+ private int id;
+
+ private RutaRule result;
+
+ public RutaRuleIdVisitor(int id) {
+ super();
+ this.id = id;
+ }
+
+ @Override
+ public boolean visit(Statement s) throws Exception {
+ if (result != null) {
+ return false;
+ }
+ if (s instanceof RutaRule) {
+ RutaRule rule = (RutaRule) s;
+ if (id == rule.getId()) {
+ result = rule;
+ }
+ }
+ return true;
+ }
+
+ public RutaRule getResult() {
+ return result;
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaSelectionEngine.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaSelectionEngine.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaSelectionEngine.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaSelectionEngine.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,462 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.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.commons.lang3.StringUtils;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.resource.metadata.TypeDescription;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.ruta.ide.core.builder.RutaProjectUtils;
+import org.apache.uima.ruta.ide.core.parser.RutaParseUtils;
+import org.apache.uima.ruta.ide.parser.ast.TMActionConstants;
+import org.apache.uima.ruta.ide.parser.ast.TMStatementConstants;
+import org.apache.uima.ruta.ide.parser.ast.RutaImportStatement;
+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.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.ScriptSelectionEngine;
+import org.eclipse.dltk.compiler.env.IModuleSource;
+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 RutaSelectionEngine extends ScriptSelectionEngine {
+
+ 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 RutaImportStatement) {
+ // handle engine imports
+ if (((RutaImportStatement) s).getType() == TMStatementConstants.S_IMPORT_ENGINE) {
+ SimpleReference sRef = (SimpleReference) ((RutaImportStatement) s).getExpression();
+ importEngine(sRef.getName());
+ }
+ // handle script imports
+ if (((RutaImportStatement) s).getType() == TMStatementConstants.S_IMPORT_SCRIPT) {
+ importScript(s);
+ }
+ // handle type system imports
+ if (((RutaImportStatement) 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 (StringUtils.isEmpty(tail)) {
+ 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.: "org.apache.uima.myengine" ".xml" will be added.
+ * @return file.exists
+ */
+ public IFile getEngine(String xmlFilePath, IScriptProject project) {
+ IFolder folder = project.getProject().getFolder(
+ RutaProjectUtils.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) ((RutaImportStatement) s).getExpression();
+ String sRefName = sRef.getName();
+ importScript(sRefName);
+ }
+
+ private void importTypesystem(Statement s) {
+ SimpleReference sRef = (SimpleReference) ((RutaImportStatement) 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(RutaProjectUtils.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 RutaSelectionParser parser = new RutaSelectionParser();
+
+ protected org.eclipse.dltk.core.ISourceModule sourceModule;
+
+ protected IDLTKLanguageToolkit toolkit;
+
+
+ public IModelElement[] select(IModuleSource 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, 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 = RutaParseUtils.startLineOrNoSymbol(selectionSourceStart, source);
+ int end = RutaParseUtils.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;
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaSelectionParser.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaSelectionParser.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaSelectionParser.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaSelectionParser.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.ruta.ide.core.codeassist;
+
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.compiler.env.IModuleSource;
+
+public class RutaSelectionParser extends RutaAssistParser {
+
+ public void handleNotInElement(ASTNode unit, int position) {
+
+ }
+
+ public void parseBlockStatements(ASTNode node, ASTNode unit, int position) {
+
+ }
+
+ public ModuleDeclaration parse(IModuleSource sourceModule) {
+ ModuleDeclaration module = (ModuleDeclaration) this.parser.parse(sourceModule, null);
+ module.rebuild();
+ return module;
+ }
+}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnAST.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnAST.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnAST.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnAST.java Mon Apr 29 14:50:56 2013
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.codeassist;
+package org.apache.uima.ruta.ide.core.codeassist;
import org.eclipse.dltk.ast.ASTNode;
import org.eclipse.dltk.ast.references.SimpleReference;
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnKeywordOrFunction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnKeywordOrFunction.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnKeywordOrFunction.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnKeywordOrFunction.java Mon Apr 29 14:50:56 2013
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.codeassist;
+package org.apache.uima.ruta.ide.core.codeassist;
import org.eclipse.dltk.ast.ASTNode;
import org.eclipse.dltk.ast.references.SimpleReference;
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnNode.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnNode.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnNode.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnNode.java Mon Apr 29 14:50:56 2013
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.codeassist;
+package org.apache.uima.ruta.ide.core.codeassist;
import org.eclipse.dltk.ast.ASTNode;
import org.eclipse.dltk.ast.references.SimpleReference;
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/TMAutoCompletionToolkit.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/TMAutoCompletionToolkit.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/TMAutoCompletionToolkit.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/TMAutoCompletionToolkit.java Mon Apr 29 14:50:56 2013
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.codeassist;
+package org.apache.uima.ruta.ide.core.codeassist;
public class TMAutoCompletionToolkit {
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ICompletionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ICompletionExtension.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ICompletionExtension.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ICompletionExtension.java Mon Apr 29 14:50:56 2013
@@ -17,14 +17,14 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.extensions;
+package org.apache.uima.ruta.ide.core.extensions;
import java.util.Set;
-import org.apache.uima.textmarker.ide.core.codeassist.CompletionOnKeywordArgumentOrFunctionArgument;
-import org.apache.uima.textmarker.ide.core.codeassist.CompletionOnKeywordOrFunction;
-import org.apache.uima.textmarker.ide.core.codeassist.TextMarkerCompletionEngine;
-import org.apache.uima.textmarker.ide.core.codeassist.TextMarkerCompletionParser;
+import org.apache.uima.ruta.ide.core.codeassist.CompletionOnKeywordArgumentOrFunctionArgument;
+import org.apache.uima.ruta.ide.core.codeassist.CompletionOnKeywordOrFunction;
+import org.apache.uima.ruta.ide.core.codeassist.RutaCompletionEngine;
+import org.apache.uima.ruta.ide.core.codeassist.RutaCompletionParser;
import org.eclipse.dltk.ast.ASTNode;
import org.eclipse.dltk.ast.expressions.Expression;
import org.eclipse.dltk.ast.statements.Statement;
@@ -32,16 +32,16 @@ import org.eclipse.dltk.core.CompletionR
public interface ICompletionExtension {
- boolean visit(Expression s, TextMarkerCompletionParser parser, int position);
+ boolean visit(Expression s, RutaCompletionParser parser, int position);
- boolean visit(Statement s, TextMarkerCompletionParser parser, int position);
+ boolean visit(Statement s, RutaCompletionParser parser, int position);
void completeOnKeywordOrFunction(CompletionOnKeywordOrFunction key, ASTNode astNodeParent,
- TextMarkerCompletionEngine engine);
+ RutaCompletionEngine engine);
void completeOnKeywordArgumentsOne(String name,
CompletionOnKeywordArgumentOrFunctionArgument compl, Set methodNames, Statement st,
- TextMarkerCompletionEngine tmCompletionEngine);
+ RutaCompletionEngine tmCompletionEngine);
void setRequestor(CompletionRequestor requestor);
}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEActionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEActionExtension.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEActionExtension.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEActionExtension.java Mon Apr 29 14:50:56 2013
@@ -17,10 +17,10 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.extensions;
+package org.apache.uima.ruta.ide.core.extensions;
-public interface IIDEActionExtension extends ITextMarkerExtension {
+public interface IIDEActionExtension extends IRutaExtension {
}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEBooleanFunctionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEBooleanFunctionExtension.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEBooleanFunctionExtension.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEBooleanFunctionExtension.java Mon Apr 29 14:50:56 2013
@@ -17,9 +17,9 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.extensions;
+package org.apache.uima.ruta.ide.core.extensions;
-public interface IIDEBooleanFunctionExtension extends ITextMarkerExtension {
+public interface IIDEBooleanFunctionExtension extends IRutaExtension {
}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEConditionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEConditionExtension.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEConditionExtension.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEConditionExtension.java Mon Apr 29 14:50:56 2013
@@ -17,10 +17,10 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.extensions;
+package org.apache.uima.ruta.ide.core.extensions;
-public interface IIDEConditionExtension extends ITextMarkerExtension {
+public interface IIDEConditionExtension extends IRutaExtension {
}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDENumberFunctionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDENumberFunctionExtension.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDENumberFunctionExtension.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDENumberFunctionExtension.java Mon Apr 29 14:50:56 2013
@@ -17,9 +17,9 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.extensions;
+package org.apache.uima.ruta.ide.core.extensions;
-public interface IIDENumberFunctionExtension extends ITextMarkerExtension {
+public interface IIDENumberFunctionExtension extends IRutaExtension {
}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEStringFunctionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEStringFunctionExtension.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEStringFunctionExtension.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEStringFunctionExtension.java Mon Apr 29 14:50:56 2013
@@ -17,9 +17,9 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.extensions;
+package org.apache.uima.ruta.ide.core.extensions;
-public interface IIDEStringFunctionExtension extends ITextMarkerExtension {
+public interface IIDEStringFunctionExtension extends IRutaExtension {
}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDETypeFunctionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDETypeFunctionExtension.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDETypeFunctionExtension.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDETypeFunctionExtension.java Mon Apr 29 14:50:56 2013
@@ -17,9 +17,9 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.extensions;
+package org.apache.uima.ruta.ide.core.extensions;
-public interface IIDETypeFunctionExtension extends ITextMarkerExtension {
+public interface IIDETypeFunctionExtension extends IRutaExtension {
}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMatchLocatorExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMatchLocatorExtension.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMatchLocatorExtension.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMatchLocatorExtension.java Mon Apr 29 14:50:56 2013
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.extensions;
+package org.apache.uima.ruta.ide.core.extensions;
import org.eclipse.dltk.ast.ASTNode;
import org.eclipse.dltk.core.search.matching.PatternLocator;
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMixinBuildVisitorExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMixinBuildVisitorExtension.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMixinBuildVisitorExtension.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMixinBuildVisitorExtension.java Mon Apr 29 14:50:56 2013
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.extensions;
+package org.apache.uima.ruta.ide.core.extensions;
public interface IMixinBuildVisitorExtension {
//
@@ -25,20 +25,20 @@ public interface IMixinBuildVisitorExten
// * If method return true, then other checks will not be provided and
// * original visit will return true
// */
- // boolean visit(MethodDeclaration s, TextMarkerMixinBuildVisitor original);
+ // boolean visit(MethodDeclaration s, RutaMixinBuildVisitor original);
//
// /**
// * If method return true, then other checks will not be provided and
// * original visit will return true
// */
- // boolean visit(TypeDeclaration s, TextMarkerMixinBuildVisitor
+ // boolean visit(TypeDeclaration s, RutaMixinBuildVisitor
// tmMixinBuildVisitor);
//
// /**
// * If method return true, then other checks will not be provided and
// * original visit will return <b>false</b>
// */
- // boolean visit(Statement s, TextMarkerMixinBuildVisitor
+ // boolean visit(Statement s, RutaMixinBuildVisitor
// tmMixinBuildVisitor);
}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaExtension.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaExtension.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaExtension.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.ruta.ide.core.extensions;
+
+import org.antlr.runtime.RecognitionException;
+import org.apache.uima.ruta.ide.validator.RutaCheckerProblemFactory;
+import org.eclipse.dltk.ast.expressions.Expression;
+import org.eclipse.dltk.compiler.problem.IProblemReporter;
+
+public interface IRutaExtension {
+
+ String[] getKnownExtensions();
+
+ boolean checkSyntax(Expression element, RutaCheckerProblemFactory problemFactory, IProblemReporter rep) throws RecognitionException;
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaLanguageExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaLanguageExtension.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaLanguageExtension.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaLanguageExtension.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.ruta.ide.core.extensions;
+
+public interface IRutaLanguageExtension {
+ String getName();
+
+ ISourceElementRequestVisitorExtension createSourceElementRequestVisitorExtension();
+
+ IMixinBuildVisitorExtension createMixinBuildVisitorExtension();
+
+ IMatchLocatorExtension createMatchLocatorExtension();
+
+ ICompletionExtension createCompletionExtension();
+
+ ISelectionExtension createSelectionExtension();
+}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISelectionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISelectionExtension.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISelectionExtension.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISelectionExtension.java Mon Apr 29 14:50:56 2013
@@ -17,20 +17,20 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.extensions;
+package org.apache.uima.ruta.ide.core.extensions;
-import org.apache.uima.textmarker.ide.core.codeassist.SelectionOnKeywordOrFunction;
-import org.apache.uima.textmarker.ide.core.codeassist.TextMarkerSelectionEngine;
+import org.apache.uima.ruta.ide.core.codeassist.SelectionOnKeywordOrFunction;
+import org.apache.uima.ruta.ide.core.codeassist.RutaSelectionEngine;
import org.eclipse.dltk.ast.ASTNode;
public interface ISelectionExtension {
void selectionOnKeywordOrFunction(SelectionOnKeywordOrFunction key,
- TextMarkerSelectionEngine tmSelectionEngine);
+ RutaSelectionEngine tmSelectionEngine);
- void selectionOnAST(ASTNode node, TextMarkerSelectionEngine tmSelectionEngine);
+ void selectionOnAST(ASTNode node, RutaSelectionEngine tmSelectionEngine);
- void selectionOnNode(ASTNode node, int position, TextMarkerSelectionEngine tmSelectionEngine);
+ void selectionOnNode(ASTNode node, int position, RutaSelectionEngine tmSelectionEngine);
}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISourceElementRequestVisitorExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISourceElementRequestVisitorExtension.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISourceElementRequestVisitorExtension.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISourceElementRequestVisitorExtension.java Mon Apr 29 14:50:56 2013
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.extensions;
+package org.apache.uima.ruta.ide.core.extensions;
import org.eclipse.dltk.ast.declarations.Declaration;
@@ -25,16 +25,16 @@ public interface ISourceElementRequestVi
int getModifiers(Declaration s);
- // boolean visit(Statement statement, TextMarkerSourceElementRequestVisitor
+ // boolean visit(Statement statement, RutaSourceElementRequestVisitor
// original);
//
// boolean extendedExitRequired(MethodDeclaration method,
- // TextMarkerSourceElementRequestVisitor tmSourceElementRequestVisitor);
+ // RutaSourceElementRequestVisitor tmSourceElementRequestVisitor);
//
// ExitFromType getExitExtended(MethodDeclaration method,
- // TextMarkerSourceElementRequestVisitor tmSourceElementRequestVisitor);
+ // RutaSourceElementRequestVisitor tmSourceElementRequestVisitor);
//
// ExitFromType processField(FieldDeclaration decl,
- // TextMarkerSourceElementRequestVisitor tmSourceElementRequestVisitor);
+ // RutaSourceElementRequestVisitor tmSourceElementRequestVisitor);
}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/RutaExternalFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/RutaExternalFactory.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/RutaExternalFactory.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/RutaExternalFactory.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.core.extensions;
+
+import java.util.List;
+
+import org.antlr.runtime.RecognitionException;
+import org.antlr.runtime.Token;
+import org.apache.uima.ruta.ide.parser.ast.ActionFactory;
+import org.apache.uima.ruta.ide.parser.ast.ConditionFactory;
+import org.apache.uima.ruta.ide.parser.ast.ExpressionFactory;
+import org.apache.uima.ruta.ide.parser.ast.RutaAction;
+import org.apache.uima.ruta.ide.parser.ast.RutaCondition;
+import org.eclipse.dltk.ast.expressions.Expression;
+
+public class RutaExternalFactory {
+
+ public RutaExternalFactory() {
+ super();
+ }
+
+
+ public RutaCondition createExternalCondition(Token id, List<Expression> args)
+ throws RecognitionException {
+ return ConditionFactory.createCondition(id, args);
+ }
+
+ public RutaAction createExternalAction(Token id, List<Expression> args)
+ throws RecognitionException {
+ return ActionFactory.createAction(id, args);
+ }
+
+ public Expression createExternalNumberFunction(Token id, List<Expression> args)
+ throws RecognitionException {
+ return ExpressionFactory.createNumberFunction(id, args);
+ }
+
+ public Expression createExternalBooleanFunction(Token id, List<Expression> args)
+ throws RecognitionException {
+ return ExpressionFactory.createBooleanFunction(id, args);
+ }
+
+ public Expression createExternalStringFunction(Token id, List<Expression> args)
+ throws RecognitionException {
+ return ExpressionFactory.createStringFunction(id, args);
+ }
+
+ public Expression createExternalTypeFunction(Token id, List<Expression> args)
+ throws RecognitionException {
+ return ExpressionFactory.createTypeFunction(id, args);
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/DLTKRutaHelper.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/DLTKRutaHelper.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/DLTKRutaHelper.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/DLTKRutaHelper.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,415 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.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.ruta.ide.RutaIdePlugin;
+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 DLTKRutaHelper {
+
+ 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(RutaIdePlugin.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 RutaPackage[] 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 RutaPackage {
+ private String name;
+
+ private Set paths = new HashSet();
+
+ private Set dependencies = new HashSet();
+
+ public RutaPackage(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;
+ RutaPackage other = (RutaPackage) 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("RutaPackage"); //$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 RutaPackage[] 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 (RutaPackage[]) packages.values().toArray(new RutaPackage[packages.size()]);
+ }
+
+ private static void populatePackage(Map packages, Node pkgNde) {
+ Element pkg = (Element) pkgNde;
+ String pkgName = pkg.getAttribute("name"); //$NON-NLS-1$
+ RutaPackage tclPackage = new RutaPackage(pkgName);
+ if (packages.containsKey(tclPackage)) {
+ tclPackage = (RutaPackage) 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();
+ RutaPackage[] packagePath = getPackagePath(content);
+ for (int i = 0; i < packagePath.length; i++) {
+ packages.add(packagePath[i].getName());
+ }
+ return packages;
+ }
+}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/Messages.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/Messages.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/Messages.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/Messages.java Mon Apr 29 14:50:56 2013
@@ -17,22 +17,22 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.packages;
+package org.apache.uima.ruta.ide.core.packages;
import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
- private static final String BUNDLE_NAME = "org.apache.uima.textmarker.ide.core.packages.messages"; //$NON-NLS-1$
+ private static final String BUNDLE_NAME = "org.apache.uima.ruta.ide.core.packages.messages"; //$NON-NLS-1$
- public static String TextMarkerCheckBuilder_interpreterNotFound;
+ public static String RutaCheckBuilder_interpreterNotFound;
- public static String TextMarkerCheckBuilder_processing;
+ public static String RutaCheckBuilder_processing;
- public static String TextMarkerCheckBuilder_retrievePackages;
+ public static String RutaCheckBuilder_retrievePackages;
- public static String TextMarkerCheckBuilder_unknownPackage;
+ public static String RutaCheckBuilder_unknownPackage;
- public static String TextMarkerCheckBuilder_unresolvedDependencies;
+ public static String RutaCheckBuilder_unresolvedDependencies;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/PackagesManager.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/PackagesManager.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/PackagesManager.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/PackagesManager.java Mon Apr 29 14:50:56 2013
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.packages;
+package org.apache.uima.ruta.ide.core.packages;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -46,8 +46,8 @@ import javax.xml.transform.TransformerFa
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import org.apache.uima.textmarker.ide.TextMarkerIdePlugin;
-import org.apache.uima.textmarker.ide.core.packages.DLTKTextMarkerHelper.TextMarkerPackage;
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.apache.uima.ruta.ide.core.packages.DLTKRutaHelper.RutaPackage;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@@ -176,7 +176,7 @@ public class PackagesManager {
}
private void initialize() {
- IPath packagesPath = TextMarkerIdePlugin.getDefault().getStateLocation().append(PACKAGES_FILE);
+ IPath packagesPath = RutaIdePlugin.getDefault().getStateLocation().append(PACKAGES_FILE);
File packagesFile = packagesPath.toFile();
if (packagesFile.exists()) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
@@ -207,7 +207,7 @@ public class PackagesManager {
}
private void save() {
- IPath packagesPath = TextMarkerIdePlugin.getDefault().getStateLocation().append(PACKAGES_FILE);
+ IPath packagesPath = RutaIdePlugin.getDefault().getStateLocation().append(PACKAGES_FILE);
File packagesFile = packagesPath.toFile();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
@@ -355,7 +355,7 @@ public class PackagesManager {
return (IPath[]) els.toArray(new IPath[els.size()]);
}
// Retrieve paths from interpreter with all dependencies.
- TextMarkerPackage[] srcs = DLTKTextMarkerHelper.getSrcs(install.getExecEnvironment(),
+ RutaPackage[] srcs = DLTKRutaHelper.getSrcs(install.getExecEnvironment(),
install.getInstallLocation(), install.getEnvironmentVariables(), packageName);
PackageInformation resultInfo = null;
@@ -427,7 +427,7 @@ public class PackagesManager {
return set;
}
// Evaluate
- Set packs = DLTKTextMarkerHelper.getPackages(install);
+ Set packs = DLTKRutaHelper.getPackages(install);
this.interpreterToPackages.put(key, packs);
save();
return packs;
@@ -488,7 +488,7 @@ public class PackagesManager {
return (IPath[]) paths.toArray(new IPath[paths.size()]);
}
// Retrieve paths from interpreter with all dependencies.
- TextMarkerPackage[] srcs = DLTKTextMarkerHelper.getSrcs(install.getExecEnvironment(),
+ RutaPackage[] srcs = DLTKRutaHelper.getSrcs(install.getExecEnvironment(),
install.getInstallLocation(), install.getEnvironmentVariables(), buf.toString());
Set result = new HashSet();
if (srcs == null) {
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/RutaBuildPathPackageCollector.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/RutaBuildPathPackageCollector.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/RutaBuildPathPackageCollector.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/RutaBuildPathPackageCollector.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.core.packages;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.apache.uima.ruta.ide.parser.ast.RutaPackageDeclaration;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.ast.statements.Statement;
+
+public class RutaBuildPathPackageCollector extends ASTVisitor {
+
+ private final List requireDirectives = new ArrayList();
+
+ private final Set packagesRequired = new HashSet();
+
+ private final Set packagesProvided = new HashSet();
+
+ public void process(ModuleDeclaration declaration) {
+ try {
+ declaration.traverse(this);
+ } catch (Exception e) {
+ RutaIdePlugin.error(e);
+ }
+ }
+
+ @Override
+ public boolean visit(Statement s) throws Exception {
+ if (s instanceof RutaPackageDeclaration) {
+ final RutaPackageDeclaration pkg = (RutaPackageDeclaration) s;
+ packagesProvided.add(pkg.getName());
+ return false;
+ }
+ return super.visit(s);
+ }
+
+ /**
+ * @return the requireDirectives
+ */
+ public List getRequireDirectives() {
+ return requireDirectives;
+ }
+
+ /**
+ * @return the packagesRequired
+ */
+ public Set getPackagesRequired() {
+ return packagesRequired;
+ }
+
+ /**
+ * @return the packagesProvided
+ */
+ public Set getPackagesProvided() {
+ return packagesProvided;
+ }
+
+}