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

(-)a/editor.indent/apichanges.xml (+14 lines)
Lines 104-109 Link Here
104
    <!-- ACTUAL CHANGES BEGIN HERE: -->
104
    <!-- ACTUAL CHANGES BEGIN HERE: -->
105
105
106
    <changes>
106
    <changes>
107
108
        <change id="CodeStylePreferences.for.embedded.mimeTypes">
109
            <summary>Adding CodeStylePreferences.get(Document doc, String mimeType)
110
            and CodeStylePreferences.get(FileObject file, String mimeType).</summary>
111
            <version major="1" minor="11"/>
112
            <date day="5" month="2" year="2008"/>
113
            <author login="dbalek"/>
114
            <compatibility source="compatible" binary="compatible" deletion="no" addition="yes" modification="no"/>
115
            <description>
116
                The new methods were added to allow for getting the formatting/indentation
117
                preferences of embedded mimeTypes.
118
            </description>
119
            <issue number="153957"/>
120
        </change>
107
121
108
        <change id="CodeStylePreferences">
122
        <change id="CodeStylePreferences">
109
            <summary>Adding org.netbeans.modules.editor.indent.spi.CodeStylePreferences</summary>
123
            <summary>Adding org.netbeans.modules.editor.indent.spi.CodeStylePreferences</summary>
(-)a/editor.indent/nbproject/project.properties (-1 / +1 lines)
Lines 39-45 Link Here
39
39
40
javac.source=1.5
40
javac.source=1.5
41
javac.compilerargs=-Xlint:unchecked
41
javac.compilerargs=-Xlint:unchecked
42
spec.version.base=1.10.0
42
spec.version.base=1.11.0
43
43
44
javadoc.arch=${basedir}/arch.xml
44
javadoc.arch=${basedir}/arch.xml
45
javadoc.apichanges=${basedir}/apichanges.xml
45
javadoc.apichanges=${basedir}/apichanges.xml
(-)a/editor.indent/src/org/netbeans/modules/editor/indent/spi/CodeStylePreferences.java (-9 / +46 lines)
Lines 41-46 Link Here
41
41
42
import java.lang.ref.Reference;
42
import java.lang.ref.Reference;
43
import java.lang.ref.WeakReference;
43
import java.lang.ref.WeakReference;
44
import java.util.HashMap;
44
import java.util.Map;
45
import java.util.Map;
45
import java.util.WeakHashMap;
46
import java.util.WeakHashMap;
46
import java.util.logging.Logger;
47
import java.util.logging.Logger;
Lines 99-108 Link Here
99
     * @return The <code>CodeStylePreferences</code>, never <code>null</code>.
100
     * @return The <code>CodeStylePreferences</code>, never <code>null</code>.
100
     */
101
     */
101
    public static CodeStylePreferences get(Document doc) {
102
    public static CodeStylePreferences get(Document doc) {
103
        return get(doc, doc != null ? (String) doc.getProperty("mimeType") : null); //NOI18N
104
    }
105
106
    /**
107
     * Gets <code>CodeStylePreferences</code> for a document and an embedding mimeType.
108
     * This is the prefered method to use. Whenever you have both <code>Document</code> and its
109
     * <code>FileObject</code> always use this method and provide the <code>Document</code>
110
     * instance.
111
     *
112
     * @param doc The document to get <code>CodeStylePreferences</code> for,
113
     *   can be <code>null</code>. If <code>null</code>, the method will return
114
     *   global preferences for 'all languages'.
115
     *
116
     * @return The <code>CodeStylePreferences</code>, never <code>null</code>.
117
     */
118
    public static CodeStylePreferences get(Document doc, String mimeType) {
102
        if (doc != null) {
119
        if (doc != null) {
103
            return get(doc, (String) doc.getProperty("mimeType")); //NOI18N
120
            return getPreferences(doc, mimeType);
104
        } else {
121
        } else {
105
            return get(null, null);
122
            return getPreferences(null, null);
106
        }
123
        }
107
    }
124
    }
108
125
Lines 118-130 Link Here
118
     * @return The <code>CodeStylePreferences</code>, never <code>null</code>.
135
     * @return The <code>CodeStylePreferences</code>, never <code>null</code>.
119
     */
136
     */
120
    public static CodeStylePreferences get(FileObject file) {
137
    public static CodeStylePreferences get(FileObject file) {
138
        return get(file, file != null ? file.getMIMEType() : null);
139
    }
140
    
141
    /**
142
     * Gets <code>CodeStylePreferences</code> for a file. If you also have a
143
     * <code>Document</code> instance you should use the {@link #get(javax.swing.text.Document)}
144
     * method.
145
     *
146
     * @param file The file to get <code>CodeStylePreferences</code> for,
147
     *   can be <code>null</code>. If <code>null</code>, the method will return
148
     *   global preferences for 'all languages'.
149
     *
150
     * @return The <code>CodeStylePreferences</code>, never <code>null</code>.
151
     */
152
    public static CodeStylePreferences get(FileObject file, String mimeType) {
121
        if (file != null) {
153
        if (file != null) {
122
            return get(file, file.getMIMEType()); //NOI18N
154
            return getPreferences(file, mimeType); //NOI18N
123
        } else {
155
        } else {
124
            return get(null, null);
156
            return getPreferences(null, null);
125
        }
157
        }
126
    }
158
    }
