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 [15/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/u...
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaColorConstants.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaColorConstants.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaColorConstants.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaColorConstants.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,60 @@
+/*
+ * 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.ui.text;
+
+import org.eclipse.dltk.ui.text.DLTKColorConstants;
+
+public final class RutaColorConstants {
+
+ private RutaColorConstants() {
+ }
+
+ public static final String TM_STRING = DLTKColorConstants.DLTK_STRING;
+
+ public static final String TM_SINGLE_LINE_COMMENT = DLTKColorConstants.DLTK_SINGLE_LINE_COMMENT;
+
+ public static final String TM_DOC_COMMENT = DLTKColorConstants.DLTK_DOC;
+
+ public static final String TM_NUMBER = DLTKColorConstants.DLTK_NUMBER;
+
+ public static final String TM_KEYWORD = DLTKColorConstants.DLTK_KEYWORD;
+
+ public static final String TM_KEYWORD_RETURN = DLTKColorConstants.DLTK_KEYWORD_RETURN;
+
+ public static final String TM_DEFAULT = DLTKColorConstants.DLTK_DEFAULT;
+
+ public static final String TM_CONDITION = "tm_condition"; //$NON-NLS-1$
+
+ public static final String TM_ACTION = "tm_action"; //$NON-NLS-1$
+
+ public static final String TM_RULE = "tm_rule";
+
+ public static final String TM_THEN = "tm_then";
+
+ public static final String TM_DECLARATION = "tm_declaration";
+
+ public static final String TM_BASICSYMBOL = "tm_basicSymbol";
+
+ public static final String TM_FUNCTION = "tm_function";
+
+ public static final String TM_VARIABLE = "tm_variable"; //$NON-NLS-1$
+
+ public static final String TM_TODO_TAG = DLTKColorConstants.TASK_TAG; // DLTKColorConstants.TASK_TAG;
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaCorrectionAssistant.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaCorrectionAssistant.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaCorrectionAssistant.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaCorrectionAssistant.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,372 @@
+/*
+ * 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.ui.text;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.dltk.ui.DLTKUIPlugin;
+import org.eclipse.dltk.ui.PreferenceConstants;
+import org.eclipse.dltk.ui.text.IColorManager;
+import org.eclipse.jface.internal.text.html.HTMLTextPresenter;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DefaultInformationControl;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.quickassist.IQuickAssistAssistant;
+import org.eclipse.jface.text.quickassist.QuickAssistAssistant;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+public class RutaCorrectionAssistant extends QuickAssistAssistant {
+
+ private ITextViewer fViewer;
+
+ private ITextEditor fEditor;
+
+ private Position fPosition;
+
+ private Annotation[] fCurrentAnnotations;
+
+ // private RutaQuickAssistLightBulbUpdater fLightBulbUpdater;
+
+ /**
+ * Constructor for JavaCorrectionAssistant.
+ *
+ * @param editor
+ * the editor
+ */
+ public RutaCorrectionAssistant(ITextEditor editor) {
+ super();
+ Assert.isNotNull(editor);
+ fEditor = editor;
+
+ RutaCorrectionProcessor processor = new RutaCorrectionProcessor(this);
+
+ setQuickAssistProcessor(processor);
+
+ setInformationControlCreator(getInformationControlCreator());
+
+ RutaTextTools textTools = RutaIdePlugin.getDefault().getTextTools();
+ IColorManager manager = textTools.getColorManager();
+
+ IPreferenceStore store = RutaIdePlugin.getDefault().getPreferenceStore();
+
+ Color c = getColor(store, PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND, manager);
+ setProposalSelectorForeground(c);
+
+ c = getColor(store, PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND, manager);
+ setProposalSelectorBackground(c);
+ }
+
+ public IEditorPart getEditor() {
+ return fEditor;
+ }
+
+ private IInformationControlCreator getInformationControlCreator() {
+ return new IInformationControlCreator() {
+ public IInformationControl createInformationControl(Shell parent) {
+ return new DefaultInformationControl(parent, new HTMLTextPresenter());
+ }
+ };
+ }
+
+ private static Color getColor(IPreferenceStore store, String key, IColorManager manager) {
+ RGB rgb = PreferenceConverter.getColor(store, key);
+ return manager.getColor(rgb);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.text.contentassist.IContentAssistant#install(org.eclipse
+ * .jface.text.ITextViewer)
+ */
+ @Override
+ public void install(ISourceViewer sourceViewer) {
+ super.install(sourceViewer);
+ fViewer = sourceViewer;
+
+ // fLightBulbUpdater = new
+ // RutaQuickAssistLightBulbUpdater(fEditor,
+ // sourceViewer);
+ // fLightBulbUpdater.install();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.text.contentassist.ContentAssistant#uninstall()
+ */
+ @Override
+ public void uninstall() {
+ // if (fLightBulbUpdater != null) {
+ // fLightBulbUpdater.uninstall();
+ // fLightBulbUpdater = null;
+ // }
+ super.uninstall();
+ }
+
+ /*
+ * @seeorg.eclipse.jface.text.quickassist.QuickAssistAssistant# showPossibleQuickAssists()
+ *
+ * @since 3.2
+ */
+
+ /**
+ * Show completions at caret position. If current position does not contain quick fixes look for
+ * next quick fix on same line by moving from left to right and restarting at end of line if the
+ * beginning of the line is reached.
+ *
+ * @see IQuickAssistAssistant#showPossibleQuickAssists()
+ */
+ @Override
+ public String showPossibleQuickAssists() {
+ fPosition = null;
+ fCurrentAnnotations = null;
+
+ if (fViewer == null || fViewer.getDocument() == null)
+ // Let superclass deal with this
+ return super.showPossibleQuickAssists();
+
+ ArrayList resultingAnnotations = new ArrayList(20);
+ try {
+ Point selectedRange = fViewer.getSelectedRange();
+ int currOffset = selectedRange.x;
+ int currLength = selectedRange.y;
+ boolean goToClosest = (currLength == 0);
+
+ int newOffset = collectQuickFixableAnnotations(fEditor, currOffset, goToClosest,
+ resultingAnnotations);
+ if (newOffset != currOffset) {
+ storePosition(currOffset, currLength);
+ fViewer.setSelectedRange(newOffset, 0);
+ fViewer.revealRange(newOffset, 0);
+ }
+ } catch (BadLocationException e) {
+ // JavaPlugin.log(e);
+ }
+ fCurrentAnnotations = (Annotation[]) resultingAnnotations
+ .toArray(new Annotation[resultingAnnotations.size()]);
+
+ return super.showPossibleQuickAssists();
+ }
+
+ private static IRegion getRegionOfInterest(ITextEditor editor, int invocationLocation)
+ throws BadLocationException {
+ IDocumentProvider documentProvider = editor.getDocumentProvider();
+ if (documentProvider == null) {
+ return null;
+ }
+ IDocument document = documentProvider.getDocument(editor.getEditorInput());
+ if (document == null) {
+ return null;
+ }
+ return document.getLineInformationOfOffset(invocationLocation);
+ }
+
+ public static int collectQuickFixableAnnotations(ITextEditor editor, int invocationLocation,
+ boolean goToClosest, ArrayList resultingAnnotations) throws BadLocationException {
+ IAnnotationModel model = DLTKUIPlugin.getDocumentProvider().getAnnotationModel(
+ editor.getEditorInput());
+ if (model == null) {
+ return invocationLocation;
+ }
+
+ ensureUpdatedAnnotations(editor);
+
+ Iterator iter = model.getAnnotationIterator();
+ if (goToClosest) {
+ IRegion lineInfo = getRegionOfInterest(editor, invocationLocation);
+ if (lineInfo == null) {
+ return invocationLocation;
+ }
+ int rangeStart = lineInfo.getOffset();
+ int rangeEnd = rangeStart + lineInfo.getLength();
+
+ ArrayList allAnnotations = new ArrayList();
+ ArrayList allPositions = new ArrayList();
+ int bestOffset = Integer.MAX_VALUE;
+ while (iter.hasNext()) {
+ Annotation annot = (Annotation) iter.next();
+ if (RutaCorrectionProcessor.isQuickFixableType(annot)) {
+ Position pos = model.getPosition(annot);
+ if (pos != null && isInside(pos.offset, rangeStart, rangeEnd)) { // inside
+ // our
+ // range?
+ allAnnotations.add(annot);
+ allPositions.add(pos);
+ bestOffset = processAnnotation(annot, pos, invocationLocation, bestOffset);
+ }
+ }
+ }
+ if (bestOffset == Integer.MAX_VALUE) {
+ return invocationLocation;
+ }
+ for (int i = 0; i < allPositions.size(); i++) {
+ Position pos = (Position) allPositions.get(i);
+ if (isInside(bestOffset, pos.offset, pos.offset + pos.length)) {
+ resultingAnnotations.add(allAnnotations.get(i));
+ }
+ }
+ return bestOffset;
+ } else {
+ while (iter.hasNext()) {
+ Annotation annot = (Annotation) iter.next();
+ if (RutaCorrectionProcessor.isQuickFixableType(annot)) {
+ Position pos = model.getPosition(annot);
+ if (pos != null && isInside(invocationLocation, pos.offset, pos.offset + pos.length)) {
+ resultingAnnotations.add(annot);
+ }
+ }
+ }
+ return invocationLocation;
+ }
+ }
+
+ private static void ensureUpdatedAnnotations(ITextEditor editor) {
+ // Object inputElement = editor.getEditorInput().getAdapter(
+ // IModelElement.class);
+
+ }
+
+ private static int processAnnotation(Annotation annot, Position pos, int invocationLocation,
+ int bestOffset) {
+ int posBegin = pos.offset;
+ int posEnd = posBegin + pos.length;
+ if (isInside(invocationLocation, posBegin, posEnd)) { // covers
+ // invocation
+ // location?
+ return invocationLocation;
+ } else if (bestOffset != invocationLocation) {
+ int newClosestPosition = computeBestOffset(posBegin, invocationLocation, bestOffset);
+ if (newClosestPosition != -1) {
+ if (newClosestPosition != bestOffset) { // new best
+ // if (JavaCorrectionProcessor.hasCorrections(annot)) { //
+ // only
+ // // jump
+ // // to
+ // // it
+ // // if
+ // // there
+ // // are
+ // // proposals
+ // return newClosestPosition;
+ // }
+ }
+ }
+ }
+ return bestOffset;
+ }
+
+ private static boolean isInside(int offset, int start, int end) {
+ return offset == start || offset == end || (offset > start && offset < end); // make sure to
+ // handle
+ // 0-length ranges
+ }
+
+ /**
+ * Computes and returns the invocation offset given a new position, the initial offset and the
+ * best invocation offset found so far.
+ * <p>
+ * The closest offset to the left of the initial offset is the best. If there is no offset on the
+ * left, the closest on the right is the best.
+ * </p>
+ *
+ * @param newOffset
+ * the offset to llok at
+ * @param invocationLocation
+ * the invocation location
+ * @param bestOffset
+ * the current best offset
+ * @return -1 is returned if the given offset is not closer or the new best offset
+ */
+ private static int computeBestOffset(int newOffset, int invocationLocation, int bestOffset) {
+ if (newOffset <= invocationLocation) {
+ if (bestOffset > invocationLocation) {
+ return newOffset; // closest was on the right, prefer on the
+ // left
+ } else if (bestOffset <= newOffset) {
+ return newOffset; // we are closer or equal
+ }
+ return -1; // further away
+ }
+
+ if (newOffset <= bestOffset)
+ return newOffset; // we are closer or equal
+
+ return -1; // further away
+ }
+
+ /*
+ * @seeorg.eclipse.jface.text.contentassist.ContentAssistant# possibleCompletionsClosed()
+ */
+ @Override
+ protected void possibleCompletionsClosed() {
+ super.possibleCompletionsClosed();
+ restorePosition();
+ }
+
+ private void storePosition(int currOffset, int currLength) {
+ fPosition = new Position(currOffset, currLength);
+ }
+
+ private void restorePosition() {
+ if (fPosition != null && !fPosition.isDeleted() && fViewer.getDocument() != null) {
+ fViewer.setSelectedRange(fPosition.offset, fPosition.length);
+ fViewer.revealRange(fPosition.offset, fPosition.length);
+ }
+ fPosition = null;
+ }
+
+ /**
+ * Returns true if the last invoked completion was called with an updated offset.
+ *
+ * @return <code> true</code> if the last invoked completion was called with an updated offset.
+ */
+ public boolean isUpdatedOffset() {
+ return fPosition != null;
+ }
+
+ /**
+ * Returns the annotations at the current offset
+ *
+ * @return the annotations at the offset
+ */
+ public Annotation[] getAnnotationsAtOffset() {
+ return fCurrentAnnotations;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaCorrectionProcessor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaCorrectionProcessor.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaCorrectionProcessor.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaCorrectionProcessor.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,197 @@
+/*
+ * 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.ui.text;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.uima.ruta.ide.core.RutaNature;
+import org.apache.uima.ruta.ide.core.RutaProblems;
+import org.apache.uima.ruta.ide.core.packages.PackagesManager;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.dltk.core.CorrectionEngine;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.DLTKLanguageManager;
+import org.eclipse.dltk.core.IDLTKLanguageToolkit;
+import org.eclipse.dltk.core.IModelElement;
+import org.eclipse.dltk.core.IScriptModelMarker;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.internal.ui.editor.ScriptEditor;
+import org.eclipse.dltk.launching.IInterpreterInstall;
+import org.eclipse.dltk.launching.ScriptRuntime;
+import org.eclipse.dltk.ui.DLTKUIPlugin;
+import org.eclipse.dltk.ui.editor.IScriptAnnotation;
+import org.eclipse.dltk.ui.text.MarkerResolutionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
+import org.eclipse.jface.text.quickassist.IQuickAssistProcessor;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.ui.texteditor.MarkerAnnotation;
+import org.eclipse.ui.texteditor.SimpleMarkerAnnotation;
+
+
+public class RutaCorrectionProcessor implements IQuickAssistProcessor {
+ RutaCorrectionAssistant fAssistant;
+
+ public RutaCorrectionProcessor(RutaCorrectionAssistant tclCorrectionAssistant) {
+ this.fAssistant = tclCorrectionAssistant;
+ }
+
+ public boolean canAssist(IQuickAssistInvocationContext invocationContext) {
+ return true;
+ }
+
+ public boolean canFix(Annotation annotation) {
+ return hasCorrections(annotation);
+ }
+
+ public ICompletionProposal[] computeQuickAssistProposals(
+ IQuickAssistInvocationContext invocationContext) {
+ final Annotation[] annotations = fAssistant.getAnnotationsAtOffset();
+ final ScriptEditor editor = (ScriptEditor) this.fAssistant.getEditor();
+ final IAnnotationModel model = DLTKUIPlugin.getDocumentProvider().getAnnotationModel(
+ editor.getEditorInput());
+ final IModelElement element = editor.getInputModelElement();
+ final IScriptProject scriptProject = element.getScriptProject();
+ List proposals = null;
+ for (int i = 0; i < annotations.length; i++) {
+ final Annotation annotation = annotations[i];
+ ICompletionProposal proposal = null;
+ if (annotation instanceof MarkerAnnotation) {
+ MarkerAnnotation mAnnot = (MarkerAnnotation) annotation;
+ IMarker marker = mAnnot.getMarker();
+ if (isFixable(marker)) {
+ final String pkgName = CorrectionEngine.getProblemArguments(marker)[0];
+ proposal = new MarkerResolutionProposal(new RutaRequirePackageMarkerResolution(
+ pkgName, scriptProject), marker);
+ }
+ } else if (annotation instanceof IScriptAnnotation) {
+ if (isFixable((IScriptAnnotation) annotation)) {
+ // final String pkgName = ((IScriptAnnotation) annotation)
+ // .getArguments()[0];
+ // proposal = new AnnotationResolutionProposal(
+ // new RutaRequirePackageMarkerResolution(pkgName,
+ // scriptProject), model, annotation);
+ }
+ }
+ if (proposal != null) {
+ if (proposals == null) {
+ proposals = new ArrayList();
+ }
+ proposals.add(proposal);
+ }
+ }
+ if (proposals != null) {
+ return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
+ }
+ return null;
+ }
+
+ public String getErrorMessage() {
+ return null;
+ }
+
+ public static boolean isQuickFixableType(Annotation annotation) {
+ return (annotation instanceof IScriptAnnotation || annotation instanceof SimpleMarkerAnnotation)
+ && !annotation.isMarkedDeleted();
+ }
+
+ public static boolean isFixable(IMarker marker) {
+ if (marker.getAttribute(IScriptModelMarker.ID, 0) == RutaProblems.UNKNOWN_REQUIRED_PACKAGE) {
+ final String[] args = CorrectionEngine.getProblemArguments(marker);
+ if (args != null && args.length != 0 && args[0] != null) {
+ IResource resource = marker.getResource();
+ IProject project = resource.getProject();
+ IScriptProject scriptProject = DLTKCore.create(project);
+ if (isFixable(args[0], scriptProject)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isFixable(IScriptAnnotation annotation) {
+// if (annotation.getId() == RutaProblems.UNKNOWN_REQUIRED_PACKAGE) {
+// final String[] args = annotation.getArguments();
+// if (args != null && args.length != 0 && args[0] != null) {
+// final ISourceModule module = annotation.getSourceModule();
+// if (module != null) {
+// final IScriptProject project = module.getScriptProject();
+// if (project != null) {
+// if (isFixable(args[0], project)) {
+// return true;
+// }
+// }
+// }
+// }
+// }
+ return false;
+ }
+
+ public static boolean isFixable(String pkgName, IScriptProject scriptProject) {
+ IDLTKLanguageToolkit toolkit = null;
+ toolkit = DLTKLanguageManager.getLanguageToolkit(scriptProject);
+ if (toolkit != null && toolkit.getNatureId().equals(RutaNature.NATURE_ID)) {
+ IInterpreterInstall install = null;
+ try {
+ install = ScriptRuntime.getInterpreterInstall(scriptProject);
+ } catch (CoreException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ if (install != null) {
+ PackagesManager manager = PackagesManager.getInstance();
+ IPath[] paths = manager.getPathsForPackage(install, pkgName);
+ if (paths != null && paths.length > 0) {
+ return true;
+ }
+ Map dependencies = manager.getDependencies(pkgName, install);
+ for (Iterator iterator = dependencies.keySet().iterator(); iterator.hasNext();) {
+ String pkg = (String) iterator.next();
+ IPath[] paths2 = manager.getPathsForPackage(install, pkg);
+ if (paths2 != null && paths2.length > 0) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean hasCorrections(Annotation annotation) {
+ if (annotation instanceof MarkerAnnotation) {
+ MarkerAnnotation mAnnot = (MarkerAnnotation) annotation;
+ IMarker marker = mAnnot.getMarker();
+ return isFixable(marker);
+ } else if (annotation instanceof IScriptAnnotation) {
+ return isFixable((IScriptAnnotation) annotation);
+ }
+ return false;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaDecoratorDetector.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaDecoratorDetector.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaDecoratorDetector.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaDecoratorDetector.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.ruta.ide.ui.text;
+
+import org.eclipse.jface.text.rules.IWordDetector;
+
+class RutaDecoratorDetector implements IWordDetector {
+
+ public boolean isWordStart(char c) {
+ return c == '@';
+ }
+
+ public boolean isWordPart(char c) {
+ return c != '\n' && c != '\r' && c != '(';
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaOutlineInformationControl.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaOutlineInformationControl.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaOutlineInformationControl.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaOutlineInformationControl.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,38 @@
+/*
+ * 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.ui.text;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.eclipse.dltk.ui.text.ScriptOutlineInformationControl;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.widgets.Shell;
+
+public class RutaOutlineInformationControl extends ScriptOutlineInformationControl {
+
+ public RutaOutlineInformationControl(Shell parent, int shellStyle, int treeStyle,
+ String commandId) {
+ super(parent, shellStyle, treeStyle, commandId);
+ }
+
+ @Override
+ protected IPreferenceStore getPreferenceStore() {
+ return RutaIdePlugin.getDefault().getPreferenceStore();
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaPairMatcher.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaPairMatcher.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaPairMatcher.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaPairMatcher.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,288 @@
+/*
+ * 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.ui.text;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.ruta.ide.core.RutaNature;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.ast.expressions.StringLiteral;
+import org.eclipse.dltk.ast.parser.ISourceParser;
+import org.eclipse.dltk.ast.statements.Block;
+import org.eclipse.dltk.compiler.env.ModuleSource;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.DLTKLanguageManager;
+import org.eclipse.dltk.core.IModelElement;
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.core.SourceParserUtil;
+import org.eclipse.dltk.internal.ui.editor.ScriptEditor;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentExtension4;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.source.ICharacterPairMatcher;
+
+
+/**
+ * Helper class for match pairs of characters.
+ */
+public final class RutaPairMatcher implements ICharacterPairMatcher {
+
+ // private char[] fPairs;
+
+ private IDocument fDocument;
+
+ private int fOffset;
+
+ private int fStartPos;
+
+ private int fEndPos;
+
+ private int fAnchor;
+
+ private ScriptEditor editor;
+
+ private class PairBlock {
+ public PairBlock(int start, int end, char c) {
+ this.start = start;
+ this.end = end;
+ this.c = c;
+ }
+
+ int start;
+
+ int end;
+
+ char c;
+ }
+
+ private PairBlock[] cachedPairs;
+
+ private long cachedStamp = -1;
+
+ private long cachedHash = -1;
+
+ public RutaPairMatcher(char[] pairs, ScriptEditor editor) {
+ // if (pairs == null) {
+ // throw new IllegalArgumentException();
+ // }
+
+ // fPairs = pairs;
+ this.editor = editor;
+ }
+
+ private PairBlock[] computePairRanges(final int offset, String contents) {
+ ISourceParser pp = null;
+ pp = DLTKLanguageManager.getSourceParser(RutaNature.NATURE_ID);
+ ModuleDeclaration md = null;// pp.parse(null, contents.toCharArray(),
+ // null);
+ IModelElement el = this.editor.getInputModelElement();
+ if (el != null && el instanceof ISourceModule) {
+ md = SourceParserUtil.getModuleDeclaration((ISourceModule) el, null);
+ }
+ if (md == null) {
+ md = (ModuleDeclaration) pp.parse(new ModuleSource(contents), null);
+ }
+ if (md == null) {
+ return new PairBlock[0];
+ }
+ final List result = new ArrayList();
+ try {
+ md.traverse(new ASTVisitor() {
+ @Override
+ public boolean visitGeneral(ASTNode node) throws Exception {
+ if (node instanceof StringLiteral) {
+ StringLiteral be = (StringLiteral) node;
+ result.add(new PairBlock(offset + be.sourceStart(), offset + be.sourceEnd() - 1, '\"'));
+ // } else if (node instanceof RutaExecuteExpression) {
+ // RutaExecuteExpression be = (RutaExecuteExpression) node;
+ // result.add(new PairBlock(offset + be.sourceStart(),
+ // offset + be.sourceEnd() - 1, '['));
+ } else if (node instanceof Block) {
+ Block be = (Block) node;
+ result.add(new PairBlock(offset + be.sourceStart(), offset + be.sourceEnd() - 1, '{'));
+ }
+ return super.visitGeneral(node);
+ }
+ });
+ } catch (Exception e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+
+ // Iterator i = statements.iterator();
+ // while (i.hasNext()) {
+ // Statement sst = (Statement) i.next();
+ // if (sst instanceof RutaStatement) {
+ // RutaStatement statement = (RutaStatement) sst;
+ // /*
+ // * result.add(new CodeBlock(statement, new Region(offset +
+ // * statement.sourceStart(), statement.sourceEnd() -
+ // * statement.sourceStart())));
+ // */
+ // Iterator si = statement.getExpressions().iterator();
+ // while (si.hasNext()) {
+ // Expression ex = (Expression) si.next();
+ // if (ex instanceof RutaBlockExpression) {
+ // RutaBlockExpression be = (RutaBlockExpression) ex;
+ // try {
+ // String newContents = contents.substring(be
+ // .sourceStart() + 1, be.sourceEnd() - 1);
+ // result.add(new PairBlock(offset + be.sourceStart(),
+ // offset + be.sourceEnd() - 1, '{'));
+ // PairBlock[] cb = computePairRanges(offset
+ // + be.sourceStart() + 1, newContents);
+ // for (int j = 0; j < cb.length; j++) {
+ // result.add(cb[j]);
+ // }
+ // } catch (StringIndexOutOfBoundsException e) {
+ // }
+ // } else if (ex instanceof StringLiteral) {
+ // StringLiteral be = (StringLiteral) ex;
+ // result.add(new PairBlock(offset + be.sourceStart(),
+ // offset + be.sourceEnd() - 1, '\"'));
+ // } else if (ex instanceof RutaExecuteExpression) {
+ // RutaExecuteExpression be = (RutaExecuteExpression) ex;
+ // result.add(new PairBlock(offset + be.sourceStart(),
+ // offset + be.sourceEnd() - 1, '['));
+ // }
+ // }
+ // }
+ // }
+ return (PairBlock[]) result.toArray(new PairBlock[result.size()]);
+ }
+
+ /**
+ * Fully recalcs pairs for document
+ *
+ * @param doc
+ * @throws BadLocationException
+ */
+ private void recalc() throws BadLocationException {
+ String content = fDocument.get(0, fDocument.getLength());
+ cachedPairs = computePairRanges(0, content);
+
+ if (fDocument instanceof IDocumentExtension4) {
+ cachedStamp = ((IDocumentExtension4) fDocument).getModificationStamp();
+ } else {
+ cachedHash = content.hashCode();
+ }
+ }
+
+ /**
+ * Recalcs pairs for the document, only if it is required
+ */
+ private void updatePairs() throws BadLocationException {
+ if (fDocument instanceof IDocumentExtension4) {
+ IDocumentExtension4 document = (IDocumentExtension4) fDocument;
+
+ if (document.getModificationStamp() == cachedStamp) {
+ return;
+ }
+
+ } else {
+ String content = fDocument.get(0, fDocument.getLength());
+
+ if (content.hashCode() == cachedHash) {
+ return;
+ }
+ }
+
+ recalc();
+ }
+
+ private static boolean isBrace(char c) {
+ return (c == '{' || c == '}' || c == '\"' || c == '[' || c == ']');
+ }
+
+ public IRegion match(IDocument document, int offset) {
+ if (document == null || offset < 0) {
+ throw new IllegalArgumentException();
+ }
+
+ try {
+ fOffset = offset;
+ fDocument = document;
+
+ if (!isBrace(fDocument.getChar(offset))
+ && (offset == 0 || !isBrace(fDocument.getChar(offset - 1)))) {
+ return null;
+ }
+
+ updatePairs();
+
+ if (matchPairsAt() && fStartPos != fEndPos)
+ return new Region(fStartPos, fEndPos - fStartPos + 1);
+ } catch (BadLocationException e) {
+ if (DLTKCore.DEBUG_PARSER)
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.text.source.ICharacterPairMatcher#getAnchor()
+ */
+ public int getAnchor() {
+ return fAnchor;
+ }
+
+ public void dispose() {
+ clear();
+ fDocument = null;
+ }
+
+ public void clear() {
+ }
+
+ private boolean matchPairsAt() {
+
+ fStartPos = -1;
+ fEndPos = -1;
+
+ for (int i = 0; i < cachedPairs.length; i++) {
+ PairBlock block = cachedPairs[i];
+
+ if (fOffset == block.end + 1) {
+ fStartPos = block.start - 1;
+ fEndPos = block.start;
+ fAnchor = LEFT;
+ return true;
+ }
+ if (fOffset == block.start + 1) {
+ fStartPos = block.end - 1;
+ fEndPos = block.end;
+ fAnchor = LEFT;
+ return true;
+ }
+
+ }
+
+ return false;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaPartitionScanner.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaPartitionScanner.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaPartitionScanner.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaPartitionScanner.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,58 @@
+/*
+ * 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.ui.text;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.ruta.ide.ui.RutaPartitions;
+import org.eclipse.jface.text.rules.EndOfLineRule;
+import org.eclipse.jface.text.rules.IPredicateRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.MultiLineRule;
+import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
+import org.eclipse.jface.text.rules.Token;
+
+
+public class RutaPartitionScanner extends RuleBasedPartitionScanner {
+
+ public RutaPartitionScanner() {
+ super();
+
+ IToken string = new Token(RutaPartitions.TM_STRING);
+ IToken comment = new Token(RutaPartitions.TM_COMMENT);
+
+ List/* < IPredicateRule > */rules = new ArrayList/* <IPredicateRule> */();
+
+ rules.add(new EndOfLineRule("//", comment));
+
+ rules.add(new MultiLineRule("\"\"\"", "\"\"\"", string, '\\'));
+
+ rules.add(new MultiLineRule("\'\'\'", "\'\'\'", string, '\\'));
+
+ rules.add(new MultiLineRule("\'", "\'", string, '\\'));
+
+ rules.add(new MultiLineRule("\"", "\"", string, '\\'));
+
+ IPredicateRule[] result = new IPredicateRule[rules.size()];
+ rules.toArray(result);
+ setPredicateRules(result);
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaRequireMarkerResolutionGenerator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaRequireMarkerResolutionGenerator.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaRequireMarkerResolutionGenerator.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaRequireMarkerResolutionGenerator.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.ui.text;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.dltk.core.CorrectionEngine;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.IMarkerResolutionGenerator;
+
+public class RutaRequireMarkerResolutionGenerator implements IMarkerResolutionGenerator {
+
+ public IMarkerResolution[] getResolutions(IMarker marker) {
+ if (RutaCorrectionProcessor.isFixable(marker)) {
+ String pkgName = CorrectionEngine.getProblemArguments(marker)[0];
+ if (pkgName != null) {
+ IProject project = marker.getResource().getProject();
+ IScriptProject scriptProject = DLTKCore.create(project);
+ return new IMarkerResolution[] { new RutaRequirePackageMarkerResolution(pkgName,
+ scriptProject) };
+ }
+ }
+ return new IMarkerResolution[0];
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaRequirePackageMarkerResolution.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaRequirePackageMarkerResolution.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaRequirePackageMarkerResolution.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaRequirePackageMarkerResolution.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.ui.text;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.launching.IInterpreterInstall;
+import org.eclipse.dltk.launching.InterpreterContainerHelper;
+import org.eclipse.dltk.launching.ScriptRuntime;
+import org.eclipse.dltk.ui.editor.IScriptAnnotation;
+import org.eclipse.dltk.ui.text.IAnnotationResolution;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.IMarkerResolution;
+
+final class RutaRequirePackageMarkerResolution implements IMarkerResolution,
+ IAnnotationResolution {
+ private String pkgName;
+
+ private IScriptProject project;
+
+ public RutaRequirePackageMarkerResolution(String pkgName, IScriptProject scriptProject) {
+ this.pkgName = pkgName;
+ this.project = scriptProject;
+ }
+
+ public String getLabel() {
+ final String msg = Messages.RutaRequirePackageMarkerResolution_addPackageToBuildpath;
+ return NLS.bind(msg, pkgName);
+ }
+
+ private boolean resolve() {
+ final IInterpreterInstall install;
+ try {
+ install = ScriptRuntime.getInterpreterInstall(project);
+ if (install != null) {
+ final Set names = new HashSet();
+ final Set autoNames = new HashSet();
+ InterpreterContainerHelper.getInterpreterContainerDependencies(project, names, autoNames);
+
+ if (names.add(pkgName)) {
+ InterpreterContainerHelper.setInterpreterContainerDependencies(project, names, autoNames);
+ return true;
+ }
+ }
+ } catch (CoreException e) {
+ RutaIdePlugin.error("require package resolve error", e); //$NON-NLS-1$
+ }
+ return false;
+ }
+
+ public void run(final IMarker marker) {
+ if (resolve()) {
+ try {
+ marker.delete();
+ } catch (CoreException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public void run(Annotation annotation, IDocument document) {
+ resolve();
+ }
+
+ public void run(IScriptAnnotation annotation, IDocument document) {
+ resolve();
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaSourceViewerConfiguration.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaSourceViewerConfiguration.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaSourceViewerConfiguration.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaSourceViewerConfiguration.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,270 @@
+/*
+ * 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.ui.text;
+
+import org.apache.uima.ruta.ide.ui.RutaPartitions;
+import org.apache.uima.ruta.ide.ui.hierarchy.RutaHierarchyInformationControl;
+import org.apache.uima.ruta.ide.ui.text.completion.RutaContentAssistPreference;
+import org.apache.uima.ruta.ide.ui.text.completion.RutaScriptCompletionProcessor;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.dltk.internal.ui.editor.EditorUtility;
+import org.eclipse.dltk.internal.ui.editor.ScriptSourceViewer;
+import org.eclipse.dltk.internal.ui.text.ScriptElementProvider;
+import org.eclipse.dltk.ui.CodeFormatterConstants;
+import org.eclipse.dltk.ui.text.AbstractScriptScanner;
+import org.eclipse.dltk.ui.text.IColorManager;
+import org.eclipse.dltk.ui.text.ScriptPresentationReconciler;
+import org.eclipse.dltk.ui.text.ScriptSourceViewerConfiguration;
+import org.eclipse.dltk.ui.text.completion.ContentAssistPreference;
+import org.eclipse.dltk.ui.text.completion.ContentAssistProcessor;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.AbstractInformationControlManager;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
+import org.eclipse.jface.text.information.IInformationPresenter;
+import org.eclipse.jface.text.information.IInformationProvider;
+import org.eclipse.jface.text.information.InformationPresenter;
+import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+
+public class RutaSourceViewerConfiguration extends ScriptSourceViewerConfiguration {
+
+ private RutaTextTools fTextTools;
+
+ private RutaCodeScanner fCodeScanner;
+
+ private AbstractScriptScanner fStringScanner;
+
+ private AbstractScriptScanner fCommentScanner;
+
+ public RutaSourceViewerConfiguration(IColorManager colorManager,
+ IPreferenceStore preferenceStore, ITextEditor editor, String partitioning) {
+ super(colorManager, preferenceStore, editor, partitioning);
+ }
+
+ @Override
+ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
+ return RutaPartitions.TM_PARTITION_TYPES;
+ }
+
+ @Override
+ public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
+ return new String[] { "\t", " " };
+ }
+
+ /*
+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getTabWidth(org
+ * .eclipse.jface.text.source.ISourceViewer)
+ */
+ @Override
+ public int getTabWidth(ISourceViewer sourceViewer) {
+ if (fPreferenceStore == null)
+ return super.getTabWidth(sourceViewer);
+ return fPreferenceStore.getInt(CodeFormatterConstants.FORMATTER_TAB_SIZE);
+ }
+
+ @Override
+ protected void initializeScanners() {
+ Assert.isTrue(isNewSetup());
+ fCodeScanner = new RutaCodeScanner(getColorManager(), fPreferenceStore);
+ fStringScanner = new RutaStringScanner(getColorManager(), fPreferenceStore);
+ fCommentScanner = createCommentScanner(RutaColorConstants.TM_SINGLE_LINE_COMMENT,
+ RutaColorConstants.TM_TODO_TAG);
+ // fCommentScanner = new SingleTokenScriptScanner(getColorManager(),
+ // fPreferenceStore,
+ // RutaColorConstants.TM_SINGLE_LINE_COMMENT);
+ }
+
+ @Override
+ protected void alterContentAssistant(ContentAssistant assistant) {
+ // IDocument.DEFAULT_CONTENT_TYPE
+ IContentAssistProcessor scriptProcessor = new RutaScriptCompletionProcessor(getEditor(),
+ assistant, IDocument.DEFAULT_CONTENT_TYPE);
+ assistant.setContentAssistProcessor(scriptProcessor, IDocument.DEFAULT_CONTENT_TYPE);
+
+ // RutaPartitions.TM_COMMENT
+ ContentAssistProcessor singleLineProcessor = new RutaScriptCompletionProcessor(
+ getEditor(), assistant, RutaPartitions.TM_COMMENT);
+ assistant.setContentAssistProcessor(singleLineProcessor, RutaPartitions.TM_COMMENT);
+
+ // RutaPartitions.TM_STRING
+ ContentAssistProcessor stringProcessor = new RutaScriptCompletionProcessor(getEditor(),
+ assistant, RutaPartitions.TM_STRING);
+ assistant.setContentAssistProcessor(stringProcessor, RutaPartitions.TM_STRING);
+ }
+
+ private boolean isNewSetup() {
+ return fTextTools == null;
+ }
+
+ protected RuleBasedScanner getStringScanner() {
+ return fStringScanner;
+ }
+
+ @Override
+ public String getCommentPrefix() {
+ return "//";
+ }
+
+ protected RuleBasedScanner getCommentScanner() {
+ return fCommentScanner;
+ }
+
+ @Override
+ public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
+ PresentationReconciler reconciler = new ScriptPresentationReconciler();
+ reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
+
+ DefaultDamagerRepairer dr = new DefaultDamagerRepairer(this.fCodeScanner);
+ reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
+
+ dr = new DefaultDamagerRepairer(getStringScanner());
+ reconciler.setDamager(dr, RutaPartitions.TM_STRING);
+ reconciler.setRepairer(dr, RutaPartitions.TM_STRING);
+
+ dr = new DefaultDamagerRepairer(getCommentScanner());
+ reconciler.setDamager(dr, RutaPartitions.TM_COMMENT);
+ reconciler.setRepairer(dr, RutaPartitions.TM_COMMENT);
+
+ return reconciler;
+ }
+
+ @Override
+ public void handlePropertyChangeEvent(PropertyChangeEvent event) {
+ Assert.isTrue(isNewSetup());
+ if (fCodeScanner.affectsBehavior(event))
+ fCodeScanner.adaptToPreferenceChange(event);
+ if (fStringScanner.affectsBehavior(event))
+ fStringScanner.adaptToPreferenceChange(event);
+ if (fCommentScanner.affectsBehavior(event)) {
+ fCommentScanner.adaptToPreferenceChange(event);
+ }
+ }
+
+ @Override
+ public boolean affectsTextPresentation(PropertyChangeEvent event) {
+ return fCodeScanner.affectsBehavior(event) || fStringScanner.affectsBehavior(event)
+ || fCommentScanner.affectsBehavior(event);
+ }
+
+ private IInformationControlCreator getHierarchyPresenterControlCreator(ISourceViewer sourceViewer) {
+ return new IInformationControlCreator() {
+ public IInformationControl createInformationControl(Shell parent) {
+ int shellStyle = SWT.RESIZE;
+ int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
+ return new RutaHierarchyInformationControl(parent, shellStyle, treeStyle);
+ }
+ };
+ }
+
+ @Override
+ public IInformationPresenter getHierarchyPresenter(ScriptSourceViewer sourceViewer,
+ boolean doCodeResolve) {
+ // Do not create hierarchy presenter if there's no CU.
+ if (getEditor() != null && getEditor().getEditorInput() != null
+ && EditorUtility.getEditorInputModelElement(getEditor(), true) == null)
+ return null;
+
+ InformationPresenter presenter = new InformationPresenter(
+ getHierarchyPresenterControlCreator(sourceViewer));
+ presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
+ presenter.setAnchor(AbstractInformationControlManager.ANCHOR_GLOBAL);
+ IInformationProvider provider = new ScriptElementProvider(getEditor(), doCodeResolve);
+ presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
+
+ presenter.setSizeConstraints(50, 20, true, false);
+ return presenter;
+ }
+
+ public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
+ if (!fPreferenceStore
+ .getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED))
+ return null;
+
+ IHyperlinkDetector[] inheritedDetectors = super.getHyperlinkDetectors(sourceViewer);
+
+ if (getEditor() == null) {
+ return inheritedDetectors;
+ }
+
+ int inheritedDetectorsLength = inheritedDetectors != null ? inheritedDetectors.length : 0;
+ IHyperlinkDetector[] detectors = new IHyperlinkDetector[inheritedDetectorsLength + 1];
+
+ for (int i = 0; i < inheritedDetectorsLength; i++)
+ detectors[i] = inheritedDetectors[i];
+ detectors[inheritedDetectorsLength] = new ExternalTypeHyperlinkDetector(getEditor());
+
+ return detectors;
+ }
+
+ @Override
+ protected IInformationControlCreator getOutlinePresenterControlCreator(
+ ISourceViewer sourceViewer, final String commandId) {
+ return new IInformationControlCreator() {
+ public IInformationControl createInformationControl(Shell parent) {
+ int shellStyle = SWT.RESIZE;
+ int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
+ return new RutaOutlineInformationControl(parent, shellStyle, treeStyle, commandId);
+ }
+ };
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getAutoEditStrategies
+ * (org.eclipse.jface.text.source.ISourceViewer, java.lang.String)
+ */
+ @Override
+ public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
+ // TODO: check contentType. think, do we really need it? :)
+ String partitioning = getConfiguredDocumentPartitioning(sourceViewer);
+ // return new IAutoEditStrategy[] { new DefaultAutoIndentStrategy() };
+ return new IAutoEditStrategy[] { new RutaAutoEditStrategy(fPreferenceStore, partitioning) };
+ }
+
+ @Override
+ protected void initializeQuickOutlineContexts(InformationPresenter presenter,
+ IInformationProvider provider) {
+ presenter.setInformationProvider(provider, RutaPartitions.TM_COMMENT);
+ presenter.setInformationProvider(provider, RutaPartitions.TM_STRING);
+ }
+
+ @Override
+ protected ContentAssistPreference getContentAssistPreference() {
+ return RutaContentAssistPreference.getDefault();
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaStringScanner.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaStringScanner.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaStringScanner.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaStringScanner.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,59 @@
+/*
+ * 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.ui.text;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.dltk.ui.text.AbstractScriptScanner;
+import org.eclipse.dltk.ui.text.IColorManager;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.rules.WhitespaceRule;
+
+public class RutaStringScanner extends AbstractScriptScanner {
+
+ private static final String[] tokenProperties = new String[] {
+ RutaColorConstants.TM_STRING, RutaColorConstants.TM_NUMBER,
+ RutaColorConstants.TM_VARIABLE };
+
+ public RutaStringScanner(IColorManager manager, IPreferenceStore store) {
+ super(manager, store);
+
+ initialize();
+ }
+
+ @Override
+ protected String[] getTokenProperties() {
+ return tokenProperties;
+ }
+
+ @Override
+ protected List createRules() {
+ List/* <IRule> */rules = new ArrayList/* <IRule> */();
+
+ // Add generic whitespace rule.
+ rules.add(new WhitespaceRule(new RutaWhitespaceDetector()));
+
+ setDefaultReturnToken(getToken(RutaColorConstants.TM_STRING));
+
+ return rules;
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaTextTools.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaTextTools.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaTextTools.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaTextTools.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,158 @@
+/*
+ * 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.ui.text;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.apache.uima.ruta.ide.ui.ISemanticHighlightingExtension;
+import org.apache.uima.ruta.ide.ui.RutaPartitions;
+import org.apache.uima.ruta.ide.ui.RutaSemanticPositionUpdater;
+import org.eclipse.dltk.core.SimpleClassDLTKExtensionManager;
+import org.eclipse.dltk.ui.editor.highlighting.ISemanticHighlightingUpdater;
+import org.eclipse.dltk.ui.editor.highlighting.SemanticHighlighting;
+import org.eclipse.dltk.ui.text.ScriptSourceViewerConfiguration;
+import org.eclipse.dltk.ui.text.ScriptTextTools;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.rules.IPartitionTokenScanner;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+public class RutaTextTools extends ScriptTextTools {
+
+ private IPartitionTokenScanner fPartitionScanner;
+
+ private SimpleClassDLTKExtensionManager extensions = new SimpleClassDLTKExtensionManager(
+ RutaIdePlugin.PLUGIN_ID + ".tmSemanticHighlighting"); //$NON-NLS-1$
+
+ private final static String[] LEGAL_CONTENT_TYPES = new String[] {
+ RutaPartitions.TM_STRING, RutaPartitions.TM_COMMENT };
+
+ public RutaTextTools(boolean autoDisposeOnDisplayDispose) {
+ super(RutaPartitions.TM_PARTITIONING, LEGAL_CONTENT_TYPES, autoDisposeOnDisplayDispose);
+ fPartitionScanner = new RutaPartitionScanner();
+ }
+
+ @Override
+ public ScriptSourceViewerConfiguration createSourceViewerConfiguraton(
+ IPreferenceStore preferenceStore, ITextEditor editor, String partitioning) {
+ return new RutaSourceViewerConfiguration(getColorManager(), preferenceStore, editor,
+ partitioning);
+ }
+
+ @Override
+ public IPartitionTokenScanner getPartitionScanner() {
+ return fPartitionScanner;
+ }
+
+ private ISemanticHighlightingExtension[] getExtensions() {
+ Object[] objects = extensions.getObjects();
+ ISemanticHighlightingExtension[] exts = new ISemanticHighlightingExtension[objects.length];
+
+ for (int i = 0; i < objects.length; i++) {
+ exts[i] = ((ISemanticHighlightingExtension) objects[i]);
+ }
+ return exts;
+ }
+
+ @Override
+ public SemanticHighlighting[] getSemanticHighlightings() {
+ List highlightings = new ArrayList();
+ ISemanticHighlightingExtension[] exts = getExtensions();
+ for (int i = 0; i < exts.length; i++) {
+ SemanticHighlighting[] hl = exts[i].getHighlightings();
+ if (hl != null) {
+ highlightings.addAll(Arrays.asList(hl));
+ }
+ }
+ SemanticHighlighting[] ret = new SemanticHighlighting[highlightings.size()];
+ for (int i = 0; i < highlightings.size(); i++)
+ ret[i] = (SemanticHighlighting) highlightings.get(i);
+
+ return ret;
+ }
+
+
+ public ISemanticHighlightingUpdater getSemanticPositionUpdater(
+ String natureId) {
+ return new RutaSemanticPositionUpdater(getExtensions());
+ }
+
+ public final static class SH extends SemanticHighlighting {
+
+ private final String preferenceKey;
+
+ private final String bgColor;
+
+ private final String description;
+
+ public SH(String editorXmlTagNameColor, String bgColor, String desc) {
+ this.preferenceKey = editorXmlTagNameColor;
+ this.bgColor = bgColor;
+ this.description = desc;
+ }
+
+ @Override
+ public boolean isSemanticOnly() {
+ return description != null;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return preferenceKey;
+ }
+
+ @Override
+ public String getBackgroundPreferenceKey() {
+ return bgColor;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((preferenceKey == null) ? 0 : preferenceKey.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final SH other = (SH) obj;
+ if (preferenceKey == null) {
+ if (other.preferenceKey != null)
+ return false;
+ } else if (!preferenceKey.equals(other.preferenceKey))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return description;
+ }
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaWhitespaceDetector.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaWhitespaceDetector.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaWhitespaceDetector.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaWhitespaceDetector.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,32 @@
+/*
+ * 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.ui.text;
+
+import org.eclipse.jface.text.rules.IWhitespaceDetector;
+
+public class RutaWhitespaceDetector implements IWhitespaceDetector {
+
+ /*
+ * (non-Javadoc) Method declared on IWhitespaceDetector
+ */
+ public boolean isWhitespace(char character) {
+ return Character.isWhitespace(character);
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaWordDetector.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaWordDetector.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaWordDetector.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaWordDetector.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,39 @@
+/*
+ * 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.ui.text;
+
+import org.eclipse.jface.text.rules.IWordDetector;
+
+public class RutaWordDetector implements IWordDetector {
+
+ /*
+ * (non-Javadoc) Method declared on IWordDetector.
+ */
+ public boolean isWordPart(char character) {
+ return Character.isJavaIdentifierPart(character);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IWordDetector.
+ */
+ public boolean isWordStart(char character) {
+ return Character.isJavaIdentifierStart(character);
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaWordRule.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaWordRule.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaWordRule.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaWordRule.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,178 @@
+/*
+ * 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.ui.text;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.text.rules.ICharacterScanner;
+import org.eclipse.jface.text.rules.IPredicateRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.IWordDetector;
+import org.eclipse.jface.text.rules.Token;
+
+public class RutaWordRule implements IPredicateRule {
+
+ /** Internal setting for the un-initialized column constraint */
+ protected static final int UNDEFINED = -1;
+
+ /** The word detector used by this rule */
+ protected IWordDetector fDetector;
+
+ /**
+ * The default token to be returned on success and if nothing else has been specified.
+ */
+ protected IToken fDefaultToken;
+
+ /** The column constraint */
+ protected int fColumn = UNDEFINED;
+
+ /** The table of predefined words and token for this rule */
+ protected Map fWords = new HashMap();
+
+ /** Buffer used for pattern detection */
+ private StringBuffer fBuffer = new StringBuffer();
+
+ // private IToken classNameToken;
+
+ // private IToken funcNameToken;
+
+ /**
+ * Creates a rule which, with the help of a word detector, will return the token associated with
+ * the detected word. If no token has been associated, the specified default token will be
+ * returned.
+ *
+ * @param detector
+ * the word detector to be used by this rule, may not be <code>null</code>
+ * @param defaultToken
+ * the default token to be returned on success if nothing else is specified, may not be
+ * <code>null</code>
+ * @param funcNameToken
+ * @param classNameToken
+ *
+ * @see #addWord(String, IToken)
+ */
+ public RutaWordRule(IWordDetector detector, IToken defaultToken, IToken classNameToken) {
+
+ Assert.isNotNull(detector);
+ Assert.isNotNull(defaultToken);
+
+ fDetector = detector;
+ fDefaultToken = defaultToken;
+ // this.classNameToken = classNameToken;
+ // this.funcNameToken = funcNameToken;
+ }
+
+ /**
+ * Adds a word and the token to be returned if it is detected.
+ *
+ * @param word
+ * the word this rule will search for, may not be <code>null</code>
+ * @param token
+ * the token to be returned if the word has been found, may not be <code>null</code>
+ */
+ public void addWord(String word, IToken token) {
+ Assert.isNotNull(word);
+ Assert.isNotNull(token);
+
+ fWords.put(word, token);
+ }
+
+ /**
+ * Sets a column constraint for this rule. If set, the rule's token will only be returned if the
+ * pattern is detected starting at the specified column. If the column is smaller then 0, the
+ * column constraint is considered removed.
+ *
+ * @param column
+ * the column in which the pattern starts
+ */
+ public void setColumnConstraint(int column) {
+ if (column < 0)
+ column = UNDEFINED;
+ fColumn = column;
+ }
+
+ private String lastFound = "";
+
+ public IToken evaluate(ICharacterScanner scanner) {
+ int c = scanner.read();
+ fBuffer.setLength(0);
+
+ // special for '->'
+ if (c == '-') {
+ fBuffer.append((char) c);
+ c = scanner.read();
+ if (c == '>') {
+ fBuffer.append((char) c);
+ String str = fBuffer.toString();
+ IToken token = (IToken) fWords.get(str);
+ if (token != null) {
+ lastFound = str;
+ return token;
+ }
+ } else {
+ // scanner.unread();
+
+ fBuffer.setLength(0);
+ }
+ }
+ // the rest
+ if (fDetector.isWordStart((char) c)) {
+ if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
+ fBuffer.setLength(0);
+
+ do {
+ fBuffer.append((char) c);
+ c = scanner.read();
+ } while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
+ scanner.unread();
+
+ String str = fBuffer.toString();
+ IToken token = (IToken) fWords.get(str);
+ if (token != null) {
+ lastFound = str;
+ return token;
+ }
+
+ if (fDefaultToken.isUndefined())
+ unreadBuffer(scanner);
+
+ return fDefaultToken;
+ }
+ }
+
+ scanner.unread();
+ return Token.UNDEFINED;
+ }
+
+ protected void unreadBuffer(ICharacterScanner scanner) {
+ for (int i = fBuffer.length() - 1; i >= 0; i--)
+ scanner.unread();
+ }
+
+ public IToken evaluate(ICharacterScanner scanner, boolean resume) {
+ return evaluate(scanner);
+ }
+
+ public IToken getSuccessToken() {
+ return this.fDefaultToken;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/SimpleRutaSourceViewerConfiguration.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/SimpleRutaSourceViewerConfiguration.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/SimpleRutaSourceViewerConfiguration.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/SimpleRutaSourceViewerConfiguration.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,106 @@
+/*
+ * 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.ui.text;
+
+import org.eclipse.dltk.ui.text.IColorManager;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.formatter.IContentFormatter;
+import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
+import org.eclipse.jface.text.information.IInformationPresenter;
+import org.eclipse.jface.text.source.IAnnotationHover;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+public class SimpleRutaSourceViewerConfiguration extends RutaSourceViewerConfiguration {
+
+ private boolean fConfigureFormatter;
+
+ public SimpleRutaSourceViewerConfiguration(IColorManager colorManager,
+ IPreferenceStore preferenceStore, ITextEditor editor, String partitioning,
+ boolean configureFormatter) {
+ super(colorManager, preferenceStore, editor, partitioning);
+ fConfigureFormatter = configureFormatter;
+ }
+
+ @Override
+ public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
+ return null;
+ }
+
+ @Override
+ public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
+ return null;
+ }
+
+ @Override
+ public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) {
+ return null;
+ }
+
+ @Override
+ public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, String contentType) {
+ return null;
+ }
+
+ @Override
+ public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
+ return null;
+ }
+
+ @Override
+ public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
+ return null;
+ }
+
+ @Override
+ public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
+ if (fConfigureFormatter)
+ return super.getContentFormatter(sourceViewer);
+ else
+ return null;
+ }
+
+ @Override
+ public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
+ return null;
+ }
+
+ @Override
+ public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {
+ return null;
+ }
+
+ public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer, boolean doCodeResolve) {
+ return null;
+ }
+
+ public IInformationPresenter getHierarchyPresenter(ISourceViewer sourceViewer,
+ boolean doCodeResolve) {
+ return null;
+ }
+
+ @Override
+ public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
+ return null;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/completion/RutaCompletionProposalCollector.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/completion/RutaCompletionProposalCollector.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/completion/RutaCompletionProposalCollector.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/completion/RutaCompletionProposalCollector.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,84 @@
+/*
+ * 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.ui.text.completion;
+
+import org.apache.uima.ruta.ide.core.RutaNature;
+import org.eclipse.dltk.core.CompletionProposal;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.ui.text.completion.IScriptCompletionProposal;
+import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposal;
+import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposalCollector;
+import org.eclipse.swt.graphics.Image;
+
+public class RutaCompletionProposalCollector extends ScriptCompletionProposalCollector {
+
+ protected final static char[] VAR_TRIGGER = new char[] { '\t', ' ', '=', ';', '.' };
+
+ @Override
+ protected char[] getVarTrigger() {
+ return VAR_TRIGGER;
+ }
+
+ public RutaCompletionProposalCollector(ISourceModule module) {
+ super(module);
+ }
+
+
+
+ // Specific proposals creation. May be use factory?
+ @Override
+ protected ScriptCompletionProposal createScriptCompletionProposal(String completion,
+ int replaceStart, int length, Image image, String displayString, int i) {
+ return new RutaScriptCompletionProposal(displayString, replaceStart, length, image,
+ displayString, i);
+ }
+
+ @Override
+ protected ScriptCompletionProposal createScriptCompletionProposal(String completion,
+ int replaceStart, int length, Image image, String displayString, int i, boolean isInDoc) {
+ return new RutaScriptCompletionProposal(displayString, replaceStart, length, image,
+ displayString, i, isInDoc);
+ }
+
+ @Override
+ protected ScriptCompletionProposal createOverrideCompletionProposal(IScriptProject scriptProject,
+ ISourceModule compilationUnit, String name, String[] paramTypes, int start, int length,
+ String displayName, String completionProposal) {
+ return new RutaOverrideCompletionProposal(scriptProject, compilationUnit, name,
+ paramTypes, start, length, displayName, completionProposal);
+ }
+
+ @Override
+ protected IScriptCompletionProposal createKeywordProposal(CompletionProposal proposal) {
+ String completion = String.valueOf(proposal.getCompletion());
+ int start = proposal.getReplaceStart();
+ int length = getLength(proposal);
+ String label = getLabelProvider().createSimpleLabel(proposal);
+ Image img = getImage(getLabelProvider().createMethodImageDescriptor(proposal));
+ int relevance = computeRelevance(proposal);
+ return createScriptCompletionProposal(completion, start, length, img, label, relevance);
+ }
+
+ @Override
+ protected String getNatureId() {
+ return RutaNature.NATURE_ID;
+ }
+}