summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-03-30 15:26:51 (EST)
committer pelder2006-03-30 15:26:51 (EST)
commit55fdf6139ceca0b71937b096bf451de56ed125a2 (patch)
tree9e492ae843d4a01baaf83d51b5050c2ee8023e37
parent28a0fc4bada307c37322148a13a1bf541641f133 (diff)
downloadorg.eclipse.jet-55fdf6139ceca0b71937b096bf451de56ed125a2.zip
org.eclipse.jet-55fdf6139ceca0b71937b096bf451de56ed125a2.tar.gz
org.eclipse.jet-55fdf6139ceca0b71937b096bf451de56ed125a2.tar.bz2
[134093] Change .jet templates to use Platform's default encoding, and the JET compiler to apply the same encoding to the generated Java file.
-rw-r--r--plugins/org.eclipse.jet/plugin.xml1
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Compiler.java46
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/MethodBodyCreator.java28
3 files changed, 33 insertions, 42 deletions
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index 58cbdc4..a3a5f5e 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -1157,7 +1157,6 @@ if 'length' is specified, convert only the specified number of characters, other
point="org.eclipse.core.runtime.contentTypes">
<content-type
base-type="org.eclipse.core.runtime.text"
- default-charset="UTF-8"
file-extensions="jet"
id="template"
name="%contentTypes.template.name"
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Compiler.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Compiler.java
index 60c8071..ddec8af 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Compiler.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/JET2Compiler.java
@@ -19,11 +19,12 @@ package org.eclipse.jet.compiler;
import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.Properties;
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@@ -33,9 +34,8 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jet.JET2Platform;
import org.eclipse.jet.internal.InternalJET2Platform;
import org.eclipse.jet.internal.compiler.JET2CompilerState;
@@ -159,7 +159,8 @@ public class JET2Compiler
try
{
- writeFile(src, project.getFile(targetPath));
+ final IFile file = project.getFile(targetPath);
+ writeFile(src, file, file.getCharset());
}
catch (CoreException e)
{
@@ -323,7 +324,7 @@ public class JET2Compiler
{
file.setDerived(false);
}
- writeFile(javaSrc, targetFile);
+ writeFile(javaSrc, targetFile, file.getCharset());
targetFile.setDerived(true);
compilerState.mapTemplate(templatePath, qualifiedClassName);
}
@@ -408,32 +409,35 @@ public class JET2Compiler
/**
* @param javaSrc
* @param targetFile
+ * @param charset the character encoding of the .jet source file
* @throws CoreException
*/
- private void writeFile(String javaSrc, IFile targetFile) throws CoreException
+ private void writeFile(String javaSrc, IFile targetFile, String charset) throws CoreException
{
ensureDirsExist(targetFile.getParent());
- InputStream is = inputStreamForString(javaSrc, targetFile.getCharset());
- if (targetFile.exists())
+ if(!targetFile.exists())
{
- targetFile.setContents(is, true, true, monitor);
+ targetFile.create(new ByteArrayInputStream(new byte[]{}), true, new SubProgressMonitor(monitor, 1));
}
- else
- {
- targetFile.create(is, true, monitor);
- }
- }
-
- private InputStream inputStreamForString(String src, String charset) throws CoreException
- {
+
+ final ITextFileBufferManager mgr = FileBuffers.getTextFileBufferManager();
+
+ mgr.connect(targetFile.getLocation(), new SubProgressMonitor(monitor, 1));
try
{
- return new ByteArrayInputStream(src.getBytes(charset));
+ final ITextFileBuffer textFileBuffer = mgr.getTextFileBuffer(targetFile.getLocation());
+ if(!targetFile.getCharset().equalsIgnoreCase(charset))
+ {
+ textFileBuffer.setEncoding(charset);
+ }
+ textFileBuffer.getDocument().set(javaSrc);
+
+ textFileBuffer.commit(new SubProgressMonitor(monitor, 1), true);
}
- catch (UnsupportedEncodingException e)
+ finally
{
- throw new CoreException(new Status(IStatus.ERROR, JET2Platform.PLUGIN_ID, IStatus.OK, e.getMessage(), e));
+ mgr.disconnect(targetFile.getLocation(), new SubProgressMonitor(monitor, 1));
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/MethodBodyCreator.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/MethodBodyCreator.java
index b104cb8..cab4b20 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/MethodBodyCreator.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/MethodBodyCreator.java
@@ -157,40 +157,28 @@ public class MethodBodyCreator extends DefaultJET2ASTVisitor
switch (text[i])
{
case '\b':
- encoded.append("\\b"); //$NON-NLS-1$
+ encoded.append("\\b"); //$NON-NLS-1$
break;
case '\f':
- encoded.append("\\f"); //$NON-NLS-1$
+ encoded.append("\\f"); //$NON-NLS-1$
break;
case '\t':
- encoded.append("\\t"); //$NON-NLS-1$
+ encoded.append("\\t"); //$NON-NLS-1$
break;
case '\r':
- encoded.append("\\r"); //$NON-NLS-1$
+ encoded.append("\\r"); //$NON-NLS-1$
break;
case '\n':
- encoded.append("\\n"); //$NON-NLS-1$
+ encoded.append("\\n"); //$NON-NLS-1$
break;
case '"':
- encoded.append("\\\""); //$NON-NLS-1$
+ encoded.append("\\\""); //$NON-NLS-1$
break;
case '\\':
- encoded.append("\\\\"); //$NON-NLS-1$
+ encoded.append("\\\\"); //$NON-NLS-1$
break;
default:
- if(text[i] > 127)
- {
- String hex = Integer.toHexString(text[i]);
- encoded.append("\\u"); //$NON-NLS-1$
- for(int j = hex.length(); j < 4; j++)
- {
- encoded.append("0"); //$NON-NLS-1$
- }
- encoded.append(hex);
- }
- else {
- encoded.append(text[i]);
- }
+ encoded.append(text[i]);
}
}