diff -u -N -r ../../HG_FRESH/main/api.debugger/apichanges.xml api.debugger/apichanges.xml --- ../../HG_FRESH/main/api.debugger/apichanges.xml 2008-08-20 02:00:43.000000000 +0200 +++ api.debugger/apichanges.xml 2009-01-25 17:37:11.000000000 +0100 @@ -278,6 +278,41 @@ + + + Lookup improvements and service annotation registration. + + + + + +

+ In order to be able to register debugger services on System FileSystem, + which brings more flexibility and better performance (see also + ), + we add non-recursive content of org.openide.util.Lookups.forPath() + into debugger lookup. + Since debugger needs retrieve context-aware services from the lookup, + ContextAwareService interface is introduced. +

+

+ Annotations are added for easy registration on module layers. + DebuggerServiceRegistration to register implementations + of interfaces, *Provider.Registration to register + implementations of appropriate providers. +

+
+ + + + + + + + + +
+ diff -u -N -r ../../HG_FRESH/main/api.debugger/manifest.mf api.debugger/manifest.mf --- ../../HG_FRESH/main/api.debugger/manifest.mf 2008-11-18 20:59:37.000000000 +0100 +++ api.debugger/manifest.mf 2009-01-25 16:50:25.000000000 +0100 @@ -1,5 +1,4 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.api.debugger/1 OpenIDE-Module-Localizing-Bundle: org/netbeans/api/debugger/Bundle.properties -OpenIDE-Module-Specification-Version: 1.15 - +OpenIDE-Module-Specification-Version: 1.16 diff -u -N -r ../../HG_FRESH/main/api.debugger/nbproject/project.properties api.debugger/nbproject/project.properties --- ../../HG_FRESH/main/api.debugger/nbproject/project.properties 2008-08-20 02:00:44.000000000 +0200 +++ api.debugger/nbproject/project.properties 2009-01-23 22:00:37.000000000 +0100 @@ -42,3 +42,4 @@ javac.source=1.5 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml +cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar diff -u -N -r ../../HG_FRESH/main/api.debugger/src/org/netbeans/api/debugger/LazyActionsManagerListener.java api.debugger/src/org/netbeans/api/debugger/LazyActionsManagerListener.java --- ../../HG_FRESH/main/api.debugger/src/org/netbeans/api/debugger/LazyActionsManagerListener.java 2008-08-20 02:00:44.000000000 +0200 +++ api.debugger/src/org/netbeans/api/debugger/LazyActionsManagerListener.java 2009-01-25 16:56:12.000000000 +0100 @@ -41,15 +41,28 @@ package org.netbeans.api.debugger; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.Map; + +import org.netbeans.debugger.registry.ContextAwareServiceHandler; +import org.netbeans.spi.debugger.ContextAwareSupport; +import org.netbeans.spi.debugger.ContextAwareService; +import org.netbeans.spi.debugger.ContextProvider; + /** * This {@link ActionsManagerListener} modification is designed to be - * registerred in "META-INF/debugger/". + * registerred in "META-INF/debugger/", or preferrably via the + * {@link Registration} annotation. * LazyActionsManagerListener should be registerred for some concrete - * {@link DebuggerEngine} (use - * "META-INF/debugger//LazyActionsManagerListener"), or - * for global {@link ActionsManager} (use - * "META-INF/debugger/LazyActionsManagerListener"). + * {@link DebuggerEngine} - use "" as a path of the + * annotation, or create + * "META-INF/debugger//LazyActionsManagerListener" file. + * For global {@link ActionsManager} (do not use the path parameter, or use + * "META-INF/debugger/LazyActionsManagerListener" file. * New instance of LazyActionsManagerListener implementation is loaded * when the new instance of {@link ActionsManager} is created, and its registerred * automatically to all properties returned by {@link #getProperties}. @@ -70,4 +83,59 @@ * @return list of properties this listener is listening on */ public abstract String[] getProperties (); + + /** + * Declarative registration of a LazyActionsManagerListener implementation. + * By marking the implementation class with this annotation, + * you automatically register that implementation for use by debugger. + * The class must be public and have a public constructor which takes + * no arguments or takes {@link ContextProvider} as an argument. + * @since 1.16 + */ + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + /** + * An optional path to register this implementation in. + * Usually the "". + */ + String path() default ""; + + } + + static class ContextAware extends LazyActionsManagerListener implements ContextAwareService { + + private String serviceName; + + private ContextAware(String serviceName) { + this.serviceName = serviceName; + } + + public LazyActionsManagerListener forContext(ContextProvider context) { + return (LazyActionsManagerListener) ContextAwareSupport.createInstance(serviceName, context); + } + + @Override + protected void destroy() { + throw new UnsupportedOperationException("Not supported."); + } + + @Override + public String[] getProperties() { + throw new UnsupportedOperationException("Not supported."); + } + + /** + * Creates instance of ContextAwareService based on layer.xml + * attribute values + * + * @param attrs attributes loaded from layer.xml + * @return new ContextAwareService instance + */ + static ContextAwareService createService(Map attrs) throws ClassNotFoundException { + String serviceName = (String) attrs.get(ContextAwareServiceHandler.SERVICE_NAME); + return new LazyActionsManagerListener.ContextAware(serviceName); + } + + } } diff -u -N -r ../../HG_FRESH/main/api.debugger/src/org/netbeans/api/debugger/Lookup.java api.debugger/src/org/netbeans/api/debugger/Lookup.java --- ../../HG_FRESH/main/api.debugger/src/org/netbeans/api/debugger/Lookup.java 2009-01-14 13:37:51.000000000 +0100 +++ api.debugger/src/org/netbeans/api/debugger/Lookup.java 2009-01-25 13:21:30.000000000 +0100 @@ -68,13 +68,19 @@ import java.util.logging.Level; import java.util.logging.Logger; +import org.netbeans.spi.debugger.ContextAwareService; +import org.netbeans.spi.debugger.ContextAwareSupport; import org.netbeans.spi.debugger.ContextProvider; import org.openide.modules.ModuleInfo; import org.openide.util.Exceptions; +import org.openide.util.Lookup.Item; import org.openide.util.LookupEvent; +import org.openide.util.LookupListener; import org.openide.util.RequestProcessor; import org.openide.util.WeakListeners; import org.openide.util.WeakSet; +import org.openide.util.lookup.Lookups; +import org.openide.util.Lookup.Result; /** @@ -147,7 +153,7 @@ if (l2 instanceof Compound) ((Compound) l2).setContext (context); if (l2 instanceof MetaInf) ((MetaInf) l2).setContext (context); } - + private class CompoundLookupList extends LookupList implements Customizer, PropertyChangeListener { @@ -227,6 +233,7 @@ MetaInf (String rootFolder) { + if (rootFolder != null && rootFolder.length() == 0) rootFolder = null; this.rootFolder = rootFolder; moduleLookupResult = org.openide.util.Lookup.getDefault().lookupResult(ModuleInfo.class); //System.err.println("\nModules = "+moduleLookupResult.allInstances().size()+"\n"); @@ -251,9 +258,11 @@ private List list(String folder, Class service) { String name = service.getName (); - String resourceName = "META-INF/debugger/" + - ((rootFolder == null) ? "" : rootFolder + "/") + - ((folder == null) ? "" : folder + "/") + + String pathResourceName = "debugger/" + + ((rootFolder == null) ? "" : rootFolder + "/") + + ((folder == null) ? "" : folder + "/"); + String resourceName = "META-INF/" + + pathResourceName + name; synchronized(registrationCache) { List l = registrationCache.get(resourceName); @@ -265,6 +274,17 @@ } } + private org.openide.util.Lookup lookupForPath(String folder) { + String pathResourceName = "Debugger/" + + ((rootFolder == null) ? "" : rootFolder + "/") + + ((folder == null) ? "" : folder + "/"); + return new PathLookup(pathResourceName); + } + + private Result listLookup(String folder, Class service) { + return lookupForPath(folder).lookupResult(service); + } + private static Set getHiddenClassNames(List l) { Set s = null; int i, k = l.size (); @@ -319,97 +339,6 @@ throw new InternalError ("Can not read from Meta-inf!"); } - private Object createInstance (String service) { - try { - ClassLoader cl = org.openide.util.Lookup.getDefault().lookup(ClassLoader.class); - String method = null; - if (service.endsWith("()")) { - int lastdot = service.lastIndexOf('.'); - if (lastdot < 0) { - Exceptions.printStackTrace( - new IllegalStateException("Bad service - dot before method name is missing: " + - "'" + service + "'.")); - return null; - } - method = service.substring(lastdot + 1, service.length() - 2).trim(); - service = service.substring(0, lastdot); - } - Class cls = cl.loadClass (service); - - Object o = null; - if (method != null) { - Method m = null; - if (context != null) { - try { - m = cls.getDeclaredMethod(method, new Class[] { Lookup.class }); - } catch (NoSuchMethodException nsmex) {} - } - if (m == null) { - try { - m = cls.getDeclaredMethod(method, new Class[] { }); - } catch (NoSuchMethodException nsmex) {} - } - if (m != null) { - o = m.invoke(null, (m.getParameterTypes().length == 0) - ? new Object[] {} : new Object[] { context }); - } - } - if (o == null && context != null) { - Constructor[] cs = cls.getConstructors (); - int i, k = cs.length; - for (i = 0; i < k; i++) { - Constructor c = cs [i]; - if (c.getParameterTypes ().length != 1) continue; - try { - o = c.newInstance (new Object[] {context}); - } catch (IllegalAccessException e) { - if (verbose) { - System.out.println("\nservice: " + service); - e.printStackTrace (); - } - } catch (IllegalArgumentException e) { - if (verbose) { - System.out.println("\nservice: " + service); - e.printStackTrace (); - } - } - } - } - if (o == null) - o = cls.newInstance (); - if (verbose) - System.out.println("\nR instance " + o + - " created"); - return o; - } catch (ClassNotFoundException e) { - Exceptions.printStackTrace( - Exceptions.attachMessage( - e, - "The service "+service+" not found.")); - } catch (InstantiationException e) { - Exceptions.printStackTrace( - Exceptions.attachMessage( - e, - "The service "+service+" can not be instantiated.")); - } catch (IllegalAccessException e) { - Exceptions.printStackTrace( - Exceptions.attachMessage( - e, - "The service "+service+" can not be accessed.")); - } catch (InvocationTargetException ex) { - Exceptions.printStackTrace( - Exceptions.attachMessage( - ex, - "The service "+service+" can not be created.")); - } catch (ExceptionInInitializerError ex) { - Exceptions.printStackTrace( - Exceptions.attachMessage( - ex, - "The service "+service+" can not be initialized.")); - } - return null; - } - private void listenOn(ClassLoader cl) { synchronized(moduleChangeListeners) { if (!moduleChangeListeners.containsKey(cl)) { @@ -447,7 +376,7 @@ } pcs.firePropertyChange("PROP_CACHE", null, null); // NOI18N } - + private final class ModuleChangeListener implements PropertyChangeListener, org.openide.util.LookupListener { private ClassLoader cl; @@ -580,40 +509,75 @@ public int notifyUnloadOrder = 0; public MetaInfLookupList(String folder, Class service) { - this(list(folder, service), service); + this(list(folder, service), listLookup(folder, service), service); this.folder = folder; } - private MetaInfLookupList(List l, Class service) { - this(l, getHiddenClassNames(l), service); + private MetaInfLookupList(List l, Result lr, Class service) { + this(l, lr, getHiddenClassNames(l), service); } - private MetaInfLookupList(List l, Set s, Class service) { + private MetaInfLookupList(List l, Result lr, Set s, Class service) { super(s); assert service != null; this.service = service; - fillInstances(l, s); + fillInstances(l, lr, s); listenOnDisabledModules(); } - private void fillInstances(List l, Set s) { + private void fillInstances(List l, Result lr, Set s) { for (String className : l) { if (className.endsWith(HIDDEN)) continue; if (s != null && s.contains (className)) continue; - Object instance = null; - synchronized(instanceCache) { - instance = instanceCache.get (className); - } - if (instance != null) { - try { - add(service.cast(instance), className); - } catch (ClassCastException cce) { - Logger.getLogger(Lookup.class.getName()).log(Level.WARNING, null, cce); - } - listenOn(instance.getClass().getClassLoader()); - } else if (checkClassName(className)) { - add(new LazyInstance(service, className), className); - } + fillClassInstance(className); + } + for (Item li : lr.allItems()) { + // TODO: We likely do not have the Item.getId() defined correctly. + // We have to check the ContextAwareService.serviceID() + String serviceName = getServiceName(li.getId()); + if (s != null && s.contains (serviceName)) continue; + add(new LazyInstance(service, li)); + } + /* + for (Object lri : lr.allInstances()) { + if (lri instanceof ContextAwareService) { + String className = ((ContextAwareService) lri).serviceName(); + if (s != null && s.contains (className)) continue; + fillClassInstance(className); + } + } + */ + } + + private String getServiceName(String itemId) { + int i = itemId.lastIndexOf('/'); + if (i < 0) i = 0; + else i++; // Skip '/' + String serviceName = itemId.substring(i); + serviceName = serviceName.replace('-', '.'); + try { + org.openide.util.Lookup.getDefault().lookup(ClassLoader.class).loadClass(serviceName); + } catch (ClassNotFoundException ex) { + // Not a class, likely a method call + serviceName = serviceName + "()"; + } + return serviceName; + } + + private void fillClassInstance(String className) { + Object instance = null; + synchronized(instanceCache) { + instance = instanceCache.get (className); + } + if (instance != null) { + try { + add(service.cast(instance), className); + } catch (ClassCastException cce) { + Logger.getLogger(Lookup.class.getName()).log(Level.WARNING, null, cce); + } + listenOn(instance.getClass().getClassLoader()); + } else if (checkClassName(className)) { + add(new LazyInstance(service, className), className); } } @@ -645,9 +609,10 @@ // can sync on it clear(); List l = list(folder, service); + Result lr = listLookup(folder, service); Set s = getHiddenClassNames(l); hiddenClassNames = s; - fillInstances(l, s); + fillInstances(l, lr, s); firePropertyChange(); } @@ -704,25 +669,43 @@ } private class LazyInstance extends LookupLazyEntry { + private String className; private Class service; + Item lookupItem; + public LazyInstance(Class service, String className) { this.service = service; this.className = className; } + public LazyInstance(Class service, Item lookupItem) { + this.service = service; + this.lookupItem = lookupItem; + } + private final Object instanceCreationLock = new Object(); protected T getEntry() { Object instance = null; - synchronized (instanceCreationLock) { - synchronized(instanceCache) { - instance = instanceCache.get (className); - } - if (instance == null) { - instance = createInstance (className); - synchronized (instanceCache) { - instanceCache.put (className, instance); + if (lookupItem != null) { + instance = lookupItem.getInstance(); + if (instance instanceof ContextAwareService) { + ContextAwareService cas = (ContextAwareService) instance; + instance = cas.forContext(Lookup.MetaInf.this.context); + lookupItem = null; + } + } + if (instance == null) { + synchronized (instanceCreationLock) { + synchronized(instanceCache) { + instance = instanceCache.get (className); + } + if (instance == null) { + instance = ContextAwareSupport.createInstance (className, Lookup.MetaInf.this.context); + synchronized (instanceCache) { + instanceCache.put (className, instance); + } } } } @@ -841,5 +824,5 @@ } } - + } diff -u -N -r ../../HG_FRESH/main/api.debugger/src/org/netbeans/api/debugger/PathLookup.java api.debugger/src/org/netbeans/api/debugger/PathLookup.java --- ../../HG_FRESH/main/api.debugger/src/org/netbeans/api/debugger/PathLookup.java 1970-01-01 01:00:00.000000000 +0100 +++ api.debugger/src/org/netbeans/api/debugger/PathLookup.java 2009-01-25 12:57:08.000000000 +0100 @@ -0,0 +1,277 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger; + +import java.util.Collection; +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.util.Set; + +import org.openide.util.Lookup.Item; +import org.openide.util.Lookup.Result; +import org.openide.util.LookupListener; +import org.openide.util.lookup.Lookups; + +/** + * + * @author Martin Entlicher + */ +class PathLookup extends org.openide.util.Lookup { + + private org.openide.util.Lookup delegate; + private String path; + + PathLookup(String path) { + this.delegate = Lookups.forPath(path); + this.path = path; + } + + @Override + public T lookup(Class clazz) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Result lookup(Template template) { + return resultJustForPath(delegate.lookup(template)); + } + + @Override + public Collection lookupAll(Class clazz) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Item lookupItem(Template template) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Result lookupResult(Class clazz) { + return resultJustForPath(delegate.lookupResult(clazz)); + } + + private Result resultJustForPath(Result result) { + int l = path.length() + 1; + int count = 0; + Collection> allItems = result.allItems(); + for (Item it : allItems) { + String filePath = it.getId(); + assert filePath.startsWith(path) : "File path '"+filePath+"' does not start with searched path '"+path+"'"; + if (filePath.indexOf('/', l) > 0) { + // This and further items are from a different folder + // We have to return a restricted result + break; + } + count++; + } + if (count < allItems.size()) { + return new PathLookupResult(result, count); + } + return result; + } + + static class PathLookupResult extends Result { + + private Result orig; + private int n; + + PathLookupResult(Result orig, int n) { + this.orig = orig; + this.n = n; + } + + @Override + public void addLookupListener(LookupListener l) { + orig.addLookupListener(l); + } + + @Override + public void removeLookupListener(LookupListener l) { + orig.removeLookupListener(l); + } + + @Override + public Collection allInstances() { + return new PathLookupCollection(orig.allInstances(), n); + } + + @Override + public Set> allClasses() { + return new PathLookupSet(orig.allClasses(), n); + } + + @Override + public Collection> allItems() { + return new PathLookupCollection(orig.allItems(), n); + } + + private static class PathLookupCollection implements Collection { + + private Collection delegate; + private int n; + + PathLookupCollection(Collection delegate, int n) { + this.delegate = delegate; + this.n = n; + } + + public int size() { + return n; + } + + public boolean isEmpty() { + return n == 0; + } + + public boolean contains(Object o) { + Iterator it = iterator(); + for (int i = 0; i < n; i++) { + Object e = it.next(); + if (o == e || o != null && o.equals(e)) { + return true; + } + } + return false; + } + + public Iterator iterator() { + return new PathLookupIterator(delegate.iterator(), n); + } + + public Object[] toArray() { + Object[] arr = new Object[n]; + Iterator it = iterator(); + for (int i = 0; i < n; i++) { + arr[i] = it.next(); + } + return arr; + } + + public T[] toArray(T[] a) { + if (a.length < n) { + a = (T[]) java.lang.reflect.Array. + newInstance(a.getClass().getComponentType(), n); + } + System.arraycopy(toArray(), 0, a, 0, n); + if (a.length > n) { + a[n] = null; + } + return a; + } + + public boolean add(IT o) { + throw new UnsupportedOperationException("Not supported."); + } + + public boolean remove(Object o) { + throw new UnsupportedOperationException("Not supported."); + } + + public boolean containsAll(Collection c) { + for (Iterator it = c.iterator(); it.hasNext(); ) { + if (!contains(it.next())) { + return false; + } + } + return true; + } + + public boolean addAll(Collection c) { + throw new UnsupportedOperationException("Not supported."); + } + + public boolean removeAll(Collection c) { + throw new UnsupportedOperationException("Not supported."); + } + + public boolean retainAll(Collection c) { + throw new UnsupportedOperationException("Not supported."); + } + + public void clear() { + delegate.clear(); + } + + } + + private static class PathLookupSet extends PathLookupCollection implements Set { + + PathLookupSet(Set delegate, int n) { + super(delegate, n); + } + + } + + + private static class PathLookupIterator implements Iterator { + + private int i; + private Iterator delegate; + private int n; + + PathLookupIterator (Iterator delegate, int n) { + this.delegate = delegate; + this.n = n; + this.i = 0; + } + + public boolean hasNext() { + return i < n; + } + + public IIT next() { + if (i < n) { + i++; + return delegate.next(); + } else { + throw new NoSuchElementException("Index = "+i+", size = "+n); + } + } + + public void remove() { + throw new UnsupportedOperationException("Not supported."); + } + + } + + } + +} diff -u -N -r ../../HG_FRESH/main/api.debugger/src/org/netbeans/debugger/registry/ContextAwareServiceHandler.java api.debugger/src/org/netbeans/debugger/registry/ContextAwareServiceHandler.java --- ../../HG_FRESH/main/api.debugger/src/org/netbeans/debugger/registry/ContextAwareServiceHandler.java 1970-01-01 01:00:00.000000000 +0100 +++ api.debugger/src/org/netbeans/debugger/registry/ContextAwareServiceHandler.java 2009-01-23 21:40:20.000000000 +0100 @@ -0,0 +1,162 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.debugger.registry; + +import org.netbeans.spi.debugger.ContextAwareSupport; +import org.netbeans.spi.debugger.ContextAwareService; +import java.lang.ref.WeakReference; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; +import java.util.WeakHashMap; +import org.netbeans.spi.debugger.ContextProvider; +import org.netbeans.spi.debugger.DebuggerServiceRegistration; +import org.openide.util.Lookup; + +/** + * Handler of context aware services that implement one or more interface. + * The services are registered through {@link DebuggerServiceRegistration} annotation. + * + * This handler guarantees that it creates only one service for given context and given set of interfaces. + * Method {@link ContextAwareService#forContext(org.netbeans.spi.debugger.ContextProvider)} + * returns the instance of the actual registered class. However, if necessary, + * this can be changed to return another proxy implementation, that will delegate + * to an instance of the actual registered class. This will allow to mask some + * methods with attributes and also can prevent from too early class loading. + * + * @author Martin Entlicher + */ +public class ContextAwareServiceHandler implements InvocationHandler { + + public static final String SERVICE_NAME = "serviceName"; // NOI18N + public static final String SERVICE_CLASSES = "serviceClasses"; // NOI18N + + private String serviceName; + private Class[] serviceClasses; + private Map methodValues; + //private ContextProvider context; + private Object delegate; + + private Map contextInstances = new WeakHashMap(); + private WeakReference noContextInstance = new WeakReference(null); + + public ContextAwareServiceHandler(String serviceName, Class[] serviceClasses, + Map methodValues) { + this(serviceName, serviceClasses, methodValues, null); + } + + private ContextAwareServiceHandler(String serviceName, Class[] serviceClasses, + Map methodValues, ContextProvider context) { + this.serviceName = serviceName; + this.serviceClasses = serviceClasses; + this.methodValues = methodValues; + //this.context = context; + } + + /* + private synchronized Object getDelegate() { + if (delegate == null) { + delegate = ContextAwareSupport.createInstance(serviceName, context); + } + return delegate; + } + */ + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + String methodName = method.getName(); + if (methodName.equals("forContext")) { + if (args.length != 1) { + throw new IllegalArgumentException("Have "+args.length+" arguments, expecting one argument."); + } + if (!(args[0] == null || args[0] instanceof ContextProvider)) { + throw new IllegalArgumentException("Argument "+args[0]+" is not an instance of ContextProvider."); + } + ContextProvider context = (ContextProvider) args[0]; + /*if (context == this.context) { + return proxy; + }*/ + synchronized (this) { + Object instance; + if (context == null) { + instance = noContextInstance.get(); + } else { + instance = contextInstances.get(context); + } + if (instance == null) { + instance = ContextAwareSupport.createInstance(serviceName, context); + if (context == null) { + noContextInstance = new WeakReference(instance); + } else { + contextInstances.put(context, instance); + } + } + return instance; + } + /* If total laziness is necessary: + ClassLoader cl = Lookup.getDefault().lookup(ClassLoader.class); + return Proxy.newProxyInstance( + cl, + serviceClasses,//new Class[] { serviceClass }, + new ContextAwareServiceHandler(serviceName, serviceClasses, methodValues, context)); + */ + //} else if (methodValues.containsKey(methodName) && args.length == 0) { + // return methodValues.get(methodName); + } else { + /* + try { + return method.invoke(getDelegate(), args); + } catch (IllegalArgumentException exc) { + throw new UnsupportedOperationException( + "Method "+method.getName()+ // NOI18N + " with arguments "+java.util.Arrays.asList(args)+ // NOI18N + " can not be called on this virtual object!", exc); // NOI18N + } + */ + throw new UnsupportedOperationException( + "Method "+method.getName()+ // NOI18N + " with arguments "+java.util.Arrays.asList(args)+ // NOI18N + " can not be called on this virtual object!"); // NOI18N + } + } + +} diff -u -N -r ../../HG_FRESH/main/api.debugger/src/org/netbeans/debugger/registry/DebuggerProcessor.java api.debugger/src/org/netbeans/debugger/registry/DebuggerProcessor.java --- ../../HG_FRESH/main/api.debugger/src/org/netbeans/debugger/registry/DebuggerProcessor.java 1970-01-01 01:00:00.000000000 +0100 +++ api.debugger/src/org/netbeans/debugger/registry/DebuggerProcessor.java 2009-01-23 21:50:25.000000000 +0100 @@ -0,0 +1,299 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ + +package org.netbeans.debugger.registry; + +import java.util.Map; +import java.util.Set; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.MirroredTypeException; +import javax.lang.model.type.NoType; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; + +import org.netbeans.api.debugger.LazyActionsManagerListener; +import org.netbeans.spi.debugger.ActionsProvider; +import org.netbeans.spi.debugger.DebuggerEngineProvider; +import org.netbeans.spi.debugger.DebuggerServiceRegistration; +import org.netbeans.spi.debugger.SessionProvider; +import org.openide.filesystems.annotations.LayerBuilder.File; +import org.openide.filesystems.annotations.LayerGeneratingProcessor; +import org.openide.filesystems.annotations.LayerGenerationException; +import org.openide.util.lookup.ServiceProvider; + +/** Processor to hide all the complexities of settings layer registration. + * + * @author Martin Entlicher + */ +@ServiceProvider(service=Processor.class) +@SupportedSourceVersion(SourceVersion.RELEASE_6) +@SupportedAnnotationTypes({"org.netbeans.spi.debugger.ActionsProvider.Registration", //NOI18N + "org.netbeans.spi.debugger.DebuggerEngineProvider.Registration", //NOI18N + "org.netbeans.spi.debugger.SessionProvider.Registration", //NOI18N + "org.netbeans.api.debugger.LazyActionsManagerListener.Registration", //NOI18N + "org.netbeans.spi.debugger.DebuggerServiceRegistration" //NOI18N + }) +public class DebuggerProcessor extends LayerGeneratingProcessor { + + + @Override + protected boolean handleProcess( + Set annotations, + RoundEnvironment env + ) throws LayerGenerationException { + if (env.processingOver()) { + return false; + } + + int cnt = 0; + for (Element e : env.getElementsAnnotatedWith(ActionsProvider.Registration.class)) { + ActionsProvider.Registration reg = e.getAnnotation(ActionsProvider.Registration.class); + + final String path = reg.path(); + handleProviderRegistrationInner(e, ActionsProvider.class, path); + //layer(e).instanceFile("Debugger/"+path, null, ActionsProvider.class). + // stringvalue("serviceName", instantiableClassOrMethod(e)). + // stringvalue("serviceClass", ActionsProvider.class.getName()). + // methodvalue("instanceCreate", "org.netbeans.debugger.registry.ActionsProviderContextAware", "createService"). + // write(); + cnt++; + } + for (Element e : env.getElementsAnnotatedWith(LazyActionsManagerListener.Registration.class)) { + LazyActionsManagerListener.Registration reg = e.getAnnotation(LazyActionsManagerListener.Registration.class); + + final String path = reg.path(); + handleProviderRegistrationInner(e, LazyActionsManagerListener.class, path); + cnt++; + } + for (Element e : env.getElementsAnnotatedWith(DebuggerEngineProvider.Registration.class)) { + DebuggerEngineProvider.Registration reg = e.getAnnotation(DebuggerEngineProvider.Registration.class); + + final String path = reg.path(); + handleProviderRegistrationInner(e, DebuggerEngineProvider.class, path); + cnt++; + } + for (Element e : env.getElementsAnnotatedWith(SessionProvider.Registration.class)) { + SessionProvider.Registration reg = e.getAnnotation(SessionProvider.Registration.class); + + final String path = reg.path(); + handleProviderRegistrationInner(e, SessionProvider.class, path); + cnt++; + } + for (Element e : env.getElementsAnnotatedWith(DebuggerServiceRegistration.class)) { + DebuggerServiceRegistration reg = e.getAnnotation(DebuggerServiceRegistration.class); + + final String path = reg.path(); + // Class[] classes = reg.types(); - Cant NOT do that, classes are not created at compile time. + // e.getAnnotationMirrors() - use this not to generate MirroredTypeException + String classNames = null; + for (AnnotationMirror am : e.getAnnotationMirrors()) { + if (am.getAnnotationType().toString().equals(DebuggerServiceRegistration.class.getName())) { + Map elementValues = + am.getElementValues(); + //System.err.println("am:\n elementValues = "+elementValues); + for (ExecutableElement ee : elementValues.keySet()) { + if (ee.getSimpleName().contentEquals("types")) { // NOI18N + classNames = elementValues.get(ee).toString(); + } + } + } + } + //System.err.println("classNames before translation = "+classNames); + classNames = translateClassNames(classNames); + //System.err.println("classNames after translation = "+classNames); + /* + Class[] classes; + String classNames; + try { + classes = reg.types(); + //className = clazz.getName(); + classNames = null; + } catch (MirroredTypeException mtex) { + TypeMirror tm = mtex.getTypeMirror(); + classes = null; + classNames = tm.toString(); + } + */ + layer(e).instanceFile("Debugger/"+path, null, null). + stringvalue(ContextAwareServiceHandler.SERVICE_NAME, instantiableClassOrMethod(e)). + stringvalue(ContextAwareServiceHandler.SERVICE_CLASSES, classNames). + methodvalue("instanceCreate", "org.netbeans.spi.debugger.ContextAwareSupport", "createService"). + write(); + cnt++; + } + return cnt == annotations.size(); + } + + private void handleProviderRegistration(Element e, Class providerClass, String path) throws IllegalArgumentException, LayerGenerationException { + String className = instantiableClassOrMethod(e); + if (!isClassOf(e, providerClass)) { + throw new IllegalArgumentException("Annotated element "+e+" is not an instance of " + providerClass); + } + layer(e).instanceFile("Debugger/"+path, null, providerClass). + stringvalue("serviceName", className). + stringvalue("serviceClass", providerClass.getName()). + methodvalue("instanceCreate", "org.netbeans.debugger.registry."+providerClass.getSimpleName()+"ContextAware", "createService"). + write(); + } + + private void handleProviderRegistrationInner(Element e, Class providerClass, String path) throws IllegalArgumentException, LayerGenerationException { + String className = instantiableClassOrMethod(e); + if (!isClassOf(e, providerClass)) { + throw new IllegalArgumentException("Annotated element "+e+" is not an instance of " + providerClass); + } + layer(e).instanceFile("Debugger/"+path, null, providerClass). + stringvalue("serviceName", className). + stringvalue("serviceClass", providerClass.getName()). + methodvalue("instanceCreate", providerClass.getName()+"$ContextAware", "createService"). + write(); + } + + private boolean isClassOf(Element e, Class providerClass) { + TypeElement te = (TypeElement) e; + TypeMirror superType = te.getSuperclass(); + if (superType.getKind().equals(TypeKind.NONE)) { + return false; + } else { + e = ((DeclaredType) superType).asElement(); + String clazz = processingEnv.getElementUtils().getBinaryName((TypeElement) e).toString(); + if (clazz.equals(providerClass.getName())) { + return true; + } else { + return isClassOf(e, providerClass); + } + } + } + + private static File commaSeparated(File f, String[] arr) { + if (arr.length == 0) { + return f; + } + + StringBuilder sb = new StringBuilder(); + String sep = ""; + for (String s : arr) { + sb.append(sep); + sb.append(s); + sep = ","; + } + return f.stringvalue("xmlproperties.ignoreChanges", sb.toString()); + } + + private String instantiableClassOrMethod(Element e) throws IllegalArgumentException, LayerGenerationException { + switch (e.getKind()) { + case CLASS: { + String clazz = processingEnv.getElementUtils().getBinaryName((TypeElement) e).toString(); + if (e.getModifiers().contains(Modifier.ABSTRACT)) { + throw new LayerGenerationException(clazz + " must not be abstract", e); + } + { + boolean hasDefaultCtor = false; + for (ExecutableElement constructor : ElementFilter.constructorsIn(e.getEnclosedElements())) { + if (constructor.getParameters().isEmpty()) { + hasDefaultCtor = true; + break; + } + } + if (!hasDefaultCtor) { + throw new LayerGenerationException(clazz + " must have a no-argument constructor", e); + } + } + /*propType = processingEnv.getElementUtils().getTypeElement("java.util.Properties").asType(); + if ( + m.getParameters().size() == 1 && + m.getSimpleName().contentEquals("writeProperties") && + m.getParameters().get(0).asType().equals(propType) && + m.getReturnType().getKind() == TypeKind.VOID + ) { + hasWrite = true; + } + } + * */ + return clazz; + } + default: + throw new IllegalArgumentException("Annotated element is not loadable as an instance: " + e); + } + } + + /** + * Translates "{org.MyClass1.class, org.MyClass2.class, ... }" to + * "org.MyClass1, org.MyClass2, ..." + * @param classNames + * @return comma-separated class names + */ + private String translateClassNames(String classNames) { + classNames = classNames.substring(1, classNames.length() - 1).trim(); + StringBuilder builder = new StringBuilder(); + int i1 = 0; + int i2; + while ((i2 = classNames.indexOf(',', i1)) > 0) { + if (i1 > 0) builder.append(','); + builder.append(translateClass(classNames.substring(i1, i2).trim())); + i1 = i2 + 1; + } + if (i1 > 0) builder.append(','); + builder.append(translateClass(classNames.substring(i1).trim())); + + return builder.toString(); + } + + private String translateClass(String className) { + if (className.endsWith(".class")) { + className = className.substring(0, className.length() - ".class".length()); + } + TypeElement type = processingEnv.getElementUtils().getTypeElement(className); + //System.err.println("translateClass("+className+") type = "+type); + return processingEnv.getElementUtils().getBinaryName(type).toString(); + } +} diff -u -N -r ../../HG_FRESH/main/api.debugger/src/org/netbeans/spi/debugger/ActionsProvider.java api.debugger/src/org/netbeans/spi/debugger/ActionsProvider.java --- ../../HG_FRESH/main/api.debugger/src/org/netbeans/spi/debugger/ActionsProvider.java 2008-08-20 02:00:44.000000000 +0200 +++ api.debugger/src/org/netbeans/spi/debugger/ActionsProvider.java 2009-01-25 16:58:49.000000000 +0100 @@ -41,7 +41,14 @@ package org.netbeans.spi.debugger; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.Map; import java.util.Set; +import org.netbeans.debugger.registry.ContextAwareServiceHandler; +import org.netbeans.spi.debugger.ContextAwareSupport; import org.openide.util.RequestProcessor; /** @@ -109,6 +116,98 @@ } }); } + + /** + * Declarative registration of an ActionsProvider implementation. + * By marking the implementation class with this annotation, + * you automatically register that implementation for use by debugger. + * The class must be public and have a public constructor which takes + * no arguments or takes {@link ContextProvider} as an argument. + * @since 1.16 + */ + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + /** + * An optional path to register this implementation in. + */ + String path() default ""; + + } + + static class ContextAware extends ActionsProvider implements ContextAwareService { + + private String serviceName; + private ContextProvider context; + private ActionsProvider delegate; + + private ContextAware(String serviceName) { + this.serviceName = serviceName; + } + + private ContextAware(String serviceName, ContextProvider context) { + this.serviceName = serviceName; + this.context = context; + } + + private synchronized ActionsProvider getDelegate() { + if (delegate == null) { + delegate = (ActionsProvider) ContextAwareSupport.createInstance(serviceName, context); + } + return delegate; + } + + @Override + public Set getActions() { + return getDelegate().getActions(); + } + + @Override + public void doAction(Object action) { + getDelegate().doAction(action); + } + + @Override + public void postAction(Object action, Runnable actionPerformedNotifier) { + getDelegate().postAction(action, actionPerformedNotifier); + } + + @Override + public boolean isEnabled(Object action) { + return getDelegate().isEnabled(action); + } + + @Override + public void addActionsProviderListener(ActionsProviderListener l) { + getDelegate().addActionsProviderListener(l); + } + + @Override + public void removeActionsProviderListener(ActionsProviderListener l) { + getDelegate().removeActionsProviderListener(l); + } + + public ActionsProvider forContext(ContextProvider context) { + if (context == this.context) { + return this; + } else { + return new ActionsProvider.ContextAware(serviceName, context); + } + } + + /** + * Creates instance of ContextAwareService based on layer.xml + * attribute values + * + * @param attrs attributes loaded from layer.xml + * @return new ContextAwareService instance + */ + static ContextAwareService createService(Map attrs) throws ClassNotFoundException { + String serviceName = (String) attrs.get(ContextAwareServiceHandler.SERVICE_NAME); + return new ActionsProvider.ContextAware(serviceName); + } + + } } diff -u -N -r ../../HG_FRESH/main/api.debugger/src/org/netbeans/spi/debugger/ContextAwareService.java api.debugger/src/org/netbeans/spi/debugger/ContextAwareService.java --- ../../HG_FRESH/main/api.debugger/src/org/netbeans/spi/debugger/ContextAwareService.java 1970-01-01 01:00:00.000000000 +0100 +++ api.debugger/src/org/netbeans/spi/debugger/ContextAwareService.java 2009-01-25 17:12:20.000000000 +0100 @@ -0,0 +1,81 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.spi.debugger; + +/** + * Instance of registry entry, that delegates to a debugger service, that can be + * context-aware. + * This instances should be registered in layers and created by ContextAwareSupport.createService factory + * method as follows: + * + *
+ *   <folder name="Debugger">
+ *       <file name="MyDebuggerService.instance">
+ *           <attr name="instanceCreate" methodvalue="org.netbeans.spi.debugger.ContextAwareSupport.createService"/>
+ *           <attr name="serviceName" stringvalue="org.netbeans.my_debugger.MyServiceImpl"/>
+ *           <attr name="serviceClass" stringvalue="org.netbeans.debugger.Service"/>
+ *       </file>
+ *   </folder>
+ * + *
+ * + * @author Martin Entlicher + * @since 1.16 + */ +public interface ContextAwareService { + + /** + * Create a debugger service in a context. + * + * @param context the context to create the service with + * @return the debugger service of type T. + */ + T forContext(ContextProvider context); + + /** + * The ID of the service, usually the implementation class name. + * Services can be made hidden by this ID. + * + * @return the session ID + */ + // Lookup.Item.getId() is used instead. + //String serviceID(); + +} diff -u -N -r ../../HG_FRESH/main/api.debugger/src/org/netbeans/spi/debugger/ContextAwareSupport.java api.debugger/src/org/netbeans/spi/debugger/ContextAwareSupport.java --- ../../HG_FRESH/main/api.debugger/src/org/netbeans/spi/debugger/ContextAwareSupport.java 1970-01-01 01:00:00.000000000 +0100 +++ api.debugger/src/org/netbeans/spi/debugger/ContextAwareSupport.java 2009-01-25 17:12:32.000000000 +0100 @@ -0,0 +1,208 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.spi.debugger; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.netbeans.debugger.registry.ContextAwareServiceHandler; +import org.openide.util.Exceptions; +import org.openide.util.Lookup; + +/** + * Support class for context-aware debugger services. + * + * @author Martin Entlicher + * @since 1.16 + */ +public final class ContextAwareSupport { + + private ContextAwareSupport() {} + + /** + * A helper method that creates a context-aware debugger service. + * The service must be a public class with public constructor or a public + * static method. The constructor or method takes + * no arguments or takes {@link ContextProvider} as an argument. + *

+ * This method is typically called by the implementation of {@link ContextAwareService} + * to create an instance with the given context. + * + * @param service The full class name or static method that ends with '()' + * @param context The context with which is the service to be created + * @return The instance of the service with the given context. + * @since 1.16 + */ + public static Object createInstance(String service, ContextProvider context) { + try { + ClassLoader cl = org.openide.util.Lookup.getDefault().lookup(ClassLoader.class); + String method = null; + if (service.endsWith("()")) { + int lastdot = service.lastIndexOf('.'); + if (lastdot < 0) { + Exceptions.printStackTrace( + new IllegalStateException("Bad service - dot before method name is missing: " + + "'" + service + "'.")); + return null; + } + method = service.substring(lastdot + 1, service.length() - 2).trim(); + service = service.substring(0, lastdot); + } + Class cls = cl.loadClass (service); + + Object o = null; + if (method != null) { + Method m = null; + if (context != null) { + try { + m = cls.getDeclaredMethod(method, new Class[] { ContextProvider.class }); + } catch (NoSuchMethodException nsmex) {} + } + if (m == null) { + try { + m = cls.getDeclaredMethod(method, new Class[] { }); + } catch (NoSuchMethodException nsmex) {} + } + if (m != null) { + o = m.invoke(null, (m.getParameterTypes().length == 0) + ? new Object[] {} : new Object[] { context }); + } + } + if (o == null && context != null) { + Constructor[] cs = cls.getConstructors (); + int i, k = cs.length; + for (i = 0; i < k; i++) { + Constructor c = cs [i]; + if (c.getParameterTypes ().length != 1 || + !ContextProvider.class.isAssignableFrom(c.getParameterTypes()[0])) { + continue; + } + try { + o = c.newInstance (new Object[] {context}); + } catch (IllegalAccessException e) { + Exceptions.printStackTrace(Exceptions.attachMessage(e, "service: " + service)); + } catch (IllegalArgumentException e) { + Exceptions.printStackTrace(Exceptions.attachMessage(e, "service: " + service)); + } + } + } + if (o == null) + o = cls.newInstance (); + if (Logger.getLogger(ContextAwareSupport.class.getName()).isLoggable(Level.FINE)) { + Logger.getLogger(ContextAwareSupport.class.getName()).fine("instance "+o+" created."); + } + return o; + } catch (ClassNotFoundException e) { + Exceptions.printStackTrace( + Exceptions.attachMessage( + e, + "The service "+service+" not found.")); + } catch (InstantiationException e) { + Exceptions.printStackTrace( + Exceptions.attachMessage( + e, + "The service "+service+" can not be instantiated.")); + } catch (IllegalAccessException e) { + Exceptions.printStackTrace( + Exceptions.attachMessage( + e, + "The service "+service+" can not be accessed.")); + } catch (InvocationTargetException ex) { + Exceptions.printStackTrace( + Exceptions.attachMessage( + ex, + "The service "+service+" can not be created.")); + } catch (ExceptionInInitializerError ex) { + Exceptions.printStackTrace( + Exceptions.attachMessage( + ex, + "The service "+service+" can not be initialized.")); + } + return null; + } + + /** + * Creates instance of ContextAwareService based on layer.xml + * attribute values + * + * @param attrs attributes loaded from layer.xml + * @return new ContextAwareService instance + */ + static ContextAwareService createService(Map attrs) throws ClassNotFoundException { + String serviceName = (String) attrs.get(ContextAwareServiceHandler.SERVICE_NAME); + String[] serviceClassNames = splitClasses((String) attrs.get(ContextAwareServiceHandler.SERVICE_CLASSES)); + + //Map methodValues = new HashMap(attrs); - MUST NOT DO THAT! Creates a loop initializing the entries from XML + //methodValues.remove(SERVICE_NAME); + //methodValues.remove(SERVICE_CLASS); + + ClassLoader cl = Lookup.getDefault().lookup(ClassLoader.class); + Class[] classes = new Class[serviceClassNames.length + 1]; + classes[0] = ContextAwareService.class; + for (int i = 0; i < serviceClassNames.length; i++) { + classes[i+1] = Class.forName(serviceClassNames[i], true, cl); + } + return (ContextAwareService) + Proxy.newProxyInstance( + cl, + classes, + new ContextAwareServiceHandler(serviceName, classes, Collections.EMPTY_MAP)); + } + + private static String[] splitClasses(String classes) { + ArrayList list = new ArrayList(); + int i1 = 0; + int i2; + while ((i2 = classes.indexOf(',', i1)) > 0) { + list.add(classes.substring(i1, i2).trim()); + i1 = i2 + 1; + } + list.add(classes.substring(i1).trim()); + return list.toArray(new String[] {}); + } + +} diff -u -N -r ../../HG_FRESH/main/api.debugger/src/org/netbeans/spi/debugger/DebuggerEngineProvider.java api.debugger/src/org/netbeans/spi/debugger/DebuggerEngineProvider.java --- ../../HG_FRESH/main/api.debugger/src/org/netbeans/spi/debugger/DebuggerEngineProvider.java 2008-08-20 02:00:44.000000000 +0200 +++ api.debugger/src/org/netbeans/spi/debugger/DebuggerEngineProvider.java 2009-01-25 17:00:15.000000000 +0100 @@ -41,7 +41,15 @@ package org.netbeans.spi.debugger; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.Map; + import org.netbeans.api.debugger.DebuggerEngine; +import org.netbeans.debugger.registry.ContextAwareServiceHandler; +import org.netbeans.spi.debugger.ContextAwareSupport; /** * Creates a new instance of {@link org.netbeans.api.debugger.DebuggerEngine} @@ -88,5 +96,88 @@ * by this instance */ public abstract void setDestructor (DebuggerEngine.Destructor desctuctor); + + /** + * Declarative registration of an DebuggerEngineProvider implementation. + * By marking the implementation class with this annotation, + * you automatically register that implementation for use by debugger. + * The class must be public and have a public constructor which takes + * no arguments or takes {@link ContextProvider} as an argument. + * @since 1.16 + */ + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + /** + * An optional path to register this implementation in. + */ + String path() default ""; + + } + + static class ContextAware extends DebuggerEngineProvider implements ContextAwareService { + + private String serviceName; + private ContextProvider context; + private DebuggerEngineProvider delegate; + + private ContextAware(String serviceName) { + this.serviceName = serviceName; + } + + private ContextAware(String serviceName, ContextProvider context) { + this.serviceName = serviceName; + this.context = context; + } + + private synchronized DebuggerEngineProvider getDelegate() { + if (delegate == null) { + delegate = (DebuggerEngineProvider) ContextAwareSupport.createInstance(serviceName, context); + } + return delegate; + } + + public DebuggerEngineProvider forContext(ContextProvider context) { + if (context == this.context) { + return this; + } else { + return new DebuggerEngineProvider.ContextAware(serviceName, context); + } + } + + @Override + public String[] getLanguages() { + return getDelegate().getLanguages(); + } + + @Override + public String getEngineTypeID() { + return getDelegate().getEngineTypeID(); + } + + @Override + public Object[] getServices() { + return getDelegate().getServices(); + } + + @Override + public void setDestructor(DebuggerEngine.Destructor desctuctor) { + getDelegate().setDestructor(desctuctor); + } + + /** + * Creates instance of ContextAwareService based on layer.xml + * attribute values + * + * @param attrs attributes loaded from layer.xml + * @return new ContextAwareService instance + */ + static ContextAwareService createService(Map attrs) throws ClassNotFoundException { + String serviceName = (String) attrs.get(ContextAwareServiceHandler.SERVICE_NAME); + return new DebuggerEngineProvider.ContextAware(serviceName); + } + + } + } diff -u -N -r ../../HG_FRESH/main/api.debugger/src/org/netbeans/spi/debugger/DebuggerServiceRegistration.java api.debugger/src/org/netbeans/spi/debugger/DebuggerServiceRegistration.java --- ../../HG_FRESH/main/api.debugger/src/org/netbeans/spi/debugger/DebuggerServiceRegistration.java 1970-01-01 01:00:00.000000000 +0100 +++ api.debugger/src/org/netbeans/spi/debugger/DebuggerServiceRegistration.java 2009-01-25 16:50:41.000000000 +0100 @@ -0,0 +1,72 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.spi.debugger; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Declarative registration of debugger service provider implementing a set + * of interfaces. + * By marking an implementation class with this annotation, + * you automatically register that implementation for use by debugger. + * The class must be public and have a public constructor which takes + * no arguments or takes {@link ContextProvider} as an argument. + * @since 1.16 + * + * @author Martin Entlicher + */ +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.TYPE}) +public @interface DebuggerServiceRegistration { + + /** + * An optional path to register this implementation in. + * Usually the session ID. + */ + String path() default ""; + + /** + * The list of interfaces that this class implements and wish to register for. + */ + Class[] types(); +} diff -u -N -r ../../HG_FRESH/main/api.debugger/src/org/netbeans/spi/debugger/SessionProvider.java api.debugger/src/org/netbeans/spi/debugger/SessionProvider.java --- ../../HG_FRESH/main/api.debugger/src/org/netbeans/spi/debugger/SessionProvider.java 2008-08-20 02:00:44.000000000 +0200 +++ api.debugger/src/org/netbeans/spi/debugger/SessionProvider.java 2009-01-25 17:00:57.000000000 +0100 @@ -41,6 +41,15 @@ package org.netbeans.spi.debugger; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.Map; + +import org.netbeans.debugger.registry.ContextAwareServiceHandler; +import org.netbeans.spi.debugger.ContextAwareSupport; + /** * Creates a new instance of {@link org.netbeans.api.debugger.Session} * for some {@link org.netbeans.api.debugger.DebuggerInfo}. @@ -80,5 +89,87 @@ * @return array of services */ public abstract Object[] getServices (); + + /** + * Declarative registration of an SessionProvider implementation. + * By marking the implementation class with this annotation, + * you automatically register that implementation for use by debugger. + * The class must be public and have a public constructor which takes + * no arguments or takes {@link ContextProvider} as an argument. + * @since 1.16 + */ + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + /** + * An optional path to register this implementation in. + */ + String path() default ""; + + } + + static class ContextAware extends SessionProvider implements ContextAwareService { + + private String serviceName; + private ContextProvider context; + private SessionProvider delegate; + + private ContextAware(String serviceName) { + this.serviceName = serviceName; + } + + private ContextAware(String serviceName, ContextProvider context) { + this.serviceName = serviceName; + this.context = context; + } + + private synchronized SessionProvider getDelegate() { + if (delegate == null) { + delegate = (SessionProvider) ContextAwareSupport.createInstance(serviceName, context); + } + return delegate; + } + + public SessionProvider forContext(ContextProvider context) { + if (context == this.context) { + return this; + } else { + return new SessionProvider.ContextAware(serviceName, context); + } + } + + @Override + public String getSessionName() { + return getDelegate().getSessionName(); + } + + @Override + public String getLocationName() { + return getDelegate().getLocationName(); + } + + @Override + public String getTypeID() { + return getDelegate().getTypeID(); + } + + @Override + public Object[] getServices() { + return getDelegate().getServices(); + } + + /** + * Creates instance of ContextAwareService based on layer.xml + * attribute values + * + * @param attrs attributes loaded from layer.xml + * @return new ContextAwareService instance + */ + static ContextAwareService createService(Map attrs) throws ClassNotFoundException { + String serviceName = (String) attrs.get(ContextAwareServiceHandler.SERVICE_NAME); + return new SessionProvider.ContextAware(serviceName); + } + } + } diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/manifest.mf spi.debugger.ui/manifest.mf --- ../../HG_FRESH/main/spi.debugger.ui/manifest.mf 2008-11-18 21:00:41.000000000 +0100 +++ spi.debugger.ui/manifest.mf 2009-01-25 17:38:02.000000000 +0100 @@ -2,6 +2,6 @@ OpenIDE-Module: org.netbeans.spi.debugger.ui/1 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/debugger/ui/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/debugger/resources/mf-layer.xml -OpenIDE-Module-Specification-Version: 2.15 +OpenIDE-Module-Specification-Version: 2.16 OpenIDE-Module-Provides: org.netbeans.spi.debugger.ui OpenIDE-Module-Install: org/netbeans/modules/debugger/ui/DebuggerModule.class diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/nbproject/project.properties spi.debugger.ui/nbproject/project.properties --- ../../HG_FRESH/main/spi.debugger.ui/nbproject/project.properties 2009-01-20 14:20:18.000000000 +0100 +++ spi.debugger.ui/nbproject/project.properties 2009-01-23 22:00:54.000000000 +0100 @@ -41,6 +41,6 @@ test.config.stable.includes=**/ts/*TestSuite.class +cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/nbproject/project.xml spi.debugger.ui/nbproject/project.xml --- ../../HG_FRESH/main/spi.debugger.ui/nbproject/project.xml 2008-09-29 16:42:38.000000000 +0200 +++ spi.debugger.ui/nbproject/project.xml 2009-01-25 17:38:19.000000000 +0100 @@ -52,7 +52,7 @@ 1 - 1.13 + 1.16 diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/ColumnModelContextAware.java spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/ColumnModelContextAware.java --- ../../HG_FRESH/main/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/ColumnModelContextAware.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/ColumnModelContextAware.java 2009-01-25 13:34:11.000000000 +0100 @@ -0,0 +1,193 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.debugger.ui.registry; + +import java.beans.PropertyEditor; +import java.util.Map; + +import org.netbeans.spi.debugger.ContextAwareService; +import org.netbeans.spi.debugger.ContextAwareSupport; +import org.netbeans.spi.debugger.ContextProvider; +import org.netbeans.spi.viewmodel.ColumnModel; + +/** + * + * @author Martin Entlicher + */ +public class ColumnModelContextAware extends ColumnModel implements ContextAwareService { + + private String serviceName; + private ContextProvider context; + private ColumnModel delegate; + + private ColumnModelContextAware(String serviceName) { + this.serviceName = serviceName; + } + + private ColumnModelContextAware(String serviceName, ContextProvider context) { + this.serviceName = serviceName; + this.context = context; + } + + private synchronized ColumnModel getDelegate() { + if (delegate == null) { + delegate = (ColumnModel) ContextAwareSupport.createInstance(serviceName, context); + } + return delegate; + } + + public ColumnModel forContext(ContextProvider context) { + if (context == this.context) { + return this; + } else { + return new ColumnModelContextAware(serviceName, context); + } + } + + @Override + public String getID() { + return getDelegate().getID(); + } + + @Override + public String getDisplayName() { + return getDelegate().getDisplayName(); + } + + @Override + public Class getType() { + return getDelegate().getType(); + } + + @Override + public int getColumnWidth() { + return getDelegate().getColumnWidth(); + } + + @Override + public int getCurrentOrderNumber() { + return getDelegate().getCurrentOrderNumber(); + } + + @Override + public Character getDisplayedMnemonic() { + return getDelegate().getDisplayedMnemonic(); + } + + @Override + public String getNextColumnID() { + return getDelegate().getNextColumnID(); + } + + @Override + public String getPreviuosColumnID() { + return getDelegate().getPreviuosColumnID(); + } + + @Override + public PropertyEditor getPropertyEditor() { + return getDelegate().getPropertyEditor(); + } + + @Override + public String getShortDescription() { + return getDelegate().getShortDescription(); + } + + @Override + public boolean isSortable() { + return getDelegate().isSortable(); + } + + @Override + public boolean isSorted() { + return getDelegate().isSorted(); + } + + @Override + public boolean isSortedDescending() { + return getDelegate().isSortedDescending(); + } + + @Override + public boolean isVisible() { + return getDelegate().isVisible(); + } + + @Override + public void setColumnWidth(int newColumnWidth) { + getDelegate().setColumnWidth(newColumnWidth); + } + + @Override + public void setCurrentOrderNumber(int newOrderNumber) { + getDelegate().setCurrentOrderNumber(newOrderNumber); + } + + @Override + public void setSorted(boolean sorted) { + getDelegate().setSorted(sorted); + } + + @Override + public void setSortedDescending(boolean sortedDescending) { + getDelegate().setSortedDescending(sortedDescending); + } + + @Override + public void setVisible(boolean visible) { + getDelegate().setVisible(visible); + } + + + + /** + * Creates instance of ContextAwareService based on layer.xml + * attribute values + * + * @param attrs attributes loaded from layer.xml + * @return new ContextAwareService instance + */ + static ContextAwareService createService(Map attrs) throws ClassNotFoundException { + String serviceName = (String) attrs.get(DebuggerProcessor.SERVICE_NAME); + return new ColumnModelContextAware(serviceName); + } + +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/DebuggerProcessor.java spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/DebuggerProcessor.java --- ../../HG_FRESH/main/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/DebuggerProcessor.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/DebuggerProcessor.java 2009-01-25 18:15:38.000000000 +0100 @@ -0,0 +1,233 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ + +package org.netbeans.modules.debugger.ui.registry; + +import java.util.Set; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; + +import org.netbeans.spi.debugger.ui.AttachType; +import org.netbeans.spi.debugger.ui.BreakpointType; +import org.netbeans.spi.debugger.ui.ColumnModelRegistration; +import org.netbeans.spi.viewmodel.ColumnModel; + +import org.openide.filesystems.annotations.LayerBuilder.File; +import org.openide.filesystems.annotations.LayerGeneratingProcessor; +import org.openide.filesystems.annotations.LayerGenerationException; +import org.openide.util.lookup.ServiceProvider; + +/** Processor to hide all the complexities of settings layer registration. + * + * @author Martin Entlicher + */ +@ServiceProvider(service=Processor.class) +@SupportedSourceVersion(SourceVersion.RELEASE_6) +@SupportedAnnotationTypes({"org.netbeans.spi.debugger.ui.AttachType.Registration", // NOI18N + "org.netbeans.spi.debugger.ui.BreakpointType.Registration", //NOI18N + "org.netbeans.spi.debugger.ui.ColumnModelRegistration"}) //NOI18N +public class DebuggerProcessor extends LayerGeneratingProcessor { + + public static final String SERVICE_NAME = "serviceName"; // NOI18N + + + @Override + protected boolean handleProcess( + Set annotations, + RoundEnvironment env + ) throws LayerGenerationException { + if (env.processingOver()) { + return false; + } + + int cnt = 0; + for (Element e : env.getElementsAnnotatedWith(AttachType.Registration.class)) { + AttachType.Registration reg = e.getAnnotation(AttachType.Registration.class); + + final String displayName = reg.displayName(); + handleProviderRegistrationDisplayName(e, AttachType.class, displayName); + cnt++; + } + for (Element e : env.getElementsAnnotatedWith(BreakpointType.Registration.class)) { + BreakpointType.Registration reg = e.getAnnotation(BreakpointType.Registration.class); + + final String displayName = reg.displayName(); + handleProviderRegistrationDisplayName(e, BreakpointType.class, displayName); + cnt++; + } + for (Element e : env.getElementsAnnotatedWith(ColumnModelRegistration.class)) { + ColumnModelRegistration reg = e.getAnnotation(ColumnModelRegistration.class); + + final String path = reg.path(); + final int position = reg.position(); + handleProviderRegistration(e, ColumnModel.class, path, position); + cnt++; + } + return cnt == annotations.size(); + } + + private void handleProviderRegistration(Element e, Class providerClass, String path, int position) throws IllegalArgumentException, LayerGenerationException { + String className = instantiableClassOrMethod(e); + if (!isClassOf(e, providerClass)) { + throw new IllegalArgumentException("Annotated element "+e+" is not an instance of " + providerClass); + } + layer(e).instanceFile("Debugger/"+path, null, providerClass). + stringvalue(SERVICE_NAME, className). + stringvalue("serviceClass", providerClass.getName()). + //methodvalue("instanceCreate", providerClass.getName()+"$ContextAware", "createService"). + methodvalue("instanceCreate", "org.netbeans.modules.debugger.ui.registry."+providerClass.getSimpleName()+"ContextAware", "createService"). + intvalue("position", position). + write(); + } + + private void handleProviderRegistrationDisplayName(Element e, Class providerClass, String displayName) throws IllegalArgumentException, LayerGenerationException { + String className = instantiableClassOrMethod(e); + if (!isClassOf(e, providerClass)) { + throw new IllegalArgumentException("Annotated element "+e+" is not an instance of " + providerClass); + } + layer(e).instanceFile("Debugger", null, providerClass). + stringvalue(SERVICE_NAME, className). + stringvalue("serviceClass", providerClass.getName()). + stringvalue("displayName", displayName). // TODO bundleValue + methodvalue("instanceCreate", providerClass.getName()+"$ContextAware", "createService"). + write(); + } + + private boolean isClassOf(Element e, Class providerClass) { + switch (e.getKind()) { + case CLASS: { + TypeElement te = (TypeElement) e; + TypeMirror superType = te.getSuperclass(); + if (superType.getKind().equals(TypeKind.NONE)) { + return false; + } else { + e = ((DeclaredType) superType).asElement(); + String clazz = processingEnv.getElementUtils().getBinaryName((TypeElement) e).toString(); + if (clazz.equals(providerClass.getName())) { + return true; + } else { + return isClassOf(e, providerClass); + } + } + } + case METHOD: { + return true; + } + default: + throw new IllegalArgumentException("Annotated element is not loadable as an instance: " + e); + } + } + + private static File commaSeparated(File f, String[] arr) { + if (arr.length == 0) { + return f; + } + + StringBuilder sb = new StringBuilder(); + String sep = ""; + for (String s : arr) { + sb.append(sep); + sb.append(s); + sep = ","; + } + return f.stringvalue("xmlproperties.ignoreChanges", sb.toString()); + } + + private String instantiableClassOrMethod(Element e) throws IllegalArgumentException, LayerGenerationException { + switch (e.getKind()) { + case CLASS: { + String clazz = processingEnv.getElementUtils().getBinaryName((TypeElement) e).toString(); + if (e.getModifiers().contains(Modifier.ABSTRACT)) { + throw new LayerGenerationException(clazz + " must not be abstract", e); + } + { + boolean hasDefaultCtor = false; + for (ExecutableElement constructor : ElementFilter.constructorsIn(e.getEnclosedElements())) { + if (constructor.getParameters().isEmpty()) { + hasDefaultCtor = true; + break; + } + } + if (!hasDefaultCtor) { + throw new LayerGenerationException(clazz + " must have a no-argument constructor", e); + } + } + /*propType = processingEnv.getElementUtils().getTypeElement("java.util.Properties").asType(); + if ( + m.getParameters().size() == 1 && + m.getSimpleName().contentEquals("writeProperties") && + m.getParameters().get(0).asType().equals(propType) && + m.getReturnType().getKind() == TypeKind.VOID + ) { + hasWrite = true; + } + } + * */ + return clazz; + } + case METHOD: { + ExecutableElement ee = (ExecutableElement) e; + String methodName = ee.getSimpleName().toString(); + String clazz = processingEnv.getElementUtils().getBinaryName((TypeElement) ee.getEnclosingElement()).toString(); + if (!e.getModifiers().contains(Modifier.STATIC)) { + throw new LayerGenerationException(ee + " must be static", e); + } + if (ee.getParameters().size() > 0) { + throw new LayerGenerationException(ee + " must not have any parameters", e); + } + return clazz+"."+methodName+"()"; + } + default: + throw new IllegalArgumentException("Annotated element is not loadable as an instance: " + e); + } + } +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/AttachType.java spi.debugger.ui/src/org/netbeans/spi/debugger/ui/AttachType.java --- ../../HG_FRESH/main/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/AttachType.java 2008-09-23 09:44:26.000000000 +0200 +++ spi.debugger.ui/src/org/netbeans/spi/debugger/ui/AttachType.java 2009-01-25 13:34:37.000000000 +0100 @@ -41,8 +41,18 @@ package org.netbeans.spi.debugger.ui; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.Map; import javax.swing.JComponent; +import org.netbeans.modules.debugger.ui.registry.DebuggerProcessor; +import org.netbeans.spi.debugger.ContextAwareService; +import org.netbeans.spi.debugger.ContextAwareSupport; +import org.netbeans.spi.debugger.ContextProvider; + /** * Support for "Attach ..." dialog. Represents one type of attaching. @@ -52,12 +62,13 @@ public abstract class AttachType { /** - * Provides display name of this Attach Type. Is used as one choice in - * ComboBox. + * TODO * * @return display name of this Attach Type */ - public abstract String getTypeDisplayName (); + public String getTypeDisplayName () { + return null; + } /** * Returns visual customizer for this Attach Type. Customizer can @@ -88,4 +99,75 @@ return null; } + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + String displayName(); + } + + static class ContextAware extends AttachType implements ContextAwareService { + + private String serviceName; + private String displayName; + private ContextProvider context; + private AttachType delegate; + + private ContextAware(String serviceName, String displayName) { + this.serviceName = serviceName; + this.displayName = displayName; + } + + private ContextAware(String serviceName, String displayName, ContextProvider context) { + this.serviceName = serviceName; + this.displayName = displayName; + this.context = context; + } + + private synchronized AttachType getDelegate() { + if (delegate == null) { + delegate = (AttachType) ContextAwareSupport.createInstance(serviceName, context); + } + return delegate; + } + + public AttachType forContext(ContextProvider context) { + if (context == this.context) { + return this; + } else { + return new AttachType.ContextAware(serviceName, displayName, context); + } + } + + @Override + public String getTypeDisplayName() { + if (displayName != null) { + return displayName; + } + return getDelegate().getTypeDisplayName(); + } + + @Override + public JComponent getCustomizer() { + return getDelegate().getCustomizer(); + } + + @Override + public Controller getController() { + return getDelegate().getController(); + } + + /** + * Creates instance of ContextAwareService based on layer.xml + * attribute values + * + * @param attrs attributes loaded from layer.xml + * @return new ContextAwareService instance + */ + static ContextAwareService createService(Map attrs) throws ClassNotFoundException { + String serviceName = (String) attrs.get(DebuggerProcessor.SERVICE_NAME); + String displayName = (String) attrs.get("displayName"); + return new AttachType.ContextAware(serviceName, displayName); + } + } + } \ No newline at end of file diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/BreakpointType.java spi.debugger.ui/src/org/netbeans/spi/debugger/ui/BreakpointType.java --- ../../HG_FRESH/main/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/BreakpointType.java 2008-09-23 09:44:26.000000000 +0200 +++ spi.debugger.ui/src/org/netbeans/spi/debugger/ui/BreakpointType.java 2009-01-25 13:34:05.000000000 +0100 @@ -41,8 +41,18 @@ package org.netbeans.spi.debugger.ui; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.Map; import javax.swing.JComponent; +import org.netbeans.modules.debugger.ui.registry.DebuggerProcessor; +import org.netbeans.spi.debugger.ContextAwareService; +import org.netbeans.spi.debugger.ContextAwareSupport; +import org.netbeans.spi.debugger.ContextProvider; + /** * Support for "New Breakpoint" dialog and Breakpoint Customizer. Represents * one breakpoint type. @@ -60,11 +70,13 @@ public abstract String getCategoryDisplayName (); /** - * Return display name of this breakpoint type (like "Line Breakppoint"). + * TODO * * @return display name of this breakpoint type */ - public abstract String getTypeDisplayName (); + public String getTypeDisplayName () { + return null; + } /** * Returns visual customizer for this breakpoint type. Customizer can @@ -103,4 +115,81 @@ * @return true of this breakpoint type should be default */ public abstract boolean isDefault (); + + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + String displayName(); + } + + static class ContextAware extends BreakpointType implements ContextAwareService { + + private String serviceName; + private String displayName; + private ContextProvider context; + private BreakpointType delegate; + + private ContextAware(String serviceName, String displayName) { + this.serviceName = serviceName; + this.displayName = displayName; + } + + private ContextAware(String serviceName, String displayName, ContextProvider context) { + this.serviceName = serviceName; + this.displayName = displayName; + this.context = context; + } + + private synchronized BreakpointType getDelegate() { + if (delegate == null) { + delegate = (BreakpointType) ContextAwareSupport.createInstance(serviceName, context); + } + return delegate; + } + + public BreakpointType forContext(ContextProvider context) { + if (context == this.context) { + return this; + } else { + return new BreakpointType.ContextAware(serviceName, displayName, context); + } + } + + @Override + public String getTypeDisplayName() { + if (displayName != null) { + return displayName; + } + return getDelegate().getTypeDisplayName(); + } + + @Override + public JComponent getCustomizer() { + return getDelegate().getCustomizer(); + } + + @Override + public String getCategoryDisplayName() { + return getDelegate().getCategoryDisplayName(); + } + + @Override + public boolean isDefault() { + return getDelegate().isDefault(); + } + + /** + * Creates instance of ContextAwareService based on layer.xml + * attribute values + * + * @param attrs attributes loaded from layer.xml + * @return new ContextAwareService instance + */ + static ContextAwareService createService(Map attrs) throws ClassNotFoundException { + String serviceName = (String) attrs.get(DebuggerProcessor.SERVICE_NAME); + String displayName = (String) attrs.get("displayName"); + return new BreakpointType.ContextAware(serviceName, displayName); + } + + } } \ No newline at end of file diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/ColumnModelRegistration.java spi.debugger.ui/src/org/netbeans/spi/debugger/ui/ColumnModelRegistration.java --- ../../HG_FRESH/main/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/ColumnModelRegistration.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/src/org/netbeans/spi/debugger/ui/ColumnModelRegistration.java 2009-01-25 17:51:24.000000000 +0100 @@ -0,0 +1,73 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.spi.debugger.ui; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.netbeans.spi.debugger.ContextProvider; + +/** + * Declarative registration of a ColumnModel implementation. + * By marking the implementation class with this annotation, + * you automatically register that implementation for use by debugger. + * The class must be public and have a public constructor which takes + * no arguments or takes {@link ContextProvider} as an argument. + * + * @author Martin Entlicher + * @since 2.16 + */ +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.TYPE, ElementType.METHOD}) +public @interface ColumnModelRegistration { + + /** + * An optional path to register this implementation in. + */ + String path(); + + /** + * An optional position in which to register this service relative to others. + * Lower-numbered services are returned in the lookup result first. + * Services with no specified position are returned last. + */ + int position() default Integer.MAX_VALUE; +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/META-INF/debugger/unittest/annotated/LocalsView/org.netbeans.spi.viewmodel.ColumnModel spi.debugger.ui/test/unit/src/META-INF/debugger/unittest/annotated/LocalsView/org.netbeans.spi.viewmodel.ColumnModel --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/META-INF/debugger/unittest/annotated/LocalsView/org.netbeans.spi.viewmodel.ColumnModel 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/META-INF/debugger/unittest/annotated/LocalsView/org.netbeans.spi.viewmodel.ColumnModel 2009-01-25 13:14:50.000000000 +0100 @@ -0,0 +1 @@ +org.netbeans.api.debugger.providers.TestColumnModelsProvider.createLocalsToStringColumn()-hidden \ No newline at end of file diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/DebuggerApiTestBase.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/DebuggerApiTestBase.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/DebuggerApiTestBase.java 2008-08-20 02:05:09.000000000 +0200 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/DebuggerApiTestBase.java 2009-01-20 13:14:05.000000000 +0100 @@ -59,7 +59,8 @@ } protected void assertInstanceOf(String msg, Object obj, Class aClass) { - if (!obj.getClass().isAssignableFrom(aClass)) + assertNotNull("An object is not an instance of "+aClass+", because it is 'null'.", obj); + if (!aClass.isAssignableFrom(obj.getClass())) { fail(msg); } diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/IDEInitializer.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/IDEInitializer.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/IDEInitializer.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/IDEInitializer.java 2009-01-20 13:35:39.000000000 +0100 @@ -0,0 +1,157 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ + +package org.netbeans.api.debugger; + +import java.beans.PropertyVetoException; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.URLStreamHandler; +import java.net.URLStreamHandlerFactory; +import java.util.Enumeration; +import junit.framework.Assert; +import org.netbeans.junit.Manager; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.MultiFileSystem; +import org.openide.filesystems.Repository; +import org.openide.filesystems.XMLFileSystem; +import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; + + +/** + * Inspired by org.netbeans.api.project.TestUtil. + * + * @author Miloslav Metelka, Jan Lahoda + */ +public class IDEInitializer extends ProxyLookup { + + public static IDEInitializer DEFAULT_LOOKUP = null; + private static FileSystem lfs; + + static { + IDEInitializer.class.getClassLoader ().setDefaultAssertionStatus (true); + System.setProperty ("org.openide.util.Lookup", IDEInitializer.class.getName ()); + Assert.assertEquals (IDEInitializer.class, Lookup.getDefault ().getClass ()); + } + + public IDEInitializer () { + Assert.assertNull (DEFAULT_LOOKUP); + DEFAULT_LOOKUP = this; + URL.setURLStreamHandlerFactory (new MyURLHandlerFactory ()); + } + + /** + * Set the global default lookup with the specified content. + * + * @param layers xml-layer URLs to be present in the system filesystem. + * @param instances object instances to be present in the default lookup. + */ + public static void setup ( + String[] layers, + Object[] instances + ) { + ClassLoader classLoader = IDEInitializer.class.getClassLoader (); + File workDir = new File (Manager.getWorkDirPath ()); + URL[] urls = new URL [layers.length]; + int i, k = urls.length; + for (i = 0; i < k; i++) + urls [i] = classLoader.getResource (layers [i]); + + // 1) create repository + XMLFileSystem systemFS = new XMLFileSystem (); + lfs = FileUtil.createMemoryFileSystem(); + try { + systemFS.setXmlUrls (urls); + } catch (Exception ex) { + ex.printStackTrace (); + } + MyFileSystem myFileSystem = new MyFileSystem ( + new FileSystem [] {lfs, systemFS} + ); + Repository repository = new Repository (myFileSystem); + + Object[] lookupContent = new Object [instances.length + 1]; + lookupContent [0] = repository; + System.arraycopy (instances, 0, lookupContent, 1, instances.length); + + DEFAULT_LOOKUP.setLookups (new Lookup[] { + Lookups.fixed (lookupContent), + Lookups.metaInfServices (classLoader), + Lookups.singleton (classLoader), + }); + Assert.assertTrue (myFileSystem.isDefault()); + } + + public static void cleanWorkDir () { + try { + Enumeration en = lfs.getRoot ().getChildren (false); + while (en.hasMoreElements ()) + ((FileObject) en.nextElement ()).delete (); + } catch (IOException ex) { + ex.printStackTrace (); + } + } + + private static class MyFileSystem extends MultiFileSystem { + public MyFileSystem (FileSystem[] fileSystems) { + super (fileSystems); + try { + setSystemName ("TestFS"); + } catch (PropertyVetoException ex) { + ex.printStackTrace(); + } + } + } + + private static class MyURLHandlerFactory implements URLStreamHandlerFactory { + public URLStreamHandler createURLStreamHandler(String protocol) { + if (protocol.equals ("nbfs")) { + return FileUtil.nbfsURLStreamHandler (); + } + return null; + } + } +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/LookupWithForPathTest.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/LookupWithForPathTest.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/LookupWithForPathTest.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/LookupWithForPathTest.java 2009-01-20 13:23:21.000000000 +0100 @@ -0,0 +1,81 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger; + +import java.util.List; +import org.netbeans.api.debugger.test.TestLookupServiceFirst; +import org.netbeans.api.debugger.test.TestNodeModelContext; +import org.netbeans.spi.viewmodel.NodeModel; + +/** + * + * @author Martin Entlicher + */ +public class LookupWithForPathTest extends DebuggerApiTestBase { + + static { + String[] layers = new String[] {"org/netbeans/api/debugger/test/mf-layer.xml"};//NOI18N + Object[] instances = new Object[] { }; + IDEInitializer.setup(layers,instances); + } + + public LookupWithForPathTest(String s) { + super(s); + } + + public void testForPath() throws Exception { + Lookup.MetaInf l = new Lookup.MetaInf("unittest"); + List list = l.lookup(null, TestLookupServiceFirst.class); + assertEquals("Wrong looked up object", 2, list.size()); + assertInstanceOf("Wrong looked up object", list.get(0), TestLookupServiceFirst.class); + assertInstanceOf("Wrong looked up object", list.get(1), TestLookupServiceFirst.class); + + Lookup testContext = new Lookup.Instance(new Object[] {}); + l.setContext(testContext); + List nodeModelList = l.lookup(null, NodeModel.class); + assertEquals("Wrong looked up object", 2, nodeModelList.size()); + assertInstanceOf("Wrong looked up object", nodeModelList.get(0), NodeModel.class); + assertInstanceOf("Wrong looked up object", nodeModelList.get(1), NodeModel.class); + assertInstanceOf("Wrong looked up object", nodeModelList.get(1), TestNodeModelContext.class); + TestNodeModelContext nmc = (TestNodeModelContext) nodeModelList.get(1); + assertNotNull(nmc.getContext()); + assertEquals(testContext, nmc.getContext()); + } +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestActionProvider.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestActionProvider.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestActionProvider.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestActionProvider.java 2009-01-22 11:57:53.000000000 +0100 @@ -0,0 +1,88 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger.providers; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import org.netbeans.spi.debugger.ActionsProvider; +import org.netbeans.spi.debugger.ActionsProviderListener; + +/** + * + * @author Martin Entlicher + */ +@ActionsProvider.Registration(path="unittest") +public class TestActionProvider extends ActionsProvider { + + public static Object ACTION_OBJECT = new Object(); + + public static Set INSTANCES = new HashSet(); + + public TestActionProvider() { + INSTANCES.add(this); + } + + @Override + public Set getActions() { + return Collections.singleton(ACTION_OBJECT); + } + + @Override + public void doAction(Object action) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean isEnabled(Object action) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void addActionsProviderListener(ActionsProviderListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void removeActionsProviderListener(ActionsProviderListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestAttachType.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestAttachType.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestAttachType.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestAttachType.java 2009-01-22 15:28:17.000000000 +0100 @@ -0,0 +1,68 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger.providers; + +import java.util.HashSet; +import java.util.Set; +import javax.swing.JComponent; +import javax.swing.JPanel; +import org.netbeans.spi.debugger.ui.AttachType; + +/** + * + * @author Martin Entlicher + */ +@AttachType.Registration(displayName="Test") +public class TestAttachType extends AttachType { + + public static Object ACTION_OBJECT = new Object(); + + public static Set INSTANCES = new HashSet(); + + public TestAttachType() { + INSTANCES.add(this); + } + + @Override + public JComponent getCustomizer() { + return new JPanel(); + } + +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestBreakpointType.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestBreakpointType.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestBreakpointType.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestBreakpointType.java 2009-01-22 15:54:39.000000000 +0100 @@ -0,0 +1,78 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger.providers; + +import java.util.HashSet; +import java.util.Set; +import javax.swing.JComponent; +import javax.swing.JPanel; +import org.netbeans.spi.debugger.ui.BreakpointType; + +/** + * + * @author Martin Entlicher + */ +@BreakpointType.Registration(displayName="Test") +public class TestBreakpointType extends BreakpointType { + + public static Object ACTION_OBJECT = new Object(); + + public static Set INSTANCES = new HashSet(); + + public TestBreakpointType() { + INSTANCES.add(this); + } + + @Override + public JComponent getCustomizer() { + return new JPanel(); + } + + @Override + public String getCategoryDisplayName() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean isDefault() { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestColumnModel.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestColumnModel.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestColumnModel.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestColumnModel.java 2009-01-25 18:11:32.000000000 +0100 @@ -0,0 +1,79 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger.providers; + +import java.util.HashSet; +import java.util.Set; +import org.netbeans.spi.debugger.ui.ColumnModelRegistration; +import org.netbeans.spi.viewmodel.ColumnModel; + +/** + * + * @author Martin Entlicher + */ +@ColumnModelRegistration(path="unittest/annotated") +public class TestColumnModel extends ColumnModel{ + + public static final String ID = "TestID"; + public static final String DisplayName = "Test Display Name"; + public static final Class TYPE = java.util.LinkedHashMap.class; + + public static Set INSTANCES = new HashSet(); + + public TestColumnModel() { + INSTANCES.add(this); + } + + @Override + public String getID() { + return ID; + } + + @Override + public String getDisplayName() { + return DisplayName; + } + + @Override + public Class getType() { + return TYPE; + } + +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestColumnModelsProvider.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestColumnModelsProvider.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestColumnModelsProvider.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestColumnModelsProvider.java 2009-01-25 18:14:40.000000000 +0100 @@ -0,0 +1,92 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger.providers; + +import org.netbeans.modules.debugger.ui.models.ColumnModels; +import org.netbeans.spi.debugger.ui.ColumnModelRegistration; +import org.netbeans.spi.viewmodel.ColumnModel; + +/** + * + * @author Martin Entlicher + */ +public class TestColumnModelsProvider { + + /** + * Defines model for one table view column. Can be used together with + * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table + * view representation. + */ + @ColumnModelRegistration(path="unittest/annotated/LocalsView", position=10) + public static ColumnModel createDefaultLocalsColumn() { + return ColumnModels.createDefaultLocalsColumn(); + } + + /** + * Defines model for one table view column. Can be used together with + * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table + * view representation. + */ + @ColumnModelRegistration(path="unittest/annotated/LocalsView", position=40) + public static ColumnModel createLocalsToStringColumn() { + return ColumnModels.createLocalsToStringColumn(); + } + + /** + * Defines model for one table view column. Can be used together with + * {@link org.netbeans.spi.viewmodel.TreeModel} for tree + * table view representation. + */ + @ColumnModelRegistration(path="unittest/annotated/LocalsView", position=20) + public static ColumnModel createLocalsTypeColumn() { + return ColumnModels.createLocalsTypeColumn(); + } + /** + * Defines model for one table view column. Can be used together with + * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table + * view representation. + */ + @ColumnModelRegistration(path="unittest/annotated/LocalsView", position=30) + public static ColumnModel createLocalsValueColumn() { + return ColumnModels.createLocalsValueColumn(); + } + + +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestDebuggerEngineProvider.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestDebuggerEngineProvider.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestDebuggerEngineProvider.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestDebuggerEngineProvider.java 2009-01-22 13:58:07.000000000 +0100 @@ -0,0 +1,73 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger.providers; + +import org.netbeans.api.debugger.DebuggerEngine.Destructor; +import org.netbeans.spi.debugger.DebuggerEngineProvider; + +/** + * + * @author Martin Entlicher + */ +@DebuggerEngineProvider.Registration(path="unittest") +public class TestDebuggerEngineProvider extends DebuggerEngineProvider { + + @Override + public String[] getLanguages() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getEngineTypeID() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Object[] getServices() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setDestructor(Destructor desctuctor) { + throw new UnsupportedOperationException("Not supported yet."); + } + + +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestLazyActionsManagerListenerAnnotated.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestLazyActionsManagerListenerAnnotated.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestLazyActionsManagerListenerAnnotated.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestLazyActionsManagerListenerAnnotated.java 2009-01-22 16:24:55.000000000 +0100 @@ -0,0 +1,72 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger.providers; + +import java.util.HashSet; +import java.util.Set; + +import org.netbeans.api.debugger.LazyActionsManagerListener; + +/** + * + * @author Martin Entlicher + */ +@LazyActionsManagerListener.Registration(path="unittest/annotated") +public class TestLazyActionsManagerListenerAnnotated extends LazyActionsManagerListener { + + public static Object ACTION_OBJECT = new Object(); + + public static Set INSTANCES = new HashSet(); + + public TestLazyActionsManagerListenerAnnotated() { + INSTANCES.add(this); + } + + @Override + protected void destroy() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String[] getProperties() { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestLazyDebuggerManagerListenerAnnotated.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestLazyDebuggerManagerListenerAnnotated.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestLazyDebuggerManagerListenerAnnotated.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestLazyDebuggerManagerListenerAnnotated.java 2009-01-23 14:47:47.000000000 +0100 @@ -0,0 +1,121 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger.providers; + +import java.beans.PropertyChangeEvent; +import java.util.HashSet; +import java.util.Set; +import org.netbeans.api.debugger.Breakpoint; +import org.netbeans.api.debugger.DebuggerEngine; +import org.netbeans.api.debugger.LazyDebuggerManagerListener; +import org.netbeans.api.debugger.Session; +import org.netbeans.api.debugger.Watch; +import org.netbeans.spi.debugger.ContextProvider; +import org.netbeans.spi.debugger.DebuggerServiceRegistration; + +/** + * + * @author Martin Entlicher + */ +@DebuggerServiceRegistration(path="unittest/annotated", types=LazyDebuggerManagerListener.class) +public class TestLazyDebuggerManagerListenerAnnotated implements LazyDebuggerManagerListener { + + public static Set INSTANCES = new HashSet(); + + public ContextProvider context; + + public TestLazyDebuggerManagerListenerAnnotated() { + INSTANCES.add(this); + } + + public TestLazyDebuggerManagerListenerAnnotated(ContextProvider context) { + INSTANCES.add(this); + this.context = context; + } + + public String[] getProperties() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Breakpoint[] initBreakpoints() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void breakpointAdded(Breakpoint breakpoint) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void breakpointRemoved(Breakpoint breakpoint) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void initWatches() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void watchAdded(Watch watch) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void watchRemoved(Watch watch) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void sessionAdded(Session session) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void sessionRemoved(Session session) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void engineAdded(DebuggerEngine engine) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void engineRemoved(DebuggerEngine engine) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void propertyChange(PropertyChangeEvent evt) { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestSessionProvider.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestSessionProvider.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestSessionProvider.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestSessionProvider.java 2009-01-22 14:41:18.000000000 +0100 @@ -0,0 +1,73 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger.providers; + +import org.netbeans.spi.debugger.SessionProvider; + +/** + * + * @author Martin Entlicher + */ +@SessionProvider.Registration(path="unittest") +public class TestSessionProvider extends SessionProvider { + + public static Object ACTION_OBJECT = new Object(); + + @Override + public String getSessionName() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getLocationName() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getTypeID() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Object[] getServices() { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestThreeModels.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestThreeModels.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestThreeModels.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestThreeModels.java 2009-01-23 15:49:09.000000000 +0100 @@ -0,0 +1,112 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger.providers; + +import java.util.HashSet; +import java.util.Set; +import org.netbeans.spi.debugger.DebuggerServiceRegistration; +import org.netbeans.spi.viewmodel.ModelListener; +import org.netbeans.spi.viewmodel.NodeModel; +import org.netbeans.spi.viewmodel.TableModel; +import org.netbeans.spi.viewmodel.TreeModel; +import org.netbeans.spi.viewmodel.UnknownTypeException; + +/** + * + * @author Martin Entlicher + */ +@DebuggerServiceRegistration(path="unittest/annotated", types={TreeModel.class,NodeModel.class, TableModel.class}) +public class TestThreeModels implements TreeModel, NodeModel, TableModel { + + public static Set INSTANCES = new HashSet(); + + public TestThreeModels() { + INSTANCES.add(this); + } + + public Object getRoot() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Object[] getChildren(Object parent, int from, int to) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public boolean isLeaf(Object node) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public int getChildrenCount(Object node) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void addModelListener(ModelListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void removeModelListener(ModelListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public String getDisplayName(Object node) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public String getIconBase(Object node) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public String getShortDescription(Object node) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Object getValueAt(Object node, String columnID) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public boolean isReadOnly(Object node, String columnID) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void setValueAt(Object node, String columnID, Object value) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/ProvidersAnnotationTest.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/ProvidersAnnotationTest.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/ProvidersAnnotationTest.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/ProvidersAnnotationTest.java 2009-01-25 13:22:29.000000000 +0100 @@ -0,0 +1,184 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger; + +import java.util.List; + +import org.netbeans.api.debugger.providers.TestActionProvider; +import org.netbeans.api.debugger.providers.TestAttachType; +import org.netbeans.api.debugger.providers.TestBreakpointType; +import org.netbeans.api.debugger.providers.TestColumnModel; +import org.netbeans.api.debugger.providers.TestLazyActionsManagerListenerAnnotated; +import org.netbeans.api.debugger.providers.TestLazyDebuggerManagerListenerAnnotated; +import org.netbeans.api.debugger.providers.TestThreeModels; +import org.netbeans.modules.debugger.ui.models.ColumnModels; +import org.netbeans.spi.debugger.ActionsProvider; +import org.netbeans.spi.debugger.DebuggerEngineProvider; +import org.netbeans.spi.debugger.SessionProvider; +import org.netbeans.spi.debugger.ui.AttachType; +import org.netbeans.spi.debugger.ui.BreakpointType; +import org.netbeans.spi.viewmodel.ColumnModel; +import org.netbeans.spi.viewmodel.NodeModel; +import org.netbeans.spi.viewmodel.TableModel; +import org.netbeans.spi.viewmodel.TreeModel; + +/** + * + * @author Martin Entlicher + */ +public class ProvidersAnnotationTest extends DebuggerApiTestBase { + + public ProvidersAnnotationTest(String s) { + super(s); + } + + public void testProviders() throws Exception { + Lookup.MetaInf l = new Lookup.MetaInf("unittest"); + + { + List list = l.lookup(null, ActionsProvider.class); + assertEquals("Wrong looked up object", 1, list.size()); + assertEquals("No test action provider instance should be created yet!", 0, TestActionProvider.INSTANCES.size()); + assertInstanceOf("Wrong looked up object", list.get(0), ActionsProvider.class); + assertEquals(TestActionProvider.ACTION_OBJECT, list.get(0).getActions().iterator().next()); + } + { + List list = l.lookup(null, DebuggerEngineProvider.class); + assertEquals("Wrong looked up object", 1, list.size()); + //assertEquals("No test action provider instance should be created yet!", 0, TestDebuggerEngineProvider.INSTANCES.size()); + assertInstanceOf("Wrong looked up object", list.get(0), DebuggerEngineProvider.class); + } + { + List list = l.lookup(null, SessionProvider.class); + assertEquals("Wrong looked up object", 1, list.size()); + //assertEquals("No test action provider instance should be created yet!", 0, TestSessionProvider.INSTANCES.size()); + assertInstanceOf("Wrong looked up object", list.get(0), SessionProvider.class); + } + { + l = new Lookup.MetaInf(""); + List list = l.lookup(null, AttachType.class); + assertEquals("Wrong looked up object: ", 1, list.size()); + assertEquals("Test", list.get(0).getTypeDisplayName()); + assertEquals("No test action provider instance should be created yet!", 0, TestAttachType.INSTANCES.size()); + assertNotNull(list.get(0).getCustomizer()); + assertEquals("One test action provider instance should be created yet!", 1, TestAttachType.INSTANCES.size()); + assertInstanceOf("Wrong looked up object", list.get(0), AttachType.class); + } + l = new Lookup.MetaInf(""); + { + List list = l.lookup(null, BreakpointType.class); + assertEquals("Wrong looked up object: ", 1, list.size()); + assertEquals("Test", list.get(0).getTypeDisplayName()); + assertEquals("No test action provider instance should be created yet!", 0, TestBreakpointType.INSTANCES.size()); + assertNotNull(list.get(0).getCustomizer()); + assertEquals("One test action provider instance should be created yet!", 1, TestBreakpointType.INSTANCES.size()); + assertInstanceOf("Wrong looked up object", list.get(0), BreakpointType.class); + } + l = new Lookup.MetaInf("unittest/annotated"); + { + List list = l.lookup(null, LazyActionsManagerListener.class); + assertEquals("Wrong looked up object: ", 1, list.size()); + assertEquals("No test action provider instance should be created yet!", 0, TestLazyActionsManagerListenerAnnotated.INSTANCES.size()); + assertInstanceOf("Wrong looked up object", list.get(0), LazyActionsManagerListener.class); + } + { + List list = l.lookup(null, LazyDebuggerManagerListener.class); + assertEquals("Wrong looked up object: ", 1, list.size()); + assertEquals("No test action provider instance should be created yet!", 0, TestLazyDebuggerManagerListenerAnnotated.INSTANCES.size()); + assertInstanceOf("Wrong looked up object", list.get(0), LazyDebuggerManagerListener.class); + Lookup cp = new Lookup.Instance(new Object[] {}); + l.setContext(cp); + list = l.lookup(null, LazyDebuggerManagerListener.class); + assertEquals("Wrong looked up object: ", 1, list.size()); + assertEquals("No new test action provider instance should be created yet!", 1, TestLazyDebuggerManagerListenerAnnotated.INSTANCES.size()); + assertEquals("Wrong context", cp, ((TestLazyDebuggerManagerListenerAnnotated) list.get(0)).context); + } + l = new Lookup.MetaInf(""); + { + List list = l.lookup("unittest/annotated", ColumnModel.class); + assertEquals("Wrong looked up object: ", 1, list.size()); + assertEquals("No test action provider instance should be created yet!", 0, TestColumnModel.INSTANCES.size()); + assertEquals(TestColumnModel.ID, list.get(0).getID()); + assertEquals(TestColumnModel.DisplayName, list.get(0).getDisplayName()); + assertEquals(TestColumnModel.TYPE, list.get(0).getType()); + assertEquals("One provider instance should be created!", 1, TestColumnModel.INSTANCES.size()); + } + } + + public void testMultipleProviders() throws Exception { + Lookup.MetaInf l = new Lookup.MetaInf("unittest/annotated"); + + { + List list = l.lookup(null, TreeModel.class); + assertEquals("Wrong looked up object", 1, list.size()); + assertEquals("No test action provider instance should be created yet!", 0, TestThreeModels.INSTANCES.size()); + assertInstanceOf("Wrong looked up object", list.get(0), TreeModel.class); + assertInstanceOf("Wrong looked up object", list.get(0), NodeModel.class); + assertInstanceOf("Wrong looked up object", list.get(0), TableModel.class); + assertEquals("One provider instance should be created!", 1, TestThreeModels.INSTANCES.size()); + + List list2 = l.lookup(null, NodeModel.class); + assertEquals("Wrong looked up object", 1, list2.size()); + assertInstanceOf("Wrong looked up object", list2.get(0), TreeModel.class); + assertInstanceOf("Wrong looked up object", list2.get(0), NodeModel.class); + assertInstanceOf("Wrong looked up object", list2.get(0), TableModel.class); + List list3 = l.lookup(null, TableModel.class); + assertEquals("Wrong looked up object", 1, list3.size()); + assertInstanceOf("Wrong looked up object", list3.get(0), TreeModel.class); + assertInstanceOf("Wrong looked up object", list3.get(0), NodeModel.class); + assertInstanceOf("Wrong looked up object", list3.get(0), TableModel.class); + assertEquals("One provider instance should be created!", 1, TestThreeModels.INSTANCES.size()); + + } + } + + public void testColumnProviders() throws Exception { + Lookup.MetaInf l = new Lookup.MetaInf("unittest/annotated"); + + { + List list = l.lookup("LocalsView", ColumnModel.class); + assertEquals("Wrong looked up object", 3, list.size()); + assertEquals(ColumnModels.createDefaultLocalsColumn().getDisplayName(), list.get(0).getDisplayName()); + assertEquals(ColumnModels.createLocalsTypeColumn().getDisplayName(), list.get(1).getDisplayName()); + assertEquals(ColumnModels.createLocalsValueColumn().getDisplayName(), list.get(2).getDisplayName()); + //assertEquals(ColumnModels.createLocalsToStringColumn().getDisplayName(), list.get(3).getDisplayName()); - was made hidden! + } + } +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/test/mf-layer.xml spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/test/mf-layer.xml --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/test/mf-layer.xml 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/test/mf-layer.xml 2009-01-20 12:57:20.000000000 +0100 @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/test/TestNodeModelContext.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/test/TestNodeModelContext.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/test/TestNodeModelContext.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/test/TestNodeModelContext.java 2009-01-20 14:29:18.000000000 +0100 @@ -0,0 +1,83 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger.test; + +import org.netbeans.spi.debugger.ContextProvider; +import org.netbeans.spi.viewmodel.ModelListener; +import org.netbeans.spi.viewmodel.NodeModel; +import org.netbeans.spi.viewmodel.UnknownTypeException; + +/** + * + * @author Martin Entlicher + */ +public class TestNodeModelContext implements NodeModel { + + private ContextProvider context; + + public TestNodeModelContext(ContextProvider context) { + this.context = context; + } + + public ContextProvider getContext() { + return context; + } + + public String getDisplayName(Object node) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public String getIconBase(Object node) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public String getShortDescription(Object node) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void addModelListener(ModelListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void removeModelListener(ModelListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff -u -N -r ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/test/TestNodeModel.java spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/test/TestNodeModel.java --- ../../HG_FRESH/main/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/test/TestNodeModel.java 1970-01-01 01:00:00.000000000 +0100 +++ spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/test/TestNodeModel.java 2009-01-20 14:29:10.000000000 +0100 @@ -0,0 +1,72 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger.test; + +import org.netbeans.spi.viewmodel.ModelListener; +import org.netbeans.spi.viewmodel.NodeModel; +import org.netbeans.spi.viewmodel.UnknownTypeException; + +/** + * + * @author Martin Entlicher + */ +public class TestNodeModel implements NodeModel { + + public String getDisplayName(Object node) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public String getIconBase(Object node) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public String getShortDescription(Object node) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void addModelListener(ModelListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void removeModelListener(ModelListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff -u -N -r ../../HG_FRESH/main/api.debugger.jpda/apichanges.xml api.debugger.jpda/apichanges.xml --- ../../HG_FRESH/main/api.debugger.jpda/apichanges.xml 2009-01-13 21:39:21.000000000 +0100 +++ api.debugger.jpda/apichanges.xml 2009-01-25 18:28:48.000000000 +0100 @@ -710,6 +710,39 @@ + + +

Annotations for debugger service registration. + + + + + +

+ In order to be able to register debugger services on System FileSystem, + which brings more flexibility and better performance (see also + ), + we add non-recursive content of org.openide.util.Lookups.forPath() + into debugger lookup. + Since debugger needs retrieve context-aware services from the lookup, + ContextAwareService interface is introduced. +

+

+ Annotations are added for easy registration on module layers. + DebuggerServiceRegistration to register implementations + of interfaces, *Provider.Registration to register + implementations of appropriate providers. +

+
+ + + + + + + + + diff -u -N -r ../../HG_FRESH/main/api.debugger.jpda/manifest.mf api.debugger.jpda/manifest.mf --- ../../HG_FRESH/main/api.debugger.jpda/manifest.mf 2009-01-13 21:39:21.000000000 +0100 +++ api.debugger.jpda/manifest.mf 2009-01-25 17:39:28.000000000 +0100 @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.api.debugger.jpda/2 OpenIDE-Module-Localizing-Bundle: org/netbeans/api/debugger/jpda/Bundle.properties -OpenIDE-Module-Specification-Version: 2.18 +OpenIDE-Module-Specification-Version: 2.19 OpenIDE-Module-Package-Dependencies: com.sun.jdi[VirtualMachineManager] diff -u -N -r ../../HG_FRESH/main/api.debugger.jpda/nbproject/project.properties api.debugger.jpda/nbproject/project.properties --- ../../HG_FRESH/main/api.debugger.jpda/nbproject/project.properties 2008-08-20 02:00:43.000000000 +0200 +++ api.debugger.jpda/nbproject/project.properties 2009-01-23 22:42:21.000000000 +0100 @@ -38,7 +38,7 @@ # made subject to such option by the copyright holder. is.autoload=true -cp.extra=${tools.jar} +cp.extra=${tools.jar}:${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar javac.compilerargs=-Xlint:unchecked javac.source=1.5 javadoc.arch=${basedir}/arch.xml diff -u -N -r ../../HG_FRESH/main/api.debugger.jpda/nbproject/project.xml api.debugger.jpda/nbproject/project.xml --- ../../HG_FRESH/main/api.debugger.jpda/nbproject/project.xml 2008-08-20 02:00:43.000000000 +0200 +++ api.debugger.jpda/nbproject/project.xml 2009-01-25 17:39:54.000000000 +0100 @@ -52,6 +52,7 @@ 1 + 1.16 diff -u -N -r ../../HG_FRESH/main/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDADebugger.java api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDADebugger.java --- ../../HG_FRESH/main/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDADebugger.java 2008-08-20 02:00:43.000000000 +0200 +++ api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDADebugger.java 2009-01-25 18:22:32.000000000 +0100 @@ -41,27 +41,29 @@ package org.netbeans.api.debugger.jpda; -import com.sun.jdi.Bootstrap; import com.sun.jdi.VirtualMachine; -import com.sun.jdi.connect.AttachingConnector; import com.sun.jdi.connect.Connector.Argument; -import com.sun.jdi.connect.IllegalConnectorArgumentsException; import com.sun.jdi.connect.ListeningConnector; import com.sun.jdi.request.EventRequest; import java.beans.PropertyChangeListener; -import java.io.File; -import java.io.IOException; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.Map; + import org.netbeans.api.debugger.DebuggerEngine; import org.netbeans.api.debugger.DebuggerInfo; import org.netbeans.api.debugger.DebuggerManager; -import org.netbeans.api.debugger.jpda.InvalidExpressionException; -import org.netbeans.api.debugger.jpda.Variable; import org.netbeans.api.debugger.jpda.event.JPDABreakpointEvent; + +import org.netbeans.modules.debugger.jpda.apiregistry.DebuggerProcessor; +import org.netbeans.spi.debugger.ContextAwareService; +import org.netbeans.spi.debugger.ContextAwareSupport; +import org.netbeans.spi.debugger.ContextProvider; import org.openide.util.NbBundle; @@ -533,4 +535,127 @@ } */ + + /** + * Declarative registration of a JPDADebugger implementation. + * By marking the implementation class with this annotation, + * you automatically register that implementation for use by debugger. + * The class must be public and have a public constructor which takes + * no arguments or takes {@link ContextProvider} as an argument. + * + * @author Martin Entlicher + * @since 2.19 + */ + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + /** + * An optional path to register this implementation in. + * Usually the session ID. + */ + String path() default ""; + + } + + static class ContextAware extends JPDADebugger implements ContextAwareService { + + private String serviceName; + + private ContextAware(String serviceName) { + this.serviceName = serviceName; + } + + public JPDADebugger forContext(ContextProvider context) { + return (JPDADebugger) ContextAwareSupport.createInstance(serviceName, context); + } + + @Override + public int getState() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public int getSuspend() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setSuspend(int s) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public JPDAThread getCurrentThread() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public CallStackFrame getCurrentCallStackFrame() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Variable evaluate(String expression) throws InvalidExpressionException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void waitRunning() throws DebuggerStartException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean canFixClasses() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean canPopFrames() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void fixClasses(Map classes) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public SmartSteppingFilter getSmartSteppingFilter() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void addPropertyChangeListener(String propertyName, PropertyChangeListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void removePropertyChangeListener(String propertyName, PropertyChangeListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Creates instance of ContextAwareService based on layer.xml + * attribute values + * + * @param attrs attributes loaded from layer.xml + * @return new ContextAwareService instance + */ + static ContextAwareService createService(Map attrs) throws ClassNotFoundException { + String serviceName = (String) attrs.get(DebuggerProcessor.SERVICE_NAME); + return new ContextAware(serviceName); + } + + } + } diff -u -N -r ../../HG_FRESH/main/api.debugger.jpda/src/org/netbeans/modules/debugger/jpda/apiregistry/DebuggerProcessor.java api.debugger.jpda/src/org/netbeans/modules/debugger/jpda/apiregistry/DebuggerProcessor.java --- ../../HG_FRESH/main/api.debugger.jpda/src/org/netbeans/modules/debugger/jpda/apiregistry/DebuggerProcessor.java 1970-01-01 01:00:00.000000000 +0100 +++ api.debugger.jpda/src/org/netbeans/modules/debugger/jpda/apiregistry/DebuggerProcessor.java 2009-01-25 18:23:18.000000000 +0100 @@ -0,0 +1,231 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ + +package org.netbeans.modules.debugger.jpda.apiregistry; + +import java.util.Set; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; + +import org.netbeans.api.debugger.jpda.JPDADebugger; +import org.netbeans.spi.debugger.jpda.EditorContext; +import org.netbeans.spi.debugger.jpda.SmartSteppingCallback; +import org.netbeans.spi.debugger.jpda.SourcePathProvider; +import org.netbeans.spi.debugger.jpda.VariablesFilter; +import org.openide.filesystems.annotations.LayerBuilder.File; +import org.openide.filesystems.annotations.LayerGeneratingProcessor; +import org.openide.filesystems.annotations.LayerGenerationException; +import org.openide.util.lookup.ServiceProvider; + +/** Processor to hide all the complexities of settings layer registration. + * + * @author Martin Entlicher + */ +@ServiceProvider(service=Processor.class) +@SupportedSourceVersion(SourceVersion.RELEASE_6) +@SupportedAnnotationTypes({"org.netbeans.api.debugger.jpda.JPDADebugger.Registration", // NOI18N + "org.netbeans.spi.debugger.ui.BreakpointType.Registration"}) //NOI18N +public class DebuggerProcessor extends LayerGeneratingProcessor { + + public static final String SERVICE_NAME = "serviceName"; // NOI18N + + + @Override + protected boolean handleProcess( + Set annotations, + RoundEnvironment env + ) throws LayerGenerationException { + if (env.processingOver()) { + return false; + } + + int cnt = 0; + for (Element e : env.getElementsAnnotatedWith(JPDADebugger.Registration.class)) { + JPDADebugger.Registration reg = e.getAnnotation(JPDADebugger.Registration.class); + + final String path = reg.path(); + handleProviderRegistration(e, JPDADebugger.class, path); + cnt++; + } + for (Element e : env.getElementsAnnotatedWith(SmartSteppingCallback.Registration.class)) { + SmartSteppingCallback.Registration reg = e.getAnnotation(SmartSteppingCallback.Registration.class); + + final String path = reg.path(); + handleProviderRegistration(e, SmartSteppingCallback.class, path); + cnt++; + } + for (Element e : env.getElementsAnnotatedWith(SourcePathProvider.Registration.class)) { + SourcePathProvider.Registration reg = e.getAnnotation(SourcePathProvider.Registration.class); + + final String path = reg.path(); + handleProviderRegistration(e, SourcePathProvider.class, path); + cnt++; + } + for (Element e : env.getElementsAnnotatedWith(EditorContext.Registration.class)) { + EditorContext.Registration reg = e.getAnnotation(EditorContext.Registration.class); + + final String path = reg.path(); + handleProviderRegistration(e, EditorContext.class, path); + cnt++; + } + for (Element e : env.getElementsAnnotatedWith(VariablesFilter.Registration.class)) { + VariablesFilter.Registration reg = e.getAnnotation(VariablesFilter.Registration.class); + + final String path = reg.path(); + handleProviderRegistration(e, VariablesFilter.class, path); + cnt++; + } + return cnt == annotations.size(); + } + + private void handleProviderRegistration(Element e, Class providerClass, String path) throws IllegalArgumentException, LayerGenerationException { + String className = instantiableClassOrMethod(e); + if (!isClassOf(e, providerClass)) { + throw new IllegalArgumentException("Annotated element "+e+" is not an instance of " + providerClass); + } + layer(e).instanceFile("Debugger/"+path, null, providerClass). + stringvalue(SERVICE_NAME, className). + stringvalue("serviceClass", providerClass.getName()). + methodvalue("instanceCreate", providerClass.getName()+"$ContextAware", "createService"). + //methodvalue("instanceCreate", "org.netbeans.modules.debugger.ui.registry."+providerClass.getSimpleName()+"ContextAware", "createService"). + write(); + } + + private boolean isClassOf(Element e, Class providerClass) { + switch (e.getKind()) { + case CLASS: { + TypeElement te = (TypeElement) e; + TypeMirror superType = te.getSuperclass(); + if (superType.getKind().equals(TypeKind.NONE)) { + return false; + } else { + e = ((DeclaredType) superType).asElement(); + String clazz = processingEnv.getElementUtils().getBinaryName((TypeElement) e).toString(); + if (clazz.equals(providerClass.getName())) { + return true; + } else { + return isClassOf(e, providerClass); + } + } + } + case METHOD: { + return true; + } + default: + throw new IllegalArgumentException("Annotated element is not loadable as an instance: " + e); + } + } + + private static File commaSeparated(File f, String[] arr) { + if (arr.length == 0) { + return f; + } + + StringBuilder sb = new StringBuilder(); + String sep = ""; + for (String s : arr) { + sb.append(sep); + sb.append(s); + sep = ","; + } + return f.stringvalue("xmlproperties.ignoreChanges", sb.toString()); + } + + private String instantiableClassOrMethod(Element e) throws IllegalArgumentException, LayerGenerationException { + switch (e.getKind()) { + case CLASS: { + String clazz = processingEnv.getElementUtils().getBinaryName((TypeElement) e).toString(); + if (e.getModifiers().contains(Modifier.ABSTRACT)) { + throw new LayerGenerationException(clazz + " must not be abstract", e); + } + { + boolean hasDefaultCtor = false; + for (ExecutableElement constructor : ElementFilter.constructorsIn(e.getEnclosedElements())) { + if (constructor.getParameters().isEmpty()) { + hasDefaultCtor = true; + break; + } + } + if (!hasDefaultCtor) { + throw new LayerGenerationException(clazz + " must have a no-argument constructor", e); + } + } + /*propType = processingEnv.getElementUtils().getTypeElement("java.util.Properties").asType(); + if ( + m.getParameters().size() == 1 && + m.getSimpleName().contentEquals("writeProperties") && + m.getParameters().get(0).asType().equals(propType) && + m.getReturnType().getKind() == TypeKind.VOID + ) { + hasWrite = true; + } + } + * */ + return clazz; + } + case METHOD: { + ExecutableElement ee = (ExecutableElement) e; + String methodName = ee.getSimpleName().toString(); + String clazz = processingEnv.getElementUtils().getBinaryName((TypeElement) ee.getEnclosingElement()).toString(); + if (!e.getModifiers().contains(Modifier.STATIC)) { + throw new LayerGenerationException(ee + " must be static", e); + } + if (ee.getParameters().size() > 0) { + throw new LayerGenerationException(ee + " must not have any parameters", e); + } + return clazz+"."+methodName+"()"; + } + default: + throw new IllegalArgumentException("Annotated element is not loadable as an instance: " + e); + } + } +} diff -u -N -r ../../HG_FRESH/main/api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/EditorContext.java api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/EditorContext.java --- ../../HG_FRESH/main/api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/EditorContext.java 2008-08-20 02:00:43.000000000 +0200 +++ api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/EditorContext.java 2009-01-25 18:22:25.000000000 +0100 @@ -41,11 +41,20 @@ package org.netbeans.spi.debugger.jpda; import java.beans.PropertyChangeListener; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import org.netbeans.api.debugger.jpda.JPDAThread; import org.netbeans.api.debugger.jpda.Variable; +import org.netbeans.modules.debugger.jpda.apiregistry.DebuggerProcessor; +import org.netbeans.spi.debugger.ContextAwareService; +import org.netbeans.spi.debugger.ContextAwareSupport; +import org.netbeans.spi.debugger.ContextProvider; /** * Defines bridge to editor and src hierarchy. It allows to use different @@ -725,5 +734,158 @@ } + + /** + * Declarative registration of a EditorContext implementation. + * By marking the implementation class with this annotation, + * you automatically register that implementation for use by debugger. + * The class must be public and have a public constructor which takes + * no arguments or takes {@link ContextProvider} as an argument. + * + * @author Martin Entlicher + * @since 2.19 + */ + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + /** + * An optional path to register this implementation in. + * Usually the session ID. + */ + String path() default ""; + + } + + static class ContextAware extends EditorContext implements ContextAwareService { + + private String serviceName; + + private ContextAware(String serviceName) { + this.serviceName = serviceName; + } + + public EditorContext forContext(ContextProvider context) { + return (EditorContext) ContextAwareSupport.createInstance(serviceName, context); + } + + @Override + public boolean showSource(String url, int lineNumber, Object timeStamp) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void createTimeStamp(Object timeStamp) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void disposeTimeStamp(Object timeStamp) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void updateTimeStamp(Object timeStamp, String url) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Object annotate(String url, int lineNumber, String annotationType, Object timeStamp) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public int getLineNumber(Object annotation, Object timeStamp) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void removeAnnotation(Object annotation) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public int getCurrentLineNumber() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getCurrentClassName() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getCurrentURL() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getCurrentMethodName() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getCurrentFieldName() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getSelectedIdentifier() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getSelectedMethodName() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public int getFieldLineNumber(String url, String className, String fieldName) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getClassName(String url, int lineNumber) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String[] getImports(String url) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void addPropertyChangeListener(String propertyName, PropertyChangeListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void removePropertyChangeListener(String propertyName, PropertyChangeListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Creates instance of ContextAwareService based on layer.xml + * attribute values + * + * @param attrs attributes loaded from layer.xml + * @return new ContextAwareService instance + */ + static ContextAwareService createService(Map attrs) throws ClassNotFoundException { + String serviceName = (String) attrs.get(DebuggerProcessor.SERVICE_NAME); + return new ContextAware(serviceName); + } + + } + } diff -u -N -r ../../HG_FRESH/main/api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/SmartSteppingCallback.java api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/SmartSteppingCallback.java --- ../../HG_FRESH/main/api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/SmartSteppingCallback.java 2008-08-20 02:00:43.000000000 +0200 +++ api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/SmartSteppingCallback.java 2009-01-25 18:22:20.000000000 +0100 @@ -41,9 +41,16 @@ package org.netbeans.spi.debugger.jpda; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.Map; import org.netbeans.api.debugger.jpda.JPDAThread; import org.netbeans.api.debugger.jpda.SmartSteppingFilter; -import org.netbeans.api.debugger.DebuggerEngine; +import org.netbeans.modules.debugger.jpda.apiregistry.DebuggerProcessor; +import org.netbeans.spi.debugger.ContextAwareService; +import org.netbeans.spi.debugger.ContextAwareSupport; import org.netbeans.spi.debugger.ContextProvider; /** @@ -74,5 +81,63 @@ * @return true if execution should be stopped on the current position */ public abstract boolean stopHere (ContextProvider lookupProvider, JPDAThread thread, SmartSteppingFilter f); + + + /** + * Declarative registration of a SmartSteppingCallback implementation. + * By marking the implementation class with this annotation, + * you automatically register that implementation for use by debugger. + * The class must be public and have a public constructor which takes + * no arguments or takes {@link ContextProvider} as an argument. + * + * @author Martin Entlicher + * @since 2.19 + */ + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + /** + * An optional path to register this implementation in. + */ + String path() default ""; + + } + + static class ContextAware extends SmartSteppingCallback implements ContextAwareService { + + private String serviceName; + + private ContextAware(String serviceName) { + this.serviceName = serviceName; + } + + public SmartSteppingCallback forContext(ContextProvider context) { + return (SmartSteppingCallback) ContextAwareSupport.createInstance(serviceName, context); + } + + @Override + public void initFilter(SmartSteppingFilter f) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean stopHere(ContextProvider lookupProvider, JPDAThread thread, SmartSteppingFilter f) { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Creates instance of ContextAwareService based on layer.xml + * attribute values + * + * @param attrs attributes loaded from layer.xml + * @return new ContextAwareService instance + */ + static ContextAwareService createService(Map attrs) throws ClassNotFoundException { + String serviceName = (String) attrs.get(DebuggerProcessor.SERVICE_NAME); + return new ContextAware(serviceName); + } + + } + } diff -u -N -r ../../HG_FRESH/main/api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/SourcePathProvider.java api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/SourcePathProvider.java --- ../../HG_FRESH/main/api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/SourcePathProvider.java 2008-08-20 02:00:43.000000000 +0200 +++ api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/SourcePathProvider.java 2009-01-25 18:22:15.000000000 +0100 @@ -41,8 +41,15 @@ package org.netbeans.spi.debugger.jpda; import java.beans.PropertyChangeListener; -import java.io.File; -import java.util.Set; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.Map; +import org.netbeans.modules.debugger.jpda.apiregistry.DebuggerProcessor; +import org.netbeans.spi.debugger.ContextAwareService; +import org.netbeans.spi.debugger.ContextAwareSupport; +import org.netbeans.spi.debugger.ContextProvider; /** * Defines source path for debugger. It translates relative path @@ -134,5 +141,87 @@ public abstract void removePropertyChangeListener ( PropertyChangeListener l ); + + + /** + * Declarative registration of a SourcePathProvider implementation. + * By marking the implementation class with this annotation, + * you automatically register that implementation for use by debugger. + * The class must be public and have a public constructor which takes + * no arguments or takes {@link ContextProvider} as an argument. + * + * @author Martin Entlicher + * @since 2.19 + */ + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + /** + * An optional path to register this implementation in. + */ + String path() default ""; + + } + + static class ContextAware extends SourcePathProvider implements ContextAwareService { + + private String serviceName; + + private ContextAware(String serviceName) { + this.serviceName = serviceName; + } + + public SourcePathProvider forContext(ContextProvider context) { + return (SourcePathProvider) ContextAwareSupport.createInstance(serviceName, context); + } + + @Override + public String getRelativePath(String url, char directorySeparator, boolean includeExtension) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getURL(String relativePath, boolean global) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String[] getSourceRoots() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setSourceRoots(String[] sourceRoots) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String[] getOriginalSourceRoots() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Creates instance of ContextAwareService based on layer.xml + * attribute values + * + * @param attrs attributes loaded from layer.xml + * @return new ContextAwareService instance + */ + static ContextAwareService createService(Map attrs) throws ClassNotFoundException { + String serviceName = (String) attrs.get(DebuggerProcessor.SERVICE_NAME); + return new ContextAware(serviceName); + } + + } } diff -u -N -r ../../HG_FRESH/main/api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/VariablesFilter.java api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/VariablesFilter.java --- ../../HG_FRESH/main/api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/VariablesFilter.java 2008-08-20 02:00:43.000000000 +0200 +++ api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/VariablesFilter.java 2009-01-25 18:22:09.000000000 +0100 @@ -41,8 +41,17 @@ package org.netbeans.spi.debugger.jpda; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.Map; import javax.swing.Action; import org.netbeans.api.debugger.jpda.Variable; +import org.netbeans.modules.debugger.jpda.apiregistry.DebuggerProcessor; +import org.netbeans.spi.debugger.ContextAwareService; +import org.netbeans.spi.debugger.ContextAwareSupport; +import org.netbeans.spi.debugger.ContextProvider; import org.netbeans.spi.viewmodel.NodeActionsProvider; import org.netbeans.spi.viewmodel.NodeModel; import org.netbeans.spi.viewmodel.TableModel; @@ -263,4 +272,117 @@ String columnID, Object value ) throws UnknownTypeException; + + + /** + * Declarative registration of a VariablesFilter implementation. + * By marking the implementation class with this annotation, + * you automatically register that implementation for use by debugger. + * The class must be public and have a public constructor which takes + * no arguments or takes {@link ContextProvider} as an argument. + * + * @author Martin Entlicher + * @since 2.19 + */ + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + /** + * An optional path to register this implementation in. + */ + String path() default ""; + + } + + static class ContextAware extends VariablesFilter implements ContextAwareService { + + private String serviceName; + + private ContextAware(String serviceName) { + this.serviceName = serviceName; + } + + public VariablesFilter forContext(ContextProvider context) { + return (VariablesFilter) ContextAwareSupport.createInstance(serviceName, context); + } + + @Override + public String[] getSupportedTypes() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String[] getSupportedAncestors() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Object[] getChildren(TreeModel original, Variable variable, int from, int to) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public int getChildrenCount(TreeModel original, Variable variable) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean isLeaf(TreeModel original, Variable variable) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getDisplayName(NodeModel original, Variable variable) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getIconBase(NodeModel original, Variable variable) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getShortDescription(NodeModel original, Variable variable) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Action[] getActions(NodeActionsProvider original, Variable variable) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void performDefaultAction(NodeActionsProvider original, Variable variable) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Object getValueAt(TableModel original, Variable variable, String columnID) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean isReadOnly(TableModel original, Variable variable, String columnID) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setValueAt(TableModel original, Variable variable, String columnID, Object value) throws UnknownTypeException { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Creates instance of ContextAwareService based on layer.xml + * attribute values + * + * @param attrs attributes loaded from layer.xml + * @return new ContextAwareService instance + */ + static ContextAwareService createService(Map attrs) throws ClassNotFoundException { + String serviceName = (String) attrs.get(DebuggerProcessor.SERVICE_NAME); + return new ContextAware(serviceName); + } + + } + }