Get the "simple" form of a class name.

@param c Class
@param pkg Package

@return Simplified class name
330135
public static String canonicalClassName(Class<?> c, Package pkg) {
    String name = c.getName();
    if(pkg != null) {
      final String pkgname = pkg.getName();
      if(name.length() > pkgname.length() && name.startsWith(pkgname) && name.charAt(pkgname.length()) == '.') {
        name = name.substring(pkgname.length() + 1);
      }
    }
    if(name.endsWith(ELKIServiceRegistry.FACTORY_POSTFIX)) {
      name = name.substring(0, name.length() - ELKIServiceRegistry.FACTORY_POSTFIX.length());
    }
    return name;
  }
749452
public Writer getFileObjectWriterInClassOutput(String pkg, String name) throws IOException {
		FileObject resource = filer.createResource(StandardLocation.CLASS_OUTPUT, pkg, name);
		return resource.openWriter();
	}
380269
public String printClass(ClassDoc c, boolean rootClass) {
	ClassInfo ci = getClassInfo(c, true);
	if(ci.nodePrinted || ci.hidden)
	    return ci.name;
	Options opt = optionProvider.getOptionsFor(c);
	if (c.isEnum() && !opt.showEnumerations)
	    return ci.name;
	String className = c.toString();
	// Associate classname's alias
	w.println(linePrefix + "// " + className);
	// Create label
	w.print(linePrefix + ci.name + " [label=");

	boolean showMembers =
		(opt.showAttributes && c.fields().length > 0) ||
		(c.isEnum() && opt.showEnumConstants && c.enumConstants().length > 0) ||
		(opt.showOperations && c.methods().length > 0) ||
		(opt.showConstructors && c.constructors().length > 0);

	final String url = classToUrl(c, rootClass);
	externalTableStart(opt, c.qualifiedName(), url);

	firstInnerTableStart(opt);
	if (c.isInterface())
	    tableLine(Align.CENTER, guilWrap(opt, "interface"));
	if (c.isEnum())
	    tableLine(Align.CENTER, guilWrap(opt, "enumeration"));
	stereotype(opt, c, Align.CENTER);
	Font font = c.isAbstract() && !c.isInterface() ? Font.CLASS_ABSTRACT : Font.CLASS;
	String qualifiedName = qualifiedName(opt, className);
	int idx = splitPackageClass(qualifiedName);
	if (opt.showComment)
	    tableLine(Align.LEFT, Font.CLASS.wrap(opt, htmlNewline(escape(c.commentText()))));
	else if (opt.postfixPackage && idx > 0 && idx < (qualifiedName.length() - 1)) {
	    String packageName = qualifiedName.substring(0, idx);
	    String cn = qualifiedName.substring(idx + 1);
	    tableLine(Align.CENTER, font.wrap(opt, escape(cn)));
	    tableLine(Align.CENTER, Font.PACKAGE.wrap(opt, packageName));
	} else {
	    tableLine(Align.CENTER, font.wrap(opt, escape(qualifiedName)));
	}
	tagvalue(opt, c);
	firstInnerTableEnd(opt);

	/*
	 * Warning: The boolean expressions guarding innerTableStart()
	 * in this block, should match those in the code block above
	 * marked: "Calculate the number of innerTable rows we will emmit"
	 */
	if (showMembers) {
	    if (opt.showAttributes) {
		innerTableStart();
		FieldDoc[] fields = c.fields();
		// if there are no fields, print an empty line to generate proper HTML
		if (fields.length == 0)
		    tableLine(Align.LEFT, "");
		else
		    attributes(opt, c.fields());
		innerTableEnd();
	    } else if(!c.isEnum() && (opt.showConstructors || opt.showOperations)) {
		// show an emtpy box if we don't show attributes but
		// we show operations
		innerTableStart();
		tableLine(Align.LEFT, "");
		innerTableEnd();
	    }
	    if (c.isEnum() && opt.showEnumConstants) {
		innerTableStart();
		FieldDoc[] ecs = c.enumConstants();
		// if there are no constants, print an empty line to generate proper HTML
		if (ecs.length == 0) {
		    tableLine(Align.LEFT, "");
		} else {
		    for (FieldDoc fd : c.enumConstants()) {
			tableLine(Align.LEFT, fd.name());
		    }
		}
		innerTableEnd();
	    }
	    if (!c.isEnum() && (opt.showConstructors || opt.showOperations)) {
		innerTableStart();
		boolean printedLines = false;
		if (opt.showConstructors)
		    printedLines |= operations(opt, c.constructors());
		if (opt.showOperations)
		    printedLines |= operations(opt, c.methods());

		if (!printedLines)
		    // if there are no operations nor constructors,
		    // print an empty line to generate proper HTML
		    tableLine(Align.LEFT, "");

		innerTableEnd();
	    }
	}
	externalTableEnd();
	if (url != null)
	    w.print(", URL=\"" + url + "\"");
	nodeProperties(opt);

	// If needed, add a note for this node
	int ni = 0;
	for (Tag t : c.tags("note")) {
	    String noteName = "n" + ni + "c" + ci.name;
	    w.print(linePrefix + "// Note annotation\n");
	    w.print(linePrefix + noteName + " [label=");
	    externalTableStart(UmlGraph.getCommentOptions(), c.qualifiedName(), url);
	    innerTableStart();
	    tableLine(Align.LEFT, Font.CLASS.wrap(UmlGraph.getCommentOptions(), htmlNewline(escape(t.text()))));
	    innerTableEnd();
	    externalTableEnd();
	    nodeProperties(UmlGraph.getCommentOptions());
	    ClassInfo ci1 = getClassInfo(c, true);
	    w.print(linePrefix + noteName + " -> " + ci1.name + "[arrowhead=none];\n");
	    ni++;
	}
	ci.nodePrinted = true;
	return ci.name;
    }
