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

(-)a/csl.api/src/org/netbeans/modules/csl/core/GsfDataObject.java (-1 / +20 lines)
Lines 51-56 Link Here
51
import org.netbeans.api.actions.Openable;
51
import org.netbeans.api.actions.Openable;
52
import org.netbeans.api.lexer.InputAttributes;
52
import org.netbeans.api.lexer.InputAttributes;
53
import org.netbeans.core.api.multiview.MultiViews;
53
import org.netbeans.core.api.multiview.MultiViews;
54
import org.netbeans.modules.csl.api.GsfLanguage;
54
import org.netbeans.modules.editor.NbEditorUtilities;
55
import org.netbeans.modules.editor.NbEditorUtilities;
55
import org.openide.cookies.CloseCookie;
56
import org.openide.cookies.CloseCookie;
56
import org.openide.cookies.EditCookie;
57
import org.openide.cookies.EditCookie;
Lines 116-121 Link Here
116
        return 1;
117
        return 1;
117
    }
118
    }
118
119
120
    @Override
121
    public void setModified(boolean modif) {
122
        super.setModified(modif);
123
        if (!modif) {
124
            GenericEditorSupport ges = getLookup().lookup(GenericEditorSupport.class);
125
            ges.removeSaveCookie();
126
        }
127
    }
128
    
129
    
130
119
    public @Override <T extends Cookie> T getCookie(Class<T> type) {
131
    public @Override <T extends Cookie> T getCookie(Class<T> type) {
120
        return getCookieSet().getCookie(type);
132
        return getCookieSet().getCookie(type);
121
    }
133
    }
Lines 265-270 Link Here
265
        
277
        
266
        protected @Override void notifyUnmodified() {
278
        protected @Override void notifyUnmodified() {
267
            super.notifyUnmodified();
279
            super.notifyUnmodified();
280
            removeSaveCookie();
281
        }
282
283
        final void removeSaveCookie() {
268
            ((Environment)this.env).removeSaveCookie();
284
            ((Environment)this.env).removeSaveCookie();
269
        }
285
        }
270
286
Lines 282-288 Link Here
282
            // Enter the file object in to InputAtrributes. It can be used by lexer.
298
            // Enter the file object in to InputAtrributes. It can be used by lexer.
283
            InputAttributes attributes = new InputAttributes();
299
            InputAttributes attributes = new InputAttributes();
284
            FileObject fileObject = NbEditorUtilities.getFileObject(doc);
300
            FileObject fileObject = NbEditorUtilities.getFileObject(doc);
285
            attributes.setValue(language.getGsfLanguage().getLexerLanguage(), FileObject.class, fileObject, false);
301
            final GsfLanguage lng = language.getGsfLanguage();
302
            if (lng != null) {
303
                attributes.setValue(lng.getLexerLanguage(), FileObject.class, fileObject, false);
304
            }
286
            doc.putProperty(InputAttributes.class, attributes);
305
            doc.putProperty(InputAttributes.class, attributes);
287
            return doc;
306
            return doc;
288
        }
307
        }
