Skip to content

Commit

Permalink
stylish haskell GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
JPMoresmau committed Jun 29, 2012
1 parent 2b4555d commit d42ca93
Show file tree
Hide file tree
Showing 27 changed files with 1,607 additions and 13 deletions.
10 changes: 10 additions & 0 deletions net.sf.eclipsefp.haskell.style.test/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry combineaccessrules="false" kind="src" path="/net.sf.eclipsefp.haskell.style"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.swt_3.7.1.v3738a.jar"/>
<classpathentry kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.swt.win32.win32.x86_3.7.1.v3738a.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions net.sf.eclipsefp.haskell.style.test/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>net.sf.eclipsefp.haskell.style.test</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* Copyright (c) 2012 by JP Moresmau
* This code is made available under the terms of the Eclipse Public License,
* version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
*/
package net.sf.eclipsefp.haskell.style;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import net.sf.eclipsefp.haskell.style.stylishhaskell.SHConfiguration;
import net.sf.eclipsefp.haskell.style.stylishhaskell.SHImports.SHImportAlign;
import net.sf.eclipsefp.haskell.style.stylishhaskell.SHPragmas.SHPragmaStyle;
import net.sf.eclipsefp.haskell.style.stylishhaskell.StylishHaskell;

import org.junit.Test;

