Permalink
Browse files

initial commit for file templates

  • Loading branch information...
1 parent 6d6c99e commit 7d360dc31a48a53a58407a42b29998ec28b5437e @JPMoresmau committed Nov 4, 2012
Showing with 1,334 additions and 843 deletions.
  1. +1 −0 docs/releasenotes/net.sf.eclipsefp.haskell_2.3.3.txt
  2. +1 −1 net.sf.eclipsefp.haskell-feature/feature.xml
  3. +1 −1 net.sf.eclipsefp.haskell.buildwrapper/META-INF/MANIFEST.MF
  4. +30 −0 net.sf.eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/BWFacade.java
  5. +25 −25 net.sf.eclipsefp.haskell.core.test/META-INF/MANIFEST.MF
  6. +1 −1 ...psefp.haskell.core.test/src/net/sf/eclipsefp/haskell/core/internal/doubles/MockCodeGenerator.java
  7. +4 −3 net.sf.eclipsefp.haskell.core/META-INF/MANIFEST.MF
  8. +33 −0 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/HaskellCorePlugin.java
  9. +16 −0 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/code/ModuleCreationInfo.java
  10. +2 −1 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/code/SourceFileGenerator.java
  11. +34 −8 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/internal/code/CodeGenerator.java
  12. +44 −14 ...clipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/internal/project/ProjectModelFilesOp.java
  13. +58 −0 ...lipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/preferences/CorePreferenceInitializer.java
  14. +13 −0 ...sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/preferences/ICorePreferenceNames.java
  15. +2 −2 ...lipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/cabal/CabalConfiguration.java
  16. +104 −101 ...kell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/cabal/CabalFoldingStructureProvider.java
  17. +78 −76 ...p.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/cabal/CabalReconcilingStrategy.java
  18. +149 −148 ...psefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/ColorProvider.java
  19. +276 −275 ...sefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/ScannerManager.java
  20. +23 −5 ...p.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/ScionTokenScanner.java
  21. +218 −0 ...clipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/NewHaskellProjectPP.java
  22. +174 −164 ...psefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/SyntaxPreviewer.java
  23. +10 −0 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/UITexts.java
  24. +11 −0 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/uitexts.properties
  25. +1 −0 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/properties/ModuleInclusionPP.java
  26. +25 −18 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/wizards/NewGtkProjectWizard.java
