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 [5/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/packages/RutaCheckBuilder.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/RutaCheckBuilder.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/RutaCheckBuilder.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/RutaCheckBuilder.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,326 @@
+/*
+ * 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.Collections;
+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.ruta.ide.RutaIdePlugin;
+import org.apache.uima.ruta.ide.core.CodeModel;
+import org.apache.uima.ruta.ide.core.RutaProblems;
+import org.apache.uima.ruta.ide.parser.ast.RutaPackageDeclaration;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.compiler.problem.DefaultProblem;
+import org.eclipse.dltk.compiler.problem.IProblemReporter;
+import org.eclipse.dltk.compiler.problem.ProblemSeverities;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.IBuildpathEntry;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.core.ModelException;
+import org.eclipse.dltk.core.builder.IBuildChange;
+import org.eclipse.dltk.core.builder.IBuildContext;
+import org.eclipse.dltk.core.builder.IBuildParticipant;
+import org.eclipse.dltk.core.builder.IBuildParticipantExtension;
+import org.eclipse.dltk.core.builder.IBuildParticipantExtension2;
+import org.eclipse.dltk.core.builder.IBuildState;
+import org.eclipse.dltk.core.environment.EnvironmentPathUtils;
+import org.eclipse.dltk.launching.IInterpreterInstall;
+import org.eclipse.dltk.launching.ScriptRuntime;
+import org.eclipse.osgi.util.NLS;
+
+public class RutaCheckBuilder implements IBuildParticipant, IBuildParticipantExtension,
+ IBuildParticipantExtension2 {
+
+ private final IScriptProject project;
+
+ private final IInterpreterInstall install;
+
+ private final PackagesManager manager = PackagesManager.getInstance();
+
+ private final RutaBuildPathPackageCollector packageCollector = new RutaBuildPathPackageCollector();
+
+ private final Map codeModels = new HashMap();
+
+ private final Map resourceToModuleInfos = new HashMap();
+
+ private final Set knownPackageNames;
+
+ private final Set buildpath;
+
+ private static class ModuleInfo {
+ final List requireDirectives;
+
+ final IProblemReporter reporter;
+
+ public ModuleInfo(IProblemReporter reporter, List requireDirectives) {
+ this.reporter = reporter;
+ this.requireDirectives = requireDirectives;
+ }
+
+ }
+
+ /**
+ * @param project
+ * @throws CoreException
+ * @throws IllegalStateException
+ * if associated interpreter could not be found
+ */
+ public RutaCheckBuilder(IScriptProject project) throws CoreException, IllegalStateException {
+ this.project = project;
+ install = ScriptRuntime.getInterpreterInstall(project);
+ if (install == null) {
+ // thrown exception is caught in the RutaPackageCheckerType
+ throw new IllegalStateException(NLS.bind(Messages.RutaCheckBuilder_interpreterNotFound,
+ project.getElementName()));
+ }
+ knownPackageNames = manager.getPackageNames(install);
+ buildpath = getBuildpath(project);
+ }
+
+ private int buildType;
+
+ public boolean beginBuild(int buildType) {
+ this.buildType = buildType;
+ if (buildType != FULL_BUILD) {
+ // retrieve packages provided by this project
+ packageCollector.getPackagesProvided().addAll(
+ manager.getInternalPackageNames(install, project));
+ }
+ loadProvidedPackagesFromRequiredProjects();
+ return true;
+ }
+
+ private void loadProvidedPackagesFromRequiredProjects() {
+ final IBuildpathEntry[] resolvedBuildpath;
+ try {
+ resolvedBuildpath = project.getResolvedBuildpath(true);
+ } catch (ModelException e) {
+ RutaIdePlugin.error(e);
+ return;
+ }
+ final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ for (int i = 0; i < resolvedBuildpath.length; i++) {
+ final IBuildpathEntry entry = resolvedBuildpath[i];
+ if (entry.getEntryKind() == IBuildpathEntry.BPE_PROJECT) {
+ final IPath path = entry.getPath();
+ final IProject project = workspaceRoot.getProject(path.lastSegment());
+ if (project.exists()) {
+ packageCollector.getPackagesProvided().addAll(
+ manager.getInternalPackageNames(install, project));
+ }
+ }
+ }
+ }
+
+ public void buildExternalModule(IBuildContext context) throws CoreException {
+ final ModuleDeclaration ast = (ModuleDeclaration) context
+ .get(IBuildContext.ATTR_MODULE_DECLARATION);
+ if (ast != null) {
+ packageCollector.getRequireDirectives().clear();
+ packageCollector.process(ast);
+ }
+ }
+
+ public void build(IBuildContext context) throws CoreException {
+ ModuleDeclaration ast = (ModuleDeclaration) context.get(ModuleDeclaration.class.getName());
+ if (ast == null) {
+ return;
+ }
+ packageCollector.getRequireDirectives().clear();
+ packageCollector.process(ast);
+ if (!packageCollector.getRequireDirectives().isEmpty()) {
+ resourceToModuleInfos.put(
+ context.getSourceModule(),
+ new ModuleInfo(context.getProblemReporter(), new ArrayList(packageCollector
+ .getRequireDirectives())));
+ }
+ }
+
+ public void endBuild(IProgressMonitor monitor) {
+ if (buildType != RECONCILE_BUILD) {
+ // Save packages provided by the project
+ manager.setInternalPackageNames(install, project, packageCollector.getPackagesProvided());
+ }
+ monitor.subTask(Messages.RutaCheckBuilder_retrievePackages);
+ // initialize manager caches after they are collected
+ final Set requiredPackages = packageCollector.getPackagesRequired();
+ if (!requiredPackages.isEmpty()) {
+ manager.getPathsForPackages(install, requiredPackages);
+ manager.getPathsForPackagesWithDeps(install, requiredPackages);
+ }
+ // process all modules
+ int remainingWork = resourceToModuleInfos.size();
+ for (Iterator i = resourceToModuleInfos.entrySet().iterator(); i.hasNext();) {
+ final Map.Entry entry = (Map.Entry) i.next();
+ final ISourceModule module = (ISourceModule) entry.getKey();
+ final ModuleInfo info = (ModuleInfo) entry.getValue();
+ monitor.subTask(NLS.bind(Messages.RutaCheckBuilder_processing, module.getElementName(),
+ Integer.toString(remainingWork)));
+ codeModels.clear();
+ --remainingWork;
+ }
+ }
+
+ private CodeModel getCodeModel(ISourceModule module) {
+ CodeModel model = (CodeModel) codeModels.get(module);
+ if (model == null) {
+ try {
+ model = new CodeModel(module.getSource());
+ codeModels.put(module, model);
+ } catch (ModelException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+ }
+ return model;
+ }
+
+ private static Set getBuildpath(IScriptProject project) {
+ final IBuildpathEntry[] resolvedBuildpath;
+ try {
+ resolvedBuildpath = project.getResolvedBuildpath(true);
+ } catch (ModelException e1) {
+ RutaIdePlugin.error(e1);
+ return Collections.EMPTY_SET;
+ }
+ final Set buildpath = new HashSet();
+ for (int i = 0; i < resolvedBuildpath.length; i++) {
+ final IBuildpathEntry entry = resolvedBuildpath[i];
+ if (entry.getEntryKind() == IBuildpathEntry.BPE_LIBRARY && entry.isExternal()) {
+ buildpath.add(EnvironmentPathUtils.getLocalPath(entry.getPath()));
+ }
+ }
+ return buildpath;
+ }
+
+ private void reportPackageProblem(RutaPackageDeclaration pkg, IProblemReporter reporter,
+ ISourceModule module, String message, String pkgName) {
+ final CodeModel model = getCodeModel(module);
+ if (model == null) {
+ return;
+ }
+ reporter.reportProblem(new DefaultProblem(message, RutaProblems.UNKNOWN_REQUIRED_PACKAGE,
+ new String[] { pkgName }, ProblemSeverities.Error, pkg.sourceStart(), pkg.sourceEnd(),
+ model.getLineNumber(pkg.sourceStart(), pkg.sourceEnd())));
+ }
+
+ private void checkPackage(ISourceModule module, RutaPackageDeclaration pkg,
+ IProblemReporter reporter) {
+ final String packageName = pkg.getName();
+
+ if (packageCollector.getPackagesProvided().contains(packageName)) {
+ return;
+ }
+ if (!isValidPackageName(packageName)) {
+ return;
+ }
+
+ // Report unknown packages
+ if (!knownPackageNames.contains(packageName)) {
+ reportPackageProblem(pkg, reporter, module,
+ NLS.bind(Messages.RutaCheckBuilder_unknownPackage, packageName), packageName);
+ return;
+ }
+
+ // Receive main package and it paths.
+ if (checkPackage(packageName)) {
+ reportPackageProblem(pkg, reporter, module,
+ NLS.bind(Messages.RutaCheckBuilder_unresolvedDependencies, packageName),
+ packageName);
+ return;
+ }
+
+ final Set dependencies = manager.getDependencies(packageName, install).keySet();
+ for (Iterator i = dependencies.iterator(); i.hasNext();) {
+ String pkgName = (String) i.next();
+ if (checkPackage(pkgName)) {
+ reportPackageProblem(pkg, reporter, module,
+ NLS.bind(Messages.RutaCheckBuilder_unresolvedDependencies, packageName),
+ packageName);
+ return;
+ }
+ }
+ }
+
+ static boolean isValidPackageName(String packageName) {
+ return packageName != null && packageName.length() != 0 && packageName.indexOf('$') == -1
+ && packageName.indexOf('[') == -1 && packageName.indexOf(']') == -1;
+ }
+
+ /**
+ * returns <code>true</code> on error
+ *
+ * @param packageName
+ * @return
+ */
+ private boolean checkPackage(String packageName) {
+ if (packageCollector.getPackagesProvided().contains(packageName)) {
+ return false;
+ }
+ return isOnBuildpath(buildpath, manager.getPathsForPackage(install, packageName));
+ }
+
+ private static boolean isOnBuildpath(Set buildpath, IPath path) {
+ if (!buildpath.contains(path)) {
+ for (Iterator i = buildpath.iterator(); i.hasNext();) {
+ IPath pp = (IPath) i.next();
+ if (pp.isPrefixOf(path)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean isOnBuildpath(Set buildpath, IPath[] paths) {
+ if (paths != null) {
+ for (int i = 0; i < paths.length; i++) {
+ final IPath path = paths[i];
+ if (!isOnBuildpath(buildpath, path)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public void prepare(IBuildChange buildChange, IBuildState buildState) throws CoreException {
+
+ }
+
+
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/RutaPackageCheckerType.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/RutaPackageCheckerType.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/RutaPackageCheckerType.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/RutaPackageCheckerType.java Mon Apr 29 14:50:56 2013
@@ -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.ruta.ide.core.packages;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.core.builder.AbstractBuildParticipantType;
+import org.eclipse.dltk.core.builder.IBuildParticipant;
+
+public class RutaPackageCheckerType extends AbstractBuildParticipantType {
+
+ @Override
+ public IBuildParticipant createBuildParticipant(IScriptProject project) throws CoreException {
+ try {
+ return new RutaCheckBuilder(project);
+ } catch (IllegalStateException e) {
+ return null;
+ }
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/DLTKRutaErrorReporter.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/DLTKRutaErrorReporter.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/DLTKRutaErrorReporter.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/DLTKRutaErrorReporter.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,309 @@
+/*
+ * 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.parser;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.FailedPredicateException;
+import org.antlr.runtime.MismatchedTokenException;
+import org.antlr.runtime.NoViableAltException;
+import org.antlr.runtime.RecognitionException;
+import org.antlr.runtime.Token;
+import org.antlr.runtime.TokenStream;
+import org.eclipse.dltk.ast.DLTKToken;
+import org.eclipse.dltk.compiler.problem.DefaultProblem;
+import org.eclipse.dltk.compiler.problem.IProblemReporter;
+import org.eclipse.dltk.compiler.problem.ProblemSeverities;
+
+/**
+ *
+ * @see org.eclipse.dltk.p y thon.internal.core.parsers.DLTKP y thonErrorReporter
+ *
+ */
+public class DLTKRutaErrorReporter {
+ IProblemReporter reporter;
+
+ DLTKTokenConverter converter;
+
+ RutaParser parser;
+
+ List problems = new ArrayList();
+
+ public DLTKRutaErrorReporter(DLTKTokenConverter converter, IProblemReporter reporter,
+ RutaParser parser) {
+ this.converter = converter;
+ this.reporter = reporter;
+ this.parser = parser;
+ }
+
+ public void reportError(RecognitionException re) {
+ if (reporter == null) {
+ return;
+ }
+ if (re.token == null) {
+ System.out.println("Token is null in ErrorReporter");
+ return;
+ }
+ Token token = re.token;
+ int line = re.token.getLine();
+ int index = token.getTokenIndex();
+ if (index < 0) {
+ index = re.index;
+ TokenStream tokenStream = parser.getTokenStream();
+ if (index > 0) {
+ token = tokenStream.get(index - 1);
+ line = token.getLine();
+ }
+ }
+
+ String message = re.getMessage();
+ String m = "";
+ if (message != null) {
+ m = message;
+ }
+ String tokenText = token.getText() == null ? "" : token.getText();
+
+ int bounds[] = RutaParseUtils.getBounds(token);
+ int st = bounds[0];
+ int et = bounds[1];
+
+ String errorPrefix = "";
+
+ //
+ //
+ if (re instanceof NoViableAltException) {
+ NoViableAltException nvae = (NoViableAltException) re;
+ errorPrefix = "Syntax error: ";
+ m = errorPrefix + nvae.grammarDecisionDescription;
+ reportProblem(line, m, st, et);
+ } else if (re instanceof MismatchedTokenException) {
+
+ errorPrefix = "Mismatched Input: ";
+ MismatchedTokenException mte = (MismatchedTokenException) re;
+ int expecting = mte.expecting;
+ String expectedToken = "";
+ if (expecting > 0) {
+ expectedToken = parser.getTokenNames()[expecting];
+ errorPrefix = errorPrefix + "Expecting \"" + expectedToken;
+ String msg = errorPrefix + "\" but found \"" + tokenText + "\".";
+ reportProblem(line, msg, st, et);
+ } else {
+ reportDefaultProblem(line, m, tokenText, st, et, errorPrefix);
+ }
+
+ } else if (re instanceof FailedPredicateException) {
+
+ errorPrefix = "Failed predicate: ";
+ reportDefaultProblem(line, m, tokenText, st, et, errorPrefix);
+
+ } else {
+ // TODO handle default syntax errors smarter:
+ String[] messages = { "Syntax Error:" + message, message };
+ if (message == null) {
+ messages[0] = re.toString();
+ }
+ DLTKToken convert = this.converter.convert(re.token);
+ // reporter.handle(CompilerOptions.OFFSET, messages, messages,
+ // st, et);
+ DefaultProblem defaultProblem = new DefaultProblem("", messages[0], 0, new String[] {},
+ ProblemSeverities.Error, st, et, re.token.getLine());
+ if (!problems.contains(defaultProblem)) {
+ reporter.reportProblem(defaultProblem);
+ problems.add(defaultProblem);
+ System.out.println(messages[0] + " ### line " + re.token.getLine());
+ }
+ }
+ }
+
+ /**
+ * @param line
+ * @param m
+ * @param tokenText
+ * @param st
+ * @param et
+ * @param errorPrefix
+ */
+ private void reportDefaultProblem(int line, String m, String tokenText, int st, int et,
+ String errorPrefix) {
+ String msg = errorPrefix + m + " : " + tokenText;
+ reportProblem(line, msg, st, et);
+ }
+
+ private void reportProblem(int line, String msg, int st, int et) {
+ DefaultProblem defaultProblem = createDefaultProblem(msg, st, et, line);
+ if (!problems.contains(defaultProblem)) {
+ reporter.reportProblem(defaultProblem);
+ problems.add(defaultProblem);
+ }
+ }
+
+ private DefaultProblem createDefaultProblem(String m, int st, int et, int line) {
+ // TODO handle filename
+ return new DefaultProblem("", m, 0, new String[] {}, ProblemSeverities.Error, st, et, line);
+ }
+
+ public void reportThrowable(Throwable extre) {
+ extre.printStackTrace();
+ // String message = extre.getLocalizedMessage();
+ // DefaultProblem defaultProblem = new DefaultProblem("", message,
+ // 0, new String[] {}, ProblemSeverities.Error, 0, 10,
+ // 0);
+ // if (!problems.contains(defaultProblem)) {
+ // reporter.reportProblem(defaultProblem);
+ // problems.add(defaultProblem);
+ // }
+ }
+
+ public void reportMessage(String msg) {
+ }
+
+ public void reportErrorOld(RecognitionException re) {
+ if (reporter == null) {
+ return;
+ }
+ if (re.token == null) {
+ System.out.println("Token is null in ErrorReporter");
+ return;
+ }
+ Token token = re.token;
+ int line = re.token.getLine();
+ int index = token.getTokenIndex();
+ if (index < 0) {
+ index = re.index;
+ TokenStream tokenStream = parser.getTokenStream();
+ try {
+ token = tokenStream.get(index - 1);
+ line = token.getLine();
+ } catch (ArrayIndexOutOfBoundsException e) {
+ e.printStackTrace();
+ }
+ }
+
+ String message = re.getMessage();
+ String m = "unknown error";
+ if (message != null) {
+ m = message;
+ }
+
+ if (re instanceof NoViableAltException) {
+ NoViableAltException ec = (NoViableAltException) re;
+ if (message == null || ec.token.getText() == null) {
+ m = ec.toString();
+ } else {
+ m = "Syntax Error:" + message + " : " + ec.token.getText();
+ }
+ String[] messages = { m };
+ int st = converter.convert(ec.token.getLine(), ec.token.getCharPositionInLine());
+ String sm = ec.token.getText();
+ int et = st + ec.token.getText().length();
+ if (st == -1)
+ return;
+ DefaultProblem defaultProblem = new DefaultProblem("", messages[0], 0, new String[] {},
+ ProblemSeverities.Error, st, et, ec.token.getLine());
+ if (!problems.contains(defaultProblem)) {
+ reporter.reportProblem(defaultProblem);
+ problems.add(defaultProblem);
+ System.out.println(messages[0] + " ### line " + ec.token.getLine());
+ }
+ } else if (re instanceof MismatchedTokenException) {
+ MismatchedTokenException ec = (MismatchedTokenException) re;
+ if (message == null || ec.token.getText() == null) {
+ m = ec.toString();
+ } else {
+ m = "mismatched input: " + message + " : " + ec.token.getText();
+ }
+ // if (message == null) {
+ // message = "mismatched input "
+ // + this.parser.getTokenErrorDisplay(ec.token);
+ // // return;
+ // }
+ String[] messages = { m }; // "Syntax Error:" + message, message,
+ // ec.token.getText() };
+ // this.converter.convert(ec.token).getColumn() - 1;
+ // String sm = ec.token.getText();
+ // st + ((sm != null) ? sm.length() : 1);
+ // TODO martin: "rewrite converter"
+ int st = converter.convert(ec.token.getLine(), ec.token.getCharPositionInLine());
+ // String sm = ec.token.getText();
+ int et = st;
+ if (ec.token.getText() != null) {
+ et = ec.token.getText().length() + st;
+ if (et >= this.converter.length()) {
+ et = this.converter.length() - 1;
+ st -= 2;
+ }
+ } else {
+ st = ((CommonToken) token).getStartIndex();
+ et = ((CommonToken) token).getStopIndex();
+ }
+ // reporter.handle(CompilerOptions.OFFSET, messages, messages,
+ // st, et);
+ DefaultProblem defaultProblem = new DefaultProblem("", messages[0], 0, new String[] {},
+ ProblemSeverities.Error, st, et, ec.line);
+ if (!problems.contains(defaultProblem)) {
+ reporter.reportProblem(defaultProblem);
+ problems.add(defaultProblem);
+ System.out.println(messages[0] + " ### line " + ec.line);
+ }
+ } else if (re instanceof FailedPredicateException) {
+ String[] messages = { "Syntax Error:" + message, message };
+ if (message == null) {
+ messages[0] = re.toString();
+ }
+ DLTKToken convert = this.converter.convert(re.token);
+ int st = convert.getColumn();
+ int et = convert.getColumn() + convert.getText().length();
+ // reporter.handle(CompilerOptions.OFFSET, messages, messages,
+ // st, et);
+ DefaultProblem defaultProblem = new DefaultProblem("", "Type not defined in this script: "
+ + convert.getText(), 0, new String[] {}, ProblemSeverities.Warning, st, et,
+ re.token.getLine());
+ if (!problems.contains(defaultProblem)) {
+ reporter.reportProblem(defaultProblem);
+ problems.add(defaultProblem);
+ System.out.println(messages[0] + " ### line " + re.token.getLine());
+ }
+ } else {
+ String[] messages = { "Syntax Error:" + message, message };
+ if (message == null) {
+ messages[0] = re.toString();
+ }
+ DLTKToken convert = this.converter.convert(re.token);
+ int st = convert.getColumn();
+ int et = convert.getColumn() + convert.getText().length();
+ // reporter.handle(CompilerOptions.OFFSET, messages, messages,
+ // st, et);
+ DefaultProblem defaultProblem = new DefaultProblem("", messages[0], 0, new String[] {},
+ ProblemSeverities.Error, st, et, re.token.getLine());
+ if (!problems.contains(defaultProblem)) {
+ reporter.reportProblem(defaultProblem);
+ problems.add(defaultProblem);
+ System.out.println(messages[0] + " ### line " + re.token.getLine());
+ }
+ }
+ // } catch (CoreException e) {
+ // if (DLTKCore.DEBUG) {
+ // e.printStackTrace();
+ // }
+ // }
+ }
+}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/DLTKTokenConverter.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/DLTKTokenConverter.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/parser/DLTKTokenConverter.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/DLTKTokenConverter.java Mon Apr 29 14:50:56 2013
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.core.parser;
+package org.apache.uima.ruta.ide.core.parser;
import org.antlr.runtime.Token;
import org.eclipse.dltk.ast.DLTKToken;
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaParseUtils.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaParseUtils.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaParseUtils.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaParseUtils.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,225 @@
+/*
+ * 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.parser;
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+import org.apache.uima.ruta.ide.parser.ast.TMTypeConstants;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.ast.expressions.Expression;
+import org.eclipse.dltk.ast.expressions.StringLiteral;
+import org.eclipse.dltk.ast.references.SimpleReference;
+import org.eclipse.dltk.ast.statements.Statement;
+import org.eclipse.dltk.core.IField;
+import org.eclipse.dltk.core.IMember;
+import org.eclipse.dltk.core.IMethod;
+import org.eclipse.dltk.core.IType;
+import org.eclipse.dltk.core.ModelException;
+
+public class RutaParseUtils {
+
+ public static boolean isAtLineStart(ASTNode node, String content) {
+ boolean blockStart = false;
+ int sourceStart = node.sourceStart();
+ while (sourceStart >= 0) {
+ sourceStart--;
+ char c = content.charAt(sourceStart);
+ if (Character.isWhitespace(c)) {
+ continue;
+ }
+ if (c == '\n' || c == '\r' || c == ';') {
+ return true;
+ } else if (c == '{') {
+ blockStart = true;
+ } else if (c == '}' && blockStart) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ public static int endLineOrSymbol(int from, String content) {
+ int pos = 0;
+ for (pos = from; pos < content.length(); ++pos) {
+ char c = content.charAt(pos);
+ if (c == '\n' || c == '\r' || c == ';') {
+ return pos;
+ }
+ if (!Character.isWhitespace(c)) {
+ return pos;
+ }
+ }
+ if (pos == content.length()) {
+ return pos;
+ }
+ return from;
+ }
+
+ public static int startLineOrSymbol(int from, String content) {
+ if (from == -1) {
+ from = 0;
+ }
+ if (from >= content.length())
+ from--;
+ for (int pos = from - 1; pos > 0; --pos) {
+ char c = content.charAt(pos);
+ if (c == '\n' || c == '\r' || c == ';') {
+ return pos + 1;
+ }
+ if (!Character.isWhitespace(c)) {
+ return pos + 1;
+ }
+ }
+ return from;
+ }
+
+ public static int endLineOrNoSymbol(int from, String content) {
+ int pos = 0;
+ if (from == -1) {
+ from = 0;
+ }
+ if (from >= content.length())
+ from--;
+ for (pos = from; pos < content.length(); ++pos) {
+ if (checkBounds(content, pos)) {
+ return pos;
+ }
+ }
+ if (pos == content.length()) {
+ return pos;
+ }
+ return pos;
+ }
+
+ private static boolean checkBounds(String content, int pos) {
+ char[] syms = { ' ', '\t', '\n', '\r', ']', '[', '}', '{', '(', ')' };
+ char c = content.charAt(pos);
+ for (int i = 0; i < syms.length; ++i) {
+ if (syms[i] == c) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static int startLineOrNoSymbol(int from, String content) {
+ if (from == -1) {
+ from = 0;
+ }
+ if (from >= content.length())
+ from--;
+ int pos;
+ for (pos = from; pos > 0; --pos) {
+ if (checkBounds(content, pos)) {
+ return pos + 1;
+ }
+ }
+ return pos;
+ }
+
+ public static String[] returnVariable(Statement node) {
+ return null;
+ }
+
+ public static SimpleReference extractVariableFromString(int sourceStart, int sourceEnd, int i,
+ String name) {
+ return null;
+ }
+
+ public static SimpleReference extractVariableFromString(StringLiteral completionNode, int pos) {
+ return null;
+ }
+
+ public static ASTNode getScopeParent(ModuleDeclaration module, Expression s) {
+ return null;
+ }
+
+ public static String processFieldName(IField field, String token) {
+ return null;
+ }
+
+ public static String processMethodName(IMethod method, String token) {
+ return null;
+ }
+
+ public static String processTypeName(IType method, String token) {
+ return null;
+ }
+
+ /**
+ * @param token
+ * @return (start, end)
+ * @throws IllegalArgumentException
+ * when token==null or !(token instanceof CommonToken)
+ */
+ public static final int[] getBounds(Token token) throws IllegalArgumentException {
+ if (token == null) {
+ throw new IllegalArgumentException();
+ }
+ if (!(token instanceof CommonToken)) {
+ throw new IllegalArgumentException();
+ }
+ CommonToken ct = (CommonToken) token;
+ int[] bounds = { ct.getStartIndex(), ct.getStopIndex() + 1 };
+ return bounds;
+ }
+
+ /**
+ * @param tokenA
+ * startToken
+ * @param tokenB
+ * endToken
+ * @return positions of a.start // b.end
+ * @throws IllegalArgumentException
+ * when some token is null or not instanceof CommonToken
+ */
+ public static final int[] getBounds(Token tokenA, Token tokenB) throws IllegalArgumentException {
+ if (!((tokenA instanceof CommonToken) && (tokenB instanceof CommonToken || tokenB == null))) {
+ throw new IllegalArgumentException();
+ }
+ CommonToken ctA = (CommonToken) tokenA;
+ if (tokenB == null) {
+ int[] bounds = { ctA.getStartIndex(), ctA.getStopIndex() + 1 };
+ return bounds;
+ } else {
+ CommonToken ctB = (CommonToken) tokenB;
+ int[] bounds = { ctA.getStartIndex(), ctB.getStopIndex() + 1 };
+ return bounds;
+ }
+ }
+
+ /**
+ * @param member
+ * @return see {@link TMTypeConstants}, -1 if not valid
+ */
+ public static final int getTypeOfIModelElement(IMember member) {
+ int type;
+ try {
+ type = member.getFlags();
+ } catch (ModelException e) {
+ return -1;
+ }
+ type &= TMTypeConstants.TM_TYPE_BITMASK;
+ return type;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceElementParser.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceElementParser.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceElementParser.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceElementParser.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.parser;
+
+import org.apache.uima.ruta.ide.core.RutaNature;
+import org.eclipse.dltk.compiler.SourceElementRequestVisitor;
+import org.eclipse.dltk.core.AbstractSourceElementParser;
+
+
+public class RutaSourceElementParser extends AbstractSourceElementParser {
+
+ /*
+ * @see org.eclipse.dltk.core.AbstractSourceElementParser#createVisitor()
+ */
+ @Override
+ protected SourceElementRequestVisitor createVisitor() {
+ return new RutaSourceElementRequestVisitor(getRequestor());
+ }
+
+ /*
+ * @see org.eclipse.dltk.core.AbstractSourceElementParser#getNatureId()
+ */
+ @Override
+ protected String getNatureId() {
+ return RutaNature.NATURE_ID;
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceElementRequestVisitor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceElementRequestVisitor.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceElementRequestVisitor.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceElementRequestVisitor.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,287 @@
+/*
+ * 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.parser;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.uima.ruta.ide.parser.ast.TMTypeConstants;
+import org.apache.uima.ruta.ide.parser.ast.RutaBasicAnnotationType;
+import org.apache.uima.ruta.ide.parser.ast.RutaImportStatement;
+import org.apache.uima.ruta.ide.parser.ast.RutaPackageDeclaration;
+import org.apache.uima.ruta.ide.parser.ast.RutaTypeDeclaration;
+import org.apache.uima.ruta.ide.parser.ast.RutaVariableDeclaration;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.Modifiers;
+import org.eclipse.dltk.ast.PositionInformation;
+import org.eclipse.dltk.ast.declarations.Argument;
+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.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.compiler.ISourceElementRequestor;
+import org.eclipse.dltk.compiler.SourceElementRequestVisitor;
+
+public class RutaSourceElementRequestVisitor extends SourceElementRequestVisitor {
+
+ private static class TypeField {
+ private String fName;
+
+ private String fInitValue;
+
+ private PositionInformation fPos;
+
+ private Expression fExpression;
+
+ private ASTNode fToNode;
+
+ private ASTNode declaredIn; // The node where the declaration was found
+
+ // (should be either class or method node)
+ TypeField(String name, String initValue, PositionInformation pos, Expression expression,
+ ASTNode toNode, ASTNode declaredIn) {
+
+ this.fName = name;
+ this.fInitValue = initValue;
+ this.fPos = pos;
+ this.fExpression = expression;
+ this.fToNode = toNode;
+ this.declaredIn = declaredIn;
+ }
+
+ String getName() {
+
+ return this.fName;
+ }
+
+ String getInitValue() {
+
+ return this.fInitValue;
+ }
+
+ PositionInformation getPos() {
+
+ return this.fPos;
+ }
+
+ Expression getExpression() {
+
+ return this.fExpression;
+ }
+
+ ASTNode getToNode() {
+
+ return this.fToNode;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+
+ if (obj instanceof TypeField) {
+ TypeField second = (TypeField) obj;
+ return second.fName.equals(this.fName) && second.fToNode.equals(this.fToNode);
+ }
+ return super.equals(obj);
+ }
+
+ @Override
+ public String toString() {
+
+ return this.fName;
+ }
+
+ public ASTNode getDeclaredIn() {
+ return declaredIn;
+ }
+
+ }
+
+ private static String ANONYMOUS_LAMBDA_FORM_MARKER = "<anonymous>";
+
+ // Used to prehold fields if adding in methods.
+ private List fNotAddedFields = new ArrayList();
+
+ private String lastLambdaFormName = ANONYMOUS_LAMBDA_FORM_MARKER;
+
+ /**
+ * Used to determine duplicate names.
+ */
+ private Map fTypeVariables = new HashMap();
+
+ //
+ public RutaSourceElementRequestVisitor(ISourceElementRequestor requestor) {
+ super(requestor);
+ }
+
+ protected String makeLanguageDependentValue(Expression value) {
+ String outValue = "";
+ return outValue;
+ }
+
+ @Override
+ protected void onEndVisitMethod(MethodDeclaration method) {
+ if (fNotAddedFields.size() >= 1) {
+ TypeField typeField = (TypeField) fNotAddedFields.get(0);
+ if (null != typeField && typeField.getDeclaredIn().equals(method)) {
+ Iterator i = this.fNotAddedFields.iterator();
+ while (i.hasNext()) {
+ TypeField field = (TypeField) i.next();
+ if (canAddVariables(field.getToNode(), field.getName())) {
+
+ PositionInformation pos = field.getPos();
+
+ ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
+ info.modifiers = Modifiers.AccStatic;
+ info.name = field.getName();
+ info.nameSourceEnd = pos.nameEnd - 2;
+ info.nameSourceStart = pos.nameStart;
+ info.declarationStart = pos.sourceStart;
+ this.fRequestor.enterField(info);
+ this.fRequestor.exitField(pos.sourceEnd);
+
+ }
+ }
+ this.fNotAddedFields.clear();
+ }
+ }
+ }
+
+ @Override
+ public boolean visit(Statement statement) throws Exception {
+ super.visit(statement);
+ if (statement instanceof RutaPackageDeclaration) {
+ this.processPackage(statement);
+ super.fNodes.pop();
+ return false;
+ }
+ if (statement instanceof FieldDeclaration) {
+ FieldDeclaration fieldDecl = (FieldDeclaration) statement;
+ processFieldDeclaration(fieldDecl.getRef(), fieldDecl);
+ super.fNodes.pop();
+ return false;
+ }
+ // TODO handle tm-import statement
+ if (statement instanceof RutaImportStatement) {
+ RutaImportStatement tmImport = (RutaImportStatement) statement;
+ super.fNodes.pop();
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean visit(Expression expression) throws Exception {
+ if (expression instanceof VariableReference) {
+ VariableReference varRef = (VariableReference) expression;
+ this.fRequestor.acceptFieldReference(varRef.getName(), varRef.sourceStart());
+ }
+ return super.visit(expression);
+ }
+
+ private void processPackage(Statement statement) {
+ RutaPackageDeclaration pack = (RutaPackageDeclaration) statement;
+ this.fRequestor.acceptPackage(pack.getNameStart(), pack.getNameEnd(),
+ pack.getName());
+ }
+
+ private void processFieldDeclaration(SimpleReference variableIDRef, Statement fullDeclaration) {
+ int modifier = Modifiers.AccDefault;
+ if (fullDeclaration instanceof RutaVariableDeclaration) {
+ modifier = Modifiers.AccPrivate;
+ modifier |= ((RutaVariableDeclaration) fullDeclaration).getKind();
+ } else if (fullDeclaration instanceof RutaBasicAnnotationType) {
+ modifier = Modifiers.AccConstant;
+ modifier |= TMTypeConstants.TM_TYPE_AT;
+ } else if (fullDeclaration instanceof RutaTypeDeclaration) {
+ modifier = Modifiers.AccPublic;
+ modifier |= TMTypeConstants.TM_TYPE_AT;
+ }
+ if (canAddVariables((ASTNode) this.fNodes.peek(), variableIDRef.getName())) {
+ ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
+ info.modifiers = modifier;
+ info.name = variableIDRef.getName();
+ info.nameSourceEnd = variableIDRef.sourceEnd() - 1;
+ info.nameSourceStart = variableIDRef.sourceStart();
+ info.declarationStart = variableIDRef.sourceStart();
+ this.fRequestor.enterField(info);
+ if (fullDeclaration != null) {
+ this.fRequestor.exitField(fullDeclaration.sourceEnd());
+ } else {
+ this.fRequestor.exitField(variableIDRef.sourceEnd());
+ }
+ }
+ }
+
+ private boolean canAddVariables(ASTNode type, String name) {
+ if (this.fTypeVariables.containsKey(type)) {
+ List variables = (List) this.fTypeVariables.get(type);
+ if (variables.contains(name)) {
+ return false;
+ }
+ variables.add(name);
+ return true;
+ } else {
+ List variables = new ArrayList();
+ variables.add(name);
+ this.fTypeVariables.put(type, variables);
+ return true;
+ }
+ }
+
+ @Override
+ public boolean endvisit(Statement s) throws Exception {
+ return true;
+ }
+
+ @Override
+ public boolean visit(MethodDeclaration method) throws Exception {
+ this.fNodes.push(method);
+ List<Argument> args = method.getArguments();
+ String[] parameter = new String[args.size()];
+ for (int a = 0; a < args.size(); a++) {
+ Argument arg = args.get(a);
+ parameter[a] = arg.getName();
+ }
+
+ ISourceElementRequestor.MethodInfo mi = new ISourceElementRequestor.MethodInfo();
+ mi.parameterNames = parameter;
+ mi.name = method.getName();
+ mi.modifiers = method.getModifiers();
+ mi.nameSourceStart = method.getNameStart();
+ mi.nameSourceEnd = method.getNameEnd() - 1;
+ mi.declarationStart = method.sourceStart();
+
+ this.fInMethod = true;
+ this.fCurrentMethod = method;
+ this.fRequestor.enterMethod(mi);
+ return true;
+ }
+
+ @Override
+ public boolean visit(ModuleDeclaration declaration) throws Exception {
+ return super.visit(declaration);
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceParser.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceParser.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceParser.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceParser.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,147 @@
+/*
+ * 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.parser;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import org.antlr.runtime.ANTLRStringStream;
+import org.antlr.runtime.CharStream;
+import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.Token;
+import org.apache.uima.ruta.ide.core.IRutaKeywords;
+import org.apache.uima.ruta.ide.core.RutaKeywordsManager;
+import org.apache.uima.ruta.ide.core.builder.DescriptorManager;
+import org.apache.uima.ruta.ide.parser.ast.RutaModuleDeclaration;
+import org.apache.uima.ruta.parser.RutaLexer;
+import org.eclipse.dltk.ast.parser.AbstractSourceParser;
+import org.eclipse.dltk.ast.parser.IModuleDeclaration;
+import org.eclipse.dltk.compiler.env.IModuleSource;
+import org.eclipse.dltk.compiler.problem.IProblemReporter;
+import org.eclipse.dltk.core.DLTKCore;
+
+public class RutaSourceParser extends AbstractSourceParser {
+
+ private CommonTokenStream tokenStream;
+
+ private IProblemReporter problemReporter = null;
+
+ public RutaSourceParser(/* IProblemReporter reporter */) {
+ // this.problemReporter = reporter;
+ }
+
+ public static class TMLexer extends RutaLexer {
+ public TMLexer(CharStream lexer) {
+ super(lexer);
+ }
+
+ @Override
+ public Token nextToken() {
+ startPos = getCharPositionInLine();
+ return super.nextToken();
+ }
+ }
+ public IModuleDeclaration parse(IModuleSource input, IProblemReporter reporter) {
+ return parse(input.getFileName(), input.getSourceContents(), reporter);
+ }
+
+ public IModuleDeclaration parse(String fileName, String content, IProblemReporter reporter) {
+ this.problemReporter = reporter;
+
+ RutaModuleDeclaration moduleDeclaration = new RutaModuleDeclaration(content.length(),
+ true);
+
+ CharStream st = new ANTLRStringStream(content);
+ RutaLexer lexer = new TMLexer(st);
+
+ CommonTokenStream tokens = new CommonTokenStream(lexer);
+ this.tokenStream = tokens;
+
+ RutaParser parser = new RutaParser(this.tokenStream);
+
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.BASIC)) {
+ parser.addPredefinedType(each);
+ }
+ // TODO refacor , also in grammar
+ List<String> variables = parser.getVariables();
+ Map<String, String> variableTypes = parser.getVariableTypes();
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.CONDITION)) {
+ variables.add(each);
+ variableTypes.put(each, "CONDITION");
+ }
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.ACTION)) {
+ variables.add(each);
+ variableTypes.put(each, "ACTION");
+ }
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.BOOLEANFUNCTION)) {
+ variables.add(each);
+ variableTypes.put(each, "BOOLEANFUNCTION");
+ }
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.NUMBERFUNCTION)) {
+ variables.add(each);
+ variableTypes.put(each, "NUMBERFUNCTION");
+ }
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.STRINGFUNCTION)) {
+ variables.add(each);
+ variableTypes.put(each, "STRINGFUNCTION");
+ }
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.TYPEFUNCTION)) {
+ variables.add(each);
+ variableTypes.put(each, "TYPEFUNCTION");
+ }
+ parser.addPredefinedType("Document");
+ parser.addPredefinedType("Annotation");
+
+ parser.md = moduleDeclaration;
+ parser.length = content.length();
+ parser.converter = new DLTKTokenConverter(content.toCharArray());
+ parser.reporter = new DLTKRutaErrorReporter(parser.converter, problemReporter, parser);
+
+ parser.descriptor = new DescriptorManager();
+
+ moduleDeclaration.descriptorInfo = parser.descriptor;
+
+ String name = "Dynamic";
+ if (fileName != null) {
+ File fn = new File(fileName);
+ name = fn.getName();
+ int lastIndexOf = name.lastIndexOf(".tm");
+ if(lastIndexOf>0) {
+ name = name.substring(0, lastIndexOf);
+ }
+ }
+ try {
+ parser.file_input(name);
+ } catch (Throwable e) {
+ if (DLTKCore.DEBUG_PARSER) {
+ e.printStackTrace();
+ }
+ }
+ return moduleDeclaration;
+ }
+
+
+ public CommonTokenStream getTokenStream() {
+ return tokenStream;
+ }
+
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceParserFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceParserFactory.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceParserFactory.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaSourceParserFactory.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,31 @@
+/*
+ * 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.parser;
+
+import org.eclipse.dltk.ast.parser.ISourceParser;
+import org.eclipse.dltk.ast.parser.ISourceParserFactory;
+
+public class RutaSourceParserFactory implements ISourceParserFactory {
+
+ public ISourceParser createSourceParser() {
+ return new RutaSourceParser();
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaTodoParserType.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaTodoParserType.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaTodoParserType.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/parser/RutaTodoParserType.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,79 @@
+/*
+ * 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.parser;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.apache.uima.ruta.ide.parser.ast.RutaScriptBlock;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.compiler.task.ITodoTaskPreferences;
+import org.eclipse.dltk.compiler.task.TodoTaskPreferences;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.core.builder.AbstractTodoTaskBuildParticipantType;
+import org.eclipse.dltk.core.builder.IBuildParticipant;
+
+public class RutaTodoParserType extends AbstractTodoTaskBuildParticipantType {
+
+ // @Override
+ // protected ITodoTaskPreferences getPreferences(IScriptProject project) {
+ // return new TodoTaskPreferencesOnPreferenceLookupDelegate(RutaIdePlugin.PLUGIN_ID,
+ // project);
+ // }
+
+ @Override
+ protected ITodoTaskPreferences getPreferences(IScriptProject project) {
+ return new TodoTaskPreferences(RutaIdePlugin.getDefault().getPluginPreferences());
+ }
+
+ @Override
+ protected IBuildParticipant getBuildParticipant(ITodoTaskPreferences preferences) {
+ return new RutaTodoTaskAstParser(preferences);
+ }
+
+ private static class RutaTodoTaskAstParser extends TodoTaskBuildParticipant implements
+ IBuildParticipant {
+
+ public RutaTodoTaskAstParser(ITodoTaskPreferences preferences) {
+ super(preferences);
+ }
+
+ @Override
+ protected boolean isSimpleNode(ASTNode node) {
+ if (node instanceof RutaScriptBlock) {
+ return true;
+ }
+ return super.isSimpleNode(node);
+ }
+
+ @Override
+ protected int findCommentStart(char[] content, int begin, int end) {
+ if (!isCheckRanges()) {
+ return super.findCommentStart(content, begin, end);
+ }
+ for (int i = begin; i < end - 1; ++i) {
+ if (content[i] == '/' && isValid(i)) {
+ return i + 2;
+ }
+ }
+ return -1;
+ }
+
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/search/RutaCallProcessor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/search/RutaCallProcessor.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/search/RutaCallProcessor.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/search/RutaCallProcessor.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,95 @@
+/*
+ * 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.search;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.dltk.ast.references.SimpleReference;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.ICallProcessor;
+import org.eclipse.dltk.core.IModelElement;
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.core.ModelException;
+import org.eclipse.dltk.core.search.IDLTKSearchConstants;
+import org.eclipse.dltk.core.search.IDLTKSearchScope;
+import org.eclipse.dltk.core.search.SearchEngine;
+import org.eclipse.dltk.core.search.SearchMatch;
+import org.eclipse.dltk.core.search.SearchParticipant;
+import org.eclipse.dltk.core.search.SearchPattern;
+import org.eclipse.dltk.core.search.SearchRequestor;
+
+public class RutaCallProcessor implements ICallProcessor {
+ public final static int GENERICS_AGNOSTIC_MATCH_RULE = SearchPattern.R_EXACT_MATCH
+ | SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_ERASURE_MATCH;
+
+ private SearchEngine searchEngine = new SearchEngine();
+
+ public Map process(final IModelElement parent, IModelElement element, IDLTKSearchScope scope,
+ IProgressMonitor monitor) {
+ final Map elements = new HashMap();
+ SearchRequestor requestor = new SearchRequestor() {
+
+ @Override
+ public void acceptSearchMatch(SearchMatch match) {
+ if ((match.getAccuracy() != SearchMatch.A_ACCURATE)) {
+ return;
+ }
+
+ if (match.isInsideDocComment()) {
+ return;
+ }
+
+ if (match.getElement() != null && match.getElement() instanceof IModelElement) {
+ IModelElement member = (IModelElement) match.getElement();
+ ISourceModule module = (ISourceModule) member.getAncestor(IModelElement.SOURCE_MODULE);
+ SimpleReference ref = new SimpleReference(match.getOffset(), match.getOffset()
+ + match.getLength(), "");
+ try {
+ IModelElement[] e = module.codeSelect(match.getOffset(), 1);
+ for (int j = 0; j < e.length; ++j) {
+ if (e[j].equals(parent)) {
+ elements.put(ref, member);
+ }
+ }
+
+ } catch (ModelException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ };
+
+ SearchPattern pattern = SearchPattern.createPattern(element.getElementName(),
+ IDLTKSearchConstants.METHOD, IDLTKSearchConstants.REFERENCES,
+ GENERICS_AGNOSTIC_MATCH_RULE, scope.getLanguageToolkit());
+ try {
+ searchEngine.search(pattern, new SearchParticipant[] { SearchEngine
+ .getDefaultSearchParticipant() }, scope, requestor, monitor);
+ } catch (CoreException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ return elements;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/search/RutaMatchLocator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/search/RutaMatchLocator.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/search/RutaMatchLocator.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/search/RutaMatchLocator.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,95 @@
+/*
+ * 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.search;
+
+import org.eclipse.dltk.ast.declarations.MethodDeclaration;
+import org.eclipse.dltk.core.IMethod;
+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.search.matching.MatchLocator;
+import org.eclipse.dltk.internal.core.BuiltinSourceModule;
+import org.eclipse.dltk.internal.core.ExternalSourceModule;
+import org.eclipse.dltk.internal.core.Openable;
+import org.eclipse.dltk.internal.core.SourceModule;
+
+public class RutaMatchLocator extends MatchLocator {
+
+ public RutaMatchLocator() {
+ super();
+ }
+
+ @Override
+ protected IModelElement createMethodHandle(ISourceModule module, String methodName) {
+ IMethod methodHandle = null;
+ // resolveDuplicates(methodHandle);
+ return methodHandle;
+ }
+
+ @Override
+ protected IModelElement createHandle(MethodDeclaration method, IModelElement parent) {
+ if (parent instanceof IType) {
+ IType type = (IType) parent;
+ return createMethodHandle(type, new String(method.getName()));
+ } else if (parent instanceof ISourceModule) {
+ if (method.getDeclaringTypeName() != null) {
+ return createMethodHandle((ISourceModule) parent, method.getDeclaringTypeName()
+ + method.getName());
+ } else {
+ return createMethodHandle((ISourceModule) parent, method.getName());
+ }
+ }
+ return null;
+ }
+
+ @Override
+ protected IModelElement createTypeHandle(IType parent, String name) {
+ return super.createTypeHandle(parent, name);
+ }
+
+ @Override
+ protected IType createTypeHandle(String name) {
+ Openable openable = this.currentPossibleMatch.openable;
+ if (openable instanceof SourceModule || openable instanceof ExternalSourceModule
+ || openable instanceof BuiltinSourceModule) {
+ IParent e = ((IParent) openable);
+ if (name.indexOf("::") != -1) {
+ String[] split = name.split("::");
+ for (int i = 0; i < split.length; i++) {
+ if (e instanceof ISourceModule) {
+ e = ((ISourceModule) e).getType(split[i]);
+ } else if (e instanceof IType) {
+ e = ((IType) e).getType(split[i]);
+ } else {
+ e = null;
+ }
+ if (e == null) {
+ return null;
+ }
+ }
+ if (e != null && e instanceof IType) {
+ return (IType) e;
+ }
+ }
+ }
+ return super.createTypeHandle(name);
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaDebugConstants.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaDebugConstants.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaDebugConstants.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaDebugConstants.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,29 @@
+/*
+ * 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.debug;
+
+public final class RutaDebugConstants {
+ private RutaDebugConstants() {
+ }
+
+ public static final String DEBUG_MODEL_ID = "org.eclipse.dltk.debug.rutaModel";
+
+ public static final String DEBUGGING_ENGINE_ID_KEY = "debugging_engine_id";
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaDebugPreferenceInitializer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaDebugPreferenceInitializer.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaDebugPreferenceInitializer.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaDebugPreferenceInitializer.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.debug;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.dltk.debug.core.DLTKDebugPreferenceConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+public class RutaDebugPreferenceInitializer extends AbstractPreferenceInitializer {
+
+ public void initializeDefaultPreferences() {
+// Preferences store = RutaIdePlugin.getDefault().getPluginPreferences();
+ IPreferenceStore store = RutaIdePlugin.getDefault().getPreferenceStore();
+ store.setDefault(RutaDebugConstants.DEBUGGING_ENGINE_ID_KEY, "");
+
+ store.setDefault(DLTKDebugPreferenceConstants.PREF_DBGP_BREAK_ON_FIRST_LINE, false);
+ store.setDefault(DLTKDebugPreferenceConstants.PREF_DBGP_ENABLE_LOGGING, false);
+
+ store.setDefault(DLTKDebugPreferenceConstants.PREF_DBGP_SHOW_SCOPE_GLOBAL, true);
+ store.setDefault(DLTKDebugPreferenceConstants.PREF_DBGP_SHOW_SCOPE_CLASS, true);
+ store.setDefault(DLTKDebugPreferenceConstants.PREF_DBGP_SHOW_SCOPE_LOCAL, true);
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaDebugPreferences.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaDebugPreferences.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaDebugPreferences.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaDebugPreferences.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,49 @@
+/*
+ * 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.debug;
+
+
+public class RutaDebugPreferences {
+ private static final String DEBUGGING_ENGINE_PATH = "debugging_engine";
+
+ private static final String DEBUGGING_ENGINE_PATH_DEFAULT = "";
+
+// private static Preferences getNode() {
+// String id = RutaIdePlugin.getDefault().getBundle().getSymbolicName();
+// return Platform.getPreferencesService().getRootNode().node(InstanceScope.SCOPE).node(id);
+// }
+
+ public static void save() {
+// try {
+// getNode().flush();
+// } catch (BackingStoreException e) {
+// // TODO: add logging
+// }
+ }
+
+ public static String getDebuggingEnginePath() {
+ return null;
+// return getNode().get(DEBUGGING_ENGINE_PATH, DEBUGGING_ENGINE_PATH_DEFAULT);
+ }
+
+ public static void setDebuggingEnginePath(String path) {
+// getNode().put(DEBUGGING_ENGINE_PATH, path);
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaTypeFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaTypeFactory.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaTypeFactory.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/RutaTypeFactory.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,44 @@
+/*
+ * 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.debug;
+
+import org.eclipse.dltk.debug.core.model.AtomicScriptType;
+import org.eclipse.dltk.debug.core.model.ComplexScriptType;
+import org.eclipse.dltk.debug.core.model.IScriptType;
+import org.eclipse.dltk.debug.core.model.IScriptTypeFactory;
+
+
+public class RutaTypeFactory implements IScriptTypeFactory {
+ private static final String[] atomicTypes = {};
+
+ public RutaTypeFactory() {
+
+ }
+
+ public IScriptType buildType(String type) {
+ for (int i = 0; i < atomicTypes.length; ++i) {
+ if (atomicTypes[i].equals(type)) {
+ return new AtomicScriptType(type);
+ }
+ }
+
+ return new ComplexScriptType(type);
+ }
+}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/Messages.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/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/debug/ui/Messages.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/Messages.java Mon Apr 29 14:50:56 2013
@@ -17,12 +17,12 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.debug.ui;
+package org.apache.uima.ruta.ide.debug.ui;
import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
- private static final String BUNDLE_NAME = "org.apache.uima.textmarker.ide.debug.ui.messages"; //$NON-NLS-1$
+ private static final String BUNDLE_NAME = "org.apache.uima.ruta.ide.debug.ui.messages"; //$NON-NLS-1$
public static String NoDebuggingEngine_title;
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/RutaDebugHover.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/RutaDebugHover.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/RutaDebugHover.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/RutaDebugHover.java Mon Apr 29 14:50:56 2013
@@ -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.ruta.ide.debug.ui;
+
+import org.eclipse.dltk.debug.ui.ScriptDebugModelPresentation;
+import org.eclipse.dltk.internal.debug.ui.ScriptDebugHover;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+public class RutaDebugHover extends ScriptDebugHover {
+
+ @Override
+ protected ScriptDebugModelPresentation getModelPresentation() {
+ return new RutaDebugModelPresentation();
+ }
+
+ public void setPreferenceStore(IPreferenceStore store) {
+
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/RutaDebugModelPresentation.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/RutaDebugModelPresentation.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/RutaDebugModelPresentation.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/RutaDebugModelPresentation.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,150 @@
+/*
+ * 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.debug.ui;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.debug.ui.IDebugUIConstants;
+import org.eclipse.dltk.debug.core.DLTKDebugPlugin;
+import org.eclipse.dltk.debug.core.model.IScriptBreakpoint;
+import org.eclipse.dltk.debug.core.model.IScriptMethodEntryBreakpoint;
+import org.eclipse.dltk.debug.core.model.IScriptValue;
+import org.eclipse.dltk.debug.core.model.IScriptVariable;
+import org.eclipse.dltk.debug.core.model.IScriptWatchpoint;
+import org.eclipse.dltk.debug.ui.ScriptDebugImageDescriptor;
+import org.eclipse.dltk.debug.ui.ScriptDebugImages;
+import org.eclipse.dltk.debug.ui.ScriptDebugModelPresentation;
+import org.eclipse.dltk.ui.DLTKPluginImages;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+
+public class RutaDebugModelPresentation extends ScriptDebugModelPresentation {
+ private static final String TM_EDITOR_ID = "org.apache.uima.ruta.ide.ui.editor.RutaEditor";
+
+ static ImageRegistry registry = new ImageRegistry(Display.getDefault());
+
+ static {
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+
+ DLTKPluginImages.get(ScriptDebugImages.IMG_OBJS_CONTENDED_MONITOR);
+ }
+
+ });
+ }
+
+ public RutaDebugModelPresentation() {
+
+ }
+
+ @Override
+ protected Image getBreakpointImage(IScriptBreakpoint breakpoint) {
+ if (breakpoint instanceof IScriptWatchpoint) {
+ IScriptWatchpoint w = (IScriptWatchpoint) breakpoint;
+ try {
+ if (w.isEnabled()) {
+ return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_WATCHPOINT);
+ }
+ } catch (CoreException e) {
+ DLTKDebugPlugin.log(e);
+ }
+ return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_WATCHPOINT_DISABLED);
+ }
+ if (breakpoint instanceof IScriptMethodEntryBreakpoint) {
+ IScriptMethodEntryBreakpoint ll = (IScriptMethodEntryBreakpoint) breakpoint;
+ int flags = 0;
+
+ try {
+ if (ll.breakOnEntry())
+ flags |= ScriptDebugImageDescriptor.ENTRY;
+ if (ll.breakOnExit())
+ flags |= ScriptDebugImageDescriptor.EXIT;
+
+ if (flags == 0)
+ return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_BREAKPOINT_DISABLED);
+ if (ll.isEnabled()) {
+ String key = flags + "enabled";
+ Image image = registry.get(key);
+ if (image == null) {
+ registry.put(
+ key,
+ new ScriptDebugImageDescriptor(DebugUITools
+ .getImageDescriptor(IDebugUIConstants.IMG_OBJS_BREAKPOINT), flags));
+ return registry.get(key);
+ }
+ return image;
+ } else {
+ String key = flags + "disabled";
+ Image image = registry.get(key);
+ if (image == null) {
+ registry.put(
+ key,
+ new ScriptDebugImageDescriptor(DebugUITools
+ .getImageDescriptor(IDebugUIConstants.IMG_OBJS_BREAKPOINT_DISABLED),
+ flags));
+ return registry.get(key);
+ }
+ return image;
+ }
+ } catch (CoreException e) {
+ DLTKDebugPlugin.log(e);
+
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ protected Image getVariableImage(IScriptVariable variable) {
+ IScriptVariable v = variable;
+ IScriptValue scriptValue;
+ try {
+ scriptValue = (IScriptValue) v.getValue();
+ } catch (DebugException e) {
+ return ScriptDebugImages.get(ScriptDebugImages.IMG_OBJS_LOCAL_VARIABLE);
+ }
+ String typeString = (scriptValue).getType().getName();
+ if (typeString.equals("function"))
+ return DLTKPluginImages.get(DLTKPluginImages.IMG_METHOD_PRIVATE);
+ if (typeString.equals("javaclass"))
+ return DLTKPluginImages.get(DLTKPluginImages.IMG_OBJS_CLASS);
+ if (typeString.equals("javaobject"))
+ return DLTKPluginImages.get(DLTKPluginImages.IMG_METHOD_PROTECTED);
+ if (typeString.equals("javaarray"))
+ return DLTKPluginImages.get(DLTKPluginImages.IMG_METHOD_DEFAULT);
+ String fullName = scriptValue.getEvalName();
+ if (fullName != null) {
+ if (fullName.indexOf('.') >= 0 || (fullName.equals("this"))) {
+ return DLTKPluginImages.get(DLTKPluginImages.IMG_METHOD_PUBLIC);
+ }
+ }
+ return ScriptDebugImages.get(ScriptDebugImages.IMG_OBJS_LOCAL_VARIABLE);
+ }
+
+ @Override
+ public String getEditorId(IEditorInput input, Object element) {
+ return TM_EDITOR_ID;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/RutaEditorDebugAdapterFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/RutaEditorDebugAdapterFactory.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/RutaEditorDebugAdapterFactory.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/RutaEditorDebugAdapterFactory.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.debug.ui;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.debug.ui.actions.IRunToLineTarget;
+import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
+import org.eclipse.dltk.internal.debug.ui.ScriptRunToLineAdapter;
+
+public class RutaEditorDebugAdapterFactory implements IAdapterFactory {
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if (adapterType == IRunToLineTarget.class) {
+ return new ScriptRunToLineAdapter();
+ } else if (adapterType == IToggleBreakpointsTarget.class) {
+ return new RutaToggleBreakpointAdapter();
+ }
+
+ return null;
+ }
+
+ public Class[] getAdapterList() {
+ return new Class[] { IRunToLineTarget.class, IToggleBreakpointsTarget.class };
+ }
+}