/**
* Tests the Stylish Haskell configuration, especially YAML I/O
* @author JP Moresmau
*
*/
public class SHConfigurationTest {


@Test
public void testDefault(){
SHConfiguration def=new SHConfiguration();
assertNull(def.getTabs());
assertNull(def.getUnicode());
assertNotNull(def.getImports());
assertEquals(SHImportAlign.GLOBAL, def.getImports().getAlign());
assertNotNull(def.getPragmas());
assertTrue(def.getPragmas().isRemoveRedundant());
assertEquals(SHPragmaStyle.VERTICAL,def.getPragmas().getStyle());
assertNotNull(def.getTrailingWhitespace());
}

@Test
public void testIODefault() throws IOException{
SHConfiguration def=new SHConfiguration();
InputStream is=getClass().getResourceAsStream("stylish-haskell-default.yaml");
assertNotNull(is);
SHConfiguration defRead=StylishHaskell.load(is);
assertEquals(def,defRead);
ByteArrayOutputStream baos=new ByteArrayOutputStream();
StylishHaskell.save(defRead, baos);
SHConfiguration defRead2=StylishHaskell.load(new ByteArrayInputStream(baos.toByteArray()));
assertEquals(def,defRead2);
}

@Test
public void testIOFull() throws IOException{
InputStream is=getClass().getResourceAsStream("stylish-haskell-full.yaml");
assertNotNull(is);
SHConfiguration confRead=StylishHaskell.load(is);
assertNotNull(confRead.getTabs());
assertEquals(4,confRead.getTabs().getSpaces());
assertNotNull(confRead.getUnicode());
assertTrue(confRead.getUnicode().isUnicodePragmas());

assertNotNull(confRead.getImports());
assertEquals(SHImportAlign.GROUP, confRead.getImports().getAlign());
assertNotNull(confRead.getPragmas());
assertFalse(confRead.getPragmas().isRemoveRedundant());
assertEquals(SHPragmaStyle.COMPACT,confRead.getPragmas().getStyle());
assertNotNull(confRead.getTrailingWhitespace());

ByteArrayOutputStream baos=new ByteArrayOutputStream();
StylishHaskell.save(confRead, baos);
SHConfiguration confRead2=StylishHaskell.load(new ByteArrayInputStream(baos.toByteArray()));
assertEquals(confRead,confRead2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# stylish-haskell configuration file
# ==================================
#
# The stylish-haskell tool is mainly configured by specifying steps. These steps
# are a list, so they have an order, and one specific step may appear more than
# once (if needed). Each file is processed by these steps in the given order.
steps:
# Convert some ASCII sequences to their Unicode equivalents. This is disabled
# by default.
# - unicode_syntax:
# # In order to make this work, we also need to insert the UnicodeSyntax
# # language pragma. If this flag is set to true, we insert it when it's
# # not already present. You may want to disable it if you configure
# # language extensions using some other method than pragmas. Default:
# # true.
# add_language_pragma: true

# Import cleanup
- imports:
# There are different ways we can align names and lists.
#
# - global: Align the import names and import list throughout the entire
# file.
#
# - group: Only align the imports per group (a group is formed by adjacent
# import lines).
#
# - none: Do not perform any alignment.
#
# Default: global.
align: global

# Language pragmas
- language_pragmas:
# We can generate different styles of language pragma lists.
#
# - vertical: Vertical-spaced language pragmas, one per line.
#
# - compact: A more compact style.
#
# Default: vertical.
style: vertical

# stylish-haskell can detect redundancy of some language pragmas. If this
# is set to true, it will remove those redundant pragmas. Default: true.
remove_redundant: true

# Replace tabs by spaces. This is disabled by default.
# - tabs:
# # Number of spaces to use for each tab. Default: 8, as specified by the
# # Haskell report.
# spaces: 8

# Remove trailing whitespace
- trailing_whitespace: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# stylish-haskell configuration file
# ==================================
#
# The stylish-haskell tool is mainly configured by specifying steps. These steps
# are a list, so they have an order, and one specific step may appear more than
# once (if needed). Each file is processed by these steps in the given order.
steps:
# Convert some ASCII sequences to their Unicode equivalents. This is disabled
# by default.
- unicode_syntax:
# In order to make this work, we also need to insert the UnicodeSyntax
# language pragma. If this flag is set to true, we insert it when it's
# not already present. You may want to disable it if you configure
# language extensions using some other method than pragmas. Default:
# true.
add_language_pragma: true

# Import cleanup
- imports:
# There are different ways we can align names and lists.
#
# - global: Align the import names and import list throughout the entire
# file.
#
# - group: Only align the imports per group (a group is formed by adjacent
# import lines).
#
# - none: Do not perform any alignment.
#
# Default: global.
align: group

# Language pragmas
- language_pragmas:
# We can generate different styles of language pragma lists.
#
# - vertical: Vertical-spaced language pragmas, one per line.
#
# - compact: A more compact style.
#
# Default: vertical.
style: compact

# stylish-haskell can detect redundancy of some language pragmas. If this
# is set to true, it will remove those redundant pragmas. Default: true.
remove_redundant: false

# Replace tabs by spaces. This is disabled by default.
- tabs:
# Number of spaces to use for each tab. Default: 8, as specified by the
# Haskell report.
spaces: 4

# Remove trailing whitespace
- trailing_whitespace: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Copyright (c) 2012 by JP Moresmau
* This code is made available under the terms of the Eclipse Public License,
* version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
*/
package net.sf.eclipsefp.haskell.style.ui;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import net.sf.eclipsefp.haskell.style.stylishhaskell.SHConfiguration;
import net.sf.eclipsefp.haskell.style.stylishhaskell.StylishHaskell;
import net.sf.eclipsefp.haskell.style.stylishhaskell.ui.SHConfigurationComposite;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
* test composite
* @author JP Moresmau
*
*/
public class SHConfigurationCompositeTest {

/**
* @param args
*/
public static void main(String[] args) {
Display display=new Display();

Shell shell=new Shell(display);
shell.setLayout(new GridLayout(1,true));
final SHConfigurationComposite comp=new SHConfigurationComposite(shell, SWT.NONE);
comp.setConfiguration(new SHConfiguration());
Button b=new Button(shell,SWT.PUSH);
b.setText("click");
b.addSelectionListener(new SelectionAdapter() {
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
SHConfiguration conf=comp.getConfiguration();
ByteArrayOutputStream baos=new ByteArrayOutputStream();
try {
StylishHaskell.save(conf, baos);
System.out.println(new String(baos.toByteArray()));
} catch (IOException ioe){
ioe.printStackTrace();
}
}
});
shell.open();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
}
display.dispose ();
}

}
1 change: 1 addition & 0 deletions net.sf.eclipsefp.haskell.style/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/snakeyaml-1.10.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
11 changes: 9 additions & 2 deletions net.sf.eclipsefp.haskell.style/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ Bundle-Activator: net.sf.eclipsefp.haskell.style.StylePlugin
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
net.sf.eclipsefp.haskell.util,
org.eclipse.ui.workbench
org.eclipse.ui.workbench,
org.eclipse.swt,
org.eclipse.jface,
org.eclipse.ui
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: %bundleVendor
Bundle-Localization: plugin
Export-Package: net.sf.eclipsefp.haskell.style,
net.sf.eclipsefp.haskell.style.stylishhaskell
net.sf.eclipsefp.haskell.style.stylishhaskell,
net.sf.eclipsefp.haskell.style.stylishhaskell.ui,
net.sf.eclipsefp.haskell.style.util
Bundle-ClassPath: lib/snakeyaml-1.10.jar,
.
4 changes: 3 additions & 1 deletion net.sf.eclipsefp.haskell.style/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.properties
plugin.properties,\
lib/snakeyaml-1.10.jar,\
plugin.xml
Binary file not shown.
4 changes: 3 additions & 1 deletion net.sf.eclipsefp.haskell.style/plugin.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# bundle manifest
bundleVendor = The EclipseFP Project
bundleName = Haskell Style and Formatting Utilities
bundleName = Haskell Style and Formatting Utilities

stylishHaskellPP_name=Stylish Haskell
25 changes: 25 additions & 0 deletions net.sf.eclipsefp.haskell.style/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.propertyPages">

<page
name="%stylishHaskellPP_name"
class="net.sf.eclipsefp.haskell.style.stylishhaskell.ui.SHConfigurationPP"
id="net.sf.eclipsefp.haskell.style.stylishhaskell.ui.SHConfigurationPP">
<filter
name="nature"
value="net.sf.eclipsefp.haskell.core.project.HaskellNature">
</filter>
<filter
name="open"
value="true">
</filter>
<enabledWhen>
<adapt type="org.eclipse.core.resources.IProject" />
</enabledWhen>
</page>
</extension>

</plugin>
Loading

0 comments on commit d42ca93

Please sign in to comment.