This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 152675
Collapse All | Expand All

(-)src/org/netbeans/modules/apisupport/project/ui/ImportantFilesNodeFactory.java (+4 lines)
Lines 55-60 Link Here
55
import org.netbeans.modules.apisupport.project.layers.LayerNode;
55
import org.netbeans.modules.apisupport.project.layers.LayerNode;
56
import org.netbeans.modules.apisupport.project.layers.LayerUtils;
56
import org.netbeans.modules.apisupport.project.layers.LayerUtils;
57
import org.netbeans.modules.apisupport.project.suite.SuiteProject;
57
import org.netbeans.modules.apisupport.project.suite.SuiteProject;
58
import org.netbeans.modules.apisupport.project.ui.services.ServicesChildFactory;
58
import org.netbeans.spi.project.ui.support.NodeFactory;
59
import org.netbeans.spi.project.ui.support.NodeFactory;
59
import org.netbeans.spi.project.ui.support.NodeList;
60
import org.netbeans.spi.project.ui.support.NodeList;
60
import org.openide.ErrorManager;
61
import org.openide.ErrorManager;
Lines 246-251 Link Here
246
                }
247
                }
247
            } else if (key instanceof LayerUtils.LayerHandle) {
248
            } else if (key instanceof LayerUtils.LayerHandle) {
248
                return new Node[] {/* #68240 */ new SpecialFileNode(new LayerNode((LayerUtils.LayerHandle) key), null)};
249
                return new Node[] {/* #68240 */ new SpecialFileNode(new LayerNode((LayerUtils.LayerHandle) key), null)};
250
            } else if (key instanceof ImportantFilesChildren) {
251
                return new Node[] { ServicesChildFactory.createRoot(project) };
249
            } else {
252
            } else {
250
                throw new AssertionError(key);
253
                throw new AssertionError(key);
251
            } 
254
            } 