@@ -15,6 +15,7 @@ Fixes:
Features:
- Evaluate GHCi expressions in debug mode even when not stopped at a breakpoint
- Can specify paths of executables in preferences for Alex, Happy and UUAGC
+ - File templates for cabal file, setup.hs, new modules... (under Preferences -> Haskell -> New Project)
Internal:
@@ -158,7 +158,7 @@ available at http://www.eclipse.org/legal/epl-v10.html.
id="net.sf.eclipsefp.haskell.buildwrapper"
download-size="0"
install-size="0"
- version="2.3.2"
+ version="2.3.3"
unpack="false"/>
<plugin
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-SymbolicName: net.sf.eclipsefp.haskell.buildwrapper;singleton:=true
-Bundle-Version: 2.3.2
+Bundle-Version: 2.3.3
Bundle-Activator: net.sf.eclipsefp.haskell.buildwrapper.BuildWrapperPlugin
Bundle-Vendor: %bundleVendor
Bundle-Localization: plugin
@@ -613,6 +613,36 @@ public void registerOutline(IFile file,OutlineResult or){
return cps;
}
+ public List<TokenDef> tokenTypes(String fn){
+ //long t0=System.currentTimeMillis();
+ LinkedList<String> command=new LinkedList<String>();
+ command.add("tokentypes");
+ command.add("--file="+fn);
+ JSONArray arr=run(command,ARRAY);
+ //long t01=System.currentTimeMillis();
+ List<TokenDef> cps;
+ if (arr!=null){
+ if (arr.length()>1){
+ JSONArray notes=arr.optJSONArray(1);
+ parseNotes(notes);
+ }
+ JSONArray objs=arr.optJSONArray(0);
+ cps=new ArrayList<TokenDef>(objs.length());
+ for (int a=0;a<objs.length();a++){
+ try {
+ cps.add(new TokenDef(fn,objs.getJSONObject(a)));
+ } catch (JSONException je){
+ BuildWrapperPlugin.logError(BWText.process_parse_outline_error, je);
+ }
+ }
+ } else {
+ cps=new ArrayList<TokenDef>();
+ }
+ //long t1=System.currentTimeMillis();
+ //BuildWrapperPlugin.logInfo("tokenTypes:"+(t1-t0)+"ms, parsing:"+(t1-t01)+"ms");
+ return cps;
+ }
+
public BuildFlags getBuildFlags(IFile file){
String path=file.getProjectRelativePath().toOSString();
LinkedList<String> command=new LinkedList<String>();
@@ -1,25 +1,25 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: Plug-in for testing Haskell Core
-Bundle-SymbolicName: net.sf.eclipsefp.haskell.core.test
-Bundle-Version: 2.2.2
-Bundle-Vendor: eclipsefp.sourceforge.net
-Require-Bundle: org.easymock;bundle-version="[2.2.0,3.0.0)",
- org.junit4,
- org.eclipse.jface;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.jface.text;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.core.expressions,
- org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
- net.sf.eclipsefp.haskell.core,
- net.sf.eclipsefp.haskell.ui,
- net.sf.eclipsefp.haskell.util,
- org.eclipse.ui;bundle-version="3.5.1"
-Export-Package: net.sf.eclipsefp.haskell.core.cabalmodel,
- net.sf.eclipsefp.haskell.core.internal.doubles;x-friends:="net.sf.eclipsefp.haskell.ui.test",
- net.sf.eclipsefp.haskell.core.internal.project,
- net.sf.eclipsefp.haskell.core.internal.util,
- net.sf.eclipsefp.haskell.core.project,
- net.sf.eclipsefp.haskell.core.project.util,
- net.sf.eclipsefp.haskell.core.test
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Plug-in for testing Haskell Core
+Bundle-SymbolicName: net.sf.eclipsefp.haskell.core.test
+Bundle-Version: 2.3.3
+Bundle-Vendor: eclipsefp.sourceforge.net
+Require-Bundle: org.easymock;bundle-version="[2.2.0,3.0.0)",
+ org.junit4,
+ org.eclipse.jface;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.jface.text;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.core.expressions,
+ org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
+ net.sf.eclipsefp.haskell.core,
+ net.sf.eclipsefp.haskell.ui,
+ net.sf.eclipsefp.haskell.util,
+ org.eclipse.ui;bundle-version="3.5.1"
+Export-Package: net.sf.eclipsefp.haskell.core.cabalmodel,
+ net.sf.eclipsefp.haskell.core.internal.doubles;x-friends:="net.sf.eclipsefp.haskell.ui.test",
+ net.sf.eclipsefp.haskell.core.internal.project,
+ net.sf.eclipsefp.haskell.core.internal.util,
+ net.sf.eclipsefp.haskell.core.project,
+ net.sf.eclipsefp.haskell.core.project.util,
+ net.sf.eclipsefp.haskell.core.test
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
@@ -19,7 +19,7 @@ public void setOutput(final String output) {
}
@Override
- public String createModuleContent(
+ public String createModuleContent(final String projectName,
final String[] folderNames,
final String name,
final EHaskellCommentStyle style)
@@ -10,11 +10,12 @@ Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)",
org.eclipse.debug.core;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui;bundle-version="3.5.0",
org.eclipse.text;bundle-version="3.5.0",
- net.sf.eclipsefp.haskell.util;bundle-version="2.3.2",
- net.sf.eclipsefp.haskell.hlint;bundle-version="2.3.2",
+ net.sf.eclipsefp.haskell.util,
+ net.sf.eclipsefp.haskell.hlint,
org.eclipse.ui.editors;bundle-version="3.5.0",
org.eclipse.ui.ide;bundle-version="3.5.2",
- net.sf.eclipsefp.haskell.buildwrapper;bundle-version="2.3.2"
+ net.sf.eclipsefp.haskell.buildwrapper,
+ org.eclipse.core.variables
Bundle-ActivationPolicy: lazy
Bundle-ManifestVersion: 2
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
@@ -6,12 +6,14 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import net.sf.eclipsefp.haskell.core.compiler.CompilerManager;
import net.sf.eclipsefp.haskell.core.expressions.HaskellPropertyTester;
import net.sf.eclipsefp.haskell.core.preferences.ICorePreferenceNames;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IStatus;
@@ -20,6 +22,9 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.core.variables.IStringVariableManager;
+import org.eclipse.core.variables.IValueVariable;
+import org.eclipse.core.variables.VariablesPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -176,4 +181,32 @@ private void collectCompilerInfo() {
public static final IEclipsePreferences instanceScopedPreferences() {
return InstanceScope.INSTANCE.getNode( getPluginId() );
}
+
+ public static String populateTemplate(final String pref,final Map<String,String> extraVars){
+ IStringVariableManager mgr=VariablesPlugin.getDefault().getStringVariableManager();
+ IEclipsePreferences coreNode = instanceScopedPreferences();
+ String template=coreNode.get( pref, "" ); //$NON-NLS-1$
+
+ try {
+ IValueVariable[] vars = new IValueVariable[0];
+ if (extraVars!=null){
+ vars = new IValueVariable[extraVars.size()];
+ int a=0;
+ for (String key:extraVars.keySet()){
+ String val=extraVars.get( key );
+ vars[a++]=mgr.newValueVariable( key, "",true,val );//$NON-NLS-1$
+
+ }
+ mgr.addVariables( vars );
+ }
+ try {
+ return mgr.performStringSubstitution( template );
+ } finally {
+ mgr.removeVariables( vars );
+ }
+ } catch (CoreException ce){
+ HaskellCorePlugin.log( ce );
+ }
+ return "";//$NON-NLS-1$
+ }
}
@@ -6,6 +6,7 @@
import net.sf.eclipsefp.haskell.core.util.ResourceUtil;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
@@ -30,6 +31,7 @@
*/
private boolean foldersQualify=true;
+ private IProject project;
// attribute setters and getters
////////////////////////////////
@@ -40,6 +42,7 @@ public ModuleCreationInfo() {
public ModuleCreationInfo(final IFile f) {
super();
+ this.project=f.getProject();
IContainer src=ResourceUtil.getSourceContainer( f );
setSourceContainer( src );
if (src!=null){
@@ -86,6 +89,9 @@ public IContainer getSourceContainer() {
public void setSourceContainer( final IContainer sourceContainer ) {
this.sourceContainer = sourceContainer;
+ if (this.sourceContainer!=null){
+ this.project=this.sourceContainer.getProject();
+ }
}
public EHaskellCommentStyle getCommentStyle() {
@@ -137,4 +143,14 @@ public void setEditorStanza( final PackageDescriptionStanza editorStanza ) {
}
+ public IProject getProject() {
+ return project;
+ }
+
+
+ public void setProject( final IProject project ) {
+ this.project = project;
+ }
+
+
}
@@ -100,7 +100,8 @@ private IFile createFile( final ModuleCreationInfo info,
final String[] segments = getPathSegments( info );
final String moduleName = info.getModuleName();
final EHaskellCommentStyle style = info.getCommentStyle();
- String fileContent = fCodeGenerator.createModuleContent( segments,
+ String pName=info.getProject()!=null?info.getProject().getName():"";
+ String fileContent = fCodeGenerator.createModuleContent( pName,segments,
moduleName,
style );
String fileName = createFileName( style, moduleName );
@@ -3,7 +3,12 @@
// version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
package net.sf.eclipsefp.haskell.core.internal.code;
+import java.util.HashMap;
+import java.util.Map;
+import net.sf.eclipsefp.haskell.core.HaskellCorePlugin;
import net.sf.eclipsefp.haskell.core.code.EHaskellCommentStyle;
+import net.sf.eclipsefp.haskell.core.preferences.ICorePreferenceNames;
+import net.sf.eclipsefp.haskell.core.preferences.TemplateVariables;
import net.sf.eclipsefp.haskell.util.PlatformUtil;
@@ -13,21 +18,42 @@
*/
public class CodeGenerator {
- // TODO honor code template for generating this
- public String createModuleContent( final String[] folderNames,
+ public String createModuleContent( final String projectName,
+ final String[] folderNames,
final String name,
final EHaskellCommentStyle style ) {
StringBuilder sb = new StringBuilder();
sb.append( PlatformUtil.NL );
sb.append(getPrefixFor( style ));
- sb.append( "module " ); //$NON-NLS-1$
+ StringBuilder module=new StringBuilder();
+ StringBuilder src=new StringBuilder();
for( int i = 0; i < folderNames.length; i++ ) {
- sb.append( folderNames[ i ] );
- sb.append( "." ); //$NON-NLS-1$
+ module.append( folderNames[ i ] );
+ module.append( "." ); //$NON-NLS-1$
+ if (src.length()>0){
+ src.append("/");//$NON-NLS-1$
+ }
+ src.append(folderNames[ i ]);
}
- sb.append( name );
- sb.append( " where" ); //$NON-NLS-1$
- sb.append( PlatformUtil.NL);
+ module.append(name);
+ Map<String,String> vars=new HashMap<String, String>();
+ vars.put( TemplateVariables.MODULE_NAME, module.toString() );
+ vars.put( TemplateVariables.PROJECT_NAME, projectName );
+ vars.put( TemplateVariables.SRC, src.toString() );
+ vars.put( TemplateVariables.USER_NAME, PlatformUtil.getCurrentUser() );
+
+ String mod=HaskellCorePlugin.populateTemplate( ICorePreferenceNames.TEMPLATE_MODULE, vars );
+ sb.append(mod);
+// sb.append( "module " ); //$NON-NLS-1$
+// for( int i = 0; i < folderNames.length; i++ ) {
+// sb.append( folderNames[ i ] );
+// sb.append( "." ); //$NON-NLS-1$
+// }
+// sb.append( name );
+// sb.append( " where" ); //$NON-NLS-1$
+// sb.append( PlatformUtil.NL);
+
+
sb.append( getSuffixFor(style) );
return sb.toString();
}
Oops, something went wrong.

0 comments on commit 7d360dc

Please sign in to comment.