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

(-)a/java.source/apichanges.xml (-2 / +15 lines)
Lines 3-9 Link Here
3
<!--
3
<!--
4
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5
5
6
Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
6
Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
7
7
8
8
9
The contents of this file are subject to the terms of either the GNU
9
The contents of this file are subject to the terms of either the GNU
Lines 27-33 Link Here
27
Contributor(s):
27
Contributor(s):
28
28
29
The Original Software is NetBeans. The Initial Developer of the Original
29
The Original Software is NetBeans. The Initial Developer of the Original
30
Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
30
Software is Sun Microsystems, Inc. Portions Copyright 1997-2010 Sun
31
Microsystems, Inc. All Rights Reserved.
31
Microsystems, Inc. All Rights Reserved.
32
32
33
If you wish your version of this file to be governed by only the CDDL
33
If you wish your version of this file to be governed by only the CDDL
Lines 105-110 Link Here
105
    <!-- ACTUAL CHANGES BEGIN HERE: -->
105
    <!-- ACTUAL CHANGES BEGIN HERE: -->
106
106
107
    <changes>
107
    <changes>
108
        <change id="TreeUtilities.exotic">
109
             <api name="general"/>
110
             <summary>Added support for encoding/decoding exotic identifiers to TreeUtilities.</summary>
111
             <version major="0" minor="56"/>
112
             <date day="24" month="2" year="2010"/>
113
             <author login="jlahoda"/>
114
             <compatibility addition="yes" binary="compatible" deletion="no" deprecation="no" modification="no" semantic="compatible" source="compatible"/>
115
             <description>
116
                Added support for encoding/decoding exotic identifiers to <code>TreeUtilities</code>.
117
             </description>
118
             <class package="org.netbeans.api.java.source" name="TreeUtilities"/>
119
             <issue number="999999"/>
120
        </change>
108
        <change id="GeneratorUtilities.copyComments">
121
        <change id="GeneratorUtilities.copyComments">
109
             <api name="general"/>
122
             <api name="general"/>
110
             <summary>Added GeneratorUtilities.copyComments method.</summary>
123
             <summary>Added GeneratorUtilities.copyComments method.</summary>
(-)a/java.source/nbproject/project.properties (-3 / +3 lines)
Lines 1-6 Link Here
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
2
#
3
# Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
3
# Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
4
#
4
#
5
# The contents of this file are subject to the terms of either the GNU
5
# The contents of this file are subject to the terms of either the GNU
6
# General Public License Version 2 only ("GPL") or the Common
6
# General Public License Version 2 only ("GPL") or the Common
Lines 23-29 Link Here
23
# Contributor(s):
23
# Contributor(s):
24
#
24
#
25
# The Original Software is NetBeans. The Initial Developer of the Original
25
# The Original Software is NetBeans. The Initial Developer of the Original
26
# Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
26
# Software is Sun Microsystems, Inc. Portions Copyright 1997-2010 Sun
27
# Microsystems, Inc. All Rights Reserved.
27
# Microsystems, Inc. All Rights Reserved.
28
#
28
#
29
# If you wish your version of this file to be governed by only the CDDL
29
# If you wish your version of this file to be governed by only the CDDL
Lines 43-49 Link Here
43
javadoc.title=Java Source
43
javadoc.title=Java Source
44
javadoc.arch=${basedir}/arch.xml
44
javadoc.arch=${basedir}/arch.xml
45
javadoc.apichanges=${basedir}/apichanges.xml
45
javadoc.apichanges=${basedir}/apichanges.xml
46
spec.version.base=0.55.0
46
spec.version.base=0.56.0
47
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
47
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
48
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
48
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
49
    ${o.n.core.dir}/lib/boot.jar:\
49
    ${o.n.core.dir}/lib/boot.jar:\
