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 129884
Collapse All | Expand All

(-)a/api.java/apichanges.xml (+15 lines)
Lines 73-78 Link Here
73
<!-- ACTUAL CHANGES BEGIN HERE: -->
73
<!-- ACTUAL CHANGES BEGIN HERE: -->
74
74
75
<changes>
75
<changes>
76
        <change id="queries">
77
            <api name="queries"/>
78
            <summary>Support for delegating SourceForBinaryQueryImplementation2</summary>
79
            <version major="1" minor="16"/>
80
            <date day="13" month="3" year="2008"/>
81
            <author login="tzezula"/>
82
            <compatibility addition="yes" modification="no" semantic="compatible" source="compatible" binary="compatible"/>
83
            <description>
84
                <p>
85
                    Added support base class for SourceForBinaryQueryImplementation2 which delegates to other SourceForBinaryQueryImplementations.
86
                </p>
87
            </description>
88
            <class package="org.netbeans.spi.java.queries.support" name="SourceForBinaryQueryImplementation2Base"/>
89
            <issue number="129884"/>
90
        </change>
76
        <change id="queries">
91
        <change id="queries">
77
            <api name="queries"/>
92
            <api name="queries"/>
78
            <summary>Support for passing hint to the java infrastructure whether it should prefer source or binary</summary>
93
            <summary>Support for passing hint to the java infrastructure whether it should prefer source or binary</summary>
(-)a/api.java/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.api.java/1
2
OpenIDE-Module: org.netbeans.api.java/1
3
OpenIDE-Module-Specification-Version: 1.15
3
OpenIDE-Module-Specification-Version: 1.16
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/java/classpath/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/java/classpath/Bundle.properties
5
AutoUpdate-Show-In-Client: false
5
AutoUpdate-Show-In-Client: false
6
6
(-)a/api.java/nbproject/project.xml (+1 lines)
Lines 100-105 Link Here
100
                <package>org.netbeans.spi.java.classpath</package>
100
                <package>org.netbeans.spi.java.classpath</package>
101
                <package>org.netbeans.spi.java.classpath.support</package>
101
                <package>org.netbeans.spi.java.classpath.support</package>
102
                <package>org.netbeans.spi.java.queries</package>
102
                <package>org.netbeans.spi.java.queries</package>
103
                <package>org.netbeans.spi.java.queries.support</package>
103
            </public-packages>
104
            </public-packages>
104
        </data>
105
        </data>
105
    </configuration>
106
    </configuration>
(-)a/api.java/src/org/netbeans/api/java/queries/SourceForBinaryQuery.java (-26 / +6 lines)
Lines 48-53 Link Here
48
import java.util.logging.Logger;
48
import java.util.logging.Logger;
49
import javax.swing.event.ChangeEvent;
49
import javax.swing.event.ChangeEvent;
50
import javax.swing.event.ChangeListener;
50
import javax.swing.event.ChangeListener;
51
import org.netbeans.modules.java.queries.SFBQImpl2Result;
51
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
52
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
52
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2;
53
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2;
53
import org.openide.filesystems.FileObject;
54
import org.openide.filesystems.FileObject;
Lines 115-127 Link Here
115
            if (impl instanceof SourceForBinaryQueryImplementation2) {
116
            if (impl instanceof SourceForBinaryQueryImplementation2) {
116
                SourceForBinaryQueryImplementation2.Result _result = ((SourceForBinaryQueryImplementation2)impl).findSourceRoots2(binaryRoot);
117
                SourceForBinaryQueryImplementation2.Result _result = ((SourceForBinaryQueryImplementation2)impl).findSourceRoots2(binaryRoot);
117
                if (_result != null) {                    
118
                if (_result != null) {                    
118
                    result = new Result2New(_result);
119
                    result = new Result2(_result);
119
                }
120
                }
120
            }
121
            }
121
            else {
122
            else {
122
                Result _result = impl.findSourceRoots(binaryRoot);
123
                Result _result = impl.findSourceRoots(binaryRoot);
123
                if (_result != null) {
124
                if (_result != null) {
124
                    result = new Result2(_result);
125
                    result = new Result2(new SFBQImpl2Result(_result));
125
                }
126
                }
126
            }
127
            }