223605
private static String convert(String pkg) {

    pkg = pkg.trim();
    if (pkg.endsWith("*")) {
      pkg = pkg.substring(0, pkg.length() - 1);
    }
    if (pkg.endsWith(".query")) {
      // always work with entity bean packages so trim
      pkg = pkg.substring(0, pkg.length() - 6);
    }
    pkg = pkg.replace('.', '/');
    return pkg.endsWith("/") ? pkg : pkg + "/";
  }
1373573
String lookupName(ClassName className) {
    // If the top level simple name is masked by a current type variable, use the canonical name.
    String topLevelSimpleName = className.topLevelClassName().simpleName();
    if (currentTypeVariables.contains(topLevelSimpleName)) {
      return className.canonicalName;
    }

    // Find the shortest suffix of className that resolves to className. This uses both local type
    // names (so `Entry` in `Map` refers to `Map.Entry`). Also uses imports.
    boolean nameResolved = false;
    for (ClassName c = className; c != null; c = c.enclosingClassName()) {
      ClassName resolved = resolve(c.simpleName());
      nameResolved = resolved != null;

      if (resolved != null && Objects.equals(resolved.canonicalName, c.canonicalName)) {
        int suffixOffset = c.simpleNames().size() - 1;
        return join(".", className.simpleNames().subList(
            suffixOffset, className.simpleNames().size()));
      }
    }

    // If the name resolved but wasn't a match, we're stuck with the fully qualified name.
    if (nameResolved) {
      return className.canonicalName;
    }

    // If the class is in the same package, we're done.
    if (Objects.equals(packageName, className.packageName())) {
      referencedNames.add(topLevelSimpleName);
      return join(".", className.simpleNames());
    }

    // We'll have to use the fully-qualified name. Mark the type as importable for a future pass.
    if (!javadoc) {
      importableType(className);
    }

    return className.canonicalName;
  }
134179
protected String getPairPunctuationText( int c ) throws IOException 
    {
        //StringBuilder isb = new StringBuilder();
        isb.clear();
        char echar = StringUtil.getPunctuationPair( (char) c);
        boolean matched = false;
        int j, ch;
        
        //replaced with IntArrayList at 2013-09-08
        //ArrayList<Integer> chArr = new ArrayList<Integer>(config.PPT_MAX_LENGTH);
        ialist.clear();
        
        for ( j = 0; j < config.PPT_MAX_LENGTH; j++ ) {
            ch = readNext();
            if ( ch == -1 ) break;
            if ( ch == echar ) {
                matched = true;
                pushBack(ch);        //push the pair punc back.
                break;
            }
            
            isb.append( (char) ch );
            ialist.add(ch);
        }
        
        if ( matched == false ) {
            for ( int i = j - 1; i >= 0; i-- ) 
                pushBack( ialist.get(i) );
            return null;
        }
        
        return isb.toString();
    }
    
    /**
     * an abstract method to gain a CJK word from the 
     * current position. simpleSeg and ComplexSeg is different to deal this, 
     * so make it a abstract method here
     * 
     * @param  chars
     * @param  index
     * @return IChunk
     * @throws IOException
     */
    protected abstract IChunk getBestCJKChunk(char chars[], int index) throws IOException;
    
}
1007166
public List<Class<?>> getClasses(final String pkg, boolean recursive, final Predicate<Class<?>> predicate)
	{
		final long started = System.currentTimeMillis();

		try
		{
			return filter(finder.findClassesInPackage(pkg, recursive), predicate);
		}
		finally
		{
			final long finished = System.currentTimeMillis();
			searchTime.addAndGet(finished - started);

			if (log.isTraceEnabled())
				log.trace("getClasses " +
				          pkg +
				          " with predicate=" +
				          predicate +
				          " returned in " +
				          (finished - started) +
				          " ms");
		}
	}