(-)a/java.source/src/org/netbeans/api/java/source/TreeUtilities.java (-1 / +125 lines)
Lines 66-78 Link Here
66
import javax.lang.model.type.TypeKind;
66
import javax.lang.model.type.TypeKind;
67
import javax.lang.model.type.TypeMirror;
67
import javax.lang.model.type.TypeMirror;
68
import javax.lang.model.util.Types;
68
import javax.lang.model.util.Types;
69
import org.netbeans.api.annotations.common.NonNull;
69
import org.netbeans.api.java.lexer.JavaTokenId;
70
import org.netbeans.api.java.lexer.JavaTokenId;
70
import org.netbeans.api.java.source.JavaSource.Phase;
71
import org.netbeans.api.java.source.JavaSource.Phase;
72
import org.netbeans.api.lexer.Token;
71
import org.netbeans.api.lexer.TokenSequence;
73
import org.netbeans.api.lexer.TokenSequence;
72
import org.netbeans.modules.java.source.builder.CommentHandlerService;
74
import org.netbeans.modules.java.source.builder.CommentHandlerService;
73
import org.netbeans.modules.java.source.builder.CommentSetImpl;
75
import org.netbeans.modules.java.source.builder.CommentSetImpl;
74
import org.netbeans.modules.java.source.parsing.SourceFileObject;
76
import org.netbeans.modules.java.source.parsing.SourceFileObject;
75
import org.netbeans.modules.java.source.query.CommentSet.RelativePosition;
76
import org.openide.util.Exceptions;
77
import org.openide.util.Exceptions;
77
78
78
/**
79
/**
Lines 715-720 Link Here
715
        }
716
        }
716
    }
717
    }
717
718
719
    /**Decode escapes defined in: http://wikis.sun.com/display/mlvm/ProjectCoinProposal, 3.1-3.9.
720
     * Must be a full token text, including possible #".
721
     *
722
     * @param text to decode
723
     * @return decoded escapes from the identifier
724
     * @see http://wikis.sun.com/display/mlvm/ProjectCoinProposal
725
     * @since 0.56
726
     */
727
    public @NonNull CharSequence decodeIdentifier(@NonNull CharSequence text) {
728
        return decodeIdentifierInternal(text);
729
    }
730
731
    /**Encode identifier using escapes defined in: http://wikis.sun.com/display/mlvm/ProjectCoinProposal, 3.1-3.9.
732
     *
733
     * @param text to encode
734
     * @return encoded identifier, including #" if necessary
735
     * @see http://wikis.sun.com/display/mlvm/ProjectCoinProposal
736
     * @since 0.56
737
     */
738
    public @NonNull CharSequence encodeIdentifier(@NonNull CharSequence ident) {
739
        return encodeIdentifierInternal(ident);
740
    }
741
742
    static @NonNull CharSequence decodeIdentifierInternal(@NonNull CharSequence text) {
743
        if (text.charAt(0) != '#') {
744
            return text;
745
        }
746
747
        int count = text.charAt(text.length() - 1) == '"' ? text.length() - 1 : text.length();
748
        StringBuilder sb = new StringBuilder(text.length());
749
750
        for (int c = 2; c < count; c++) {
751
            if (text.charAt(c) == '\\' && ++c < count) {
752
                if (EXOTIC_ESCAPE.contains(text.charAt(c))) {
753
                    sb.append('\\');
754
                    sb.append(text.charAt(c));
755
                } else {
756
                    //XXX: handle \012
757
                    Character remaped = ESCAPE_UNENCODE.get(text.charAt(c));
758
759
                    if (remaped != null) {
760
                        sb.append(remaped);
761
                    } else {
762
                        //TODO: illegal?
763
                        sb.append(text.charAt(c));
764
                    }
765
                }
766
            } else {
767
                sb.append(text.charAt(c));
768
            }
769
        }
770
771
        return sb.toString();
772
    }
