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/12 13:00:51 UTC
svn commit: r1157047 [5/27] - in
/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide: ./ .settings/
META-INF/ icons/ 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/...
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerProjectUtils.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerProjectUtils.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerProjectUtils.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerProjectUtils.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,190 @@
+/*
+ * 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.textmarker.ide.core.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.textmarker.ide.TextMarkerIdePlugin;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.IModelElement;
+import org.eclipse.dltk.core.IScriptFolder;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.core.ModelException;
+
+public class TextMarkerProjectUtils {
+
+ public static IPath getEngineDescriptorPath(IPath scriptPath, IProject project) {
+ String elementName = getModuleName(scriptPath);
+ IPath descPackagePath = getDescriptorPackagePath(scriptPath, project);
+ IPath result = descPackagePath.append(elementName + "Engine.xml");
+ return result;
+ }
+
+ public static IPath getTypeSystemDescriptorPath(IPath scriptPath, IProject project) {
+ String elementName = getModuleName(scriptPath);
+ IPath descPackagePath = getDescriptorPackagePath(scriptPath.makeAbsolute(), project);
+ IPath result = descPackagePath.append(elementName + "TypeSystem.xml");
+ return result;
+ }
+
+ public static IPath getDescriptorRootPath(IProject project) {
+ IPath projectPath = project.getLocation();
+ IPath descPath = projectPath.append(getDefaultDescriptorLocation());
+ return descPath;
+ }
+
+ public static List<IFolder> getAllScriptFolders(IScriptProject proj) throws CoreException {
+ List<IFolder> result = new ArrayList<IFolder>();
+ result.addAll(getScriptFolders(proj));
+ result.addAll(getReferencedScriptFolders(proj));
+ return result;
+ }
+
+ public static List<IFolder> getReferencedScriptFolders(IScriptProject proj) throws CoreException {
+ List<IFolder> result = new ArrayList<IFolder>();
+ IProject[] referencedProjects = proj.getProject().getReferencedProjects();
+ for (IProject eachProject : referencedProjects) {
+ IScriptProject scriptProject = DLTKCore.create(eachProject);
+ result.addAll(TextMarkerProjectUtils.getScriptFolders(scriptProject));
+ }
+ return result;
+ }
+
+ public static List<IFolder> getScriptFolders(IScriptProject proj) {
+ List<IFolder> result = new ArrayList<IFolder>();
+ try {
+ IScriptFolder[] scriptFolders = proj.getScriptFolders();
+ for (IScriptFolder eachScriptFolder : scriptFolders) {
+ IModelElement parent = eachScriptFolder.getParent();
+ IResource resource = parent.getResource();
+ if (parent != null && resource != null && resource instanceof IFolder) {
+ if (!result.contains(resource)) {
+ result.add((IFolder) resource);
+ }
+ }
+ }
+ } catch (ModelException e) {
+ TextMarkerIdePlugin.error(e);
+ }
+ return result;
+ }
+
+ public static List<IFolder> getAllDescriptorFolders(IProject proj) throws CoreException {
+ List<IFolder> result = new ArrayList<IFolder>();
+ result.addAll(getDescriptorFolders(proj));
+ result.addAll(getReferencedDescriptorFolders(proj));
+ return result;
+ }
+
+ public static List<IFolder> getReferencedDescriptorFolders(IProject proj) throws CoreException {
+ List<IFolder> result = new ArrayList<IFolder>();
+ IProject[] referencedProjects = proj.getReferencedProjects();
+ for (IProject eachProject : referencedProjects) {
+ result.addAll(TextMarkerProjectUtils.getDescriptorFolders(eachProject));
+ }
+ return result;
+ }
+
+ public static List<IFolder> getDescriptorFolders(IProject proj) throws ModelException {
+ List<IFolder> result = new ArrayList<IFolder>();
+ IFolder findElement = proj.getFolder(getDefaultDescriptorLocation());
+ if (findElement != null) {
+ result.add((IFolder) findElement);
+ }
+ return result;
+ }
+
+ public static List<String> getFolderLocations(List<IFolder> folders) {
+ List<String> result = new ArrayList<String>();
+ if (folders == null)
+ return result;
+ for (IFolder each : folders) {
+ String portableString = each.getLocation().toPortableString();
+ result.add(portableString);
+ }
+ return result;
+ }
+
+ public static IPath getScriptRootPath(IProject project) {
+ IPath projectPath = project.getLocation();
+ IPath descPath = projectPath.append(getDefaultScriptLocation());
+ return descPath;
+ }
+
+ public static IPath getDescriptorPackagePath(IPath scriptPath, IProject project) {
+ IPath projectPath = project.getLocation().makeAbsolute();
+ IPath packagePath = scriptPath.removeLastSegments(1);
+ IPath relativePackagePath;
+ relativePackagePath = packagePath.makeRelativeTo(projectPath).removeFirstSegments(1);
+ IPath descPackagePath = projectPath.append(getDefaultDescriptorLocation());
+ descPackagePath = descPackagePath.append(relativePackagePath);
+ return descPackagePath;
+ }
+
+ public static String getModuleName(IPath path) {
+ String result = path.lastSegment();
+ int lastIndexOf = result.lastIndexOf(".tm");
+ if (lastIndexOf != -1) {
+ result = result.substring(0, lastIndexOf);
+ }
+ return result;
+ }
+
+ public static void setProjectDataPath(IProject project, IFolder folder) throws CoreException {
+ project.setPersistentProperty(new QualifiedName("", "CDEdataPath"), folder.getLocation()
+ .toPortableString());
+
+ }
+
+ public static String getDefaultInputLocation() {
+ return "input";
+ }
+
+ public static String getDefaultOutputLocation() {
+ return "output";
+ }
+
+ public static String getDefaultTestLocation() {
+ return "test";
+ }
+
+ public static String getDefaultScriptLocation() {
+ return "script";
+ }
+
+ public static String getDefaultResourcesLocation() {
+ return "resources";
+ }
+
+ public static String getDefaultDescriptorLocation() {
+ return "descriptor";
+ }
+
+ public static String getDefaultTempTestLocation() {
+ return "temp";
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerProjectUtils.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerProjectUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerSimpleBuilder.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerSimpleBuilder.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerSimpleBuilder.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerSimpleBuilder.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,447 @@
+/*
+ * 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.textmarker.ide.core.builder;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.uima.ResourceSpecifierFactory;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.metadata.Capability;
+import org.apache.uima.resource.metadata.ConfigurationParameterSettings;
+import org.apache.uima.resource.metadata.FsIndexDescription;
+import org.apache.uima.resource.metadata.Import;
+import org.apache.uima.resource.metadata.TypeDescription;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.resource.metadata.impl.Import_impl;
+import org.apache.uima.textmarker.engine.TextMarkerEngine;
+import org.apache.uima.util.CasCreationUtils;
+import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.XMLInputSource;
+import org.apache.uima.util.XMLSerializer;
+import org.apache.uima.util.XMLizable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+public class TextMarkerSimpleBuilder {
+
+ private static ResourceSpecifierFactory uimaFactory = UIMAFramework.getResourceSpecifierFactory();
+
+ private TypeSystemDescription typeSystemDescription;
+
+ private AnalysisEngineDescription analysisEngineDescription;
+
+ private final String defaultTypeSystem;
+
+ public TextMarkerSimpleBuilder(String defaultTypeSystem, String defaultEngine)
+ throws InvalidXMLException, IOException {
+ super();
+ this.defaultTypeSystem = defaultTypeSystem;
+ initialize(defaultEngine);
+ }
+
+ private void initialize(String defaultEngine) throws InvalidXMLException, IOException {
+ typeSystemDescription = uimaFactory.createTypeSystemDescription();
+ analysisEngineDescription = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(
+ new XMLInputSource(new File(defaultEngine)));
+ }
+
+ public void build(DescriptorManager desc, String typeSystemOutput, String engineOutput,
+ TextMarkerBuildOptions option, String mainScript, String[] scriptPaths,
+ String[] enginePaths) throws SAXException, TextMarkerBuildException, InvalidXMLException,
+ IOException, ResourceInitializationException {
+ Map<String, String> typeNameMap = new HashMap<String, String>();
+ Capability capability = uimaFactory.createCapability();
+ // String defaultTypeSystem2 = defaultTypeSystem.replaceAll("/", "\\\\");
+ File defaultTypeSystemFile = new File(defaultTypeSystem);
+ if (!defaultTypeSystemFile.exists()) {
+ System.out.println("Does not exist: " + defaultTypeSystemFile.getName());
+ }
+ TypeSystemDescription initialTypeSystem = UIMAFramework.getXMLParser()
+ .parseTypeSystemDescription(new XMLInputSource(defaultTypeSystemFile));
+ CAS cas = CasCreationUtils.createCas(initialTypeSystem, null, new FsIndexDescription[0]);
+ fillTypeNameMap(typeNameMap, cas.getTypeSystem());
+ cas.release();
+ List<Import> importList = new ArrayList<Import>();
+ Import_impl import_impl = new Import_impl();
+ if (option.isImportByName()) {
+ String name = initialTypeSystem.getName();
+ import_impl.setName(name);
+ } else if (option.isResolveImports()) {
+ String absoluteLocation = initialTypeSystem.getSourceUrlString();
+ import_impl.setLocation(absoluteLocation);
+ } else {
+ String relativeLocation = getRelativeLocation(defaultTypeSystemFile.getAbsolutePath(),
+ typeSystemOutput);
+ import_impl.setLocation(relativeLocation);
+ }
+ importList.add(import_impl);
+ for (String eachName : desc.getImportedTypeSystems()) {
+ String locate = TextMarkerEngine.locate(eachName, enginePaths, ".xml");
+ File file = new File(locate);
+ TypeSystemDescription each = getTypeSystemDescriptor(file, option);
+ if (each != null) {
+ fillTypeNameMap(typeNameMap, each);
+ import_impl = new Import_impl();
+ if (option.isImportByName()) {
+ import_impl.setName(eachName);
+ } else if (option.isResolveImports()) {
+ String absoluteLocation = each.getSourceUrlString();
+ import_impl.setLocation(absoluteLocation);
+ } else {
+ String relativeLocation = getRelativeLocation(file.getAbsolutePath(), typeSystemOutput);
+ import_impl.setLocation(relativeLocation);
+ }
+ importList.add(import_impl);
+ } else {
+ throw new FileNotFoundException("Build process can't find " + eachName + " in "
+ + mainScript);
+ }
+ }
+ for (String eachName : desc.getImportedScripts()) {
+ String locate = TextMarkerEngine.locate(eachName, enginePaths, "TypeSystem.xml");
+ File file = new File(locate);
+ TypeSystemDescription each = getTypeSystemDescriptor(file, option);
+ if (each != null) {
+ fillTypeNameMap(typeNameMap, each);
+ import_impl = new Import_impl();
+ if (option.isImportByName()) {
+ import_impl.setName(eachName + "TypeSystem");
+ } else if (option.isResolveImports()) {
+ String absoluteLocation = each.getSourceUrlString();
+ import_impl.setLocation(absoluteLocation);
+ } else {
+ String relativeLocation = getRelativeLocation(file.getAbsolutePath(), typeSystemOutput);
+ import_impl.setLocation(relativeLocation);
+ }
+ importList.add(import_impl);
+ } else {
+ throw new FileNotFoundException("Build process can't find " + eachName + " in "
+ + mainScript);
+ }
+ }
+
+ Import[] newImports = importList.toArray(new Import[0]);
+ typeSystemDescription.setImports(newImports);
+ if (option.isResolveImports()) {
+ try {
+ typeSystemDescription.resolveImports();
+ } catch (InvalidXMLException e) {
+ throw new TextMarkerBuildException("Failed to resolve imported Type Systems", e);
+ }
+ }
+
+ // TODO hotfixes: where do I get the final types??
+ Set<String> finalTypes = new HashSet<String>();
+ finalTypes.addAll(Arrays.asList(new String[] { "uima.cas.Boolean", "uima.cas.Byte",
+ "uima.cas.Short", "uima.cas.Integer", "uima.cas.Long", "uima.cas.Float", "uima.cas.Double",
+ "uima.cas.BooleanArray", "uima.cas.ByteArray", "uima.cas.ShortArray",
+ "uima.cas.IntegerArray", "uima.cas.LongArray", "uima.cas.FloatArray",
+ "uima.cas.DoubleArray", "uima.cas.StringArray", "uima.cas.FSArray" }));
+
+ int typeIndex = 0;
+ for (String eachType : desc.getTypeShortNames()) {
+ StringTriple typeTriple = desc.getTypeTriples().get(typeIndex);
+ typeTriple = resolveType(typeTriple, typeNameMap, mainScript);
+ if (typeSystemDescription.getType(typeTriple.getName()) != null) {
+ continue;
+ }
+ if (!finalTypes.contains(typeTriple.getParent())) {
+ TypeDescription newType = typeSystemDescription.addType(typeTriple.getName(),
+ typeTriple.getDescription(), typeTriple.getParent());
+ capability.addInputType(typeTriple.getName(), false);
+ capability.addOutputType(typeTriple.getName(), false);
+ Collection<StringTriple> collection = desc.getFeatures().get(eachType);
+ if (collection != null) {
+ for (StringTriple eachFeature : collection) {
+ eachFeature = resolveFeature(eachFeature, typeNameMap);
+ newType.addFeature(eachFeature.getName(), eachFeature.getDescription(),
+ eachFeature.getParent());
+ // capability.addInputFeature(eachFeature.getName());
+ // capability.addOutputFeature(eachFeature.getName());
+ }
+ }
+ }
+ typeIndex++;
+ }
+
+ Set<String> names = new HashSet<String>();
+ List<TypeDescription> types = new ArrayList<TypeDescription>();
+ for (TypeDescription each : typeSystemDescription.getTypes()) {
+ String name = each.getName();
+ if (!names.contains(name)) {
+ names.add(name);
+ types.add(each);
+ }
+ }
+
+ typeSystemDescription.setTypes(types.toArray(new TypeDescription[0]));
+ File typeSystemFile = getFile(typeSystemOutput);
+ typeSystemDescription.setName(mainScript + "TypeSystem");
+ typeSystemDescription.setSourceUrl(typeSystemFile.toURI().toURL());
+ TypeSystemDescription aets = uimaFactory.createTypeSystemDescription();
+ import_impl = new Import_impl();
+ if (option.isImportByName()) {
+ import_impl.setName(typeSystemDescription.getName());
+ } else {
+ String relativeLocation = getRelativeLocation(engineOutput, typeSystemOutput);
+ import_impl.setLocation(relativeLocation);
+ }
+
+ File engineFile = configureEngine(desc, engineOutput, option, mainScript, scriptPaths,
+ enginePaths, capability, import_impl, aets);
+
+ toFile(typeSystemDescription, typeSystemFile);
+ toFile(analysisEngineDescription, engineFile);
+ }
+
+ private void fillTypeNameMap(Map<String, String> typeNameMap, TypeSystem typeSystem) {
+ Iterator<Type> typeIterator = typeSystem.getTypeIterator();
+ while (typeIterator.hasNext()) {
+ Type type = (Type) typeIterator.next();
+ String shortName = type.getShortName();
+ String name = type.getName();
+ typeNameMap.put(shortName, name);
+ }
+ }
+
+ private boolean fillTypeNameMap(Map<String, String> typeNameMap, TypeSystemDescription desc) {
+ boolean contained = false;
+ for (TypeDescription each : desc.getTypes()) {
+ String name = each.getName();
+ int lastIndexOf = name.lastIndexOf(".");
+ String shortName = name.substring(lastIndexOf + 1, name.length());
+ typeNameMap.put(shortName, name);
+ }
+ return contained;
+ }
+
+ private StringTriple resolveFeature(StringTriple eachFeature, Map<String, String> types) {
+ String parent = eachFeature.getParent();
+ String name = eachFeature.getName();
+ parent = translate(parent);
+ if (parent.indexOf(".") == -1 && types.containsKey(parent)) {
+ parent = types.get(parent);
+ }
+ return new StringTriple(name, eachFeature.getDescription(), parent);
+ }
+
+ private StringTriple resolveType(StringTriple typeTriple, Map<String, String> types,
+ String packageName) {
+ String parent = typeTriple.getParent();
+ String name = typeTriple.getName();
+ if (parent == null) {
+ parent = "uima.tcas.Annotation";
+ }
+ parent = translate(parent);
+ name = translate(name);
+ if (parent.indexOf(".") == -1 && types.containsKey(parent)) {
+ parent = types.get(parent);
+ }
+ if (name.indexOf(".") == -1) {
+ if (types.containsKey(name)) {
+ name = types.get(name);
+ } else {
+ name = packageName + "." + name;
+ }
+ }
+ int lastIndexOf = name.lastIndexOf(".");
+ String shortName = name.substring(lastIndexOf + 1, name.length());
+ types.put(shortName, name);
+ return new StringTriple(name, typeTriple.getDescription(), parent);
+ }
+
+ private String translate(String name) {
+ if (name == null) {
+ return null;
+ }
+ if (name.equals("Annotation")) {
+ return "uima.tcas.Annotation";
+ } else if (name.equals("STRING")) {
+ return "uima.cas.String";
+ } else if (name.equals("INT")) {
+ return "uima.cas.Integer";
+ } else if (name.equals("DOUBLE")) {
+ return "uima.cas.Double";
+ } else if (name.equals("BOOLEAN")) {
+ return "uima.cas.Boolean";
+ } else if (name.equals("TYPE")) {
+ return "uima.cas.String";
+ }
+ return name;
+ }
+
+ private File configureEngine(DescriptorManager desc, String engineOutput,
+ TextMarkerBuildOptions option, String mainScript, String[] scriptPaths,
+ String[] descriptorPaths, Capability capability, Import_impl import_impl,
+ TypeSystemDescription aets) throws MalformedURLException {
+ aets.setImports(new Import[] { import_impl });
+ analysisEngineDescription.getAnalysisEngineMetaData().setTypeSystem(aets);
+ File file = getFile(engineOutput);
+ analysisEngineDescription.setSourceUrl(file.toURI().toURL());
+
+ if (!desc.getTypeShortNames().isEmpty()) {
+ Capability[] capabilities = analysisEngineDescription.getAnalysisEngineMetaData()
+ .getCapabilities();
+ Capability[] newArray = new Capability[capabilities.length + 1];
+ System.arraycopy(capabilities, 0, newArray, 0, capabilities.length);
+ newArray[capabilities.length] = capability;
+ analysisEngineDescription.getAnalysisEngineMetaData().setCapabilities(newArray);
+ }
+
+ analysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings()
+ .setParameterValue(TextMarkerEngine.MAIN_SCRIPT, mainScript);
+ analysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings()
+ .setParameterValue(TextMarkerEngine.SCRIPT_PATHS, scriptPaths);
+ analysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings()
+ .setParameterValue(TextMarkerEngine.DESCRIPTOR_PATHS, descriptorPaths);
+ String[] parameterValue = (String[]) analysisEngineDescription.getAnalysisEngineMetaData()
+ .getConfigurationParameterSettings().getParameterValue(TextMarkerEngine.RESOURCE_PATHS);
+ Set<String> resourceLocations = new HashSet<String>();
+
+ if (parameterValue != null && parameterValue.length != 0) {
+ resourceLocations.addAll(Arrays.asList(parameterValue));
+ }
+ for (String string : descriptorPaths) {
+ File descDir = new File(string);
+ File defaultResourceDir = new File(descDir.getParent(),
+ TextMarkerProjectUtils.getDefaultResourcesLocation());
+ resourceLocations.add(defaultResourceDir.getAbsolutePath());
+ }
+ analysisEngineDescription
+ .getAnalysisEngineMetaData()
+ .getConfigurationParameterSettings()
+ .setParameterValue(TextMarkerEngine.RESOURCE_PATHS,
+ resourceLocations.toArray(new String[0]));
+
+ String[] additionalScriptsArray = desc.getImportedScripts().toArray(new String[] {});
+ analysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings()
+ .setParameterValue(TextMarkerEngine.ADDITIONAL_SCRIPTS, additionalScriptsArray);
+
+ String[] additionalEnginesArray = desc.getImportedEngines().toArray(new String[] {});
+ analysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings()
+ .setParameterValue(TextMarkerEngine.ADDITIONAL_ENGINES, additionalEnginesArray);
+
+ String styleMapLocation = getStyleMapLocation(mainScript, engineOutput);
+ analysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings()
+ .setParameterValue(TextMarkerEngine.STYLE_MAP, styleMapLocation);
+ analysisEngineDescription.getAnalysisEngineMetaData().setTypeSystem(typeSystemDescription);
+
+ configureExtensions(option);
+ return file;
+ }
+
+ private String getRelativeLocation(String target, String base) {
+ IPath targetPath = Path.fromOSString(target);
+ IPath basePath = Path.fromPortableString(base);
+ IPath result = targetPath.makeRelativeTo(basePath);
+ // TODO remove the first part! Should be correct in first place!
+ result = result.removeFirstSegments(1);
+ return result.toPortableString();
+ }
+
+ private void configureExtensions(TextMarkerBuildOptions options) {
+ ConfigurationParameterSettings configurationParameterSettings = analysisEngineDescription
+ .getAnalysisEngineMetaData().getConfigurationParameterSettings();
+
+ List<String> languageExtensions = options.getLanguage();
+
+ configurationParameterSettings.setParameterValue(TextMarkerEngine.ADDITIONAL_EXTENSIONS,
+ languageExtensions.toArray(new String[0]));
+ configurationParameterSettings.setParameterValue(TextMarkerEngine.ADDITIONAL_ENGINE_LOADERS,
+ options.getEngines().toArray(new String[0]));
+ }
+
+ private String getPackage(String eachName) {
+ if (eachName.endsWith(".tm")) {
+ int indexOf = eachName.lastIndexOf(".tm");
+ eachName = eachName.substring(0, indexOf);
+ }
+ int lastIndexOf = eachName.lastIndexOf(".");
+ if (lastIndexOf != -1) {
+ eachName = eachName.substring(0, lastIndexOf);
+ return eachName;
+ }
+ return "";
+ }
+
+ private String getModuleName(String eachName) {
+ if (eachName.endsWith(".tm")) {
+ int indexOf = eachName.lastIndexOf(".tm");
+ eachName = eachName.substring(0, indexOf);
+ }
+ int lastIndexOf = eachName.lastIndexOf(".");
+ if (lastIndexOf != -1) {
+ eachName = eachName.substring(lastIndexOf + 1, eachName.length());
+ }
+ return eachName;
+ }
+
+ private TypeSystemDescription getTypeSystemDescriptor(File file, TextMarkerBuildOptions option)
+ throws InvalidXMLException, IOException {
+ TypeSystemDescription tsdesc = UIMAFramework.getXMLParser().parseTypeSystemDescription(
+ new XMLInputSource(file));
+ if (option.isResolveImports()) {
+ tsdesc.resolveImports();
+ }
+ return tsdesc;
+ }
+
+ private String getStyleMapLocation(String scriptLocation, String engineDescriptorOutputLocation) {
+ String module = getModuleName(scriptLocation);
+ String pack = getPackage(scriptLocation);
+ return pack + "." + module + "StyleMap";
+ }
+
+ private File getFile(String location) {
+ return new File(location);
+ }
+
+ private void toFile(XMLizable desc, File destination) throws SAXException, FileNotFoundException {
+ destination.getParentFile().mkdirs();
+ OutputStream out = new FileOutputStream(destination);
+ XMLSerializer sax = new XMLSerializer(out);
+ ContentHandler ch = sax.getContentHandler();
+ ch.startDocument();
+ desc.toXML(ch);
+ ch.endDocument();
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerSimpleBuilder.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerSimpleBuilder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnKeywordArgumentOrFunctionArgument.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnKeywordArgumentOrFunctionArgument.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnKeywordArgumentOrFunctionArgument.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnKeywordArgumentOrFunctionArgument.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,103 @@
+/*
+ * 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.textmarker.ide.core.codeassist;
+
+import org.apache.uima.textmarker.ide.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/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnKeywordArgumentOrFunctionArgument.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnKeywordArgumentOrFunctionArgument.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnKeywordOrFunction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnKeywordOrFunction.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnKeywordOrFunction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnKeywordOrFunction.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,57 @@
+/*
+ * 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.textmarker.ide.core.codeassist;
+
+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/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnKeywordOrFunction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnKeywordOrFunction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnVariable.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnVariable.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnVariable.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnVariable.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,74 @@
+/*
+ * 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.textmarker.ide.core.codeassist;
+
+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/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnVariable.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/CompletionOnVariable.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnAST.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnAST.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnAST.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnAST.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,37 @@
+/*
+ * 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.textmarker.ide.core.codeassist;
+
+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/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnAST.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnAST.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnKeywordOrFunction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnKeywordOrFunction.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnKeywordOrFunction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnKeywordOrFunction.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,36 @@
+/*
+ * 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.textmarker.ide.core.codeassist;
+
+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/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnKeywordOrFunction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnKeywordOrFunction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnNode.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnNode.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnNode.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnNode.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,46 @@
+/*
+ * 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.textmarker.ide.core.codeassist;
+
+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/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnNode.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/SelectionOnNode.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TMAutoCompletionToolkit.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TMAutoCompletionToolkit.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TMAutoCompletionToolkit.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TMAutoCompletionToolkit.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,100 @@
+/*
+ * 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.textmarker.ide.core.codeassist;
+
+public class TMAutoCompletionToolkit {
+
+ private int wordOffset;
+
+ private int currentOffset;
+
+ private int relativeReplacementStart;
+
+ private String wordPrefix;
+
+ public TMAutoCompletionToolkit(String text, int offset) {
+ this.currentOffset = offset;
+ wordOffset = getWordOffset(text, offset) + 1;
+ wordPrefix = text.substring(wordOffset, offset);
+ relativeReplacementStart = offset - wordOffset;
+
+ }
+
+ private int getWordOffset(String text, int offset) {
+ for (int i = offset - 1; i > 0; i--) {
+ switch (text.charAt(i)) {
+ case ' ': {
+ return i;
+ }
+ case '\n': {
+ return i;
+ }
+ case '\r': {
+ return i;
+ }
+ case '\t': {
+ return i;
+ }
+ case '[': {
+ return i;
+ }
+ case ']': {
+ return i;
+ }
+ case '(': {
+ return i;
+ }
+ case ')': {
+ return i;
+ }
+ case '{': {
+ return i;
+ }
+ case '}': {
+ return i;
+ }
+ case ',': {
+ return i;
+ }
+ case ';': {
+ return i;
+ }
+ }
+ }
+ return -1;
+ }
+
+ public int getWordOffset() {
+ return this.wordOffset;
+ }
+
+ public int getCurrentOffset() {
+ return this.currentOffset;
+ }
+
+ public int getRelativeReplacementStart() {
+ return relativeReplacementStart;
+ }
+
+ public String getWordPrefix() {
+ return wordPrefix;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TMAutoCompletionToolkit.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TMAutoCompletionToolkit.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerASTUtil.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerASTUtil.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerASTUtil.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerASTUtil.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,116 @@
+/*
+ * 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.textmarker.ide.core.codeassist;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.textmarker.ide.core.parser.TextMarkerParseUtils;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.declarations.MethodDeclaration;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.ast.declarations.TypeDeclaration;
+import org.eclipse.dltk.ast.expressions.Expression;
+import org.eclipse.dltk.ast.statements.Block;
+import org.eclipse.dltk.core.DLTKCore;
+
+
+public class TextMarkerASTUtil {
+ public static List getStatements(ASTNode node) {
+ if (node instanceof ModuleDeclaration) {
+ return ((ModuleDeclaration) node).getStatements();
+ } else if (node instanceof TypeDeclaration) {
+ return ((TypeDeclaration) node).getStatements();
+ } else if (node instanceof MethodDeclaration) {
+ return ((MethodDeclaration) node).getStatements();
+ } else if (node instanceof Block) {
+ return ((Block) node).getStatements();
+ } else {
+ final List innerBlockStatements = new ArrayList();
+ // Lets traverse to see inner blocks.
+ ASTVisitor visitor = new ASTVisitor() {
+ @Override
+ public boolean visit(Expression s) throws Exception {
+ if (s instanceof Block) {
+ List tStatements = ((Block) s).getStatements();
+ innerBlockStatements.addAll(tStatements);
+ }
+ return false;
+ }
+
+ @Override
+ public boolean visit(MethodDeclaration s) throws Exception {
+ return false;
+ }
+
+ @Override
+ public boolean visit(TypeDeclaration s) throws Exception {
+ return false;
+ }
+ };
+ try {
+ node.traverse(visitor);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return innerBlockStatements;
+ }
+ // return null;
+ }
+
+ /**
+ * We need to extend all statements to end of lines or to begining of next statement. This is
+ * needed to for correct completion in statements. Such as variable completion and so on.
+ */
+ public static void extendStatements(ASTNode node, String content) {
+ List statements = getStatements(node);
+
+ if (statements != null) {
+ int len = statements.size();
+ for (int i = 0; i < len; ++i) {
+ ASTNode nde = (ASTNode) statements.get(i);
+
+ extendStatement(nde, content);
+ extendStatements(nde, content);
+ }
+ }
+ }
+
+ public static void extendStatement(ASTNode node, String content) {
+ int newValueStart = startLineOrSymbol(node, content);
+ int newValueEnd = endLineOrSymbol(node, content);
+ if (DLTKCore.DEBUG_COMPLETION) {
+ if (node.sourceEnd() != newValueEnd || node.sourceStart() != newValueStart) {
+ // TODO
+ }
+ }
+ node.setStart(newValueStart);
+ node.setEnd(newValueEnd);
+ }
+
+ public static int endLineOrSymbol(ASTNode node, String content) {
+ return TextMarkerParseUtils.endLineOrSymbol(node.sourceEnd(), content);
+ }
+
+ public static int startLineOrSymbol(ASTNode node, String content) {
+ return TextMarkerParseUtils.startLineOrSymbol(node.sourceStart(), content);
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerASTUtil.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerASTUtil.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerAssistParser.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerAssistParser.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerAssistParser.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerAssistParser.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,114 @@
+/*
+ * 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.textmarker.ide.core.codeassist;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.textmarker.ide.core.TextMarkerNature;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.ast.parser.ISourceParser;
+import org.eclipse.dltk.codeassist.IAssistParser;
+import org.eclipse.dltk.compiler.env.ISourceModule;
+import org.eclipse.dltk.core.DLTKLanguageManager;
+
+
+public abstract class TextMarkerAssistParser implements IAssistParser {
+ public static final int MODULE = 0;// ITextMarkerKeywords.MODULE;
+
+ public static final int NAMESPACE = 1;// ITextMarkerKeywords.NAMESPACE;
+
+ public static final int FUNCTION = 2;// ITextMarkerKeywords.FUNCTION;
+
+ public static final int EXEC_EXPRESSION = 3;// ITextMarkerKeywords.EXEC_EXPRESSION;
+
+ protected ISourceParser parser = null;
+
+ protected ModuleDeclaration module;
+
+ protected ASTNode assistNodeParent = null;
+
+ public TextMarkerAssistParser() {
+ // try {
+ this.parser = DLTKLanguageManager.getSourceParser(TextMarkerNature.NATURE_ID);
+ // } catch (CoreException e) {
+ // if (DLTKCore.DEBUG) {
+ // e.printStackTrace();
+ // }
+ // }
+ }
+
+ public ASTNode getAssistNodeParent() {
+ return assistNodeParent;
+ }
+
+ protected void findElementsTo(List statements, ASTNode node, List elements) {
+ if (statements == null) {
+ return;
+ }
+ Iterator i = statements.iterator();
+ while (i.hasNext()) {
+ ASTNode n = (ASTNode) i.next();
+ if (n.equals(node)) {
+ elements.add(n);
+ return;
+ }
+ if (n.sourceStart() <= node.sourceStart() && node.sourceEnd() <= n.sourceEnd()) {
+ elements.add(n);
+ findElementsTo(TextMarkerASTUtil.getStatements(n), node, elements);
+ return;
+ }
+ }
+
+ }
+
+ protected List findLevelsTo(ASTNode astNodeParent) {
+ List elements = new ArrayList();
+ if (this.module != null || astNodeParent instanceof ModuleDeclaration) {
+ if (this.module == null) {
+ this.module = (ModuleDeclaration) astNodeParent;
+ }
+ elements.add(this.module);
+ findElementsTo(TextMarkerASTUtil.getStatements(this.module), astNodeParent, elements);
+ }
+ return elements;
+ }
+
+ public void setSource(ModuleDeclaration unit) {
+ this.module = unit;
+ }
+
+ public ModuleDeclaration parse(ISourceModule sourceUnit) {
+ module = this.parser.parse(sourceUnit.getFileName(), sourceUnit.getSourceContents()
+ .toCharArray(), null);
+ module.rebuild();
+
+ // TextMarkerASTUtil.extendStatements(module, sourceUnit
+ // .getSourceContents());
+
+ return module;
+ }
+
+ public ModuleDeclaration getModule() {
+ return this.module;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerAssistParser.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerAssistParser.java
------------------------------------------------------------------------------
svn:mime-type = text/plain