[ann] IDEA-82436 (check unclosed non-empty char literals)

This commit is contained in:
Roman Shevchenko
2012-03-15 19:08:59 +01:00
parent 5b5dbadbba
commit 81f0d72e8f
3 changed files with 28 additions and 4 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -955,7 +955,11 @@ public class HighlightUtil {
return null;
}
else if (type == JavaTokenType.CHARACTER_LITERAL) {
if (value == null) {
// todo[r.sh] clean this mess up
if (value != null) {
if (!StringUtil.endsWithChar(text, '\'')) return JavaErrorMessages.message("unclosed.char.literal");
}
else {
if (!StringUtil.startsWithChar(text, '\'')) return null;
if (StringUtil.endsWithChar(text, '\'')) {
if (text.length() == 1) return JavaErrorMessages.message("illegal.line.end.in.character.literal");
@@ -276,6 +276,7 @@ illegal.escape.character.in.character.literal=Illegal escape character in charac
too.many.characters.in.character.literal=Too many characters in character literal
empty.character.literal=Empty character literal
illegal.line.end.in.string.literal=Illegal line end in string literal
unclosed.char.literal=Unclosed character literal
illegal.escape.character.in.string.literal=Illegal escape character in string literal
floating.point.number.too.large=Floating point number too large
floating.point.number.too.small=Floating point number too small
@@ -1,3 +1,19 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// string literal
public class a {
char c1 = <error descr="Empty character literal">''</error>;
@@ -8,7 +24,8 @@ public class a {
char[] cA = new char[] { 'd','\b','\f','\n','\r'
,'\t','"','\\',' ','\u1234','\uFFFF'
, '\7', '\77', '\345', '\0'};
, '\7', '\77', '\345', '\0', <error descr="Unclosed character literal">'x</error>
};
String s1 = <error descr="Illegal escape character in string literal">"\xd"</error>;
String s11= <error descr="Illegal escape character in string literal">"\udX"</error>;
@@ -29,5 +46,7 @@ public class a {
);
}
String[] s = {
<error descr="Illegal line end in string literal">"unclosed</error>
};
}