You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by jo...@apache.org on 2011/08/12 13:00:51 UTC

svn commit: r1157047 [24/27] - in /uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide: ./ .settings/ META-INF/ icons/ schema/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/uima/ src/main/java/org...

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerPairMatcher.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerPairMatcher.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerPairMatcher.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerPairMatcher.java Fri Aug 12 11:00:38 2011
@@ -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.textmarker.ide.ui.text;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.textmarker.ide.core.TextMarkerNature;
+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.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 TextMarkerPairMatcher 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 TextMarkerPairMatcher(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(TextMarkerNature.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 = pp.parse(null, contents.toCharArray(), 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 TextMarkerExecuteExpression) {
+            // TextMarkerExecuteExpression be = (TextMarkerExecuteExpression) 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 TextMarkerStatement) {
+    // TextMarkerStatement statement = (TextMarkerStatement) 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 TextMarkerBlockExpression) {
+    // TextMarkerBlockExpression be = (TextMarkerBlockExpression) 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 TextMarkerExecuteExpression) {
+    // TextMarkerExecuteExpression be = (TextMarkerExecuteExpression) 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;
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerPairMatcher.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerPairMatcher.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerPartitionScanner.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerPartitionScanner.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerPartitionScanner.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerPartitionScanner.java Fri Aug 12 11:00:38 2011
@@ -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.textmarker.ide.ui.text;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.textmarker.ide.ui.TextMarkerPartitions;
+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 TextMarkerPartitionScanner extends RuleBasedPartitionScanner {
+
+  public TextMarkerPartitionScanner() {
+    super();
+
+    IToken string = new Token(TextMarkerPartitions.TM_STRING);
+    IToken comment = new Token(TextMarkerPartitions.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);
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerPartitionScanner.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerPartitionScanner.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerRequireMarkerResolutionGenerator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerRequireMarkerResolutionGenerator.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerRequireMarkerResolutionGenerator.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerRequireMarkerResolutionGenerator.java Fri Aug 12 11:00:38 2011
@@ -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.textmarker.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 TextMarkerRequireMarkerResolutionGenerator implements IMarkerResolutionGenerator {
+
+  public IMarkerResolution[] getResolutions(IMarker marker) {
+    if (TextMarkerCorrectionProcessor.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 TextMarkerRequirePackageMarkerResolution(pkgName,
+                scriptProject) };
+      }
+    }
+    return new IMarkerResolution[0];
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerRequireMarkerResolutionGenerator.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerRequireMarkerResolutionGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerRequirePackageMarkerResolution.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerRequirePackageMarkerResolution.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerRequirePackageMarkerResolution.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerRequirePackageMarkerResolution.java Fri Aug 12 11:00:38 2011
@@ -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.textmarker.ide.ui.text;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.uima.textmarker.ide.TextMarkerIdePlugin;
+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 TextMarkerRequirePackageMarkerResolution implements IMarkerResolution,
+        IAnnotationResolution {
+  private String pkgName;
+
+  private IScriptProject project;
+
+  public TextMarkerRequirePackageMarkerResolution(String pkgName, IScriptProject scriptProject) {
+    this.pkgName = pkgName;
+    this.project = scriptProject;
+  }
+
+  public String getLabel() {
+    final String msg = Messages.TextMarkerRequirePackageMarkerResolution_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) {
+      TextMarkerIdePlugin.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();
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerRequirePackageMarkerResolution.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerRequirePackageMarkerResolution.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerSourceViewerConfiguration.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerSourceViewerConfiguration.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerSourceViewerConfiguration.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerSourceViewerConfiguration.java Fri Aug 12 11:00:38 2011
@@ -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.textmarker.ide.ui.text;
+
+import org.apache.uima.textmarker.ide.ui.TextMarkerPartitions;
+import org.apache.uima.textmarker.ide.ui.hierarchy.TextMarkerHierarchyInformationControl;
+import org.apache.uima.textmarker.ide.ui.text.completion.TextMarkerContentAssistPreference;
+import org.apache.uima.textmarker.ide.ui.text.completion.TextMarkerScriptCompletionProcessor;
+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 TextMarkerSourceViewerConfiguration extends ScriptSourceViewerConfiguration {
+
+  private TextMarkerTextTools fTextTools;
+
+  private TextMarkerCodeScanner fCodeScanner;
+
+  private AbstractScriptScanner fStringScanner;
+
+  private AbstractScriptScanner fCommentScanner;
+
+  public TextMarkerSourceViewerConfiguration(IColorManager colorManager,
+          IPreferenceStore preferenceStore, ITextEditor editor, String partitioning) {
+    super(colorManager, preferenceStore, editor, partitioning);
+  }
+
+  @Override
+  public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
+    return TextMarkerPartitions.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 TextMarkerCodeScanner(getColorManager(), fPreferenceStore);
+    fStringScanner = new TextMarkerStringScanner(getColorManager(), fPreferenceStore);
+    fCommentScanner = createCommentScanner(TextMarkerColorConstants.TM_SINGLE_LINE_COMMENT,
+            TextMarkerColorConstants.TM_TODO_TAG);
+    // fCommentScanner = new SingleTokenScriptScanner(getColorManager(),
+    // fPreferenceStore,
+    // TextMarkerColorConstants.TM_SINGLE_LINE_COMMENT);
+  }
+
+  @Override
+  protected void alterContentAssistant(ContentAssistant assistant) {
+    // IDocument.DEFAULT_CONTENT_TYPE
+    IContentAssistProcessor scriptProcessor = new TextMarkerScriptCompletionProcessor(getEditor(),
+            assistant, IDocument.DEFAULT_CONTENT_TYPE);
+    assistant.setContentAssistProcessor(scriptProcessor, IDocument.DEFAULT_CONTENT_TYPE);
+
+    // TextMarkerPartitions.TM_COMMENT
+    ContentAssistProcessor singleLineProcessor = new TextMarkerScriptCompletionProcessor(
+            getEditor(), assistant, TextMarkerPartitions.TM_COMMENT);
+    assistant.setContentAssistProcessor(singleLineProcessor, TextMarkerPartitions.TM_COMMENT);
+
+    // TextMarkerPartitions.TM_STRING
+    ContentAssistProcessor stringProcessor = new TextMarkerScriptCompletionProcessor(getEditor(),
+            assistant, TextMarkerPartitions.TM_STRING);
+    assistant.setContentAssistProcessor(stringProcessor, TextMarkerPartitions.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, TextMarkerPartitions.TM_STRING);
+    reconciler.setRepairer(dr, TextMarkerPartitions.TM_STRING);
+
+    dr = new DefaultDamagerRepairer(getCommentScanner());
+    reconciler.setDamager(dr, TextMarkerPartitions.TM_COMMENT);
+    reconciler.setRepairer(dr, TextMarkerPartitions.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 TextMarkerHierarchyInformationControl(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 TextMarkerOutlineInformationControl(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 TextMarkerAutoEditStrategy(fPreferenceStore, partitioning) };
+  }
+
+  @Override
+  protected void initializeQuickOutlineContexts(InformationPresenter presenter,
+          IInformationProvider provider) {
+    presenter.setInformationProvider(provider, TextMarkerPartitions.TM_COMMENT);
+    presenter.setInformationProvider(provider, TextMarkerPartitions.TM_STRING);
+  }
+
+  @Override
+  protected ContentAssistPreference getContentAssistPreference() {
+    return TextMarkerContentAssistPreference.getDefault();
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerSourceViewerConfiguration.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerSourceViewerConfiguration.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerStringScanner.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerStringScanner.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerStringScanner.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerStringScanner.java Fri Aug 12 11:00:38 2011
@@ -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.textmarker.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 TextMarkerStringScanner extends AbstractScriptScanner {
+
+  private static final String[] tokenProperties = new String[] {
+      TextMarkerColorConstants.TM_STRING, TextMarkerColorConstants.TM_NUMBER,
+      TextMarkerColorConstants.TM_VARIABLE };
+
+  public TextMarkerStringScanner(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 TextMarkerWhitespaceDetector()));
+
+    setDefaultReturnToken(getToken(TextMarkerColorConstants.TM_STRING));
+
+    return rules;
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerStringScanner.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerStringScanner.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerTextTools.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerTextTools.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerTextTools.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerTextTools.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.ide.ui.text;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.uima.textmarker.ide.TextMarkerIdePlugin;
+import org.apache.uima.textmarker.ide.ui.ISemanticHighlightingExtension;
+import org.apache.uima.textmarker.ide.ui.TextMarkerPartitions;
+import org.apache.uima.textmarker.ide.ui.TextMarkerSemanticPositionUpdater;
+import org.eclipse.dltk.core.SimpleClassDLTKExtensionManager;
+import org.eclipse.dltk.ui.editor.highlighting.ISemanticHighlighter;
+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 TextMarkerTextTools extends ScriptTextTools {
+
+  private IPartitionTokenScanner fPartitionScanner;
+
+  private SimpleClassDLTKExtensionManager extensions = new SimpleClassDLTKExtensionManager(
+          TextMarkerIdePlugin.PLUGIN_ID + ".tmSemanticHighlighting"); //$NON-NLS-1$
+
+  private final static String[] LEGAL_CONTENT_TYPES = new String[] {
+      TextMarkerPartitions.TM_STRING, TextMarkerPartitions.TM_COMMENT };
+
+  public TextMarkerTextTools(boolean autoDisposeOnDisplayDispose) {
+    super(TextMarkerPartitions.TM_PARTITIONING, LEGAL_CONTENT_TYPES, autoDisposeOnDisplayDispose);
+    fPartitionScanner = new TextMarkerPartitionScanner();
+  }
+
+  @Override
+  public ScriptSourceViewerConfiguration createSourceViewerConfiguraton(
+          IPreferenceStore preferenceStore, ITextEditor editor, String partitioning) {
+    return new TextMarkerSourceViewerConfiguration(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;
+  }
+
+  @Override
+  public ISemanticHighlighter getSemanticPositionUpdater() {
+    return new TextMarkerSemanticPositionUpdater(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;
+    }
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerTextTools.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerTextTools.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWhitespaceDetector.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWhitespaceDetector.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWhitespaceDetector.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWhitespaceDetector.java Fri Aug 12 11:00:38 2011
@@ -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.textmarker.ide.ui.text;
+
+import org.eclipse.jface.text.rules.IWhitespaceDetector;
+
+public class TextMarkerWhitespaceDetector implements IWhitespaceDetector {
+
+  /*
+   * (non-Javadoc) Method declared on IWhitespaceDetector
+   */
+  public boolean isWhitespace(char character) {
+    return Character.isWhitespace(character);
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWhitespaceDetector.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWhitespaceDetector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWordDetector.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWordDetector.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWordDetector.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWordDetector.java Fri Aug 12 11:00:38 2011
@@ -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.textmarker.ide.ui.text;
+
+import org.eclipse.jface.text.rules.IWordDetector;
+
+public class TextMarkerWordDetector 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);
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWordDetector.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWordDetector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWordRule.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWordRule.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWordRule.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWordRule.java Fri Aug 12 11:00:38 2011
@@ -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.textmarker.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 TextMarkerWordRule 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 TextMarkerWordRule(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;
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWordRule.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/TextMarkerWordRule.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerCompletionProposalCollector.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerCompletionProposalCollector.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerCompletionProposalCollector.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerCompletionProposalCollector.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.ide.ui.text.completion;
+
+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.CompletionProposalLabelProvider;
+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.dltk.ui.text.completion.ScriptContentAssistInvocationContext;
+import org.eclipse.swt.graphics.Image;
+
+public class TextMarkerCompletionProposalCollector extends ScriptCompletionProposalCollector {
+
+  protected final static char[] VAR_TRIGGER = new char[] { '\t', ' ', '=', ';', '.' };
+
+  @Override
+  protected char[] getVarTrigger() {
+    return VAR_TRIGGER;
+  }
+
+  public TextMarkerCompletionProposalCollector(ISourceModule module) {
+    super(module);
+  }
+
+  // Label provider
+  @Override
+  protected CompletionProposalLabelProvider createLabelProvider() {
+    return new TextMarkerCompletionProposalLabelProvider();
+  }
+
+  // Invocation context
+  @Override
+  protected ScriptContentAssistInvocationContext createScriptContentAssistInvocationContext(
+          ISourceModule sourceModule) {
+    return new ScriptContentAssistInvocationContext(sourceModule) {
+      @Override
+      protected CompletionProposalLabelProvider createLabelProvider() {
+        return new TextMarkerCompletionProposalLabelProvider();
+      }
+    };
+  }
+
+  // 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 TextMarkerScriptCompletionProposal(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 TextMarkerScriptCompletionProposal(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 TextMarkerOverrideCompletionProposal(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);
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerCompletionProposalCollector.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerCompletionProposalCollector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerCompletionProposalLabelProvider.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerCompletionProposalLabelProvider.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerCompletionProposalLabelProvider.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerCompletionProposalLabelProvider.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.ide.ui.text.completion;
+
+import org.eclipse.dltk.core.CompletionProposal;
+import org.eclipse.dltk.ui.text.completion.CompletionProposalLabelProvider;
+
+public class TextMarkerCompletionProposalLabelProvider extends CompletionProposalLabelProvider {
+  @Override
+  protected String createMethodProposalLabel(CompletionProposal methodProposal) {
+    StringBuffer nameBuffer = new StringBuffer();
+
+    // method name
+    nameBuffer.append(methodProposal.getName());
+
+    // parameters
+    nameBuffer.append('(');
+    appendUnboundedParameterList(nameBuffer, methodProposal);
+    nameBuffer.append(')');
+
+    return nameBuffer.toString();
+  }
+
+  @Override
+  protected String createOverrideMethodProposalLabel(CompletionProposal methodProposal) {
+    StringBuffer nameBuffer = new StringBuffer();
+
+    // method name
+    nameBuffer.append(methodProposal.getName());
+
+    // parameters
+    nameBuffer.append('(');
+    appendUnboundedParameterList(nameBuffer, methodProposal);
+    nameBuffer.append(")  "); //$NON-NLS-1$
+
+    return nameBuffer.toString();
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerCompletionProposalLabelProvider.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerCompletionProposalLabelProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerContentAssistPreference.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerContentAssistPreference.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerContentAssistPreference.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerContentAssistPreference.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.ide.ui.text.completion;
+
+import org.apache.uima.textmarker.ide.TextMarkerIdePlugin;
+import org.eclipse.dltk.ui.text.ScriptTextTools;
+import org.eclipse.dltk.ui.text.completion.ContentAssistPreference;
+
+public class TextMarkerContentAssistPreference extends ContentAssistPreference {
+  static TextMarkerContentAssistPreference sDefault;
+
+  @Override
+  protected ScriptTextTools getTextTools() {
+    return TextMarkerIdePlugin.getDefault().getTextTools();
+  }
+
+  public static ContentAssistPreference getDefault() {
+    if (sDefault == null) {
+      sDefault = new TextMarkerContentAssistPreference();
+    }
+    return sDefault;
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerContentAssistPreference.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerContentAssistPreference.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerNoTypeCompletionProposalComputer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerNoTypeCompletionProposalComputer.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerNoTypeCompletionProposalComputer.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerNoTypeCompletionProposalComputer.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.ide.ui.text.completion;
+
+import org.apache.uima.textmarker.ide.TextMarkerIdePlugin;
+import org.apache.uima.textmarker.ide.ui.templates.TextMarkerTemplateCompletionProcessor;
+import org.eclipse.dltk.core.CompletionProposal;
+import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposalCollector;
+import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposalComputer;
+import org.eclipse.dltk.ui.text.completion.ScriptContentAssistInvocationContext;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.templates.TemplateCompletionProcessor;
+
+public class TextMarkerNoTypeCompletionProposalComputer extends ScriptCompletionProposalComputer {
+
+  @Override
+  protected ScriptCompletionProposalCollector createCollector(
+          ScriptContentAssistInvocationContext context) {
+    ScriptCompletionProposalCollector collector = new TextMarkerCompletionProposalCollector(
+            context.getSourceModule());
+
+    collector.setIgnored(CompletionProposal.FIELD_REF, false);
+    collector.setIgnored(CompletionProposal.KEYWORD, false);
+    collector.setIgnored(CompletionProposal.PACKAGE_REF, false);
+    collector.setIgnored(CompletionProposal.LABEL_REF, false);
+    collector.setIgnored(CompletionProposal.LOCAL_VARIABLE_REF, false);
+    collector.setIgnored(CompletionProposal.METHOD_DECLARATION, false);
+    collector.setIgnored(CompletionProposal.METHOD_NAME_REFERENCE, false);
+    collector.setIgnored(CompletionProposal.METHOD_REF, false);
+    collector.setIgnored(CompletionProposal.POTENTIAL_METHOD_DECLARATION, false);
+    collector.setIgnored(CompletionProposal.VARIABLE_DECLARATION, false);
+
+    // collector.setIgnored(CompletionProposal.TYPE_REF, true);
+    collector.setIgnored(CompletionProposal.TYPE_REF, false);
+    IPreferenceStore preferenceStore = TextMarkerIdePlugin.getDefault().getPreferenceStore();
+
+    return collector;
+  }
+
+  @Override
+  protected TemplateCompletionProcessor createTemplateProposalComputer(
+          ScriptContentAssistInvocationContext context) {
+    return new TextMarkerTemplateCompletionProcessor(context);
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerNoTypeCompletionProposalComputer.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerNoTypeCompletionProposalComputer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerOverrideCompletionProposal.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerOverrideCompletionProposal.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerOverrideCompletionProposal.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerOverrideCompletionProposal.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.ide.ui.text.completion;
+
+import org.apache.uima.textmarker.ide.TextMarkerIdePlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.ui.PreferenceConstants;
+import org.eclipse.dltk.ui.text.completion.ScriptTypeCompletionProposal;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ContextInformation;
+import org.eclipse.jface.text.contentassist.ICompletionProposalExtension4;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+
+public class TextMarkerOverrideCompletionProposal extends ScriptTypeCompletionProposal implements
+        ICompletionProposalExtension4 {
+
+  private String methodName;
+
+  public TextMarkerOverrideCompletionProposal(IScriptProject project, ISourceModule cu,
+          String methodName, String[] paramTypes, int start, int length, String displayName,
+          String completionProposal) {
+    super(completionProposal, cu, start, length, null, displayName, 0);
+    Assert.isNotNull(project);
+    Assert.isNotNull(methodName);
+    Assert.isNotNull(paramTypes);
+    Assert.isNotNull(cu);
+
+    this.methodName = methodName;
+
+    setReplacementString(completionProposal);
+  }
+
+  @Override
+  public CharSequence getPrefixCompletionText(IDocument document, int completionOffset) {
+    return methodName;
+  }
+
+  @Override
+  protected boolean updateReplacementString(IDocument document, char trigger, int offset)
+          throws CoreException, BadLocationException {
+    final IDocument buffer = new Document(document.get());
+    int index = offset - 1;
+    while (index >= 0 && Character.isJavaIdentifierPart(buffer.getChar(index)))
+      index--;
+    final int length = offset - index - 1;
+    buffer.replace(index + 1, length, " "); //$NON-NLS-1$
+    return true;
+  }
+
+  public boolean isAutoInsertable() {
+    return false;
+  }
+
+  @Override
+  public IContextInformation getContextInformation() {
+    return new ContextInformation(getDisplayString(), getDisplayString());
+  }
+
+  @Override
+  protected boolean insertCompletion() {
+    IPreferenceStore preference = TextMarkerIdePlugin.getDefault().getPreferenceStore();
+    return preference.getBoolean(PreferenceConstants.CODEASSIST_INSERT_COMPLETION);
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerOverrideCompletionProposal.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerOverrideCompletionProposal.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerScriptCompletionProcessor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerScriptCompletionProcessor.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerScriptCompletionProcessor.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerScriptCompletionProcessor.java Fri Aug 12 11:00:38 2011
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.ide.ui.text.completion;
+
+import org.apache.uima.textmarker.ide.TextMarkerIdePlugin;
+import org.apache.uima.textmarker.ide.core.TextMarkerNature;
+import org.eclipse.dltk.ui.text.completion.CompletionProposalLabelProvider;
+import org.eclipse.dltk.ui.text.completion.ContentAssistInvocationContext;
+import org.eclipse.dltk.ui.text.completion.ScriptCompletionProcessor;
+import org.eclipse.dltk.ui.text.completion.ScriptContentAssistInvocationContext;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.TextPresentation;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationPresenter;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+import org.eclipse.ui.IEditorPart;
+
+public class TextMarkerScriptCompletionProcessor extends ScriptCompletionProcessor {
+  public TextMarkerScriptCompletionProcessor(IEditorPart editor, ContentAssistant assistant,
+          String partition) {
+    super(editor, assistant, partition);
+  }
+
+  @Override
+  protected IPreferenceStore getPreferenceStore() {
+    return TextMarkerIdePlugin.getDefault().getPreferenceStore();
+  }
+
+  @Override
+  protected ContentAssistInvocationContext createContext(ITextViewer viewer, int offset) {
+    return new ScriptContentAssistInvocationContext(viewer, offset, fEditor,
+            TextMarkerNature.NATURE_ID) {
+      @Override
+      protected CompletionProposalLabelProvider createLabelProvider() {
+        return new TextMarkerCompletionProposalLabelProvider();
+      }
+    };
+  }
+
+  @Override
+  protected String getNatureId() {
+    return TextMarkerNature.NATURE_ID;
+  }
+
+  protected static class Validator implements IContextInformationValidator,
+          IContextInformationPresenter {
+
+    private int initialOffset;
+
+    public boolean isContextInformationValid(int offset) {
+      return Math.abs(offset - initialOffset) < 5;
+    }
+
+    public void install(IContextInformation info, ITextViewer viewer, int offset) {
+      initialOffset = offset;
+    }
+
+    public boolean updatePresentation(int documentPosition, TextPresentation presentation) {
+      return false;
+    }
+  }
+
+  @Override
+  protected CompletionProposalLabelProvider getProposalLabelProvider() {
+    return new TextMarkerCompletionProposalLabelProvider();
+  }
+
+  private IContextInformationValidator validator;
+
+  @Override
+  public IContextInformationValidator getContextInformationValidator() {
+    if (validator == null) {
+      validator = new Validator();
+    }
+    return validator;
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerScriptCompletionProcessor.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerScriptCompletionProcessor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerScriptCompletionProposal.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerScriptCompletionProposal.java?rev=1157047&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerScriptCompletionProposal.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerScriptCompletionProposal.java Fri Aug 12 11:00:38 2011
@@ -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.textmarker.ide.ui.text.completion;
+
+import org.apache.uima.textmarker.ide.TextMarkerIdePlugin;
+import org.eclipse.dltk.ui.PreferenceConstants;
+import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposal;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.graphics.Image;
+
+public class TextMarkerScriptCompletionProposal extends ScriptCompletionProposal {
+
+  public TextMarkerScriptCompletionProposal(String replacementString, int replacementOffset,
+          int replacementLength, Image image, String displayString, int relevance) {
+    super(replacementString, replacementOffset, replacementLength, image, displayString, relevance);
+  }
+
+  public TextMarkerScriptCompletionProposal(String replacementString, int replacementOffset,
+          int replacementLength, Image image, String displayString, int relevance, boolean isInDoc) {
+    super(replacementString, replacementOffset, replacementLength, image, displayString, relevance,
+            isInDoc);
+  }
+
+  @Override
+  protected boolean isSmartTrigger(char trigger) {
+    if (trigger == '.') {
+      return true;
+    }
+    return false;
+  }
+
+  @Override
+  protected boolean isCamelCaseMatching() {
+    return true;
+  }
+
+  @Override
+  protected boolean insertCompletion() {
+    IPreferenceStore preference = TextMarkerIdePlugin.getDefault().getPreferenceStore();
+    return preference.getBoolean(PreferenceConstants.CODEASSIST_INSERT_COMPLETION);
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerScriptCompletionProposal.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/text/completion/TextMarkerScriptCompletionProposal.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain