1 19 20 package org.netbeans.modules.javacore.astmatching; 21 22 import java.util.Collections ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 import java.util.StringTokenizer ; 26 import javax.swing.text.BadLocationException ; 27 import javax.swing.text.StyledDocument ; 28 import org.netbeans.jmi.javamodel.Element; 29 import org.netbeans.jmi.javamodel.JavaClass; 30 import org.netbeans.jmi.javamodel.JavaModelPackage; 31 import org.netbeans.jmi.javamodel.Method; 32 import org.netbeans.jmi.javamodel.codegen.Utility; 33 import org.netbeans.modules.javacore.internalapi.JavaMetamodel; 34 35 39 public class MatchUtils { 40 41 public static void addElement(StyledDocument doc, Element afterElement, String newElement) { 42 int offset = JavaMetamodel.getManager().getElementPosition(afterElement).getEnd().getOffset(); 43 try { 44 doc.insertString(offset, newElement, null); 45 } catch (BadLocationException bad) { 46 throw new RuntimeException (bad); 47 } 48 49 Utility.saveAll(); 50 Utility.addModified(afterElement); 51 } 52 53 public static Method getMethod(JavaClass clazz, String name, String parameters) { 54 JavaModelPackage pkg = (JavaModelPackage)clazz.refImmediatePackage(); 55 StringTokenizer tokenizer = new StringTokenizer (parameters, ","); 56 List params = new LinkedList (); 57 while (tokenizer.hasMoreTokens()) { 58 params.add(pkg.getType().resolve(tokenizer.nextToken())); 59 } 60 61 Method me = clazz.getMethod(name, params, false); 62 return me; 63 } 64 } 65 | Popular Tags |