diff -r 7b2eaa138aec openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java --- a/openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java Sat Jun 06 01:13:42 2009 +0200 +++ b/openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java Wed Jun 10 19:36:26 2009 +0200 @@ -40,13 +40,15 @@ package org.netbeans.modules.openide.awt; import java.awt.event.ActionListener; -import java.util.Arrays; +import java.util.Map.Entry; 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.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -55,6 +57,10 @@ import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.util.ElementFilter; +import javax.lang.model.util.Elements; +import javax.lang.model.util.Types; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReference.Meta; import org.openide.awt.ActionRegistration; import org.openide.filesystems.annotations.LayerBuilder.File; import org.openide.filesystems.annotations.LayerGeneratingProcessor; @@ -96,6 +102,42 @@ } f.boolvalue("noIconInMenu", !ar.iconInMenu()); f.write(); + + ActionReference ref = e.getAnnotation(ActionReference.class); + if (ref != null) { + String shadid = ref.id().length() == 0 ? id : ref.id(); + assert ref.refcategory().length() == 0; + assert ref.refid().length() == 0; + File shad = layer(e).file(ref.path() + "/" + shadid + ".shadow"); + shad.stringvalue("originalFile", f.getPath()); + shad.write(); + } + Elements eu = processingEnv.getElementUtils(); + Types tu = processingEnv.getTypeUtils(); + for (AnnotationMirror am : e.getAnnotationMirrors()) { + System.err.println("am: " + am); + String s = am.toString().substring(1); + int open = s.indexOf('('); + if (open != -1) { + s = s.substring(0, open); + } + System.err.println("name: " + s); + TypeElement anno = eu.getTypeElement(s); + Meta meta = anno.getAnnotation(ActionReference.Meta.class); + if (meta == null) { + continue; + } + System.err.println("me: " + meta); + String path = meta.path(); + for (Entry et : am.getElementValues().entrySet()) { + String v = et.getValue().toString().substring(1); + v = v.substring(0, v.length() - 1); + path = path.replace(et.getKey().toString(), v); + } + File shad = layer(e).file(path + "/" + id + ".shadow"); + shad.stringvalue("originalFile", f.getPath()); + shad.write(); + } } return true; } diff -r 7b2eaa138aec openide.awt/src/org/openide/awt/ActionReference.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.awt/src/org/openide/awt/ActionReference.java Wed Jun 10 19:36:26 2009 +0200 @@ -0,0 +1,66 @@ +/* + * 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.openide.awt; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.openide.awt.ActionReference.Meta; + +/** + * + * @author Jaroslav Tulach + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +//@Meta(path="${path}") +public @interface ActionReference { + String refcategory() default ""; + String refid() default ""; + String path(); + String id() default ""; + + @Target(ElementType.ANNOTATION_TYPE) + @Retention(RetentionPolicy.CLASS) + public @interface Meta { + String path(); + } +} diff -r 7b2eaa138aec openide.awt/test/unit/src/org/netbeans/modules/openide/awt/ActionProcessorTest.java --- a/openide.awt/test/unit/src/org/netbeans/modules/openide/awt/ActionProcessorTest.java Sat Jun 06 01:13:42 2009 +0200 +++ b/openide.awt/test/unit/src/org/netbeans/modules/openide/awt/ActionProcessorTest.java Wed Jun 10 19:36:26 2009 +0200 @@ -41,11 +41,16 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.Collection; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.ActionMap; import org.netbeans.junit.NbTestCase; +import org.openide.awt.ActionReference; import org.openide.awt.ActionRegistration; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; @@ -102,6 +107,9 @@ id="my-action", key="klic" ) + @ActionReference( + path="Loaders/text/x-test/Actions" + ) public static final class Callback implements ActionListener { static int cnt; public void actionPerformed(ActionEvent e) { @@ -111,8 +119,13 @@ public void testCallbackAction() throws Exception { FileObject fo = FileUtil.getConfigFile( - "Actions/Tools/my-action.instance" + "Loaders/text/x-test/Actions/my-action.shadow" ); + assertNotNull("Shadow found", fo); + String orig = (String) fo.getAttribute("originalFile"); + assertNotNull("reference defined", orig); + + fo = FileUtil.getConfigFile(orig); assertNotNull("File found", fo); Object obj = fo.getAttribute("instanceCreate"); assertNotNull("Attribute present", obj); @@ -145,11 +158,19 @@ assertEquals("Global Action called", 200, Callback.cnt); } + @ActionReference.Meta(path="Loaders/mimeType()/Actions") + @Retention(RetentionPolicy.SOURCE) + @Target(ElementType.TYPE) + public @interface MimeAction { + String mimeType(); + } + @ActionRegistration( category="Tools", displayName="#OnInt", id="on-int" ) + @MimeAction(mimeType="text/mime") public static final class Context implements ActionListener { private final int context; @@ -167,8 +188,13 @@ public void testContextAction() throws Exception { FileObject fo = FileUtil.getConfigFile( - "Actions/Tools/on-int.instance" + "Loaders/text/mime/Actions/on-int.shadow" ); + assertNotNull("Shadow found", fo); + String orig = (String) fo.getAttribute("originalFile"); + assertNotNull("reference defined", orig); + + fo = FileUtil.getConfigFile(orig); assertNotNull("File found", fo); Object obj = fo.getAttribute("instanceCreate"); assertNotNull("Attribute present", obj);