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

/*
 * PackageImpScope.java
 *
 * Created on October 3, 2002, 12:06 PM
 */

package org.netbeans.modules.javacore.parser;

import java.util.*;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.jmi.javamodel.JavaClass;
import org.netbeans.modules.javacore.ClassIndex;


/**
 *
 * @author  Tomas Hurka
 */
class PackageImpScope implements ScopeMember {
    private String jPackage;
    private ClassPath classPath;
    private Map positiveCache;
    private Set negativeCache;
    
    static PackageImpScope createScope(String pack,ClassPath cp) {
        PackageImpScope scope;
        
//        if (sc==null)
            scope=new PackageImpScope(pack, cp);
/*        else {
            Map cache=sc.getCacheFor(PackageImpScope.class.getName());
            scope=(PackageImpScope)cache.get(pack);
            if (scope==null) {
                scope=new PackageImpScope(pack, cp, sc);
                cache.put(pack,scope);
            }
        }
*/        return scope;
    }
    
    /** Creates a new instance of PackageImpScope */
    private PackageImpScope(String pack,ClassPath cp) {
        jPackage=pack==null?".":pack.concat("."); // NOI18N
        classPath=cp;
        positiveCache=new HashMap();
        negativeCache=new HashSet();
    }
    
    public Object lookup(Object key) {
        Object val;
        String className;
        JavaClass jcls;
        
        if (negativeCache.contains(key))
            return null;
        val=positiveCache.get(key);
        if (val!=null)
            return val;
        className=jPackage.concat((String)key);
        jcls=ClassIndex.getClassByFqn(className,classPath);
        if (jcls!=null) {
            String name=jcls.getName();
            
            positiveCache.put(key, name);
            return name;
        }
        negativeCache.add(key);
        return null;
    }
}
... 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.