# HG changeset patch # User mentlicher@netbeans.org # Date 1232726726 -3600 # Node ID 96d7b0b3803cf4b8b347645892d743d7f05488e8 # Parent 52c42ef090d0f46c81125fa16b135097ebd26f3e #153093 - After Lookups.forPath() was added to debugger's Lookup.MetaInf, generate declarative registration of debugger services into module layer via annotations. Tests added. diff -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/manifest.mf --- a/api.debugger/manifest.mf Fri Jan 23 17:01:51 2009 +0100 +++ b/api.debugger/manifest.mf Fri Jan 23 17:05:26 2009 +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-Implementation-Version: 70 diff -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/nbproject/project.properties --- a/api.debugger/nbproject/project.properties Fri Jan 23 17:01:51 2009 +0100 +++ b/api.debugger/nbproject/project.properties Fri Jan 23 17:05:26 2009 +0100 @@ -37,8 +37,10 @@ # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. +spec.version.base=1.15 is.autoload=true javac.compilerargs=-Xlint:unchecked 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 -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/src/org/netbeans/api/debugger/LazyActionsManagerListener.java --- a/api.debugger/src/org/netbeans/api/debugger/LazyActionsManagerListener.java Fri Jan 23 17:01:51 2009 +0100 +++ b/api.debugger/src/org/netbeans/api/debugger/LazyActionsManagerListener.java Fri Jan 23 17:05:26 2009 +0100 @@ -41,6 +41,12 @@ 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 org.openide.util.lookup.Lookups; + /** * This {@link ActionsManagerListener} modification is designed to be @@ -70,4 +76,15 @@ * @return list of properties this listener is listening on */ public abstract String[] getProperties (); + + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + /** + * An optional path to register this implementation in. + */ + String path() default ""; + + } + } diff -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/src/org/netbeans/api/debugger/Lookup.java --- a/api.debugger/src/org/netbeans/api/debugger/Lookup.java Fri Jan 23 17:01:51 2009 +0100 +++ b/api.debugger/src/org/netbeans/api/debugger/Lookup.java Fri Jan 23 17:05:26 2009 +0100 @@ -69,6 +69,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.debugger.registry.ContextAwareService; +import org.netbeans.debugger.registry.ContextAwareSupport; import org.netbeans.spi.debugger.ContextProvider; import org.openide.modules.ModuleInfo; import org.openide.util.Exceptions; @@ -336,97 +337,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)) { @@ -761,9 +671,8 @@ instance = lookupItem.getInstance(); if (instance instanceof ContextAwareService) { ContextAwareService cas = (ContextAwareService) instance; - className = cas.serviceName(); + instance = cas.forContext(Lookup.MetaInf.this.context); lookupItem = null; - instance = null; } } if (instance == null) { @@ -772,7 +681,7 @@ instance = instanceCache.get (className); } if (instance == null) { - instance = createInstance (className); + instance = ContextAwareSupport.createInstance (className, Lookup.MetaInf.this.context); synchronized (instanceCache) { instanceCache.put (className, instance); } diff -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/src/org/netbeans/debugger/registry/ActionsProviderContextAware.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api.debugger/src/org/netbeans/debugger/registry/ActionsProviderContextAware.java Fri Jan 23 17:05:26 2009 +0100 @@ -0,0 +1,119 @@ +/* + * 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 java.util.Map; +import java.util.Set; +import org.netbeans.spi.debugger.ActionsProvider; +import org.netbeans.spi.debugger.ActionsProviderListener; +import org.netbeans.spi.debugger.ContextProvider; + +/** + * + * @author Martin Entlicher + */ +public class ActionsProviderContextAware extends ActionsProvider implements ContextAwareService { + + private String serviceName; + private ContextProvider context; + private ActionsProvider delegate; + + private ActionsProviderContextAware(String serviceName) { + this.serviceName = serviceName; + } + + private ActionsProviderContextAware(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 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 ActionsProviderContextAware(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 ActionsProviderContextAware(serviceName); + } + +} diff -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/src/org/netbeans/debugger/registry/ContextAwareService.java --- a/api.debugger/src/org/netbeans/debugger/registry/ContextAwareService.java Fri Jan 23 17:01:51 2009 +0100 +++ b/api.debugger/src/org/netbeans/debugger/registry/ContextAwareService.java Fri Jan 23 17:05:26 2009 +0100 @@ -39,6 +39,8 @@ package org.netbeans.debugger.registry; +import org.netbeans.spi.debugger.ContextProvider; + /** * Instance of registry entry, that delegates to a debugger service, that can be * context-aware. @@ -58,8 +60,8 @@ * * @author Martin Entlicher */ -public interface ContextAwareService { +public interface ContextAwareService { - String serviceName(); + T forContext(ContextProvider context); } diff -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/src/org/netbeans/debugger/registry/ContextAwareServiceHandler.java --- a/api.debugger/src/org/netbeans/debugger/registry/ContextAwareServiceHandler.java Fri Jan 23 17:01:51 2009 +0100 +++ b/api.debugger/src/org/netbeans/debugger/registry/ContextAwareServiceHandler.java Fri Jan 23 17:05:26 2009 +0100 @@ -39,32 +39,121 @@ package org.netbeans.debugger.registry; +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 { - private static final String SERVICE_NAME = "serviceName"; // NOI18N - private static final String SERVICE_CLASS = "serviceClass"; // NOI18N + public static final String SERVICE_NAME = "serviceName"; // NOI18N + static final String SERVICE_CLASSES = "serviceClasses"; // NOI18N private String serviceName; + private Class[] serviceClasses; + private Map methodValues; + //private ContextProvider context; + private Object delegate; - private ContextAwareServiceHandler(String serviceName) { - this.serviceName = serviceName; + private Map contextInstances = new WeakHashMap(); + private WeakReference noContextInstance = new WeakReference(null); + + private 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 { - if (method.getName().equals("serviceName")) { // NOI18N - return serviceName; + 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 { - throw new UnsupportedOperationException("Method "+method.getName()+" can not be called on this virtual object!"); // NOI18N + /* + 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 } } @@ -77,15 +166,35 @@ */ static ContextAwareService createService(Map attrs) throws ClassNotFoundException { String serviceName = (String) attrs.get(SERVICE_NAME); - String serviceClass = (String) attrs.get(SERVICE_CLASS); + String[] serviceClassNames = splitClasses((String) attrs.get(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, - new Class[] { ContextAwareService.class, - Class.forName(serviceClass, true, cl) }, - new ContextAwareServiceHandler(serviceName)); + 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 -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/src/org/netbeans/debugger/registry/ContextAwareSupport.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api.debugger/src/org/netbeans/debugger/registry/ContextAwareSupport.java Fri Jan 23 17:05:26 2009 +0100 @@ -0,0 +1,146 @@ +/* + * 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 java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.netbeans.spi.debugger.ContextProvider; +import org.openide.util.Exceptions; + +/** + * + * @author Martin Entlicher + */ +public final class ContextAwareSupport { + + private ContextAwareSupport() {} + + 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; + } + +} diff -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/src/org/netbeans/debugger/registry/DebuggerEngineProviderContextAware.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api.debugger/src/org/netbeans/debugger/registry/DebuggerEngineProviderContextAware.java Fri Jan 23 17:05:26 2009 +0100 @@ -0,0 +1,114 @@ +/* + * 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 java.util.Map; + +import org.netbeans.api.debugger.DebuggerEngine.Destructor; +import org.netbeans.spi.debugger.ContextProvider; +import org.netbeans.spi.debugger.DebuggerEngineProvider; + +/** + * + * @author Martin Entlicher + */ +public class DebuggerEngineProviderContextAware extends DebuggerEngineProvider implements ContextAwareService { + + private String serviceName; + private ContextProvider context; + private DebuggerEngineProvider delegate; + + private DebuggerEngineProviderContextAware(String serviceName) { + this.serviceName = serviceName; + } + + private DebuggerEngineProviderContextAware(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 DebuggerEngineProviderContextAware(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(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 DebuggerEngineProviderContextAware(serviceName); + } + +} diff -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/src/org/netbeans/debugger/registry/DebuggerProcessor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api.debugger/src/org/netbeans/debugger/registry/DebuggerProcessor.java Fri Jan 23 17:05:26 2009 +0100 @@ -0,0 +1,286 @@ +/* + * 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.spi.debugger.InterfaceRegistration" //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(); + handleProviderRegistration(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(); + handleProviderRegistration(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(); + handleProviderRegistration(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(); + handleProviderRegistration(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.debugger.registry.ContextAwareServiceHandler", "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 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 -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/src/org/netbeans/debugger/registry/LazyActionsManagerListenerContextAware.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api.debugger/src/org/netbeans/debugger/registry/LazyActionsManagerListenerContextAware.java Fri Jan 23 17:05:26 2009 +0100 @@ -0,0 +1,85 @@ +/* + * 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 java.util.Map; + +import org.netbeans.api.debugger.LazyActionsManagerListener; +import org.netbeans.spi.debugger.ContextProvider; + +/** + * + * @author Martin Entlicher + */ +public class LazyActionsManagerListenerContextAware extends LazyActionsManagerListener implements ContextAwareService { + + private String serviceName; + + private LazyActionsManagerListenerContextAware(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 LazyActionsManagerListenerContextAware(serviceName); + } + +} diff -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/src/org/netbeans/debugger/registry/SessionProviderContextAware.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api.debugger/src/org/netbeans/debugger/registry/SessionProviderContextAware.java Fri Jan 23 17:05:26 2009 +0100 @@ -0,0 +1,113 @@ +/* + * 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 java.util.Map; + +import org.netbeans.spi.debugger.ContextProvider; +import org.netbeans.spi.debugger.SessionProvider; + +/** + * + * @author Martin Entlicher + */ +public class SessionProviderContextAware extends SessionProvider implements ContextAwareService { + + private String serviceName; + private ContextProvider context; + private SessionProvider delegate; + + private SessionProviderContextAware(String serviceName) { + this.serviceName = serviceName; + } + + private SessionProviderContextAware(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 SessionProviderContextAware(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 SessionProviderContextAware(serviceName); + } + +} diff -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/src/org/netbeans/spi/debugger/ActionsProvider.java --- a/api.debugger/src/org/netbeans/spi/debugger/ActionsProvider.java Fri Jan 23 17:01:51 2009 +0100 +++ b/api.debugger/src/org/netbeans/spi/debugger/ActionsProvider.java Fri Jan 23 17:05:26 2009 +0100 @@ -41,6 +41,10 @@ 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.Set; import org.openide.util.RequestProcessor; @@ -109,6 +113,16 @@ } }); } + + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + /** + * An optional path to register this implementation in. + */ + String path() default ""; + + } } diff -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/src/org/netbeans/spi/debugger/DebuggerEngineProvider.java --- a/api.debugger/src/org/netbeans/spi/debugger/DebuggerEngineProvider.java Fri Jan 23 17:01:51 2009 +0100 +++ b/api.debugger/src/org/netbeans/spi/debugger/DebuggerEngineProvider.java Fri Jan 23 17:05:26 2009 +0100 @@ -40,6 +40,11 @@ */ 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 org.netbeans.api.debugger.DebuggerEngine; @@ -88,5 +93,16 @@ * by this instance */ public abstract void setDestructor (DebuggerEngine.Destructor desctuctor); + + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + /** + * An optional path to register this implementation in. + */ + String path() default ""; + + } + } diff -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/src/org/netbeans/spi/debugger/DebuggerServiceRegistration.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api.debugger/src/org/netbeans/spi/debugger/DebuggerServiceRegistration.java Fri Jan 23 17:05:26 2009 +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 org.openide.util 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 -r 52c42ef090d0 -r 96d7b0b3803c api.debugger/src/org/netbeans/spi/debugger/SessionProvider.java --- a/api.debugger/src/org/netbeans/spi/debugger/SessionProvider.java Fri Jan 23 17:01:51 2009 +0100 +++ b/api.debugger/src/org/netbeans/spi/debugger/SessionProvider.java Fri Jan 23 17:05:26 2009 +0100 @@ -41,6 +41,13 @@ 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 org.openide.util.lookup.Lookups; + /** * Creates a new instance of {@link org.netbeans.api.debugger.Session} * for some {@link org.netbeans.api.debugger.DebuggerInfo}. @@ -80,5 +87,16 @@ * @return array of services */ public abstract Object[] getServices (); + + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + /** + * An optional path to register this implementation in. + */ + String path() default ""; + + } + } diff -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/manifest.mf --- a/spi.debugger.ui/manifest.mf Fri Jan 23 17:01:51 2009 +0100 +++ b/spi.debugger.ui/manifest.mf Fri Jan 23 17:05:26 2009 +0100 @@ -2,6 +2,5 @@ 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-Provides: org.netbeans.spi.debugger.ui OpenIDE-Module-Install: org/netbeans/modules/debugger/ui/DebuggerModule.class diff -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/nbproject/project.properties --- a/spi.debugger.ui/nbproject/project.properties Fri Jan 23 17:01:51 2009 +0100 +++ b/spi.debugger.ui/nbproject/project.properties Fri Jan 23 17:05:26 2009 +0100 @@ -37,9 +37,11 @@ # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. +spec.version.base=2.15 is.autoload=true javac.compilerargs=-Xlint -Xlint:-serial javac.source=1.5 javadoc.arch=${basedir}/arch.xml test.timeout=1800000 test.config.stable.includes=**/ts/*TestSuite.class +cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar diff -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/nbproject/project.xml --- a/spi.debugger.ui/nbproject/project.xml Fri Jan 23 17:01:51 2009 +0100 +++ b/spi.debugger.ui/nbproject/project.xml Fri Jan 23 17:05:26 2009 +0100 @@ -52,7 +52,7 @@ 1 - 1.13 + @@ -174,11 +174,11 @@ - org.netbeans.modules.nbjunit - - - - + org.netbeans.modules.nbjunit + + + + org.netbeans.modules.jellytools diff -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/AttachTypeContextAware.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/AttachTypeContextAware.java Fri Jan 23 17:05:26 2009 +0100 @@ -0,0 +1,115 @@ +/* + * 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.util.Map; +import java.util.Set; + +import javax.swing.JComponent; +import org.netbeans.debugger.registry.ContextAwareService; +import org.netbeans.debugger.registry.ContextAwareServiceHandler; +import org.netbeans.debugger.registry.ContextAwareSupport; +import org.netbeans.spi.debugger.ContextProvider; +import org.netbeans.spi.debugger.ui.AttachType; + +/** + * + * @author Martin Entlicher + */ +public class AttachTypeContextAware extends AttachType implements ContextAwareService { + + private String serviceName; + private String displayName; + private ContextProvider context; + private AttachType delegate; + + private AttachTypeContextAware(String serviceName, String displayName) { + this.serviceName = serviceName; + this.displayName = displayName; + } + + private AttachTypeContextAware(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 AttachTypeContextAware(serviceName, displayName, context); + } + } + + @Override + public String getTypeDisplayName() { + if (displayName != null) { + return displayName; + } + return getDelegate().getTypeDisplayName(); + } + + @Override + public JComponent getCustomizer() { + return getDelegate().getCustomizer(); + } + + /** + * 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 displayName = (String) attrs.get("displayName"); + return new AttachTypeContextAware(serviceName, displayName); + } + +} diff -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/BreakpointTypeContextAware.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/BreakpointTypeContextAware.java Fri Jan 23 17:05:26 2009 +0100 @@ -0,0 +1,125 @@ +/* + * 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.util.Map; +import javax.swing.JComponent; + +import org.netbeans.debugger.registry.ContextAwareService; +import org.netbeans.debugger.registry.ContextAwareServiceHandler; +import org.netbeans.debugger.registry.ContextAwareSupport; + +import org.netbeans.spi.debugger.ContextProvider; +import org.netbeans.spi.debugger.ui.BreakpointType; + +/** + * + * @author Martin Entlicher + */ +public class BreakpointTypeContextAware extends BreakpointType implements ContextAwareService { + + private String serviceName; + private String displayName; + private ContextProvider context; + private BreakpointType delegate; + + private BreakpointTypeContextAware(String serviceName, String displayName) { + this.serviceName = serviceName; + this.displayName = displayName; + } + + private BreakpointTypeContextAware(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 BreakpointTypeContextAware(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(ContextAwareServiceHandler.SERVICE_NAME); + String displayName = (String) attrs.get("displayName"); + return new BreakpointTypeContextAware(serviceName, displayName); + } + +} diff -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/ColumnModelContextAware.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/ColumnModelContextAware.java Fri Jan 23 17:05:26 2009 +0100 @@ -0,0 +1,195 @@ +/* + * 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 javax.swing.JComponent; +import org.netbeans.debugger.registry.ContextAwareService; +import org.netbeans.debugger.registry.ContextAwareServiceHandler; +import org.netbeans.debugger.registry.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(ContextAwareServiceHandler.SERVICE_NAME); + return new ColumnModelContextAware(serviceName); + } + +} diff -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/DebuggerProcessor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/registry/DebuggerProcessor.java Fri Jan 23 17:05:26 2009 +0100 @@ -0,0 +1,205 @@ +/* + * 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.ActionsProvider; +import org.netbeans.spi.debugger.ui.AttachType; +import org.netbeans.spi.debugger.ui.BreakpointType; +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 +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(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(ColumnModel.Registration.class)) { + ColumnModel.Registration reg = e.getAnnotation(ColumnModel.Registration.class); + + final String path = reg.path(); + handleProviderRegistration(e, ColumnModel.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("serviceName", className). + stringvalue("serviceClass", providerClass.getName()). + methodvalue("instanceCreate", "org.netbeans.modules.debugger.ui.registry."+providerClass.getSimpleName()+"ContextAware", "createService"). + 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("serviceName", className). + stringvalue("serviceClass", providerClass.getName()). + stringvalue("displayName", displayName). // TODO bundleValue + methodvalue("instanceCreate", "org.netbeans.modules.debugger.ui.registry."+providerClass.getSimpleName()+"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); + } + } +} diff -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/src/org/netbeans/spi/debugger/ui/AttachType.java --- a/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/AttachType.java Fri Jan 23 17:01:51 2009 +0100 +++ b/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/AttachType.java Fri Jan 23 17:05:26 2009 +0100 @@ -41,6 +41,10 @@ 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 javax.swing.JComponent; @@ -52,12 +56,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 +93,10 @@ return null; } + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + String displayName(); + } + } \ No newline at end of file diff -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/src/org/netbeans/spi/debugger/ui/BreakpointType.java --- a/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/BreakpointType.java Fri Jan 23 17:01:51 2009 +0100 +++ b/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/BreakpointType.java Fri Jan 23 17:05:26 2009 +0100 @@ -41,6 +41,10 @@ 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 javax.swing.JComponent; /** @@ -60,11 +64,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 +109,11 @@ * @return true of this breakpoint type should be default */ public abstract boolean isDefault (); + + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + String displayName(); + } + } \ No newline at end of file diff -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/ProvidersAnnotationTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/ProvidersAnnotationTest.java Fri Jan 23 17:05:26 2009 +0100 @@ -0,0 +1,171 @@ +/* + * 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.spi.debugger.ActionsProvider; +import org.netbeans.spi.debugger.ContextProvider; +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()); + + } + } +} diff -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestActionProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestActionProvider.java Fri Jan 23 17:05:26 2009 +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 -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestAttachType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestAttachType.java Fri Jan 23 17:05:26 2009 +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 -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestBreakpointType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestBreakpointType.java Fri Jan 23 17:05:26 2009 +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 -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestColumnModel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestColumnModel.java Fri Jan 23 17:05:26 2009 +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 org.netbeans.spi.viewmodel.ColumnModel; + +/** + * + * @author Martin Entlicher + */ +@ColumnModel.Registration(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 -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestDebuggerEngineProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestDebuggerEngineProvider.java Fri Jan 23 17:05:26 2009 +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 -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestLazyActionsManagerListenerAnnotated.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestLazyActionsManagerListenerAnnotated.java Fri Jan 23 17:05:26 2009 +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 -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestLazyDebuggerManagerListenerAnnotated.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestLazyDebuggerManagerListenerAnnotated.java Fri Jan 23 17:05:26 2009 +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 -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestSessionProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestSessionProvider.java Fri Jan 23 17:05:26 2009 +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 -r 52c42ef090d0 -r 96d7b0b3803c spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestThreeModels.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/providers/TestThreeModels.java Fri Jan 23 17:05:26 2009 +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 -r 52c42ef090d0 -r 96d7b0b3803c spi.viewmodel/src/org/netbeans/spi/viewmodel/ColumnModel.java --- a/spi.viewmodel/src/org/netbeans/spi/viewmodel/ColumnModel.java Fri Jan 23 17:01:51 2009 +0100 +++ b/spi.viewmodel/src/org/netbeans/spi/viewmodel/ColumnModel.java Fri Jan 23 17:05:26 2009 +0100 @@ -42,7 +42,10 @@ package org.netbeans.spi.viewmodel; import java.beans.PropertyEditor; -import javax.swing.table.TableCellEditor; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import javax.swing.table.TableCellRenderer; @@ -260,4 +263,11 @@ // public TableCellRenderer getTableCellRenderer () { // return null; // } + + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + public @interface Registration { + String path(); + } + }