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

(-)a/api.java/apichanges.xml (+19 lines)
Lines 76-81 Link Here
76
<!-- ACTUAL CHANGES BEGIN HERE: -->
76
<!-- ACTUAL CHANGES BEGIN HERE: -->
77
77
78
<changes>
78
<changes>
79
        <change id="source-level-changes">
80
            <api name="queries"/>
81
            <summary>Added notifications about source level changes into SourceLevelQuery</summary>
82
            <version major="1" minor="30"/>
83
            <date day="7" month="7" year="2010"/>
84
            <author login="tzezula"/>
85
            <compatibility addition="yes" semantic="compatible" source="compatible" binary="compatible"/>
86
            <description>
87
                <p>
88
                    The SourceLevelQuery did not allow listening on the source level changes. Such a
89
                    notifications are required by the annotation processor support and indexing.
90
                    This API change adds a SourceLevelQuery.getSourceLevel2 which returns a Result object
91
                    which allows listening like other queries.
92
                </p>
93
            </description>
94
            <class package="org.netbeans.api.java.queries" name="SourceLevelQuery" />
95
            <class package="org.netbeans.spi.java.queries" name="SourceLevelQueryImplementation2" />
96
            <issue number="185031"/>
97
        </change>
79
        <change id="ap-query-triggers">
98
        <change id="ap-query-triggers">
80
            <api name="classpath"/>
99
            <api name="classpath"/>
81
            <summary>Introducing AnnotationProcessingQuery.Result.Trigger</summary>
100
            <summary>Introducing AnnotationProcessingQuery.Result.Trigger</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.29
3
OpenIDE-Module-Specification-Version: 1.30
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/java/queries/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/java/queries/Bundle.properties
5
AutoUpdate-Show-In-Client: false
5
AutoUpdate-Show-In-Client: false
6
6
(-)a/api.java/nbproject/project.xml (+8 lines)
Lines 76-81 Link Here
76
                    </run-dependency>
76
                    </run-dependency>
77
                </dependency>
77
                </dependency>
78
                <dependency>
78
                <dependency>
79
                    <code-name-base>org.openide.modules</code-name-base>
80
                    <build-prerequisite/>
81
                    <compile-dependency/>
82
                    <run-dependency>
83
                        <specification-version>7.18</specification-version>
84
                    </run-dependency>
85
                </dependency>
86
                <dependency>
79
                    <code-name-base>org.openide.util</code-name-base>
87
                    <code-name-base>org.openide.util</code-name-base>
80
                    <build-prerequisite/>
88
                    <build-prerequisite/>
81
                    <compile-dependency/>
89
                    <compile-dependency/>
(-)a/api.java/src/org/netbeans/api/java/queries/SourceLevelQuery.java (+153 lines)
Lines 47-55 Link Here
47
import java.util.logging.Level;
47
import java.util.logging.Level;
48
import java.util.logging.Logger;
48
import java.util.logging.Logger;
49
import java.util.regex.Pattern;
49
import java.util.regex.Pattern;
50
import javax.swing.event.ChangeEvent;
51
import javax.swing.event.ChangeListener;
52
import org.netbeans.api.annotations.common.CheckForNull;
53
import org.netbeans.api.annotations.common.NonNull;
50
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation;
54
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation;
55
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
51
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileObject;
57
import org.openide.modules.SpecificationVersion;
58
import org.openide.util.ChangeSupport;
52
import org.openide.util.Lookup;
59
import org.openide.util.Lookup;
60
import org.openide.util.Parameters;
61
import org.openide.util.Union2;
62
import org.openide.util.WeakListeners;
53
63
54
/**
64
/**
55
 * Returns source level of the given Java source file if it is known.
65
 * Returns source level of the given Java source file if it is known.
Lines 66-71 Link Here
66
    private static final Lookup.Result<? extends SourceLevelQueryImplementation> implementations =
76
    private static final Lookup.Result<? extends SourceLevelQueryImplementation> implementations =
67
        Lookup.getDefault().lookupResult (SourceLevelQueryImplementation.class);
77
        Lookup.getDefault().lookupResult (SourceLevelQueryImplementation.class);
68
78
79
    private static final Lookup.Result<? extends SourceLevelQueryImplementation2> implementations2 =
80
        Lookup.getDefault().lookupResult (SourceLevelQueryImplementation2.class);
81
82
    private static final Result EMPTY_RESULT = new Result();
83
69
    private SourceLevelQuery() {
84
    private SourceLevelQuery() {
70
    }
85
    }
71
86
Lines 78-83 Link Here
78
     *     if it is not known
93
     *     if it is not known
79
     */
94
     */