Lines 254-259 Link Here
254
        private void refreshKeys() {
257
        private void refreshKeys() {
255
            Set<FileObject> files = new HashSet<FileObject>();
258
            Set<FileObject> files = new HashSet<FileObject>();
256
            List<Object> newVisibleFiles = new ArrayList<Object>();
259
            List<Object> newVisibleFiles = new ArrayList<Object>();
260
            newVisibleFiles.add (this);
257
            LayerUtils.LayerHandle handle = LayerUtils.layerForProject(project);
261
            LayerUtils.LayerHandle handle = LayerUtils.layerForProject(project);
258
            FileObject layerFile = handle.getLayerFile();
262
            FileObject layerFile = handle.getLayerFile();
259
            if (layerFile != null) {
263
            if (layerFile != null) {
(-)src/org/netbeans/modules/apisupport/project/ui/services/Bundle.properties (+38 lines)
Line 0 Link Here
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
4
#
5
# The contents of this file are subject to the terms of either the GNU
6
# General Public License Version 2 only ("GPL") or the Common
7
# Development and Distribution License("CDDL") (collectively, the
8
# "License"). You may not use this file except in compliance with the
9
# License. You can obtain a copy of the License at
10
# http://www.netbeans.org/cddl-gplv2.html
11
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
12
# specific language governing permissions and limitations under the
13
# License.  When distributing the software, include this License Header
14
# Notice in each file and include the License file at
15
# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
16
# particular file as subject to the "Classpath" exception as provided
17
# by Sun in the GPL Version 2 section of the License file that
18
# accompanied this code. If applicable, add the following below the
19
# License Header, with the fields enclosed by brackets [] replaced by
20
# your own identifying information:
21
# "Portions Copyrighted [year] [name of copyright owner]"
22
#
23
# If you wish your version of this file to be governed by only the CDDL
24
# or only the GPL Version 2, indicate your decision by adding
25
# "[Contributor] elects to include this software in this distribution
26
# under the [CDDL or GPL Version 2] license." If you do not indicate a
27
# single choice of license, a recipient has the option to distribute
28
# your version of this file under either the CDDL, the GPL Version 2 or
29
# to extend the choice of license to its licensees as provided above.
30
# However, if you add GPL Version 2 code and therefore, elected the GPL
31
# Version 2 license, then the option applies only if the new code is
32
# made subject to such option by the copyright holder.
33
#
34
# Contributor(s):
35
#
36
# Portions Copyrighted 2009 Sun Microsystems, Inc.
37
38
SERVICES=Default Lookup
(-)src/org/netbeans/modules/apisupport/project/ui/services/ServiceNode.java (+80 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.apisupport.project.ui.services;
41
42
import java.awt.Image;
43
import javax.swing.Action;
44
import org.openide.actions.EditAction;
45
import org.openide.actions.OpenAction;
46
import org.openide.cookies.EditCookie;
47
import org.openide.cookies.OpenCookie;
48
import org.openide.nodes.FilterNode;
49
import org.openide.nodes.Node;
50
import org.openide.util.ImageUtilities;
51
import org.openide.util.actions.SystemAction;
52
53
/**
54
 *
55
 * @author Tim Boudreau
56
 */
57
final class ServiceNode extends FilterNode {
58
    public ServiceNode(Node nodeDelegate, String fqn) {
59
        super (nodeDelegate);
60
        disableDelegation(DELEGATE_SET_DISPLAY_NAME);
61
        disableDelegation(DELEGATE_GET_DISPLAY_NAME);
62
        //PENDING:  Could listen for name changes instead of
63
        //relying on parent node refresh
64
        setDisplayName(fqn);
65
    }
66
67
    @Override
68
    public Action[] getActions (boolean ignored) {
69
        EditCookie ec = getLookup().lookup(EditCookie.class);
70
        if (ec != null) {
71
            return new Action[] { SystemAction.get(EditAction.class) };
72
        } else {
73
            OpenCookie oc = getLookup().lookup(OpenCookie.class);
74
            if (oc != null) {
75
                return new Action[] { SystemAction.get(OpenAction.class) };
76
            }
77
        }
78
        return new Action[0];
79
    }
80
}
(-)src/org/netbeans/modules/apisupport/project/ui/services/ServicesChildFactory.java (+188 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
package org.netbeans.modules.apisupport.project.ui.services;
40
41
import java.beans.PropertyChangeEvent;
42
import java.beans.PropertyChangeListener;
43
import java.util.Collections;
44
import java.util.HashSet;
45
import java.util.List;
46
import java.util.Set;
47
import org.netbeans.api.java.classpath.ClassPath;
48
import org.netbeans.api.project.Project;
49
import org.netbeans.modules.apisupport.project.NbModuleProject;
50
import org.netbeans.modules.apisupport.project.queries.ClassPathProviderImpl;
51
import org.netbeans.spi.java.classpath.ClassPathProvider;
52
import org.openide.filesystems.FileChangeAdapter;
53
import org.openide.filesystems.FileEvent;
54
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileRenameEvent;
56
import org.openide.loaders.DataObject;
57
import org.openide.loaders.DataObjectNotFoundException;
58
import org.openide.nodes.AbstractNode;
59
import org.openide.nodes.ChildFactory;
60
import org.openide.nodes.Children;
61
import org.openide.nodes.Node;
62
import org.openide.util.Exceptions;
63
import org.openide.util.NbBundle;
64
import org.openide.util.lookup.Lookups;
65
import org.openide.util.lookup.ServiceProvider;
66
67
/**
68
 *
69
 * @author Tim Boudreau
70
 */
71
public final class ServicesChildFactory extends ChildFactory.Detachable<ServicesEntry> implements PropertyChangeListener {
72
    private static final String ICON_BASE =
73
        "org/netbeans/modules/apisupport/project/resources/defaultLookup.png"; //NOI18N
74
    private final Project project;
75
    private final Set<String> paths = Collections.synchronizedSet(new HashSet<String>());
76
    private final FL fl = new FL();
77
78
    public ServicesChildFactory(Project p) {
79
        this.project = p;
80
    }
81
82
    public static Node createRoot(Project project) {
83
        AbstractNode result = new AbstractNode(Children.create(
84
                new ServicesChildFactory(project), true), Lookups.singleton(project));
85
        result.setDisplayName(NbBundle.getMessage(ServicesChildFactory.class, 
86
                "SERVICES")); //NOI18N
87
        result.setIconBaseWithExtension(ICON_BASE);
88
        return result;
89
    }
90
91
    @Override
92
    protected boolean createKeys(final List<ServicesEntry> toPopulate) {
93
        ClassPathProviderImpl prov = project.getLookup().lookup(ClassPathProviderImpl.class);
94
        TypeFinder.Callback cb = new TypeFinder.Callback() {
95
            public void foundFileObject(FileObject fo, String className) {
96
                toPopulate.add(new ServicesEntry(fo, className));
97
                paths.add(fo.getPath());
98
            }
99
        };
100
        if (prov != null) {
101
            for (ClassPath srcPath : prov.getProjectClassPaths(ClassPath.SOURCE)) {
102
                TypeFinder finder = new TypeFinder(ServiceProvider.class.getName(), srcPath);
103
                finder.findTypes(cb);
104
            }
105
        }
106
        return true;
107
    }
108
109
    @Override
110
    protected Node createNodeForKey(ServicesEntry key) {
111
        if (key.fo.isValid()) {
112
            try {
113
                return new ServiceNode(DataObject.find(key.fo).getNodeDelegate(), key.fqn);
114
            } catch (DataObjectNotFoundException ex) {
115
                Exceptions.printStackTrace(ex);
116
            }
117
        }
118
        return null;
119
    }
120
121
    public void propertyChange(PropertyChangeEvent evt) {
122
        if (ClassPath.PROP_ROOTS.equals(evt.getPropertyName())) {
123
            refresh(true);
124
        }
125
    }
126
127
    @Override
128
    protected void addNotify() {
129
        super.addNotify();
130
        ClassPathProvider prov = project.getLookup().lookup(ClassPathProvider.class);
131
        NbModuleProject m = (NbModuleProject) project;
132
        if (prov != null) {
133
            ClassPath srcPath = prov.findClassPath(m.getSourceDirectory(), ClassPath.SOURCE);
134
            init(srcPath);
135
        }
136
    }
137
138
    @Override
139
    protected void removeNotify() {
140
        ClassPathProvider prov = project.getLookup().lookup(ClassPathProvider.class);
141
        NbModuleProject m = (NbModuleProject) project;
142
        if (prov != null) {
143
            ClassPath srcPath = prov.findClassPath(m.getSourceDirectory(), ClassPath.SOURCE);
144
            uninit(srcPath);
145
        }
146
        super.removeNotify();
147
    }
148
149
    private void init(ClassPath srcPath) {
150
        srcPath.addPropertyChangeListener(this);
151
        for (FileObject root : srcPath.getRoots()) {
152
            root.addFileChangeListener(fl);
153
        }
154
    }
155
156
    private void uninit(ClassPath srcPath) {
157
        srcPath.removePropertyChangeListener(this);
158
        for (FileObject root : srcPath.getRoots()) {
159
            root.removeFileChangeListener(fl);
160
        }
161
    }
162
163
    private class FL extends FileChangeAdapter {
164
165
        @Override
166
        public void fileChanged(FileEvent fe) {
167
            FileObject fo = (FileObject) fe.getSource();
168
            if ("text/x-java".equals(fo.getMIMEType())) { //NOI18N
169
                String path = fo.getPath();
170
                if (!paths.contains(path)) {
171
                    //XXX scan just this file, not everything
172
                    refresh(false);
173
                }
174
            }
175
        }
176
177
        @Override
178
        public void fileRenamed(FileRenameEvent fe) {
179
            FileObject fo = (FileObject) fe.getSource();
180
            if ("text/x-java".equals(fo.getMIMEType())) { //NOI18N
181
                String path = fo.getParent().getPath() + "/" + fe.getName() + "." + fe.getExt();
182
                if (paths.contains(path)) {
183
                    refresh(false);
184
                }
185
            }
186
        }
187
    }
188
}
(-)src/org/netbeans/modules/apisupport/project/ui/services/ServicesEntry.java (+15 lines)
Line 0 Link Here
1
package org.netbeans.modules.apisupport.project.ui.services;
2
3
import org.openide.filesystems.FileObject;
4
5
public final class ServicesEntry {
6
7
    FileObject fo;
8
    String fqn;
9
10
    public ServicesEntry(FileObject fo, String fqn) {
11
        super();
12
        this.fo = fo;
13
        this.fqn = fqn;
14
    }
15
}
(-)src/org/netbeans/modules/apisupport/project/ui/services/TypeFinder.java (+203 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.modules.apisupport.project.ui.services;
42
43
import com.sun.source.tree.AnnotationTree;
44
import com.sun.source.tree.ClassTree;
45
import com.sun.source.tree.CompilationUnitTree;
46
import com.sun.source.tree.Tree;
47
import com.sun.source.tree.TreeVisitor;
48
import com.sun.source.util.SimpleTreeVisitor;
49
import com.sun.source.util.TreePath;
50
import com.sun.source.util.Trees;
51
import org.netbeans.api.java.classpath.ClassPath;
52
import org.netbeans.api.java.source.CancellableTask;
53
import org.netbeans.api.java.source.CompilationController;
54
import org.netbeans.api.java.source.JavaSource;
55
import org.netbeans.api.java.source.JavaSource.Phase;
56
import org.openide.filesystems.FileObject;
57
58
import javax.lang.model.type.TypeMirror;
59
import javax.lang.model.util.Types;
60
import java.awt.*;
61
import java.io.IOException;
62
import java.util.List;
63
import java.util.logging.Level;
64
import java.util.logging.Logger;
65
import org.openide.util.Parameters;
66
67
/**
68
 * Scans a classpath and finds all subtypes of a given type.
69
 *
70
 * @author Tim Boudreau
71
 */
72
public class TypeFinder implements CancellableTask<CompilationController> {
73
    private volatile boolean cancelled;
74
    private final ClassPath classpath;
75
    private final String fqn;
76
    private Callback callback;
77
78
    public TypeFinder(String fqn, ClassPath path) {
79
        this.classpath = path;
80
        this.fqn = fqn;
81
        Parameters.notNull ("Classpath", path); //NOI18N
82
        Parameters.notNull ("AnnotationName", fqn); //NOI18N
83
    }
84
85
    public interface Callback {
86
        public void foundFileObject(FileObject fo, String className);
87
    }
88
89
    public void findTypes(Callback callback) {
90
        //Don't ever do this kind of IO-heavy work on the event thread
91
        assert !EventQueue.isDispatchThread();
92
        this.callback = callback;
93
        //recursively iterate all children
94
        for (FileObject fo : classpath.getRoots()) {
95
            analyze(fo);
96
        }
97
    }
98
99
100
    private void analyze(FileObject fo) {
101
        if (fo.isFolder()) {
102
            for (FileObject child : fo.getChildren()) {
103
                analyze(child);
104
            }
105
        } else if ("java".equals(fo.getExt())) { //NOI18N
106
            JavaSource src = JavaSource.forFileObject(fo);
107
            try {
108
                src.runUserActionTask(this, true);
109
            } catch (IOException ex) {
110
                Logger.getLogger(TypeFinder.class.getName()).log(Level.INFO,
111
                        "Problem scanning " + fo.getPath(), ex); //NOI18N
112
            }
113
        }
114
    }
115
116
    public void reset() {
117
        cancelled = false;
118
    }
119
120
    public void cancel() {
121
        cancelled = true;
122
    }
123
124
    public void run(CompilationController compiler) throws Exception {
125
        if (cancelled) {
126
            return;
127
        }
128
        compiler.toPhase(Phase.RESOLVED);
129
        if (cancelled) {
130
            return;
131
        }
132
        List <? extends Tree> types =
133
                compiler.getCompilationUnit().getTypeDecls();
134
        for (Tree tree: types) {
135
            if (cancelled) {
136
                return;
137
            }
138
            TypeMirror mirror = compiler.getTrees().getTypeMirror(
139
                    TreePath.getPath(compiler.getCompilationUnit(),
140
                    tree));
141
            if (tree instanceof ClassTree && match(compiler, (ClassTree) tree)) {
142
                callback.foundFileObject(compiler.getFileObject(),
143
                        mirror.toString());
144
            }
145
        }
146
    }
147
148
    boolean match(CompilationController compiler, ClassTree t) {
149
//        compiler.getTrees(), compiler.getTypes(), compiler.getCompilationUnit()/
150
//        TypeMirror mirror = trees.getTypeMirror(TreePath.getPath(unit, t));
151
        V v = new V(compiler);
152
        return t.accept(v, callback);
153
//        return match(mirror, types);
154
    }
155
156
    /*
157
    boolean match(TypeMirror mirror, Types types) {
158
        boolean result = false;
159
        if (mirror != null && 
160
            !"java.lang.Object".equals(mirror.toString())) { //NOI18N
161
162
            result = fqn.equals(mirror.toString());
163
            if (!result) {
164
                List<? extends TypeMirror> l = 
165
                        types.directSupertypes(mirror);
166
167
                for (TypeMirror tm : l) {
168
                    result = match(tm, types);
169
                    if (cancelled) return result;
170
                    if (result) break;
171
                }
172
            }
173
        }
174
        return result;
175
    }
176
     */
177
178
    private class V extends SimpleTreeVisitor <Boolean, Callback> {
179
        private final CompilationController compiler;
180
        V (CompilationController compiler) {
181
            this.compiler = compiler;
182
        }
183
184
        @Override
185
        public Boolean visitAnnotation(AnnotationTree node, Callback p) {
186
            TypeMirror mirror = compiler.getTrees().getTypeMirror(TreePath.getPath(compiler.getCompilationUnit(), node));
187
            return fqn.equals (mirror.toString());
188
        }
189
190
        @Override
191
        public Boolean visitClass(ClassTree node, Callback p) {
192
            boolean result = false;
193
            for (AnnotationTree t : node.getModifiers().getAnnotations()) {
194
                result = visitAnnotation(t, p);
195
                if (result) {
196
                    break;
197
                }
198
            }
199
            return result;
200
        }
201
202
    }
203
}

Return to bug 152675