127
            if (result != null) {
128
            if (result != null) {
Lines 183-194 Link Here
183
     */
184
     */
184
    public static class Result2 implements Result {
185
    public static class Result2 implements Result {
185
        
186
        
186
        private final Result delegate;
187
        SourceForBinaryQueryImplementation2.Result delegate;
187
        //@GuardedBy(this)
188
        //@GuardedBy(this)
188
        private ChangeListener spiListener;
189
        private ChangeListener spiListener;
189
        private final ChangeSupport changeSupport;
190
        private final ChangeSupport changeSupport;
190
        
191
        
191
        private Result2 (final Result result) {
192
        private Result2 (final  SourceForBinaryQueryImplementation2.Result result) {
192
            assert result != null;
193
            assert result != null;
193
            this.delegate = result;
194
            this.delegate = result;
194
            this.changeSupport = new ChangeSupport(this);
195
            this.changeSupport = new ChangeSupport(this);
Lines 225-257 Link Here
225
         * @return true if sources should be used by the java infrastructure
226
         * @return true if sources should be used by the java infrastructure
226
         */
227
         */
227
        public boolean preferSources() {
228
        public boolean preferSources() {
228
            //Preserve the old behavior from 4.0 to 6.1, ignore sources inside archives
229
            final FileObject[] roots = this.delegate.getRoots();
230
            for (FileObject root : roots) {
231
                if (FileUtil.getArchiveFile(root) != null) {
232
                    return false;
233
                }
234
            }
235
            return true;
236
        }
237
    }
238
    
239
    private static final class Result2New extends Result2 {
240
        
241
        private final SourceForBinaryQueryImplementation2.Result delegate;
242
        
243
        private Result2New (final SourceForBinaryQueryImplementation2.Result delegate) {
244
            super (delegate);
245
            this.delegate = delegate;
246
        }
247
        
248
        public boolean preferSources() {
249
            return this.delegate.preferSources();
229
            return this.delegate.preferSources();
250
        }
230
        }
251
    }
231
    }
252
    
232
    
253
    private static final Result EMPTY_RESULT = new EmptyResult();
233
    private static final Result EMPTY_RESULT = new EmptyResult();
254
    private static final Result2 EMPTY_RESULT2 = new Result2 (EMPTY_RESULT);
234
    private static final Result2 EMPTY_RESULT2 = new Result2 (new SFBQImpl2Result(EMPTY_RESULT));
255
    private static final class EmptyResult implements Result {
235
    private static final class EmptyResult implements Result {
256
        private static final FileObject[] NO_ROOTS = new FileObject[0];
236
        private static final FileObject[] NO_ROOTS = new FileObject[0];
257
        EmptyResult() {}
237
        EmptyResult() {}
(-)a/api.java/src/org/netbeans/modules/java/queries/SFBQImpl2Result.java (+83 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 2008 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 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.java.queries;
41
42
import javax.swing.event.ChangeListener;
43
import org.netbeans.api.java.queries.SourceForBinaryQuery;
44
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2;
45
import org.openide.filesystems.FileObject;
46
import org.openide.filesystems.FileUtil;
47
48
/**
49
 *
50
 * @author Tomas Zezula
51
 */
52
public class SFBQImpl2Result implements SourceForBinaryQueryImplementation2.Result {
53
    
54
    private final SourceForBinaryQuery.Result delegate;
55
    
56
    public SFBQImpl2Result (final SourceForBinaryQuery.Result result) {
57
        assert result != null;
58
        this.delegate = result;
59
    }
60
61
    public boolean preferSources() {
62
        //Preserve the old behavior from 4.0 to 6.1, ignore sources inside archives
63
        final FileObject[] roots = this.delegate.getRoots();
64
        for (FileObject root : roots) {
65
            if (FileUtil.getArchiveFile(root) != null) {
66
                return false;
67
            }
68
        }
69
        return true;
70
    }
71
72
    public FileObject[] getRoots () {
73
        return this.delegate.getRoots();
74
    }
75
76
    public void addChangeListener(ChangeListener l) {
77
        this.delegate.addChangeListener(l);
78
    }
79
80
    public void removeChangeListener(ChangeListener l) {
81
        this.delegate.removeChangeListener(l);
82
    }
83
}
(-)a/api.java/src/org/netbeans/spi/java/queries/SourceForBinaryQueryImplementation2.java (-1 lines)
Lines 81-85 Link Here
81
         */
81
         */
82
        public boolean preferSources();
82
        public boolean preferSources();
83
    }
83
    }
84
    
85
}
84
}
(-)a/api.java/src/org/netbeans/spi/java/queries/support/SourceForBinaryQueryimplementation2Base.java (+66 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 2008 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 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.java.queries.support;
41
42
import org.netbeans.api.java.queries.SourceForBinaryQuery;
43
import org.netbeans.modules.java.queries.SFBQImpl2Result;
44
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2;
45
46
/**
47
 * Base class for {@link SourceForBinaryQueryImplementation2} which need to delegate
48
 * to other {@link SourceForBinaryQueryImplementation}.
49
 * @since 1.16
50
 * @author Tomas Zezula
51
 */
52
public abstract class SourceForBinaryQueryimplementation2Base implements SourceForBinaryQueryImplementation2 {
53
54
    /**
55
     * Creates a wrapper for {@link SourceForBinaryQuery.Result}. This method
56
     * should be used by delegating {@link SourceForBinaryQueryImplementation2}
57
     * which need to delegate to {@link SourceForBinaryQueryImplementation}. 
58
     * @param result returned by {@link SourceForBinaryQueryImplementation},
59
     * if null the method returns null.
60
     * @return a {@link SourceForBinaryQueryImplementation2.Result}, returns
61
     * null when result parameter is null.
62
     */
63
    protected final Result asResult (SourceForBinaryQuery.Result result) {
64
        return result == null ? null : new SFBQImpl2Result(result);
65
    }
66
}
(-)a/api.java/test/unit/src/org/netbeans/api/java/queries/SourceForBinaryQueryTest.java (+309 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 2008 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 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.api.java.queries;
41
42
import java.io.File;
43
import java.io.FileOutputStream;
44
import java.net.URL;
45
import java.util.Arrays;
46
import java.util.Collections;
47
import java.util.HashMap;
48
import java.util.List;
49
import java.util.Map;
50
import java.util.concurrent.atomic.AtomicBoolean;
51
import java.util.zip.ZipEntry;
52
import java.util.zip.ZipOutputStream;
53
import javax.swing.event.ChangeEvent;
54
import javax.swing.event.ChangeListener;
55
import org.netbeans.api.java.queries.SourceForBinaryQuery.Result;
56
import org.netbeans.junit.MockServices;
57
import org.netbeans.junit.NbTestCase;
58
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
59
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2;
60
import org.netbeans.spi.java.queries.support.SourceForBinaryQueryimplementation2Base;
61
import org.openide.filesystems.FileObject;
62
import org.openide.filesystems.FileUtil;
63
import org.openide.util.ChangeSupport;
64
65
/**
66
 *
67
 * @author Tomas Zezula
68
 */
69
public class SourceForBinaryQueryTest extends NbTestCase {
70
    
71
    public SourceForBinaryQueryTest (final String name) {
72
        super (name);
73
    }
74
    
75
    private FileObject br1;
76
    private FileObject br2;
77
    private FileObject sr1;
78
    private FileObject sr2;
79
    
80
    private static final Map<URL,List<FileObject>> map = new HashMap<URL, List<FileObject>>();
81
82
    @Override
83
    protected void setUp() throws Exception {
84
        this.clearWorkDir();
85
        super.setUp();
86
        File wd = this.getWorkDir();
87
        FileObject wdfo = FileUtil.toFileObject(wd);
88
        br1 = wdfo.createFolder("bin1");
89
        br2 = wdfo.createFolder("bin2");
90
        sr1 = wdfo.createFolder("src1");
91
        File zf = new File (wd,"src2.zip");
92
        ZipOutputStream zos = new ZipOutputStream (new FileOutputStream (zf));
93
        zos.putNextEntry(new ZipEntry("foo.java"));
94
        zos.closeEntry();
95
        zos.close();
96
        sr2 = FileUtil.getArchiveRoot(FileUtil.toFileObject(zf));
97
        map.put(br1.getURL(), Collections.singletonList(sr1));
98
        map.put(br2.getURL(), Collections.singletonList(sr2));
99
    }
100
    
101
    public void testSFBQImpl () throws Exception {
102
        MockServices.setServices(LegacySFBQImpl.class);
103
        SourceForBinaryQuery.Result2 res = SourceForBinaryQuery.findSourceRoots2(br1.getURL());
104
        assertNotNull(res);
105
        assertEquals(1, res.getRoots().length);
106
        assertEquals(Collections.singletonList(sr1), Arrays.asList(res.getRoots()));
107
        assertTrue(res.preferSources());
108
        
109
        res = SourceForBinaryQuery.findSourceRoots2(br2.getURL());
110
        assertNotNull(res);
111
        assertEquals(1, res.getRoots().length);
112
        assertEquals(Collections.singletonList(sr2), Arrays.asList(res.getRoots()));
113
        assertFalse(res.preferSources());
114
        
115
        res = SourceForBinaryQuery.findSourceRoots2(getWorkDir().toURI().toURL());
116
        assertNotNull(res);
117
        assertEquals(0, res.getRoots().length);
118
        assertTrue(res.preferSources());        
119
    }
120
    
121
    public void testSFBQImpl2 () throws Exception {
122
        MockServices.setServices(LeafSFBQImpl.class);
123
        SourceForBinaryQuery.Result2 res = SourceForBinaryQuery.findSourceRoots2(br1.getURL());
124
        assertNotNull(res);
125
        assertEquals(1, res.getRoots().length);
126
        assertEquals(Collections.singletonList(sr1), Arrays.asList(res.getRoots()));
127
        assertFalse(res.preferSources());
128
        
129
        res = SourceForBinaryQuery.findSourceRoots2(br2.getURL());
130
        assertNotNull(res);
131
        assertEquals(1, res.getRoots().length);
132
        assertEquals(Collections.singletonList(sr2), Arrays.asList(res.getRoots()));
133
        assertTrue(res.preferSources());
134
        
135
        res = SourceForBinaryQuery.findSourceRoots2(getWorkDir().toURI().toURL());
136
        assertNotNull(res);
137
        assertEquals(0, res.getRoots().length);
138
        assertTrue(res.preferSources());        
139
        
140
    }
141
    
142
    
143
    public void testSFBQDelegatingImpl () throws Exception {
144
        DelegatingSFBImpl.impl = new LegacySFBQImpl();
145
        MockServices.setServices(DelegatingSFBImpl.class);
146
        SourceForBinaryQuery.Result2 res = SourceForBinaryQuery.findSourceRoots2(br1.getURL());
147
        assertNotNull(res);
148
        assertEquals(1, res.getRoots().length);
149
        assertEquals(Collections.singletonList(sr1), Arrays.asList(res.getRoots()));
150
        assertTrue(res.preferSources());
151
        
152
        res = SourceForBinaryQuery.findSourceRoots2(br2.getURL());
153
        assertNotNull(res);
154
        assertEquals(1, res.getRoots().length);
155
        assertEquals(Collections.singletonList(sr2), Arrays.asList(res.getRoots()));
156
        assertFalse(res.preferSources());
157
        
158
        res = SourceForBinaryQuery.findSourceRoots2(getWorkDir().toURI().toURL());
159
        assertNotNull(res);
160
        assertEquals(0, res.getRoots().length);
161
        assertTrue(res.preferSources());        
162
        
163
    }
164
    
165
    
166
    public void testSFBQDelegatingImpl2 () throws Exception {
167
        DelegatingSFBImpl.impl = new LeafSFBQImpl();
168
        MockServices.setServices(DelegatingSFBImpl.class);
169
        SourceForBinaryQuery.Result2 res = SourceForBinaryQuery.findSourceRoots2(br1.getURL());
170
        assertNotNull(res);
171
        assertEquals(1, res.getRoots().length);
172
        assertEquals(Collections.singletonList(sr1), Arrays.asList(res.getRoots()));
173
        assertFalse(res.preferSources());
174
        
175
        res = SourceForBinaryQuery.findSourceRoots2(br2.getURL());
176
        assertNotNull(res);
177
        assertEquals(1, res.getRoots().length);
178
        assertEquals(Collections.singletonList(sr2), Arrays.asList(res.getRoots()));
179
        assertTrue(res.preferSources());
180
        
181
        res = SourceForBinaryQuery.findSourceRoots2(getWorkDir().toURI().toURL());
182
        assertNotNull(res);
183
        assertEquals(0, res.getRoots().length);
184
        assertTrue(res.preferSources());                
185
    }
186
    
187
    
188
    public void testListening () throws Exception {
189
        DelegatingSFBImpl.impl = new LeafSFBQImpl();
190
        MockServices.setServices(DelegatingSFBImpl.class);
191
        SourceForBinaryQuery.Result2 res = SourceForBinaryQuery.findSourceRoots2(br1.getURL());
192
        final AtomicBoolean fired = new AtomicBoolean ();
193
        ChangeListener l;
194
        res.addChangeListener( l = new ChangeListener() {
195
            public void stateChanged(ChangeEvent e) {
196
                fired.set(true);
197
            }
198
        });
199
        ((LeafSFBQImpl)DelegatingSFBImpl.impl).lastResult.fire();
200
        res.removeChangeListener(l);
201
        assertTrue(fired.get());
202
    }
203
    
204
    //Prefers sources for archives => behaves opposite to default
205
    public static class LeafSFBQImpl implements SourceForBinaryQueryImplementation2 {
206
        
207
        static R2 lastResult;
208
        
209
        public Result findSourceRoots2(URL binaryRoot) {
210
            lastResult = null;
211
            List<FileObject> data =  map.get(binaryRoot);
212
            if (data != null) {
213
                return lastResult = new R2(data.toArray(new FileObject[data.size()]), prefSources(data));
214
            }
215
            return null;
216
        }
217
        
218
        private static boolean prefSources(List<FileObject> l) {
219
            for (FileObject f : l ) {
220
                if (FileUtil.getArchiveFile(f) != null) {
221
                    return true;
222
                }
223
            }
224
            return false;
225
        }
226
227
        public Result findSourceRoots(URL binaryRoot) {
228
            return this.findSourceRoots2(binaryRoot);
229
        }
230
        
231
    }
232
    
233
    public static class DelegatingSFBImpl extends SourceForBinaryQueryimplementation2Base {
234
        
235
        private static SourceForBinaryQueryImplementation impl; 
236
        
237
        
238
        public Result findSourceRoots2(URL binaryRoot) {
239
            if (this.impl == null) {
240
                throw new IllegalStateException ();
241
            }
242
            else if (this.impl instanceof SourceForBinaryQueryImplementation2) {
243
                return ((SourceForBinaryQueryImplementation2)this.impl).findSourceRoots2(binaryRoot);
244
            }
245
            else {
246
                return asResult(this.impl.findSourceRoots(binaryRoot));
247
            }
248
        }
249
250
        public Result findSourceRoots(URL binaryRoot) {
251
            return this.findSourceRoots2(binaryRoot);
252
        }
253
        
254
    }
255
    
256
    public static class LegacySFBQImpl implements SourceForBinaryQueryImplementation {
257
258
        public Result findSourceRoots(URL binaryRoot) {
259
            List<FileObject> data =  map.get(binaryRoot);
260
            if (data != null) {
261
                return new R(data.toArray(new FileObject[data.size()]));
262
            }
263
            return null;
264
        }
265
        
266
    }
267
    
268
    private static class R implements SourceForBinaryQuery.Result {
269
        
270
        final FileObject[] roots;
271
        private final ChangeSupport chs = new ChangeSupport(this);
272
        
273
        public R (final FileObject[] roots) {
274
            this.roots = roots;
275
        }
276
277
        public FileObject[] getRoots() {
278
            return this.roots;
279
        }
280
281
        public void addChangeListener(ChangeListener l) {
282
            chs.addChangeListener(l);
283
        }
284
285
        public void removeChangeListener(ChangeListener l) {
286
            chs.removeChangeListener(l);
287
        }
288
        
289
        void fire () {
290
            chs.fireChange();
291
        }
292
        
293
    }
294
    
295
    private static class R2 extends R implements SourceForBinaryQueryImplementation2.Result {
296
        
297
        final boolean ps;
298
        
299
        public R2 (final FileObject[] roots, final boolean ps) {
300
            super (roots);
301
            this.ps = ps;
302
        }
303
304
        public boolean preferSources() {
305
            return ps;
306
        }
307
    }
308
309
}
(-)a/java.platform/src/org/netbeans/modules/java/platform/queries/PlatformSourceForBinaryQuery.java (-1 lines)
Lines 50-56 Link Here
50
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.FileUtil;
51
import org.openide.filesystems.FileUtil;
52
import org.openide.filesystems.URLMapper;
52
import org.openide.filesystems.URLMapper;
53
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
54
import org.netbeans.api.java.classpath.ClassPath;
53
import org.netbeans.api.java.classpath.ClassPath;
55
import org.netbeans.api.java.platform.JavaPlatformManager;
54
import org.netbeans.api.java.platform.JavaPlatformManager;
56
import org.netbeans.api.java.platform.JavaPlatform;
55
import org.netbeans.api.java.platform.JavaPlatform;
(-)a/java.project/src/org/netbeans/modules/java/project/ProjectSourceForBinaryQuery.java (-1 / +20 lines)
Lines 46-58 Link Here
46
import org.netbeans.api.project.FileOwnerQuery;
46
import org.netbeans.api.project.FileOwnerQuery;
47
import org.netbeans.api.project.Project;
47
import org.netbeans.api.project.Project;
48
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
48
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
49
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2;
50
import org.netbeans.spi.java.queries.support.SourceForBinaryQueryimplementation2Base;
49
51
50
/**
52
/**
51
 * Finds sources corresponding to binaries.
53
 * Finds sources corresponding to binaries.
52
 * Assumes an instance of SourceForBinaryQueryImplementation is in project's lookup.
54
 * Assumes an instance of SourceForBinaryQueryImplementation is in project's lookup.
53
 * @author Jesse Glick, Tomas Zezula
55
 * @author Jesse Glick, Tomas Zezula
54
 */
56
 */
55
public class ProjectSourceForBinaryQuery implements SourceForBinaryQueryImplementation {
57
public class ProjectSourceForBinaryQuery extends SourceForBinaryQueryimplementation2Base {
56
    
58
    
57
    /** Default constructor for lookup. */
59
    /** Default constructor for lookup. */
58
    public ProjectSourceForBinaryQuery() {}
60
    public ProjectSourceForBinaryQuery() {}
Lines 67-71 Link Here
67
        }
69
        }
68
        return null;
70
        return null;
69
    }
71
    }
72
73
    
74
    public Result findSourceRoots2(URL binaryRoot) {
75
        Project project = FileOwnerQuery.getOwner(URI.create(binaryRoot.toString()));
76
        if (project != null) {
77
            SourceForBinaryQueryImplementation sfbqi = project.getLookup().lookup(SourceForBinaryQueryImplementation.class);
78
            if (sfbqi != null) {
79
                if (sfbqi instanceof SourceForBinaryQueryImplementation2) {
80
                    return ((SourceForBinaryQueryImplementation2)sfbqi).findSourceRoots2(binaryRoot);
81
                }
82
                else {
83
                    return asResult (sfbqi.findSourceRoots(binaryRoot));
84
                }
85
            }
86
        }
87
        return null;
88
    }
70
    
89
    
71
}
90
}
(-)a/java.project/src/org/netbeans/spi/java/project/support/LookupMergerSupport.java (-1 / +22 lines)
Lines 45-50 Link Here
45
import org.netbeans.api.java.queries.SourceForBinaryQuery;
45
import org.netbeans.api.java.queries.SourceForBinaryQuery;
46
import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation;
46
import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation;
47
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
47
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
48
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2;
49
import org.netbeans.spi.java.queries.support.SourceForBinaryQueryimplementation2Base;
48
import org.netbeans.spi.project.LookupMerger;
50
import org.netbeans.spi.project.LookupMerger;
49
import org.openide.util.Lookup;
51
import org.openide.util.Lookup;
50
52
Lines 88-94 Link Here
88
        
90
        
89
    }