80
    public static String getSourceLevel(FileObject javaFile) {
95
    public static String getSourceLevel(FileObject javaFile) {
96
        for (SourceLevelQueryImplementation2 sqi : implementations2.allInstances()) {
97
            final SourceLevelQueryImplementation2.Result result = sqi.getSourceLevel(javaFile);
98
            if (result != null) {
99
                final SpecificationVersion version = result.getSourceLevel();
100
                if (version != null){
101
                    final String s = version.toString();
102
                    if (!SOURCE_LEVEL.matcher(s).matches()) {
103
                        LOGGER.log(Level.WARNING, "#83994: Ignoring bogus source level {0} for {1} from {2}", new Object[] {s, javaFile, sqi}); //NOI18N
104
                        continue;
105
                    }
106
                    LOGGER.log(Level.FINE, "Found source level {0} for {1} from {2}", new Object[] {s, javaFile, sqi});     //NOI18N
107
                    return s;
108
                }
109
            }
110
        }
81
        for  (SourceLevelQueryImplementation sqi : implementations.allInstances()) {
111
        for  (SourceLevelQueryImplementation sqi : implementations.allInstances()) {
82
            String s = sqi.getSourceLevel(javaFile);
112
            String s = sqi.getSourceLevel(javaFile);
83
            if (s != null) {
113
            if (s != null) {
Lines 93-96 Link Here
93
        return null;
123
        return null;
94
    }
124
    }
95
125
126
    /**
127
     * Returns a source level of the given Java file, Java package or source folder. For acceptable return values
128
     * see the documentation of <code>-source</code> command line switch of
129
     * <code>javac</code> compiler .
130
     * @param javaFile Java source file, Java package or source folder in question
131
     * @return a {@link Result} object encapsulating the source level of the Java file. Results created for source
132
     * levels provided by the {@link SourceLevelQueryImplementation} do not support listening. Use {@link Result#supportsChanges()}
133
     * to check if the result supports listening.
134
     * @since 1.30
135
     */
136
    public static @NonNull Result getSourceLevel2(final @NonNull FileObject javaFile) {
137
        for (SourceLevelQueryImplementation2 sqi : implementations2.allInstances()) {
138
            final SourceLevelQueryImplementation2.Result result = sqi.getSourceLevel(javaFile);
139
            if (result != null) {
140
                LOGGER.log(Level.FINE, "Found source level {0} for {1} from {2}", new Object[] {result, javaFile, sqi}); //NOI18N
141
                return new Result(result);
142
            }
143
        }
144
        LOGGER.log(Level.FINE, "No source level found for {0}", javaFile);
145
        for (SourceLevelQueryImplementation sqi : implementations.allInstances()) {
146
            String s = sqi.getSourceLevel(javaFile);
147
            if (s != null) {
148
                if (!SOURCE_LEVEL.matcher(s).matches()) {
149
                    LOGGER.log(Level.WARNING, "#83994: Ignoring bogus source level {0} for {1} from {2}", new Object[] {s, javaFile, sqi});
150
                    continue;
151
                }
152
                LOGGER.log(Level.FINE, "Found source level {0} for {1} from {2}", new Object[] {s, javaFile, sqi});
153
                return new Result(s);
154
            }
155
        }
156
        return EMPTY_RESULT;
157
    }
158
159
    /**
160
     * Result of finding source level, encapsulating the answer as well as the
161
     * ability to listen to it.
162
     * @since 1.30
163
     */
164
    public static final class Result {
165
166
        private final Union2<SourceLevelQueryImplementation2.Result,String> delegate;
167
        private final ChangeSupport cs = new ChangeSupport(this);
168
        private /**@GuardedBy("this")*/ ChangeListener spiListener;
169
170
        private Result(@NonNull final SourceLevelQueryImplementation2.Result delegate) {
171
            Parameters.notNull("delegate", delegate);   //NOI18N
172
            this.delegate = Union2.<SourceLevelQueryImplementation2.Result,String>createFirst(delegate);
173
        }
174
        
175
        private Result(@NonNull final String sourceLevel) {
176
            Parameters.notNull("sourceLevel", sourceLevel);
177
            this.delegate = Union2.<SourceLevelQueryImplementation2.Result,String>createSecond(sourceLevel);
178
        }
179
        
180
        private Result() {
181
            this.delegate = null;
182
        }
183
184
        /**
185
         * Get the source level.
186
         * @return a source level as a {@link SpecificationVersion}
187
         * or null if the source level is unknown.
188
         */
189
        public @CheckForNull SpecificationVersion getSourceLevel() {
190
            return delegate == null ? null :
191
                delegate.hasFirst() ? delegate.first().getSourceLevel() : new SpecificationVersion(delegate.second());
192
        }
193
194
        /**
195
         * Add a listener to changes of source level.
196
         * @param listener a listener to add
197
         */
198
        public void addChangeListener(@NonNull ChangeListener listener) {
199
            Parameters.notNull("listener", listener);   //NOI18N
200
            final SourceLevelQueryImplementation2.Result _delegate = getDelegate();
201
            if (_delegate == null) {
202
                throw new UnsupportedOperationException("Listening is not supported");  //NOI18N
203
            }
204
            cs.addChangeListener(listener);
205
            synchronized (this) {
206
                if (spiListener == null) {
207
                    spiListener = new ChangeListener() {
208
                        @Override
209
                        public void stateChanged(ChangeEvent e) {
210
                            cs.fireChange();
211
                        }
212
                    };
213
                    _delegate.addChangeListener(WeakListeners.change(spiListener, _delegate));
214
                }
215
            }
216
            
217
        }
218
219
        /**
220
         * Remove a listener to changes of source level.
221
         * @param listener a listener to add
222
         */
223
        public void removeChangeListener(@NonNull ChangeListener listener) {
224
            Parameters.notNull("listener", listener);   //NOI18N
225
            final SourceLevelQueryImplementation2.Result _delegate = getDelegate();
226
            if (_delegate == null) {
227
                throw new UnsupportedOperationException("Listening is not supported");  //NOI18N
228
            }
229
            cs.removeChangeListener(listener);
230
        }
231
232
        /**
233
         * Returns true if the result support updates and client may
234
         * listen on it. If false client should always ask again to
235
         * obtain current value. The results created for values returned
236
         * by the {@link SourceLevelQueryImplementation} do not support
237
         * listening.
238
         * @return true if the result supports changes and listening
239
         */
240
        public boolean supportsChanges() {
241
            return getDelegate() != null;
242
        }
243
244
        private SourceLevelQueryImplementation2.Result getDelegate() {
245
            return delegate != null && delegate.hasFirst() ? delegate.first() : null;
246
        }
247
    }    
248
96
}
249
}
(-)a/api.java/src/org/netbeans/spi/java/queries/SourceLevelQueryImplementation2.java (+109 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.spi.java.queries;
44
45
import javax.swing.event.ChangeListener;
46
import org.netbeans.api.annotations.common.CheckForNull;
47
import org.netbeans.api.annotations.common.NonNull;
48
import org.netbeans.api.java.queries.SourceLevelQuery;
49
import org.openide.filesystems.FileObject;
50
import org.openide.modules.SpecificationVersion;
51
52
/**
53
 *
54
 * Permits providers to return specification source level of Java source file.
55
 * <p>
56
 * A default implementation is registered by the
57
 * <code>org.netbeans.modules.java.project</code> module which looks up the
58
 * project corresponding to the file (if any) and checks whether that
59
 * project has an implementation of this interface in its lookup. If so, it
60
 * delegates to that implementation. Therefore it is not generally necessary
61
 * for a project type provider to register its own global implementation of
62
 * this query, if it depends on the Java Project module and uses this style.
63
 * </p>
64
 * @see org.netbeans.api.java.queries.SourceLevelQuery
65
 * @see org.netbeans.api.queries.FileOwnerQuery
66
 * @see org.netbeans.api.project.Project#getLookup
67
 * @see org.netbeans.api.java.classpath.ClassPath#BOOT
68
 * @author Tomas Zezula
69
 * @since 1.30
70
 */
71
public interface SourceLevelQueryImplementation2 {
72
73
    /**
74
     * Returns source level of the given Java file. For acceptable return values
75
     * see the documentation of <code>-source</code> command line switch of
76
     * <code>javac</code> compiler .
77
     * @param javaFile Java source file in question
78
     * @return source level of the Java file encapsulated as {@link Result}, or
79
     *    null if the file is not handled by this provider.
80
     */
81
    Result getSourceLevel(FileObject javaFile);
82
83
    /**
84
     * Result of finding source level, encapsulating the answer as well as the
85
     * ability to listen to it.
86
     * @since 1.30
87
     */
88
    interface Result {
89
90
        /**
91
         * Get the source level.
92
         * @return a source level as a {@link SpecificationVersion}
93
         * or null if the source level is unknown.
94
         */
95
        @CheckForNull SpecificationVersion getSourceLevel();
96
97
        /**
98
         * Add a listener to changes of source level.
99
         * @param listener a listener to add
100
         */
101
        void addChangeListener(@NonNull ChangeListener listener);
102
103
        /**
104
         * Remove a listener to changes of source level.
105
         * @param listener a listener to add
106
         */
107
        void removeChangeListener(@NonNull ChangeListener listener);
108
    }
109
}
(-)a/api.java/test/unit/src/org/netbeans/api/java/queries/SourceLevelQueryTest.java (-1 / +45 lines)
Lines 44-54 Link Here
44
44
45
package org.netbeans.api.java.queries;
45
package org.netbeans.api.java.queries;
46
46
47
import java.util.HashMap;
48
import java.util.Map;
49
import javax.swing.event.ChangeListener;
47
import org.netbeans.junit.MockServices;
50
import org.netbeans.junit.MockServices;
48
import org.netbeans.junit.NbTestCase;
51
import org.netbeans.junit.NbTestCase;
49
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation;
52
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation;
53
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
50
import org.openide.filesystems.FileObject;
54
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.FileUtil;
55
import org.openide.filesystems.FileUtil;
56
import org.openide.modules.SpecificationVersion;
52
57
53
/**
58
/**
54
 * @author Jesse Glick
59
 * @author Jesse Glick
Lines 59-70 Link Here
59
        super(n);
64
        super(n);
60
    }
65
    }
61
66
67
    private static Map<FileObject, String> slq2Files  = new HashMap<FileObject, String>();
62
    private static String LEVEL;
68
    private static String LEVEL;
63
    private FileObject f;
69
    private FileObject f;
64
70
65
    protected void setUp() throws Exception {
71
    protected void setUp() throws Exception {
66
        super.setUp();
72
        super.setUp();
67
        MockServices.setServices(SLQ.class);
73
        MockServices.setServices(SLQ.class,SLQ2.class);
68
        LEVEL = null;
74
        LEVEL = null;
69
        f = FileUtil.createMemoryFileSystem().getRoot();
75
        f = FileUtil.createMemoryFileSystem().getRoot();
70
    }
76
    }
Lines 85-90 Link Here
85
        assertNull(SourceLevelQuery.getSourceLevel(f));
91
        assertNull(SourceLevelQuery.getSourceLevel(f));
86
    }
92
    }
87
93
94
    public void testSLQ2() throws Exception {
95
        LEVEL = "1.3";
96
        FileObject f1 = f.createFolder("f1");   //NOI18N
97
        FileObject f2 = f.createFolder("f2");   //NOI18N
98
        assertEquals("1.3", SourceLevelQuery.getSourceLevel(f1));   //NOI18N
99
        assertEquals("1.3", SourceLevelQuery.getSourceLevel(f2));   //NOI18N
100
        slq2Files.put(f1, "1.5");   //NOI18N
101
        assertEquals("1.5", SourceLevelQuery.getSourceLevel(f1));   //NOI18N
102
        assertEquals("1.3", SourceLevelQuery.getSourceLevel(f2));   //NOI18N
103
        assertEquals("1.5", SourceLevelQuery.getSourceLevel2(f1).getSourceLevel().toString());   //NOI18N
104
        assertTrue(SourceLevelQuery.getSourceLevel2(f1).supportsChanges());
105
        assertEquals("1.3",SourceLevelQuery.getSourceLevel2(f2).getSourceLevel().toString());   //NOI18N
106
        assertFalse(SourceLevelQuery.getSourceLevel2(f2).supportsChanges());
107
    }
108
88
    public static final class SLQ implements SourceLevelQueryImplementation {
109
    public static final class SLQ implements SourceLevelQueryImplementation {
89
110
90
        public SLQ() {}
111
        public SLQ() {}
Lines 92-97 Link Here
92
        public String getSourceLevel(FileObject javaFile) {
113
        public String getSourceLevel(FileObject javaFile) {
93
            return LEVEL;
114
            return LEVEL;
94
        }
115
        }
116
    }
117
118
    public static final class SLQ2 implements SourceLevelQueryImplementation2 {
119
120
        @Override
121
        public Result getSourceLevel(FileObject javaFile) {
122
            final String sl = slq2Files.get(javaFile);
123
            if (sl != null) {
124
                return new SourceLevelQueryImplementation2.Result() {
125
                    @Override
126
                    public SpecificationVersion getSourceLevel() {
127
                        return new SpecificationVersion(sl);
128
                    }
129
                    @Override
130
                    public void addChangeListener(ChangeListener listener) {
131
                    }
132
                    @Override
133
                    public void removeChangeListener(ChangeListener listener) {
134
                    }
135
                };
136
            }
137
            return null;
138
        }
95
139
96
    }
140
    }
97
141
(-)a/java.api.common/apichanges.xml (+15 lines)
Lines 105-110 Link Here
105
105
106
    <!-- ACTUAL CHANGES BEGIN HERE: -->
106
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <changes>
107
    <changes>
108
        <change id="source-level-query-2">
109
            <api name="java-api-common"/>
110
            <summary>Added a factory method to create SourceLevelQueryImplementation2</summary>
111
            <version major="1" minor="22"/>
112
            <date day="7" month="7" year="2010"/>
113
            <author login="tzezula"/>
114
            <compatibility addition="yes"/>
115
            <description>
116
                <p>
117
                    Added a factory method to create default ant project based SourceLevelQueryImplementation2.
118
                </p>
119
            </description>
120
            <class package="org.netbeans.modules.java.api.common.queries" name="QuerySupport"/>
121
            <issue number="185031"/>
122
        </change>
108
        <change id="sources-support">
123
        <change id="sources-support">
109
            <api name="java-api-common"/>
124
            <api name="java-api-common"/>
110
            <summary>Support for mutable Sources</summary>
125
            <summary>Support for mutable Sources</summary>
(-)a/java.api.common/manifest.mf (-1 / +1 lines)
Lines 1-4 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.java.api.common/0
2
OpenIDE-Module: org.netbeans.modules.java.api.common/0
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/api/common/resources/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/api/common/resources/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.21
4
OpenIDE-Module-Specification-Version: 1.22
(-)a/java.api.common/nbproject/project.xml (-34 / +34 lines)
Lines 29-68 Link Here
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>1</release-version>
31
                        <release-version>1</release-version>
32
                        <specification-version>1.28</specification-version>
32
                        <specification-version>1.30</specification-version>
33
                    </run-dependency>
34
                </dependency>
35
                <dependency>
36
                    <code-name-base>org.netbeans.modules.java.source</code-name-base>
37
                    <build-prerequisite/>
38
                    <compile-dependency/>
39
                    <run-dependency>
40
                        <specification-version>0.2</specification-version>
41
                    </run-dependency>
42
                </dependency>
43
                <dependency>
44
                    <code-name-base>org.netbeans.modules.java.sourceui</code-name-base>
45
                    <build-prerequisite/>
46
                    <compile-dependency/>
47
                    <run-dependency>
48
                        <release-version>1</release-version>
49
                        <specification-version>1.1</specification-version>
50
                    </run-dependency>
51
                </dependency>
52
                <dependency>
53
                    <code-name-base>org.openide.execution</code-name-base>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
56
                    <run-dependency>
57
                        <specification-version>1.2</specification-version>
58
                    </run-dependency>
59
                </dependency>
60
                <dependency>
61
                    <code-name-base>org.netbeans.libs.javacapi</code-name-base>
62
                    <build-prerequisite/>
63
                    <compile-dependency/>
64
                    <run-dependency>
65
                        <specification-version>0.5</specification-version>
66
                    </run-dependency>
33
                    </run-dependency>
67
                </dependency>
34
                </dependency>
68
                <dependency>
35
                <dependency>
Lines 84-89 Link Here
84
                    </run-dependency>
51
                    </run-dependency>
85
                </dependency>
52
                </dependency>
86
                <dependency>
53
                <dependency>
54
                    <code-name-base>org.netbeans.libs.javacapi</code-name-base>
55
                    <build-prerequisite/>
56
                    <compile-dependency/>
57
                    <run-dependency>
58
                        <specification-version>0.5</specification-version>
59
                    </run-dependency>
60
                </dependency>
61
                <dependency>
87
                    <code-name-base>org.netbeans.modules.java.platform</code-name-base>
62
                    <code-name-base>org.netbeans.modules.java.platform</code-name-base>
88
                    <build-prerequisite/>
63
                    <build-prerequisite/>
89
                    <compile-dependency/>
64
                    <compile-dependency/>
Lines 102-107 Link Here
102
                    </run-dependency>
77
                    </run-dependency>
103
                </dependency>
78
                </dependency>
104
                <dependency>
79
                <dependency>
80
                    <code-name-base>org.netbeans.modules.java.source</code-name-base>
81
                    <build-prerequisite/>
82
                    <compile-dependency/>
83
                    <run-dependency>
84
                        <specification-version>0.2</specification-version>
85
                    </run-dependency>
86
                </dependency>
87
                <dependency>
88
                    <code-name-base>org.netbeans.modules.java.sourceui</code-name-base>
89
                    <build-prerequisite/>
90
                    <compile-dependency/>
91
                    <run-dependency>
92
                        <release-version>1</release-version>
93
                        <specification-version>1.1</specification-version>
94
                    </run-dependency>
95
                </dependency>
96
                <dependency>
105
                    <code-name-base>org.netbeans.modules.project.ant</code-name-base>
97
                    <code-name-base>org.netbeans.modules.project.ant</code-name-base>
106
                    <build-prerequisite/>
98
                    <build-prerequisite/>
107
                    <compile-dependency/>
99
                    <compile-dependency/>
Lines 170-175 Link Here
170
                    </run-dependency>
162
                    </run-dependency>
171
                </dependency>
163
                </dependency>
172
                <dependency>
164
                <dependency>
165
                    <code-name-base>org.openide.execution</code-name-base>
166
                    <build-prerequisite/>
167
                    <compile-dependency/>
168
                    <run-dependency>
169
                        <specification-version>1.2</specification-version>
170
                    </run-dependency>
171
                </dependency>
172
                <dependency>
173
                    <code-name-base>org.openide.filesystems</code-name-base>
173
                    <code-name-base>org.openide.filesystems</code-name-base>
174
                    <build-prerequisite/>
174
                    <build-prerequisite/>
175
                    <compile-dependency/>
175
                    <compile-dependency/>
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/queries/QuerySupport.java (+12 lines)
Lines 57-62 Link Here
57
import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation;
57
import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation;
58
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
58
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
59
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation;
59
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation;
60
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
60
import org.netbeans.spi.project.SourceGroupModifierImplementation;
61
import org.netbeans.spi.project.SourceGroupModifierImplementation;
61
import org.netbeans.spi.project.support.ant.AntProjectHelper;
62
import org.netbeans.spi.project.support.ant.AntProjectHelper;
62
import org.netbeans.spi.project.support.ant.AntProjectListener;
63
import org.netbeans.spi.project.support.ant.AntProjectListener;
Lines 207-212 Link Here
207
    }
208
    }
208
209
209
    /**
210
    /**
211
     * Create a new query to find out source level of Java source files (SourceLevelQueryImplementation2).
212
     * @param evaluator {@link PropertyEvaluator} used for obtaining needed properties.
213
     * @return a {@link SourceLevelQueryImplementation2} to find out source level of Java source files.
214
     * @since 1.22
215
     */
216
    public static SourceLevelQueryImplementation2 createSourceLevelQuery2(@NonNull PropertyEvaluator evaluator) {
217
        Parameters.notNull("evaluator", evaluator); // NOI18N
218
        return new SourceLevelQueryImpl2(evaluator);
219
    }
220
221
    /**
210
     * Create a new query to find Java package roots of unit tests for Java package root of sources and vice versa.
222
     * Create a new query to find Java package roots of unit tests for Java package root of sources and vice versa.
211
     * @param sourceRoots a list of source roots.
223
     * @param sourceRoots a list of source roots.
212
     * @param testRoots a list of test roots.
224
     * @param testRoots a list of test roots.
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/queries/SourceLevelQueryImpl.java (-6 / +8 lines)
Lines 43-51 Link Here
43
 */
43
 */
44
package org.netbeans.modules.java.api.common.queries;
44
package org.netbeans.modules.java.api.common.queries;
45
45
46
import org.netbeans.api.java.platform.JavaPlatform;
47
import org.netbeans.api.java.platform.JavaPlatformManager;
48
import org.netbeans.api.java.platform.Specification;
49
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
46
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
50
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation;
47
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation;
51
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
48
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
Lines 67-82 Link Here
67
        this.evaluator = evaluator;
64
        this.evaluator = evaluator;
68
    }
65
    }
69
    
66
    
67
    @Override
70
    public String getSourceLevel(FileObject javaFile) {
68
    public String getSourceLevel(FileObject javaFile) {
71
        final String activePlatform = evaluator.getProperty("platform.active"); //NOI18N
69
        return findSourceLevel(evaluator);
70
    }
71
72
    static String findSourceLevel (final PropertyEvaluator eval) {
73
        final String activePlatform = eval.getProperty("platform.active"); //NOI18N
72
        if (CommonProjectUtils.getActivePlatform(activePlatform) != null) {
74
        if (CommonProjectUtils.getActivePlatform(activePlatform) != null) {
73
            String sl = evaluator.getProperty("javac.source"); //NOI18N
75
            String sl = eval.getProperty("javac.source"); //NOI18N
74
            if (sl != null && sl.length() > 0) {
76
            if (sl != null && sl.length() > 0) {
75
                return sl;
77
                return sl;
76
            }
78
            }
77
            return null;
79
            return null;
78
        }
80
        }
79
        
81
80
        EditableProperties props = PropertyUtils.getGlobalProperties();
82
        EditableProperties props = PropertyUtils.getGlobalProperties();
81
        String sl = props.get("default.javac.source"); //NOI18N
83
        String sl = props.get("default.javac.source"); //NOI18N
82
        if (sl != null && sl.length() > 0) {
84
        if (sl != null && sl.length() > 0) {
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/queries/SourceLevelQueryImpl2.java (+121 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.java.api.common.queries;
44
45
import java.beans.PropertyChangeEvent;
46
import java.beans.PropertyChangeListener;
47
import javax.swing.event.ChangeListener;
48
import org.netbeans.api.annotations.common.NonNull;
49
import org.netbeans.api.java.queries.SourceLevelQuery;
50
import org.netbeans.api.java.queries.SourceLevelQuery.Result;
51
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
52
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
53
import org.openide.filesystems.FileObject;
54
import org.openide.modules.SpecificationVersion;
55
import org.openide.util.ChangeSupport;
56
import org.openide.util.Parameters;
57
import org.openide.util.WeakListeners;
58
59
/**
60
 * @author Tomas Zezula
61
 */
62
class SourceLevelQueryImpl2 implements SourceLevelQueryImplementation2 {
63
    
64
    private final PropertyEvaluator eval;
65
    private final Result result;
66
67
    SourceLevelQueryImpl2(final @NonNull PropertyEvaluator eval) {
68
        Parameters.notNull("eval", eval);   //NOI18N
69
        this.eval = eval;
70
        this.result = new R();
71
    }
72
73
    @Override
74
    public Result getSourceLevel(FileObject javaFile) {
75
        return this.result;
76
    }
77
78
    private class R implements Result, PropertyChangeListener {
79
        
80
        private final ChangeSupport cs = new ChangeSupport(this);
81
82
        @SuppressWarnings("LeakingThisInConstructor")
83
        private R() {
84
            eval.addPropertyChangeListener(WeakListeners.propertyChange(this, eval));
85
        }
86
87
        @Override
88
        public SpecificationVersion getSourceLevel() {
89
            final String ver = SourceLevelQueryImpl.findSourceLevel(eval);
90
            return ver == null ? null : new SpecificationVersion(ver);
91
        }
92
93
        @Override
94
        public void addChangeListener(ChangeListener listener) {
95
            this.cs.addChangeListener(listener);
96
        }
97
98
        @Override
99
        public void removeChangeListener(ChangeListener listener) {
100
            this.cs.removeChangeListener(listener);
101
        }
102
103
        @Override
104
        public void propertyChange(PropertyChangeEvent evt) {
105
            final String name = evt.getPropertyName();
106
            if (name == null ||
107
                "javac.source".equals(name) ||     //NOI18N
108
                "platform.active".equals(name)) {  //NOI18N
109
                this.cs.fireChange();
110
            }
111
        }
112
113
        @Override
114
        public String toString() {
115
            final SpecificationVersion sl = getSourceLevel();
116
            return sl == null ? "" : sl.toString(); //NOI18M
117
        }
118
119
    }
120
121
}
(-)a/java.api.common/test/unit/src/org/netbeans/modules/java/api/common/queries/SourceLevelQueryImplTest.java (+37 lines)
Lines 52-64 Link Here
52
import java.util.List;
52
import java.util.List;
53
import java.util.Map;
53
import java.util.Map;
54
import java.util.Properties;
54
import java.util.Properties;
55
import java.util.concurrent.atomic.AtomicInteger;
56
import javax.swing.event.ChangeEvent;
57
import javax.swing.event.ChangeListener;
55
import org.netbeans.api.java.classpath.ClassPath;
58
import org.netbeans.api.java.classpath.ClassPath;
56
import org.netbeans.api.java.platform.JavaPlatform;
59
import org.netbeans.api.java.platform.JavaPlatform;
57
import org.netbeans.api.java.platform.Specification;
60
import org.netbeans.api.java.platform.Specification;
61
import org.netbeans.api.java.queries.SourceLevelQuery;
58
import org.netbeans.api.project.Project;
62
import org.netbeans.api.project.Project;
59
import org.netbeans.api.project.ProjectManager;
63
import org.netbeans.api.project.ProjectManager;
60
import org.netbeans.junit.NbTestCase;
64
import org.netbeans.junit.NbTestCase;
61
import org.netbeans.modules.java.platform.JavaPlatformProvider;
65
import org.netbeans.modules.java.platform.JavaPlatformProvider;
66
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
62
import org.netbeans.spi.project.support.ant.PropertyUtils;
67
import org.netbeans.spi.project.support.ant.PropertyUtils;
63
import org.openide.filesystems.FileObject;
68
import org.openide.filesystems.FileObject;
64
import org.netbeans.api.project.TestUtil;
69
import org.netbeans.api.project.TestUtil;
Lines 170-175 Link Here
170
        assertEquals(DEFAULT_JAVAC_SOURCE, sl);
175
        assertEquals(DEFAULT_JAVAC_SOURCE, sl);
171
    }
176
    }
172
177
178
    public void testSourceLevelQuery2() throws Exception {
179
        this.prepareProject(TEST_PLATFORM);
180
        final FileObject dummy = projdir.createData("Dummy.java");
181
        final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval);
182
        final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy);
183
        assertNotNull(result);
184
        assertEquals(JAVAC_SOURCE, result.getSourceLevel().toString());
185
    }
186
187
    public void testFiring() throws Exception {
188
        this.prepareProject(TEST_PLATFORM);
189
        final FileObject dummy = projdir.createData("Dummy.java");
190
        final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval);
191
        final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy);
192
        assertNotNull(result);
193
        assertEquals(JAVAC_SOURCE, result.getSourceLevel().toString());
194
        class TestChangeListener implements ChangeListener {
195
            final AtomicInteger ec = new AtomicInteger();
196
            @Override
197
            public void stateChanged(final ChangeEvent event) {
198
                ec.incrementAndGet();
199
            }
200
        }
201
        final TestChangeListener tl = new TestChangeListener();
202
        result.addChangeListener(tl);
203
        final EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
204
        props.setProperty("javac.source", "1.7");
205
        helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
206
        assertEquals(1, tl.ec.intValue());
207
        assertEquals("1.7", result.getSourceLevel().toString());
208
    }
