|
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-2002 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.javacore.parser; import java.util.*; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.jmi.javamodel.ClassDefinition; import org.netbeans.jmi.javamodel.Import; import org.netbeans.jmi.javamodel.JavaClass; import org.netbeans.jmi.javamodel.JavaPackage; import org.netbeans.jmi.javamodel.ParameterizedType; import org.netbeans.jmi.javamodel.Resource; import org.netbeans.jmi.javamodel.UnresolvedClass; import org.netbeans.modules.javacore.jmiimpl.javamodel.JavaClassImpl; /** * * @author thurka */ public class MethodScope implements ScopeMember { private MethodScope parentScope; private Map positiveCache; private Set negativeCache; private ArrayList members; /** Creates a new instance of Scope */ MethodScope(MethodScope parent) { parentScope=parent; positiveCache=new HashMap(); negativeCache=new HashSet(); members=new ArrayList(); } public Object lookup(final Object key) { Object val=positiveCache.get(key); Object valParent=null; if (val!=null) return val; if (negativeCache.contains(key)) return null; val=lookupMembers(key); if (parentScope!=null) valParent=parentScope.lookup(key); val=combine(val,valParent); if (val!=null) positiveCache.put(key,val); else negativeCache.add(key); return val; } void addMember(final ScopeMember member) { positiveCache.clear(); negativeCache.clear(); members.add(member); } public boolean equals(Object obj) { if (obj!=null && obj instanceof MethodScope) { MethodScope sc=(MethodScope)obj; if (!members.equals(sc.members)) return false; if (parentScope==null) return parentScope==sc.parentScope; return parentScope.equals(sc.parentScope); } return false; } protected Object clone() { MethodScope cloned=new MethodScope(parentScope); cloned.members=(ArrayList)members.clone(); return cloned; } private Object combine(Object val,Object val1) { List valList; if (val==null) return val1; if (val1==null) return val; if (!(val instanceof List)) { valList=new ArrayList(); valList.add(val); } else { valList=(List)val; } if (!(val1 instanceof List)) { valList.add(val1); } else { valList.addAll((Collection)val1); } return valList; } private Object lookupMembers(final Object key) { Iterator it=members.iterator(); Object value=null; while(it.hasNext()) { ScopeMember m=(ScopeMember)it.next(); Object val=m.lookup(key); if (val==null) continue; if (value==null) { value=val; continue; } value=combine(value,val); } return value; } } |
... 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.