269340
public static PackageDescriptor forName(String packageName,
                                            ClassLoader classLoader) {
        
        PackageDescriptor pd = new PackageDescriptor(packageName);
        if (classLoader == null) {
            classLoader = ClassLoader.getSystemClassLoader();
        }
        
        if (packageName == null || packageName.trim().length() == 0) {
            return pd;
        }
        
        String packageInfoClassName = packageName;

        if (!packageInfoClassName.endsWith(".")) {
            packageInfoClassName = packageInfoClassName + ".";
        }
        
        packageInfoClassName = packageInfoClassName + "PackageInfo";


        Class<?> packageInfoClass = null;
        
        try {
            if (classLoader != null) {
                packageInfoClass = 
                    classLoader.loadClass(packageInfoClassName);
            }
            else {
                packageInfoClass = Class.forName(packageInfoClassName);
            }
        }
        catch (Throwable t) {
        }

        if (packageInfoClass != null) {
            try {
                initFromPackageInfo(pd, packageInfoClass);
            }
            catch (Throwable t) {
            }
        }
        else {

            Package pkg = null;
            
            if (classLoader != null) {
                // Get around getPackage's protected access
                PackageLoader packageLoader = 
                    new PackageLoader(classLoader);
                
                pkg = packageLoader.getPackage(packageName);
            }
            
            if (pkg == null) {
                pkg = Package.getPackage(packageName);
            }                        

            if (pkg != null) {
                initFromPackage(pd, pkg);
            }
        }

        return pd;
    }
445883
private static String resolveName(Class<?> c, String name) {
       if (name == null) {
           return name;
       }
       if (!name.startsWith("/")) {
           while (c.isArray()) {
               c = c.getComponentType();
           }
           String baseName = c.getName();
           int index = baseName.lastIndexOf('.');
           if (index != -1) {
               name = baseName.substring(0, index).replace('.', '/')
                   +"/"+name;
           }
       } else {
           name = name.substring(1);
       }
       return name;
   }
766455
public Set<Class<? extends Job>> getJobClasses(String pkgname) {

    Set<Class<? extends Job>> classes = new HashSet<Class<? extends Job>>();

    String[] packages = pkgname.split("[\\:,]");
    if (packages.length > 1) {
      for (String pkg : packages) {
        classes.addAll(getJobClasses(pkg));
      }
    } else {
      String relPath = pkgname.replace('.', '/').replace("%20", " ");

      // Get a File object for the package
      URL resource = getResource(relPath);
      if (resource == null) {
        throw new RuntimeException("Unexpected problem: No resource for " + relPath);
      }
      String resPath = "";
      try {
        resPath = URLDecoder.decode(resource.getPath(), "UTF-8");
      } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
      }

      logger.info("Package: '" + pkgname + "' becomes Resource: '" + resPath + "'");

      if (resource.toString().startsWith("jar:")) {
        processJarfile(resPath, pkgname, classes);
      } else {
        processDirectory(resPath, pkgname, classes);
      }
    }

    return classes;
  }
1268403
public Class getClassByName(String name)
	{

		if (name.indexOf(".") != -1)
		{
			try
			{
				return Class.forName(name,true,gt.getClassLoader());
			}
			catch (ClassNotFoundException e)
			{
				return null;
			}

		}
		else
		{
			Class cls = map.get(name);
			if (cls == null)
			{
				for (String pkg : pkgList)
				{
					try
					{
						String clsName = pkg.concat(name);
						cls = Class.forName(clsName,true,gt.getClassLoader());
						map.put(name, cls);
						return cls;

					}
					catch (Exception ex)
					{
						// continue;
					}
				}
				return null;
			}
			else
			{
				return cls;
			}

		}

	}
954174
public TypeElement findClassInPackageElement(PackageElement pkg, String className) {
        for (TypeElement c : getAllClasses(pkg)) {
            if (getSimpleName(c).equals(className)) {
                return c;
            }
        }
        return null;
    }
579847
public static String simpleClassName(Class<?> clazz) {
        String className = checkNotNull(clazz, "clazz").getName();
        final int lastDotIdx = className.lastIndexOf(PACKAGE_SEPARATOR_CHAR);
        if (lastDotIdx > -1) {
            return className.substring(lastDotIdx + 1);
        }
        return className;
    }
421034
private String getPackageName(ObjectMappableAnnotatedClass clazz) {
    PackageElement pkg = elements.getPackageOf(clazz.getElement());
    return pkg.isUnnamed() ? "" : pkg.getQualifiedName().toString();
  }
252256
Module findModuleFromPackageName(String pkg) {
        int cp = pkg.indexOf(':');
        assert(cp != -1);
        String mod = pkg.substring(0, cp);
        return lookupModule(mod);
    }
1332332
@SuppressWarnings("unchecked")
	@Override
	public <E> E getBean(Class<E> c) {
		String name = c.getSimpleName();
		String beanName = name.substring(0, 1).toLowerCase() + name.substring(1);
		String className = c.getName();
		// System.out.println("name:" + name);
		logger.info("beanName:" + beanName + " className:" + className);
		return (E) getBean(beanName);
	}
665257
public static String getPackageName(Class< ? > clazz,
                                        Package pkg) {
        String pkgName = "";
        if ( pkg == null ) {
            int index = clazz.getName().lastIndexOf( '.' );
            if ( index != -1 ) pkgName = clazz.getName().substring( 0,
                                                                    index );
        } else {
            pkgName = pkg.getName();
        }
        return pkgName;

    }