209
173
    private static class TestPlatformProvider implements JavaPlatformProvider {
210
    private static class TestPlatformProvider implements JavaPlatformProvider {
174
211
175
        private JavaPlatform platform;
212
        private JavaPlatform platform;
(-)a/java.j2seproject/nbproject/project.xml (-1 / +1 lines)
Lines 125-131 Link Here
125
                    <compile-dependency/>
125
                    <compile-dependency/>
126
                    <run-dependency>
126
                    <run-dependency>
127
                        <release-version>0-1</release-version>
127
                        <release-version>0-1</release-version>
128
                        <specification-version>1.21</specification-version>
128
                        <specification-version>1.22</specification-version>
129
                    </run-dependency>
129
                    </run-dependency>
130
                </dependency>
130
                </dependency>
131
                <dependency>
131
                <dependency>
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java (-1 / +1 lines)
Lines 356-362 Link Here
356
            new ProjectXmlSavedHookImpl(),
356
            new ProjectXmlSavedHookImpl(),
357
            UILookupMergerSupport.createProjectOpenHookMerger(new ProjectOpenedHookImpl()),
357
            UILookupMergerSupport.createProjectOpenHookMerger(new ProjectOpenedHookImpl()),
358
            QuerySupport.createUnitTestForSourceQuery(getSourceRoots(), getTestSourceRoots()),
358
            QuerySupport.createUnitTestForSourceQuery(getSourceRoots(), getTestSourceRoots()),
359
            QuerySupport.createSourceLevelQuery(evaluator()),
359
            QuerySupport.createSourceLevelQuery2(evaluator()),
360
            QuerySupport.createSources(this, helper, evaluator(), getSourceRoots(), getTestSourceRoots(), Roots.nonSourceRoots(ProjectProperties.BUILD_DIR, J2SEProjectProperties.DIST_DIR)),
360
            QuerySupport.createSources(this, helper, evaluator(), getSourceRoots(), getTestSourceRoots(), Roots.nonSourceRoots(ProjectProperties.BUILD_DIR, J2SEProjectProperties.DIST_DIR)),
361
            QuerySupport.createSharabilityQuery(helper, evaluator(), getSourceRoots(), getTestSourceRoots()),
361
            QuerySupport.createSharabilityQuery(helper, evaluator(), getSourceRoots(), getTestSourceRoots()),
362
            new CoSAwareFileBuiltQueryImpl(QuerySupport.createFileBuiltQuery(helper, evaluator(), getSourceRoots(), getTestSourceRoots()), this),
362
            new CoSAwareFileBuiltQueryImpl(QuerySupport.createFileBuiltQuery(helper, evaluator(), getSourceRoots(), getTestSourceRoots()), this),
(-)a/java.project/nbproject/project.xml (-1 / +1 lines)
Lines 82-88 Link Here
82
                    <compile-dependency/>
82
                    <compile-dependency/>
83
                    <run-dependency>
83
                    <run-dependency>
84
                        <release-version>1</release-version>
84
                        <release-version>1</release-version>
85
                        <specification-version>1.18</specification-version>
85
                        <specification-version>1.30</specification-version>
86
                    </run-dependency>
86
                    </run-dependency>
87
                </dependency>
87
                </dependency>
88
                <dependency>
88
                <dependency>
(-)a/java.project/src/org/netbeans/modules/java/project/ProjectSourceLevelQueryImpl2.java (+71 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.java.project;
44
45
import org.netbeans.api.java.queries.SourceLevelQuery.Result;
46
import org.netbeans.api.project.FileOwnerQuery;
47
import org.netbeans.api.project.Project;
48
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
49
import org.openide.filesystems.FileObject;
50
import org.openide.util.lookup.ServiceProvider;
51
52
/**
53
 *
54
 * @author Tomas Zezula
55
 */
56
@ServiceProvider(service=SourceLevelQueryImplementation2.class,position=99)
57
public class ProjectSourceLevelQueryImpl2 implements SourceLevelQueryImplementation2 {
58
59
    @Override
60
    public Result getSourceLevel(FileObject javaFile) {
61
        final Project project = FileOwnerQuery.getOwner(javaFile);
62
        if (project != null) {
63
            SourceLevelQueryImplementation2 impl = project.getLookup().lookup(SourceLevelQueryImplementation2.class);
64
            if (impl != null) {
65
                return impl.getSourceLevel(javaFile);
66
            }
67
        }
68
        return null;
69
    }
70
71
}

Return to bug 188304