/**
 * !(#) AstUtil.java
 * Copyright (c) 2014 DNW Technologies and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     DNW Technologies - initial API and implementation
 *
 * Create by manbaum since Oct 14, 2014.
 */
package com.dnw.plugin.ast;

import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.TypeDeclaration;

/**
 * Class/Interface AstUtil.
 * 
 * @author manbaum
 * @since Oct 14, 2014
 */
public final class AstUtil {

	/**
	 * Method replaceAllGenericTypeParameters.
	 * 
	 * @author manbaum
	 * @since Oct 14, 2014
	 * @param name
	 * @return
	 */
	public final static String replaceAllGenericTypeParameters(String name) {
		return name.replaceAll("<[^>]+>", "<?>");
	}

	/**
	 * Method nameOf.
	 * 
	 * @author manbaum
	 * @since Oct 10, 2014
	 * @param type
	 * @return
	 */
	public final static String nameOf(ITypeBinding type) {
		return type.getErasure().getQualifiedName();
	}

	/**
	 * Method displayNameOf.
	 * 
	 * @author manbaum
	 * @since Oct 10, 2014
	 * @param type
	 * @return
	 */
	public final static String captionOf(ITypeBinding type) {
		return type.getErasure().getName();
	}

	/**
	 * Method nameOf.
	 * 
	 * @author manbaum
	 * @since Oct 10, 2014
	 * @param method
	 * @return
	 */
	public final static String nameOf(IMethodBinding method) {
		StringBuffer sb = new StringBuffer();
		sb.append(method.getDeclaringClass().getErasure().getQualifiedName());
		sb.append(Modifier.isStatic(method.getModifiers()) ? '/' : '#');
		sb.append(method.getName());
		sb.append('(');
		boolean first = true;
		for (ITypeBinding t : method.getParameterTypes()) {
			if (first) {
				first = false;
			} else {
				sb.append(',');
			}
			sb.append(t.getErasure().getQualifiedName());
		}
		sb.append(')');
		return sb.toString();
	}

	/**
	 * Method displayNameOf.
	 * 
	 * @author manbaum
	 * @since Oct 10, 2014
	 * @param method
	 * @return
	 */
	public final static String captionOf(IMethodBinding method) {
		StringBuffer sb = new StringBuffer();
		sb.append(method.getName());
		sb.append("()");
		return sb.toString();
	}

	/**
	 * Method fileInfo.
	 * 
	 * @author manbaum
	 * @since Oct 11, 2014
	 * @param node
	 * @return
	 */

	/**
	 * Method tellTypeDeclaration.
	 * 
	 * @author manbaum
	 * @since Oct 11, 2014
	 * @param node
	 * @param type
	 */
	public static String infoOf(VisitContext context, TypeDeclaration node, ITypeBinding type) {
		StringBuffer sb = new StringBuffer();
		sb.append("  . ");
		sb.append(node.getName());
		sb.append(" bound to: ");
		sb.append(type != null ? type.getQualifiedName() : "nothing");
		sb.append(" (");
		sb.append(context.fileInfo(node));
		sb.append(")");
		return sb.toString();
	}

	/**
	 * Method tellMethodDeclaration.
	 * 
	 * @author manbaum
	 * @since Oct 11, 2014
	 * @param node
	 * @param method
	 */
	public static String infoOf(VisitContext context, MethodDeclaration node, IMethodBinding method) {
		StringBuffer sb = new StringBuffer();
		sb.append("  . ");
		sb.append(node.getName());
		sb.append(" bound to: ");
		sb.append(method != null ? method.getName() + "()" : "nothing");
		sb.append(" (");
		sb.append(context.fileInfo(node));
		sb.append(")");
		return sb.toString();
	}

	/**
	 * Method tellMethodInvocation.
	 * 
	 * @author manbaum
	 * @since Oct 11, 2014
	 * @param node
	 * @param method
	 */
	public static String infoOf(VisitContext context, MethodInvocation node, IMethodBinding method) {
		StringBuffer sb = new StringBuffer();
		sb.append("  . ");
		sb.append(node.getName());
		sb.append(" bound to: ");
		sb.append(method != null ? method.getName() + "()" : "nothing");
		sb.append(" (");
		sb.append(context.fileInfo(node));
		sb.append(")");
		return sb.toString();
	}
}

@@ -886,31 +886,20 @@
 ethod re
-placeAllGeneric
+move
 TypePara
@@ -1022,23 +1022,12 @@
 g re
-placeAllGeneric
+move
 Type
@@ -1093,11 +1093,8 @@
 %22, %22
-%3C?%3E
 %22);%0A
@@ -1268,33 +1268,41 @@
 %09return 
-type.getErasure()
+removeTypeParameters(type
 .getQual
@@ -1308,24 +1308,25 @@
 lifiedName()
+)
 ;%0A%09%7D%0A%0A%09/**%0A%09
@@ -1504,25 +1504,33 @@
 urn 
-type.getErasure()
+removeTypeParameters(type
 .get
@@ -1535,16 +1535,17 @@
 etName()
+)
 ;%0A%09%7D%0A%0A%09/
@@ -1754,32 +1754,39 @@
 ();%0A%09%09sb.append(
+nameOf(
 method.getDeclar
@@ -1799,39 +1799,8 @@
 ss()
-.getErasure().getQualifiedName(
 ));%0A
@@ -2082,40 +2082,16 @@
 end(
-t.getErasure().getQualifiedName(
+nameOf(t
 ));%0A

Change ASTNode name generating.