127
    
159
128
    public Preferences getPreferences() {
160
    public Preferences getPreferences() {
129
        synchronized (this) {
161
        synchronized (this) {
130
            // This is here solely for the purpose of previewing changes in formatting settings
162
            // This is here solely for the purpose of previewing changes in formatting settings
Lines 153-159 Link Here
153
    private static final String DEFAULT_PROFILE = "default"; // NOI18N
185
    private static final String DEFAULT_PROFILE = "default"; // NOI18N
154
    private static final String PROJECT_PROFILE = "project"; // NOI18N
186
    private static final String PROJECT_PROFILE = "project"; // NOI18N
155
187
156
    private static final Map<Object, CodeStylePreferences> cache = new WeakHashMap<Object, CodeStylePreferences>();
188
    private static final Map<Object, Map<String, CodeStylePreferences>> cache = new WeakHashMap<Object, Map<String, CodeStylePreferences>>();
157
    
189
    
158
    private final String mimeType;
190
    private final String mimeType;
159
    private final Reference<Document> refDoc;
191
    private final Reference<Document> refDoc;
Lines 175-183 Link Here
175
        }
207
        }
176
    };
208
    };
177
    
209
    
178
    private static CodeStylePreferences get(Object obj, String mimeType) {
210
    private static CodeStylePreferences getPreferences(Object obj, String mimeType) {
179
        synchronized (cache) {
211
        synchronized (cache) {
180
            CodeStylePreferences csp = cache.get(obj);
212
            Map<String, CodeStylePreferences> csps = cache.get(obj);
213
            CodeStylePreferences csp = csps != null ? csps.get(mimeType) : null;
181
            if (csp == null) {
214
            if (csp == null) {
182
                Document doc;
215
                Document doc;
183
                FileObject file;
216
                FileObject file;
Lines 195-201 Link Here
195
                        mimeType, 
228
                        mimeType, 
196
                        doc == null ? null : new WeakReference<Document>(doc),
229
                        doc == null ? null : new WeakReference<Document>(doc),
197
                        file == null ? "no file" : file.getPath()); //NOI18N
230
                        file == null ? "no file" : file.getPath()); //NOI18N
198
                cache.put(obj, csp);
231
                if (csps == null) {
232
                    csps = new HashMap<String, CodeStylePreferences>();
233
                    cache.put(obj, csps);
234
                }
235
                csps.put(mimeType, csp);
199
            }
236
            }
200
237
201
            return csp;
238
            return csp;
(-)a/java.source/nbproject/project.xml (-1 / +1 lines)
Lines 137-143 Link Here
137
                    <compile-dependency/>
137
                    <compile-dependency/>
138
                    <run-dependency>
138
                    <run-dependency>
139
                        <release-version>2</release-version>
139
                        <release-version>2</release-version>
140
                        <specification-version>1.9</specification-version>
140
                        <specification-version>1.11</specification-version>
141
                    </run-dependency>
141
                    </run-dependency>
142
                </dependency>
142
                </dependency>
143
                <dependency>
143
                <dependency>
(-)a/java.source/src/org/netbeans/api/java/source/CodeStyle.java (-2 / +3 lines)
Lines 45-50 Link Here
45
import javax.swing.text.Document;
45
import javax.swing.text.Document;
46
import org.netbeans.api.project.Project;
46
import org.netbeans.api.project.Project;
47
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences;
47
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences;
48
import org.netbeans.modules.java.source.parsing.JavacParser;
48
import org.netbeans.modules.java.ui.FmtOptions;
49
import org.netbeans.modules.java.ui.FmtOptions;
49
50
50
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.FileObject;
Lines 99-105 Link Here
99
     * @since 0.39
100
     * @since 0.39
100
     */
101
     */
101
    public synchronized static CodeStyle getDefault(FileObject file) {
102
    public synchronized static CodeStyle getDefault(FileObject file) {
102
        Preferences prefs = CodeStylePreferences.get(file).getPreferences();
103
        Preferences prefs = CodeStylePreferences.get(file, JavacParser.MIME_TYPE).getPreferences();
103
        return FmtOptions.codeStyleProducer.create(prefs);
104
        return FmtOptions.codeStyleProducer.create(prefs);
104
    }
105
    }
105
106
Lines 115-121 Link Here
115
     * @since 0.39
116
     * @since 0.39
116
     */
117
     */
117
    public synchronized static CodeStyle getDefault(Document doc) {
118
    public synchronized static CodeStyle getDefault(Document doc) {
118
        Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
119
        Preferences prefs = CodeStylePreferences.get(doc, JavacParser.MIME_TYPE).getPreferences();
119
        return FmtOptions.codeStyleProducer.create(prefs);
120
        return FmtOptions.codeStyleProducer.create(prefs);
120
    }
121
    }
121
    
122
    

Return to bug 153957