773
774
    static @NonNull CharSequence encodeIdentifierInternal(@NonNull CharSequence ident) {
775
        if (ident.length() == 0) {
776
            //???
777
            return ident;
778
        }
779
780
        StringBuilder sb = new StringBuilder(ident.length());
781
        boolean needsExotic = Character.isJavaIdentifierStart(ident.charAt(0));
782
783
        //XXX: code points?
784
        for (int i = 0; i < ident.length(); i++) {
785
            char c = ident.charAt(i);
786
787
            if (Character.isJavaIdentifierPart(c)) {
788
                sb.append(c);
789
                continue;
790
            }
791
792
            needsExotic = true;
793
794
            Character target = ESCAPE_ENCODE.get(c);
795
796
            if (target != null) {
797
                sb.append('\\');
798
                sb.append(target);
799
            } else {
800
                sb.append(c);
801
            }
802
        }
803
804
        if (needsExotic) {
805
            sb.append("\"");
806
            sb.insert(0, "#\"");
807
808
            return sb.toString();
809
        } else {
810
            return ident;
811
        }
812
    }
813
814
    static Set<Character> EXOTIC_ESCAPE = new HashSet<Character>(
815
            Arrays.<Character>asList('!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-',
816
                                     ':', '=', '?', '@', '^', '_', '`', '{', '|', '}')
817
    );
818
819
    private static final Map<Character, Character> ESCAPE_UNENCODE;
820
    private static final Map<Character, Character> ESCAPE_ENCODE;
821
822
    static {
823
        Map<Character, Character> unencode = new HashMap<Character, Character>();
824
825
        unencode.put('n', '\n');
826
        unencode.put('t', '\t');
827
        unencode.put('b', '\b');
828
        unencode.put('r', '\r');
829
830
        ESCAPE_UNENCODE = Collections.unmodifiableMap(unencode);
831
832
        Map<Character, Character> encode = new HashMap<Character, Character>();
833
834
        encode.put('\n', 'n');
835
        encode.put('\t', 't');
836
        encode.put('\b', 'b');
837
        encode.put('\r', 'r');
838
839
        ESCAPE_ENCODE = Collections.unmodifiableMap(encode);
840
    }
841
718
    private void copyInnerClassIndexes(Tree from, Tree to) {
842
    private void copyInnerClassIndexes(Tree from, Tree to) {
719
        final int[] fromIdx = {-2};
843
        final int[] fromIdx = {-2};
720
        TreeScanner<Void, Void> scanner = new TreeScanner<Void, Void>() {
844
        TreeScanner<Void, Void> scanner = new TreeScanner<Void, Void>() {
(-)a/java.source/test/unit/src/org/netbeans/api/java/source/TreeUtilitiesTest.java (+19 lines)
Lines 430-433 Link Here
430
430
431
        assertEquals(golden, uncaughtExceptionStrings);
431
        assertEquals(golden, uncaughtExceptionStrings);
432
    }
432
    }
433
434
    public void testExoticIdentifiers() throws Exception {
435
        performExoticIdentiferDecodeTest("#\"a\"", "a");
436
        for (char c : TreeUtilities.EXOTIC_ESCAPE) {
437
            performExoticIdentiferDecodeTest("#\"\\" + c + "\"", "\\" + c);
438
        }
439
        performExoticIdentiferDecodeTest("#\"\\n\"", "\n");
440
441
        performExoticIdentiferDecodeTest("a", "a");
442
        performExoticIdentiferEncodeTest("\n", "#\"\\n\"");
443
    }
444
445
    private void performExoticIdentiferDecodeTest(String exotic, String golden) throws Exception {
446
        assertEquals(golden, TreeUtilities.decodeIdentifierInternal(exotic).toString());
447
    }
448
    
449
    private void performExoticIdentiferEncodeTest(String exotic, String golden) throws Exception {
450
        assertEquals(golden, TreeUtilities.encodeIdentifierInternal(exotic).toString());
451
    }
433
}
452
}

Return to bug 180842