alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

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-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */


package org.netbeans.modules.java.ui.wizard;

import java.util.ResourceBundle;
import java.util.StringTokenizer;

import org.openide.src.*;
import org.openide.loaders.TemplateWizard;
import org.openide.util.Utilities;

public class Util {
    static String getString(String key) {
        return org.openide.util.NbBundle.getMessage(Util.class, key);
    }
    
    /** Returns true, if the passed string can be used as a qualified identifier.
     * it does not check for semantic, only for syntax.
     * The function returns true for any sequence of identifiers separated by
     * dots.
     */
    static boolean isValidPackageName(String str) {
        if (str.length() > 0 && str.charAt(0) == '.') return false;
        StringTokenizer tukac = new StringTokenizer(str, "."); // NOI18N
        while (tukac.hasMoreTokens()) {
            String token = tukac.nextToken();
            if ("".equals(token))
                return false;
            if (!Utilities.isJavaIdentifier(token))
                return false;
        }
        return true;
    }
    
    static boolean isValidTypeIdentifier(String ident) {
        if (ident == null || "".equals(ident))
            return false;
        try {
            Type t = Type.parse(ident);
            return t.isClass();
        } catch (IllegalArgumentException e) {
            return false;
        }
    }
    
    static boolean implementsInterface(ClassElement clazz, Identifier id) {
        Identifier[] implemented = clazz.getInterfaces();
        for (int i = 0; i < implemented.length; i++) {
            if (implemented[i].equals(id)) {
                return true;
            }
        }
        return false;
    }
    
    static TemplateWizard.Iterator packageIt;
    
    public static TemplateWizard.Iterator createPackageIterator() {
        if (packageIt == null)
            packageIt = JavaPackageIterator.create();
        return packageIt;
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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.