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>() { |