summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-03-29 09:31:10 (EST)
committer pelder2006-03-29 09:31:10 (EST)
commit9c0118baf54aabd4d269d61ecabcb12b763daea7 (patch)
tree88656a0ada7c6ce1debfaf341c508a3b4057be0b
parent1421494ed63e4f41a6bc3991101a8440dde10484 (diff)
downloadorg.eclipse.jet-9c0118baf54aabd4d269d61ecabcb12b763daea7.zip
org.eclipse.jet-9c0118baf54aabd4d269d61ecabcb12b763daea7.tar.gz
org.eclipse.jet-9c0118baf54aabd4d269d61ecabcb12b763daea7.tar.bz2
[133840] Add <c:marker> tag.
-rw-r--r--plugins/org.eclipse.jet/plugin.properties3
-rw-r--r--plugins/org.eclipse.jet/plugin.xml27
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/IWriterListener.java5
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Writer.java3
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/MarkerTag.java60
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/MarkerHelper.java128
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagUtil.java53
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java45
9 files changed, 280 insertions, 46 deletions
diff --git a/plugins/org.eclipse.jet/plugin.properties b/plugins/org.eclipse.jet/plugin.properties
index 62a52e1..dc8092e 100644
--- a/plugins/org.eclipse.jet/plugin.properties
+++ b/plugins/org.eclipse.jet/plugin.properties
@@ -28,4 +28,5 @@ tagLibraries.java.name = Standard JET Java Tags
tagLibraries.f.name = Standard JET Format Tags
markers.runtimeProblem.name = JET Transform Runtime Problem
-markers.compileProblem.name = JET Template Compile Problem \ No newline at end of file
+markers.compileProblem.name = JET Template Compile Problem
+markers.taskmarker.name = Task
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index 75f1d5a..32a65b7 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -578,6 +578,24 @@ If the 'name' attribute refers to an existing attribute on the selected object,
</description>
</attribute>
</containerTag>
+ <containerTag
+ allowAsEmpty="false"
+ class="org.eclipse.jet.internal.taglib.control.MarkerTag"
+ name="marker"
+ processContents="standard"
+ whenContainingLineIsEmpty="remove">
+ <description>
+ Create an Eclipse task marker refering to the text contained in the tag. If the description attribute is specified, then the tasks description is the value of that attribute, otherwise, it is the same as the text refered to by the marker.
+ </description>
+ <attribute
+ name="description"
+ type="string"
+ use="optional">
+ <description>
+ The description to use in the task marker. The default is to use the text the marker refers to (the tag's content).
+ </description>
+ </attribute>
+ </containerTag>
</tagLibrary>
<tagLibrary
id="workspaceTags"
@@ -1046,7 +1064,7 @@ if 'length' is specified, convert only the specified number of characters, other
id="runtimeProblem"
name="%markers.runtimeProblem.name"
point="org.eclipse.core.resources.markers">
- <super type="org.eclipse.core.resources.problemmarker"/>
+ <super type="org.eclipse.core.resources.problemmarker"/>
</extension>
<extension
id="compileProblem"
@@ -1128,5 +1146,12 @@ if 'length' is specified, convert only the specified number of characters, other
<inspects class="org.eclipse.jet.internal.xpath.inspectors.EMFXMLNodeWrapper"/>
</inspector>
</extension>
+ <extension
+ id="taskmarker"
+ name="%markers.taskmarker.name"
+ point="org.eclipse.core.resources.markers">
+ <super type="org.eclipse.core.resources.taskmarker"/>
+ <persistent value="true"/>
+ </extension>
</plugin>
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 3412911..3dd063e 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java
@@ -177,7 +177,7 @@ public class BodyContentWriter implements JET2Writer
}
}
- public final void contentCommitted(Object committedObject)
+ public final void contentCommitted(Object committedObject) throws JET2TagException
{
for (Iterator i = listeners.values().iterator(); i.hasNext();)
{
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/IWriterListener.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/IWriterListener.java
index 0b2a747..acfba20 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/IWriterListener.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/IWriterListener.java
@@ -33,7 +33,7 @@ public interface IWriterListener
* @param file a handle to object to which the content will ultimately be written. The standard
* JET2 Workspace tags pass an org.eclipse.core.resources.IFile, but other tags may pass objects
* of other types.
- * @throws JET2TagException
+ * @throws JET2TagException if the method cannot complete normally
*/
public abstract void finalizeContent(JET2Writer writer, Object file) throws JET2TagException;
@@ -43,7 +43,8 @@ public interface IWriterListener
* @param file a handle to the object containing the comitted content. The standard
* JET2 Workspace tags pass an org.eclipse.core.resources.IFile, but other tags may pass objects
* of other types.
+ * @throws JET2TagException if method cannot complete normally.
*/
- public abstract void postCommitContent(JET2Writer writer, Object file);
+ public abstract void postCommitContent(JET2Writer writer, Object file) throws JET2TagException;
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Writer.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Writer.java
index b8dcef6..e9ccbd8 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Writer.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Writer.java
@@ -138,8 +138,9 @@ public interface JET2Writer
* is committed. The standard JET2 Workspace tags pass an org.eclipse.core.resources.IFile.
* </p>
* @param committedObject the committed object.
+ * @throws JET2TagException if event handle cannot terminate correctly.
*/
- public abstract void contentCommitted(Object committedObject);
+ public abstract void contentCommitted(Object committedObject) throws JET2TagException;
/**
* Add a listener to the writer life cycle events. The writer records one listener per
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/MarkerTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/MarkerTag.java
new file mode 100644
index 0000000..401e286
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/MarkerTag.java
@@ -0,0 +1,60 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.taglib.control;
+
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.taglib.AbstractContainerTag;
+import org.eclipse.jet.taglib.JET2TagException;
+import org.eclipse.jet.taglib.MarkerHelper;
+import org.eclipse.jet.taglib.TagInfo;
+import org.eclipse.jet.transform.TransformContextExtender;
+
+/**
+ * Implement the standard JET2 tag &lt;c:marker&gt;.
+ */
+public class MarkerTag extends AbstractContainerTag
+{
+
+ int startOffset;
+ /**
+ *
+ */
+ public MarkerTag()
+ {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.ContainerTag#doBeforeBody(org.eclipse.jet.taglib.TagInfo, org.eclipse.jet.JET2Context, org.eclipse.jet.JET2Writer)
+ */
+ public void doBeforeBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
+ {
+ startOffset = out.getLength();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.ContainerTag#doAfterBody(org.eclipse.jet.taglib.TagInfo, org.eclipse.jet.JET2Context, org.eclipse.jet.JET2Writer)
+ */
+ public void doAfterBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
+ {
+ String description = getAttribute("description"); //$NON-NLS-1$
+ int endOffset = out.getLength();
+ MarkerHelper.createMarkerOnWriter(out, startOffset, endOffset, description, td, TransformContextExtender.getInstance(context).getTemplatePath());
+ }
+
+}
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
new file mode 100644
index 0000000..2090043
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/MarkerHelper.java
@@ -0,0 +1,128 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.taglib;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jet.IWriterListener;
+import org.eclipse.jet.JET2Writer;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Position;
+
+/**
+ * Helper for implementing task markers on writer output.
+ */
+public class MarkerHelper implements IWriterListener
+{
+
+ private static final String TASKMARKER_ID = "org.eclipse.jet.taskmarker"; //$NON-NLS-1$
+
+ private static final class MarkerPosition extends Position
+ {
+
+ public final String description;
+ public final TagInfo tagInfo;
+ public final String templatePath;
+
+ public MarkerPosition(int start, int length, String description, TagInfo tagInfo, String templatePath)
+ {
+ super(start, length);
+ this.description = description;
+ this.tagInfo = tagInfo;
+ this.templatePath = templatePath;
+ }
+
+ }
+
+ private static final String MARKER_CATEGORY = MarkerHelper.class.getName();
+ /**
+ *
+ */
+ private MarkerHelper()
+ {
+ // do nothing
+ }
+
+ public void finalizeContent(JET2Writer writer, Object file) throws JET2TagException
+ {
+ // nothing to do...
+ }
+
+ public void postCommitContent(JET2Writer writer, Object file) throws JET2TagException
+ {
+ if(file instanceof IFile)
+ {
+ IFile iFile = (IFile)file;
+ try
+ {
+ iFile.deleteMarkers(TASKMARKER_ID, false, IResource.DEPTH_ZERO);
+ Position[] positions = writer.getPositions(MARKER_CATEGORY);
+ for (int i = 0; i < positions.length; i++)
+ {
+ MarkerPosition markerPos = (MarkerPosition)positions[i];
+
+ final IMarker marker = iFile.createMarker(TASKMARKER_ID);
+ int line = writer.getDocument().getLineOfOffset(markerPos.offset);
+ int start = markerPos.offset;
+ int end = markerPos.offset + markerPos.length;
+
+ // for empty marked regions, turn this into a marker on the line.
+ if(start == end)
+ {
+ final IRegion lineInformation = writer.getDocument().getLineInformation(line);
+ start = lineInformation.getOffset();
+ end = start + lineInformation.getLength();
+ }
+
+ String msg = markerPos.description;
+ if(msg == null || msg.length() == 0)
+ {
+ msg = writer.getDocument().get(start, end - start);
+ }
+ marker.setAttribute(IMarker.LINE_NUMBER, line);
+ marker.setAttribute(IMarker.CHAR_START, start);
+ marker.setAttribute(IMarker.CHAR_END, end);
+ marker.setAttribute(IMarker.MESSAGE, msg);
+// marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
+ }
+ }
+ catch (CoreException e)
+ {
+ final String msg = "Unable to create marker on file {0}";
+ throw new JET2TagException(MessageFormat.format(msg, new Object[] {iFile.getFullPath().toString()}), e);
+ }
+ catch (BadLocationException e)
+ {
+ throw new JET2TagException(e);
+ }
+
+ }
+ }
+
+ public static void createMarkerOnWriter(JET2Writer writer, int start, int end, String description, TagInfo tagInfo, String templatePath)
+ {
+ writer.addPositionCategory(MARKER_CATEGORY);
+ final MarkerPosition markerPosition = new MarkerPosition(start, end - start, description, tagInfo, templatePath);
+ writer.addPosition(MARKER_CATEGORY, markerPosition);
+ writer.addEventListener(MARKER_CATEGORY, new MarkerHelper());
+ }
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagUtil.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagUtil.java
new file mode 100644
index 0000000..ef49b4a
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/TagUtil.java
@@ -0,0 +1,53 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.taglib;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+
+/**
+ * Utility class with various functions useful to tag implementations
+ */
+public class TagUtil
+{
+
+ /**
+ *
+ */
+ private TagUtil()
+ {
+ super();
+ }
+
+ public static String getContents(IPath location) throws CoreException
+ {
+ final ITextFileBufferManager mgr = FileBuffers.getTextFileBufferManager();
+ mgr.connect(location, new NullProgressMonitor());
+ try
+ {
+ return mgr.getTextFileBuffer(location).getDocument().get();
+ }
+ finally
+ {
+ mgr.disconnect(location, new NullProgressMonitor());
+ }
+ }
+
+}
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 052ff3d..77b4979 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
@@ -1,16 +1,9 @@
package org.eclipse.jet.taglib;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
-
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.jet.IWriterListener;
import org.eclipse.jet.JET2Writer;
-import org.eclipse.jet.internal.InternalJET2Platform;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
@@ -48,7 +41,7 @@ public final class UserRegionHelper implements IWriterListener
String fileContents;
try
{
- fileContents = getContents(iFile.getContents(), iFile.getCharset());
+ fileContents = TagUtil.getContents(iFile.getLocation());
}
catch (CoreException e)
{
@@ -83,7 +76,10 @@ public final class UserRegionHelper implements IWriterListener
if (existingEndMarkerOffset != -1)
{
final String existingRegion = fileContents.substring(existingRegionOffset, existingEndMarkerOffset + endMarker.length());
- document.replace(userRegionPosition.offset, userRegionPosition.length, existingRegion);
+ if(!existingRegion.equals(document.get(userRegionPosition.offset, userRegionPosition.length)))
+ {
+ document.replace(userRegionPosition.offset, userRegionPosition.length, existingRegion);
+ }
}
}
@@ -118,37 +114,6 @@ public final class UserRegionHelper implements IWriterListener
return null;
}
- private String getContents(InputStream in, String charset) throws CoreException
- {
- try
- {
- InputStreamReader reader = new InputStreamReader(in, charset);
- StringBuffer contents = new StringBuffer();
- char[] buffer = new char [1024];
- while (true)
- {
- int read = reader.read(buffer);
- if (read > 0)
- {
- contents.append(buffer, 0, read);
- }
- else
- {
- break;
- }
- }
- return contents.toString();
- }
- catch (UnsupportedEncodingException e)
- {
- throw new CoreException(InternalJET2Platform.newStatus(IStatus.ERROR, e.getLocalizedMessage(), e));
- }
- catch (IOException e)
- {
- throw new CoreException(InternalJET2Platform.newStatus(IStatus.ERROR, e.getLocalizedMessage(), e));
- }
- }
-
public void postCommitContent(JET2Writer writer, Object file)
{
// nothing to do here...