package com.redhat.ceylon.eclipse.imp.foldingUpdater;

import java.util.HashMap;
import java.util.List;

import org.eclipse.imp.services.base.FolderBase;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;

import com.redhat.ceylon.compiler.typechecker.tree.Tree;
import com.redhat.ceylon.compiler.typechecker.tree.Visitor;

/**
 * This file provides a skeletal implementation of the language-dependent aspects
 * of a source-text folder.  This implementation is generated from a template that
 * is parameterized with respect to the name of the language, the package containing
 * the language-specific types for AST nodes and AbstractVisitors, and the name of
 * the folder package and class.
 */
public class CeylonFoldingUpdater extends FolderBase {

    @Override
	public void sendVisitorToAST(HashMap<Annotation,Position> newAnnotations, 
	        List<Annotation> annotations, Object ast) {
		new Visitor() {
			@Override 
			public void visit(Tree.Body body) {
                super.visit(body);
				makeAnnotation(body);
			}
            //TODO: we should also allow multiline comments 
			//      to be folded, but currently there is no
			//      treenode for them!
		}.visit((Tree.CompilationUnit) ast);
	}
	
    /*public void makeRangeAnnotation(Object n) {
        ISourcePositionLocator nodeLocator = parseController.getSourcePositionLocator();
        DefaultRangeIndicator annotation= new DefaultRangeIndicator();
        newAnnotations.put(annotation, 
                new Position(nodeLocator.getStartOffset(n), nodeLocator.getEndOffset(n)));
        annotations.add(annotation);
    }*/
}

@@ -1038,12 +1038,108 @@
 y);%0A
-%09%09%09%09
+                if (body.getEndToken().getLine()-body.getToken().getLine()%3E1) %7B%0A                    
 make
@@ -1156,16 +1156,34 @@
 (body);%0A
+                %7D%0A
 %09%09%09%7D%0A   
@@ -1367,394 +1367,7 @@
 %0A%09%7D%0A
-%09%0A    /*public void makeRangeAnnotation(Object n) %7B%0A        ISourcePositionLocator nodeLocator = parseController.getSourcePositionLocator();%0A        DefaultRangeIndicator annotation= new DefaultRangeIndicator();%0A        newAnnotations.put(annotation, %0A                new Position(nodeLocator.getStartOffset(n), nodeLocator.getEndOffset(n)));%0A        annotations.add(annotation);%0A    %7D*/
 %0A%7D%0A

disable folding for empty bodies