summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-04-30 13:33:08 (EDT)
committerpelder2007-04-30 13:33:08 (EDT)
commit87cd27e970a034a8234ba0e65739ac577bb709a4 (patch)
tree2017f62b72837998aa66f69f7f95fdd363106f92
parent931a3386ee7bdb85a65b8f356fa9964598febe67 (diff)
downloadorg.eclipse.jet-87cd27e970a034a8234ba0e65739ac577bb709a4.zip
org.eclipse.jet-87cd27e970a034a8234ba0e65739ac577bb709a4.tar.gz
org.eclipse.jet-87cd27e970a034a8234ba0e65739ac577bb709a4.tar.bz2
[184735] Check for position category installation. If not installed, add the category and a position updater. Centralize this logic in an single method.
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java9
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SafeJETASTVisitor.java8
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/DocumentHelper.java45
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportsLocationTag.java6
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java4
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/MarkerHelper.java4
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java8
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaActionsUtil.java4
8 files changed, 70 insertions, 18 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java
index 01cea45..21a9f86 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java
@@ -22,6 +22,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
import org.eclipse.jet.internal.InternalJET2Platform;
+import org.eclipse.jet.internal.taglib.DocumentHelper;
import org.eclipse.jface.text.AbstractDocument;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;
@@ -169,7 +170,7 @@ public class BodyContentWriter implements BufferedJET2Writer
for (int i = 0; i < categories.length; i++)
{
// ensure 'document' has the category - no harm in doing this if the category is already there
- document.addPositionCategory(categories[i]);
+ DocumentHelper.installPositionCategory(document, categories[i]);
Position[] positions = childDocument.getPositions(categories[i]);
for (int j = 0; j < positions.length; j++)
{
@@ -238,11 +239,7 @@ public class BodyContentWriter implements BufferedJET2Writer
public final void addPositionCategory(String category)
{
- if (!document.containsPositionCategory(category))
- {
- document.addPositionCategory(category);
- document.addPositionUpdater(new DefaultPositionUpdater(category));
- }
+ DocumentHelper.installPositionCategory(document, category);
}
public final void addPosition(String category, Position position)
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SafeJETASTVisitor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SafeJETASTVisitor.java
index 3943736..ebfbacd 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SafeJETASTVisitor.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SafeJETASTVisitor.java
@@ -12,7 +12,7 @@
*
* </copyright>
*
- * $Id: SafeJETASTVisitor.java,v 1.1 2007/04/04 14:59:32 pelder Exp $
+ * $Id: SafeJETASTVisitor.java,v 1.2 2007/04/30 17:33:08 pelder Exp $
*/
package org.eclipse.jet.internal.compiler;
@@ -24,8 +24,10 @@ import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.core.parser.ast.JETASTVisitor;
import org.eclipse.jet.internal.core.NewLineUtil;
+import org.eclipse.jet.internal.taglib.DocumentHelper;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DefaultPositionUpdater;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
@@ -74,9 +76,7 @@ public class SafeJETASTVisitor extends JETASTVisitor
public void addPositionCategory(String category)
{
IDocument document = getDocument();
- if(document != null) {
- document.addPositionCategory(category);
- }
+ DocumentHelper.installPositionCategory(document, category);
}
public IDocument getDocument()
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/DocumentHelper.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/DocumentHelper.java
new file mode 100644
index 0000000..23cbb04
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/DocumentHelper.java
@@ -0,0 +1,45 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: DocumentHelper.java,v 1.1 2007/04/30 17:33:08 pelder Exp $
+ */
+package org.eclipse.jet.internal.taglib;
+
+import org.eclipse.jface.text.DefaultPositionUpdater;
+import org.eclipse.jface.text.IDocument;
+
+/**
+ * Helper class for handling IDocument instances
+ */
+public class DocumentHelper
+{
+
+ private DocumentHelper() {
+ // prevent instantiation.
+ }
+
+ /**
+ * Install the position category if it is not already installed.
+ * @param document the document into which the category should be installed
+ * @param category the category.
+ */
+ public static void installPositionCategory(IDocument document, String category)
+ {
+ if(!document.containsPositionCategory(category)) {
+ document.addPositionCategory(category);
+ document.addPositionUpdater(new DefaultPositionUpdater(category));
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportsLocationTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportsLocationTag.java
index cc5bcc9..015b801 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportsLocationTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/ImportsLocationTag.java
@@ -26,12 +26,14 @@ import org.eclipse.jet.IWriterListener;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.internal.taglib.DocumentHelper;
import org.eclipse.jet.taglib.AbstractEmptyTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
import org.eclipse.jet.taglib.java.JavaActionsUtil;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DefaultPositionUpdater;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
@@ -145,7 +147,7 @@ public class ImportsLocationTag extends AbstractEmptyTag
out.write(" "); //$NON-NLS-1$
Position importsPosition = new ImportsPosition(importsOffset, compilationUnitPackage, bufferedWriter.getContent());
- document.addPositionCategory(IMPORTS_POSITION_CATEGORY);
+ DocumentHelper.installPositionCategory(document, IMPORTS_POSITION_CATEGORY);
try
{
document.addPosition(IMPORTS_POSITION_CATEGORY, importsPosition);
@@ -168,7 +170,7 @@ public class ImportsLocationTag extends AbstractEmptyTag
BufferedJET2Writer bufferedWriter = (BufferedJET2Writer)writer;
IDocument document = (IDocument)bufferedWriter.getAdapter(IDocument.class);
// defense add of the category, in case it is not already added to the document
- document.addPositionCategory(IMPORTS_POSITION_CATEGORY);
+ DocumentHelper.installPositionCategory(document, IMPORTS_POSITION_CATEGORY);
try
{
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java
index 1b407a0..cfd9048 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/java/MergeTag.java
@@ -32,6 +32,7 @@ import org.eclipse.jet.IWriterListener;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.internal.taglib.DocumentHelper;
import org.eclipse.jet.taglib.AbstractEmptyTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
@@ -39,6 +40,7 @@ import org.eclipse.jet.taglib.TagUtil;
import org.eclipse.jet.transform.TransformContextExtender;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DefaultPositionUpdater;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
@@ -226,7 +228,7 @@ private static final String JMERGE_POSITION_CATEGORY = MergeTag.class.getName();
{
URL rulesURL = new URL(baseURL, rules);
- document.addPositionCategory(JMERGE_POSITION_CATEGORY);
+ DocumentHelper.installPositionCategory(document, JMERGE_POSITION_CATEGORY);
document.addPosition(JMERGE_POSITION_CATEGORY, new MergePosition(rulesURL, bufferedWriter.getContentLength()));
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/MarkerHelper.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/MarkerHelper.java
index b112410..fa39477 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/MarkerHelper.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/MarkerHelper.java
@@ -25,8 +25,10 @@ import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.IWriterListener;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.internal.taglib.DocumentHelper;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DefaultPositionUpdater;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Position;
@@ -153,7 +155,7 @@ public class MarkerHelper implements IWriterListener
if(document == null) {
throw new UnsupportedOperationException();
}
- document.addPositionCategory(MARKER_CATEGORY);
+ DocumentHelper.installPositionCategory(document, MARKER_CATEGORY);
final MarkerPosition markerPosition = new MarkerPosition(start, end - start, description, tagInfo, templatePath);
document.addPosition(MARKER_CATEGORY, markerPosition);
writer.addEventListener(MARKER_CATEGORY, new MarkerHelper());
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java
index 3366bb6..462380e 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java
@@ -16,8 +16,10 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.IWriterListener;
import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.internal.taglib.DocumentHelper;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DefaultPositionUpdater;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
@@ -183,7 +185,7 @@ public final class UserRegionHelper implements IWriterListener
if(document == null) {
throw new NullPointerException();
}
- document.addPositionCategory(INITIALCODE_POSITION_CATEGORY);
+ DocumentHelper.installPositionCategory(document, INITIALCODE_POSITION_CATEGORY);
try
{
if (unmodifiedMarker == null)
@@ -237,8 +239,8 @@ public final class UserRegionHelper implements IWriterListener
if(document == null) {
throw new NullPointerException();
}
- document.addPositionCategory(INITIALCODE_POSITION_CATEGORY);
- document.addPositionCategory(USERREGION_POSITION_CATEGORY);
+ DocumentHelper.installPositionCategory(document, INITIALCODE_POSITION_CATEGORY);
+ DocumentHelper.installPositionCategory(document, USERREGION_POSITION_CATEGORY);
try
{
document.addPosition(USERREGION_POSITION_CATEGORY, new Position(regionStart, regionEnd - regionStart));
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaActionsUtil.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaActionsUtil.java
index 22eb69f..df3996c 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaActionsUtil.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/java/JavaActionsUtil.java
@@ -37,6 +37,7 @@ import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jet.BufferedJET2Writer;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.internal.taglib.DocumentHelper;
import org.eclipse.jet.internal.taglib.java.ImportsLocationTag;
import org.eclipse.jet.internal.taglib.java.PackageTag;
import org.eclipse.jet.internal.taglib.java.ImportsLocationTag.ImportsPosition;
@@ -44,6 +45,7 @@ import org.eclipse.jet.taglib.CustomTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.workspace.ActionsUtil;
import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DefaultPositionUpdater;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
@@ -203,7 +205,7 @@ public class JavaActionsUtil
IDocument document = (IDocument)bufferedWriter.getAdapter(IDocument.class);
// defensive add of the category...
- document.addPositionCategory(ImportsLocationTag.IMPORTS_POSITION_CATEGORY);
+ DocumentHelper.installPositionCategory(document, ImportsLocationTag.IMPORTS_POSITION_CATEGORY);
try
{