|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.javacore.astmatching; import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.StringTokenizer; import javax.swing.text.BadLocationException; import javax.swing.text.StyledDocument; import org.netbeans.jmi.javamodel.Element; import org.netbeans.jmi.javamodel.JavaClass; import org.netbeans.jmi.javamodel.JavaModelPackage; import org.netbeans.jmi.javamodel.Method; import org.netbeans.jmi.javamodel.codegen.Utility; import org.netbeans.modules.javacore.internalapi.JavaMetamodel; /** * * @author Jan Becicka */ public class MatchUtils { public static void addElement(StyledDocument doc, Element afterElement, String newElement) { int offset = JavaMetamodel.getManager().getElementPosition(afterElement).getEnd().getOffset(); try { doc.insertString(offset, newElement, null); } catch (BadLocationException bad) { throw new RuntimeException(bad); } Utility.saveAll(); Utility.addModified(afterElement); } public static Method getMethod(JavaClass clazz, String name, String parameters) { JavaModelPackage pkg = (JavaModelPackage)clazz.refImmediatePackage(); StringTokenizer tokenizer = new StringTokenizer(parameters, ","); List params = new LinkedList(); while (tokenizer.hasMoreTokens()) { params.add(pkg.getType().resolve(tokenizer.nextToken())); } Method me = clazz.getMethod(name, params, false); return me; } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.