(-)db41f88fcafd (+71 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 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 Development and
11
 * Distribution License("CDDL") (collectively, the "License"). You may not use
12
 * this file except in compliance with the License. You can obtain a copy of
13
 * the License at http://www.netbeans.org/cddl-gplv2.html or
14
 * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language
15
 * governing permissions and limitations under the License. When distributing
16
 * the software, include this License Header Notice in each file and include
17
 * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
18
 * particular file as subject to the "Classpath" exception as provided by
19
 * Oracle in the GPL Version 2 section of the License file that accompanied
20
 * this code. If applicable, add the following below the License Header, with
21
 * the fields enclosed by brackets [] replaced by your own identifying
22
 * information: "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL or
25
 * only the GPL Version 2, indicate your decision by adding "[Contributor]
26
 * elects to include this software in this distribution under the [CDDL or GPL
27
 * Version 2] license." If you do not indicate a single choice of license, a
28
 * recipient has the option to distribute your version of this file under
29
 * either the CDDL, the GPL Version 2 or to extend the choice of license to its
30
 * licensees as provided above. However, if you add GPL Version 2 code and
31
 * therefore, elected the GPL Version 2 license, then the option applies only
32
 * if the new code is made subject to such option by the copyright holder.
33
 *
34
 * Contributor(s):
35
 *
36
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
37
 */
38
package org.netbeans.modules.csl.core;
39
40
import org.netbeans.junit.NbTestCase;
41
import org.openide.cookies.EditorCookie;
42
import org.openide.cookies.SaveCookie;
43
import org.openide.filesystems.FileObject;
44
import org.openide.filesystems.FileSystem;
45
import org.openide.filesystems.FileUtil;
46
import org.openide.loaders.DataObject;
47
48
public class GsfDataObjectTest extends NbTestCase {
49
    static {
50
        FileUtil.setMIMEType("test", "text/x-test");
51
    }
52
53
    public GsfDataObjectTest(String name) {
54
        super(name);
55
    }
56
57
    public void testSetModifiedRemovesSaveCookie() throws Exception {
58
        FileSystem fs = FileUtil.createMemoryFileSystem();
59
        FileObject f = fs.getRoot().createData("index.test");
60
        DataObject dob = DataObject.find(f);
61
        assertEquals("The right object", GsfDataObject.class, dob.getClass());
62
63
        dob.getLookup().lookup(EditorCookie.class).openDocument().insertString(0,
64
                "modified", null);
65
        assertTrue("Should be modified.", dob.isModified());
66
        dob.setModified(false);
67
        assertFalse("Should not be modified.", dob.isModified());
68
        assertNull("Should not have SaveCookie.",
69
                dob.getLookup().lookup(SaveCookie.class));
70
    }
71
}
(-)a/csl.api/test/unit/src/org/netbeans/modules/csl/spi/LanguageRegistrationTest.java (-2 / +47 lines)
Lines 42-50 Link Here
42
42
43
package org.netbeans.modules.csl.spi;
43
package org.netbeans.modules.csl.spi;
44
44
45
import java.util.Collection;
46
import java.util.EnumSet;
47
import org.netbeans.api.lexer.TokenId;
45
import org.netbeans.junit.NbTestCase;
48
import org.netbeans.junit.NbTestCase;
46
import org.netbeans.modules.csl.core.Language;
49
import org.netbeans.modules.csl.core.Language;
47
import org.netbeans.modules.csl.core.LanguageRegistry;
50
import org.netbeans.modules.csl.core.LanguageRegistry;
51
import org.netbeans.spi.lexer.LanguageHierarchy;
52
import org.netbeans.spi.lexer.Lexer;
53
import org.netbeans.spi.lexer.LexerRestartInfo;
48
54
49
/**
55
/**
50
 *
56
 *
Lines 71-83 Link Here
71
77
72
        @Override
78
        @Override
73
        public org.netbeans.api.lexer.Language getLexerLanguage() {
79
        public org.netbeans.api.lexer.Language getLexerLanguage() {
74
            throw new UnsupportedOperationException("Not supported yet.");
80
            return new Lang("text/x-test").language();
75
        }
81
        }
76
82
77
        @Override
83
        @Override
78
        public String getDisplayName() {
84
        public String getDisplayName() {
79
            throw new UnsupportedOperationException("Not supported yet.");
85
            return "test language";
80
        }
86
        }
81
        
87
        
82
    }
88
    }
89
    
90
    private static enum TestTokenId implements TokenId {
91
92
        TOKEN_ID1,
93
        TOKEN_ID2;
94
95
        private TestTokenId() {
96
        }
97
98
        @Override
99
        public String primaryCategory() {
100
            return null;
101
        }
102
    } // End of TestTokenId
103
104
    private static final class Lang extends LanguageHierarchy<TestTokenId> {
105
106
        private String mimeType;
107
108
        public Lang(String mimeType) {
109
            this.mimeType = mimeType;
110
        }
111
112
        @Override
113
        protected Lexer<TestTokenId> createLexer(LexerRestartInfo<TestTokenId> info) {
114
            return null;
115
        }
116
117
        @Override
118
        protected Collection<TestTokenId> createTokenIds() {
119
            return EnumSet.allOf(TestTokenId.class);
120
        }
121
122
        @Override
123
        public String mimeType() {
124
            return mimeType;
125
        }
126
    } // End of Lang class
127
    
83
}
128
}

Return to bug 202127