Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

test automatic type insertion

  • Loading branch information...
commit 21a773234c55b4625a2a074888bb8b09fabfe338 1 parent feefa2c
@JPMoresmau authored
View
44 net.sf.eclipsefp.haskell.ui.test/META-INF/MANIFEST.MF
@@ -1,22 +1,22 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: Haskell UI Test Plug-in
-Bundle-SymbolicName: net.sf.eclipsefp.haskell.ui.test
-Bundle-Version: 2.2.2
-Bundle-Vendor: eclipsefp.sourceforge.net
-Require-Bundle: org.junit4,
- org.easymock;bundle-version="[2.2.0,3.0.0)",
- org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.jface.text;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.ui.console,
- org.eclipse.ui.editors;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.ui.ide;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.ui.workbench.texteditor;bundle-version="[3.2.0,4.0.0)",
- net.sf.eclipsefp.haskell.ui,
- net.sf.eclipsefp.haskell.core,
- net.sf.eclipsefp.haskell.core.test,
- net.sf.eclipsefp.haskell.util
-Export-Package: net.sf.eclipsefp.haskell.ui.test
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Haskell UI Test Plug-in
+Bundle-SymbolicName: net.sf.eclipsefp.haskell.ui.test
+Bundle-Version: 2.3.0
+Bundle-Vendor: eclipsefp.sourceforge.net
+Require-Bundle: org.junit4,
+ org.easymock;bundle-version="[2.2.0,3.0.0)",
+ org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.jface.text;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.ui.console,
+ org.eclipse.ui.editors;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.ui.ide;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.ui.workbench.texteditor;bundle-version="[3.2.0,4.0.0)",
+ net.sf.eclipsefp.haskell.ui,
+ net.sf.eclipsefp.haskell.core,
+ net.sf.eclipsefp.haskell.core.test,
+ net.sf.eclipsefp.haskell.util
+Export-Package: net.sf.eclipsefp.haskell.ui.test
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
View
48 ...f.eclipsefp.haskell.ui.test/src/net/sf/eclipsefp/haskell/ui/internal/resolve/MissingTypeWarningTest.java
@@ -0,0 +1,48 @@
+/**
+ * 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.ui.internal.resolve;
+
+import static org.junit.Assert.assertEquals;
+import net.sf.eclipsefp.haskell.buildwrapper.types.GhcMessages;
+import org.junit.Test;
+
+
+/**
+ * Test missing type warning, since several different type syntaxes may cause the wrong type to be automatically added
+ * @author JP Moresmau
+ *
+ */
+public class MissingTypeWarningTest {
+
+ @Test
+ public void testWithPackage(){
+ String full="Top-level binding with no type signature:\n commonHome :: forall s a a1.\n (ToWidget s App a1, blaze-markup-0.5.1.0:Text.Blaze.ToMarkup a) =>\n a1 -> a -> Maybe Search -> GHandler s App RepHtml";
+ String type="commonHome :: forall s a a1.\n (ToWidget s App a1, Text.Blaze.ToMarkup a) =>\n a1 -> a -> Maybe Search -> GHandler s App RepHtml";
+ assertEquals(type,MissingTypeWarningResolution.extractTypeFromMessage( GhcMessages.WARNING_NOTYPE_TOPLEVEL_CONTAINS, full ));
+ }
+
+ @Test
+ public void testWith2Packages(){
+ String full="Top-level binding with no type signature:\n commonHome :: forall s a a1.\n (blaze-markup-0.5.1.0:Text.Blaze.ToMarkup a1, blaze-markup-0.5.1.0:Text.Blaze.ToMarkup a) =>\n a1 -> a -> Maybe Search -> GHandler s App RepHtml";
+ String type="commonHome :: forall s a a1.\n (Text.Blaze.ToMarkup a1, Text.Blaze.ToMarkup a) =>\n a1 -> a -> Maybe Search -> GHandler s App RepHtml";
+ assertEquals(type,MissingTypeWarningResolution.extractTypeFromMessage( GhcMessages.WARNING_NOTYPE_TOPLEVEL_CONTAINS, full ));
+ }
+
+ @Test
+ public void testWithKind(){
+ String full="Top-level binding with no type signature:\n f :: forall (x :: * -> *) y t. (t -> x y) -> t -> D x y";
+ String type="f :: forall (x :: * -> *) y t. (t -> x y) -> t -> D x y";
+ assertEquals(type,MissingTypeWarningResolution.extractTypeFromMessage( GhcMessages.WARNING_NOTYPE_TOPLEVEL_CONTAINS, full ));
+ }
+
+ @Test
+ public void testForAll(){
+ String full="Top-level binding with no type signature:\n fun :: forall t. t -> [Char] -> [Char]";
+ String type="fun :: forall t. t -> [Char] -> [Char]";
+ assertEquals(type,MissingTypeWarningResolution.extractTypeFromMessage( GhcMessages.WARNING_NOTYPE_TOPLEVEL_CONTAINS, full ));
+ }
+
+}
View
1  net.sf.eclipsefp.haskell.ui/META-INF/MANIFEST.MF
@@ -68,6 +68,7 @@ Export-Package: net.sf.eclipsefp.common.ui.dialog;uses:="org.eclipse.swt.widgets
net.sf.eclipsefp.haskell.ui.internal.editors.text;x-friends:="net.sf.eclipsefp.haskell.ui.test",
net.sf.eclipsefp.haskell.ui.internal.preferences;x-friends:="net.sf.eclipsefp.haskell.ui.test,net.sf.eclipsefp.haskell.debug.ui",
net.sf.eclipsefp.haskell.ui.internal.preferences.editor;x-friends:="net.sf.eclipsefp.haskell.ui.test,net.sf.eclipsefp.haskell.debug.ui",
+ net.sf.eclipsefp.haskell.ui.internal.resolve,
net.sf.eclipsefp.haskell.ui.internal.scion,
net.sf.eclipsefp.haskell.ui.internal.util;uses:="org.eclipse.osgi.util",
net.sf.eclipsefp.haskell.ui.internal.views.common;x-friends:="net.sf.eclipsefp.haskell.ui.test",
View
90 ....eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/resolve/MissingTypeWarningResolution.java
@@ -31,38 +31,80 @@ public String getLabel() {
return UITexts.resolve_missingtype;
}
- @Override
- public ICompletionProposal getCompletionProposal( final IMarker marker,final IDocument document){
- String msg=marker.getAttribute(IMarker.MESSAGE,""); //$NON-NLS-1$
- //String toSearch=GhcMessages.WARNING_INFERREDTYPE_START;
- int ix=msg.toLowerCase().indexOf( toSearch);
+ /**
+ * extract the proper type from the message
+ * @param prefix
+ * @param msg
+ * @return
+ */
+ public static String extractTypeFromMessage(final String prefix,final String msg){
+ int ix=msg.toLowerCase().indexOf( prefix);
if (ix>-1){
- String type=msg.substring(ix+toSearch.length()).trim();
+ String type=msg.substring(ix+prefix.length()).trim();
int ixStartType=type.indexOf( "::" );
if (ixStartType>-1){
- for (int a=ixStartType;a<type.length();a++){
- if (Character.isUpperCase( type.charAt( a ) )){
- break;
- } else if (Character.isLowerCase( type.charAt( a ) )){
- int start=a;
- // I don't remember why we search for :
- int end=type.indexOf( ":",a );
- // but if we have :: inside, it's a kind signature, maybe?, so we don' truncate
- if (end>-1 && type.indexOf( ":",end+1 )!=end+1){
- type=type.substring( 0,start )+type.substring( end+1,type.length() );
- break;
- }
+ StringBuilder sb=new StringBuilder();
+ String name= type.substring( 0,ixStartType );
+ // if we're in Main, symbol name gets prefixed with Main.
+ int lidx=name.lastIndexOf( '.' );
+ if (lidx>-1){
+ name=name.substring(lidx+1);
}
- }
+ sb.append(name );
+ sb.append("::" );
+// for (int a=ixStartType;a<type.length();a++){
+// if (Character.isUpperCase( type.charAt( a ) )){
+// break;
+// } else if (Character.isLowerCase( type.charAt( a ) )){
+ int start=ixStartType+2;
+ // package names can appear in signature
+ int end=type.indexOf( ":",start );
+ while (end>-1){
+ // but if we have :: inside, it's a kind signature, maybe?, so we don't truncate
+ if (type.indexOf( ":",end+1 )!=end+1){
+ int startPkg1=type.substring(start,end).lastIndexOf( ' ' );
+ int startPkg2=type.substring(start,end).lastIndexOf( '(' );
+ int startPkg=Math.max( startPkg1, startPkg2 );
+ if (startPkg==-1){
+ startPkg=start;
+ } else {
+ startPkg+=start+1;
+ }
+ sb.append(type.substring( start,startPkg ));
+ start=end+1;
+ } else {
+ sb.append(type.substring( start,end ));
+ sb.append("::");
+ start=end+2;
+ }
+
+ end=type.indexOf( ":",start );
+ }
+ sb.append(type.substring( start ));
+ //type=type.substring( 0,startPkg )+type.substring( end+1,type.length() );
+// break;
+// }
+// }
+// }
// if we're in Main, symbol name gets prefixed with Main.
- int lidx=type.substring(0,ixStartType).lastIndexOf( '.' );
- if (lidx>-1){
- type=type.substring(lidx+1);
- }
+// int lidx=type.substring(0,ixStartType).lastIndexOf( '.' );
+// if (lidx>-1){
+// type=type.substring(lidx+1);
+// }
+ return sb.toString();
}
+ return type;
+ }
+ return null;
+ }
-
+ @Override
+ public ICompletionProposal getCompletionProposal( final IMarker marker,final IDocument document){
+ String msg=marker.getAttribute(IMarker.MESSAGE,""); //$NON-NLS-1$
+ //String toSearch=GhcMessages.WARNING_INFERREDTYPE_START;
+ String type=extractTypeFromMessage( toSearch, msg );
+ if (type!=null){
int line=marker.getAttribute(IMarker.LINE_NUMBER, 0);
try {
Please sign in to comment.
Something went wrong with that request. Please try again.