Lines 19-24
Link Here
|
19 |
import org.eclipse.jdt.core.dom.AST; |
19 |
import org.eclipse.jdt.core.dom.AST; |
20 |
import org.eclipse.jdt.core.dom.ASTNode; |
20 |
import org.eclipse.jdt.core.dom.ASTNode; |
21 |
import org.eclipse.jdt.core.dom.ArrayInitializer; |
21 |
import org.eclipse.jdt.core.dom.ArrayInitializer; |
|
|
22 |
import org.eclipse.jdt.core.dom.AssertStatement; |
22 |
import org.eclipse.jdt.core.dom.Assignment; |
23 |
import org.eclipse.jdt.core.dom.Assignment; |
23 |
import org.eclipse.jdt.core.dom.Block; |
24 |
import org.eclipse.jdt.core.dom.Block; |
24 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
25 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
Lines 816-819
Link Here
|
816 |
SimpleName simpleName = fragment.getName(); |
817 |
SimpleName simpleName = fragment.getName(); |
817 |
assertEquals("Not length isn't correct", 0, simpleName.getLength()); //$NON-NLS-1$ |
818 |
assertEquals("Not length isn't correct", 0, simpleName.getLength()); //$NON-NLS-1$ |
818 |
} |
819 |
} |
|
|
820 |
|
821 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=143212 |
822 |
public void test0015() throws JavaModelException { |
823 |
this.workingCopies = new ICompilationUnit[1]; |
824 |
this.workingCopies[0] = getWorkingCopy( |
825 |
"/Converter/src/test/X.java", |
826 |
"package test;\n"+ |
827 |
"\n"+ |
828 |
"public class X {\n"+ |
829 |
" void foo() {\n"+ |
830 |
" assert 0 == 0 : a[0;\n"+ |
831 |
" }\n"+ |
832 |
"}\n"); |
833 |
|
834 |
char[] source = this.workingCopies[0].getSource().toCharArray(); |
835 |
ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true); |
836 |
|
837 |
assertASTNodeEquals( |
838 |
"package test;\n" + |
839 |
"public class X {\n" + |
840 |
" void foo(){\n" + |
841 |
" assert 0 == 0 : a[0];\n" + |
842 |
" }\n" + |
843 |
"}\n", |
844 |
result); |
845 |
|
846 |
ASTNode node = getASTNode((CompilationUnit) result, 0, 0); |
847 |
assertNotNull(node); |
848 |
assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$ |
849 |
MethodDeclaration methodDeclaration = (MethodDeclaration) node; |
850 |
assertTrue("Flag as RECOVERED", (methodDeclaration.getFlags() & ASTNode.RECOVERED) == 0); |
851 |
Block block = methodDeclaration.getBody(); |
852 |
assertTrue("Flag as RECOVERED", (block.getFlags() & ASTNode.RECOVERED) == 0); |
853 |
List statements = block.statements(); |
854 |
assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$ |
855 |
Statement statement = (Statement) statements.get(0); |
856 |
assertTrue("Not an assert statement", statement.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$ |
857 |
AssertStatement assertStatement = (AssertStatement) statement; |
858 |
checkSourceRange(assertStatement, "assert 0 == 0 : a[0;", source); //$NON-NLS-1$ |
859 |
assertTrue("Flag as RECOVERED", (assertStatement.getFlags() & ASTNode.RECOVERED) == 0); |
860 |
Expression message = assertStatement.getMessage(); |
861 |
assertTrue("No message expression", message != null); //$NON-NLS-1$ |
862 |
checkSourceRange(message, "a[0;", source); //$NON-NLS-1$ |
863 |
assertTrue("Not flag as RECOVERED", (message.getFlags() & ASTNode.RECOVERED) != 0); |
864 |
} |
865 |
|
866 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=143212 |
867 |
public void test0016() throws JavaModelException { |
868 |
this.workingCopies = new ICompilationUnit[1]; |
869 |
this.workingCopies[0] = getWorkingCopy( |
870 |
"/Converter/src/test/X.java", |
871 |
"package test;\n"+ |
872 |
"\n"+ |
873 |
"public class X {\n"+ |
874 |
" void foo() {\n"+ |
875 |
" assert 0 == 0 : foo(;\n"+ |
876 |
" }\n"+ |
877 |
"}\n"); |
878 |
|
879 |
char[] source = this.workingCopies[0].getSource().toCharArray(); |
880 |
ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true); |
881 |
|
882 |
assertASTNodeEquals( |
883 |
"package test;\n" + |
884 |
"public class X {\n" + |
885 |
" void foo(){\n" + |
886 |
" assert 0 == 0 : foo();\n" + |
887 |
" }\n" + |
888 |
"}\n", |
889 |
result); |
890 |
|
891 |
ASTNode node = getASTNode((CompilationUnit) result, 0, 0); |
892 |
assertNotNull(node); |
893 |
assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$ |
894 |
MethodDeclaration methodDeclaration = (MethodDeclaration) node; |
895 |
assertTrue("Flag as RECOVERED", (methodDeclaration.getFlags() & ASTNode.RECOVERED) == 0); |
896 |
Block block = methodDeclaration.getBody(); |
897 |
assertTrue("Flag as RECOVERED", (block.getFlags() & ASTNode.RECOVERED) == 0); |
898 |
List statements = block.statements(); |
899 |
assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$ |
900 |
Statement statement = (Statement) statements.get(0); |
901 |
assertTrue("Not an assert statement", statement.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$ |
902 |
AssertStatement assertStatement = (AssertStatement) statement; |
903 |
checkSourceRange(assertStatement, "assert 0 == 0 : foo(;", source); //$NON-NLS-1$ |
904 |
assertTrue("Flag as RECOVERED", (assertStatement.getFlags() & ASTNode.RECOVERED) == 0); |
905 |
Expression message = assertStatement.getMessage(); |
906 |
assertTrue("No message expression", message != null); //$NON-NLS-1$ |
907 |
checkSourceRange(message, "foo(", source); //$NON-NLS-1$ |
908 |
assertTrue("Not flag as RECOVERED", (message.getFlags() & ASTNode.RECOVERED) != 0); |
909 |
} |
910 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=143212 |
911 |
public void test0017() throws JavaModelException { |
912 |
this.workingCopies = new ICompilationUnit[1]; |
913 |
this.workingCopies[0] = getWorkingCopy( |
914 |
"/Converter/src/test/X.java", |
915 |
"package test;\n"+ |
916 |
"\n"+ |
917 |
"public class X {\n"+ |
918 |
" void foo() {\n"+ |
919 |
" assert 0 == 0 : (\"aa\";\n"+ |
920 |
" }\n"+ |
921 |
"}\n"); |
922 |
|
923 |
char[] source = this.workingCopies[0].getSource().toCharArray(); |
924 |
ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true); |
925 |
|
926 |
assertASTNodeEquals( |
927 |
"package test;\n" + |
928 |
"public class X {\n" + |
929 |
" void foo(){\n" + |
930 |
" assert 0 == 0 : (\"aa\");\n" + |
931 |
" }\n" + |
932 |
"}\n", |
933 |
result); |
934 |
|
935 |
ASTNode node = getASTNode((CompilationUnit) result, 0, 0); |
936 |
assertNotNull(node); |
937 |
assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$ |
938 |
MethodDeclaration methodDeclaration = (MethodDeclaration) node; |
939 |
assertTrue("Flag as RECOVERED", (methodDeclaration.getFlags() & ASTNode.RECOVERED) == 0); |
940 |
Block block = methodDeclaration.getBody(); |
941 |
assertTrue("Flag as RECOVERED", (block.getFlags() & ASTNode.RECOVERED) == 0); |
942 |
List statements = block.statements(); |
943 |
assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$ |
944 |
Statement statement = (Statement) statements.get(0); |
945 |
assertTrue("Not an assert statement", statement.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$ |
946 |
AssertStatement assertStatement = (AssertStatement) statement; |
947 |
checkSourceRange(assertStatement, "assert 0 == 0 : (\"aa\";", source); //$NON-NLS-1$ |
948 |
assertTrue("Flag as RECOVERED", (assertStatement.getFlags() & ASTNode.RECOVERED) == 0); |
949 |
Expression message = assertStatement.getMessage(); |
950 |
assertTrue("No message expression", message != null); //$NON-NLS-1$ |
951 |
checkSourceRange(message, "(\"aa\"", source); //$NON-NLS-1$ |
952 |
assertTrue("Not flag as RECOVERED", (message.getFlags() & ASTNode.RECOVERED) != 0); |
953 |
} |
819 |
} |
954 |
} |