91
    }
90
    
92
    
91
    private static class SFBIMerged implements SourceForBinaryQueryImplementation {
93
    private static class SFBIMerged extends SourceForBinaryQueryimplementation2Base {
92
        private Lookup lookup;
94
        private Lookup lookup;
93
        
95
        
94
        public SFBIMerged(Lookup lkp) {
96
        public SFBIMerged(Lookup lkp) {
Lines 100-105 Link Here
100
                SourceForBinaryQuery.Result res = impl.findSourceRoots(binaryRoot);
102
                SourceForBinaryQuery.Result res = impl.findSourceRoots(binaryRoot);
101
                if (res != null) {
103
                if (res != null) {
102
                    return res;
104
                    return res;
105
                }
106
            }
107
            return null;
108
        }
109
110
        public Result findSourceRoots2(URL binaryRoot) {
111
            Collection<? extends SourceForBinaryQueryImplementation> col = lookup.lookupAll(SourceForBinaryQueryImplementation.class);
112
            for (SourceForBinaryQueryImplementation impl : col) {
113
                if (impl instanceof SourceForBinaryQueryImplementation2) {
114
                    SourceForBinaryQueryImplementation2.Result res = ((SourceForBinaryQueryImplementation2)impl).findSourceRoots2(binaryRoot);
115
                    if (res != null) {
116
                        return res;
117
                    }
118
                }
119
                else {
120
                    SourceForBinaryQuery.Result res = impl.findSourceRoots(binaryRoot);
121
                    if (res != null) {
122
                        return asResult(res);
123
                    }
103
                }
124
                }
104
            }
125
            }
105
            return null;
126
            return null;

Return to bug 129884