Example usage for org.eclipse.jdt.core.tests.util Util writeToFile

List of usage examples for org.eclipse.jdt.core.tests.util Util writeToFile

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.tests.util Util writeToFile.

Prototype

public static void writeToFile(String contents, String destinationFilePath) 

Source Link

Usage

From source file:org.eclipse.objectteams.otdt.tests.otjld.other.Java7.java

License:Open Source License

public void testA01_tryWithResources01() {
    String fileName = OUTPUT_DIR + "/p1/data.txt";
    new File(OUTPUT_DIR + "/p1").mkdirs();
    Util.writeToFile("Hello Reader", fileName);
    runConformTest(false, // should not flush
            new String[] { "p1/TeamA01twr01.java",
                    "package p1;\n" + "import java.io.*;\n" + "public team class TeamA01twr01 {\n"
                            + "    protected class ReaderRole implements AutoCloseable playedBy TA01twr01 {\n"
                            + "        public char[] content;\n"
                            + "        protected void read12() throws IOException {\n"
                            + "            content = new char[12];\n" + "            read(content);\n"
                            + "        }\n" + "        void read(char[] chars) -> int read(char[] chars);\n"
                            + "        close -> close;\n" + "    }\n"
                            + "    void test(TA01twr01 bfr) throws Exception {\n"
                            + "        try (ReaderRole r = new ReaderRole(bfr)) {\n"
                            + "            r.read12();\n"
                            + "            System.out.println(String.valueOf(r.content));\n" + "        }\n"
                            + "    } \n" + "    public static void main(String[] args) throws Exception {\n"
                            + "        new TeamA01twr01().test(new TA01twr01(\"" + fileName + "\"));\n"
                            + "    }\n" + "}",
                    "p1/TA01twr01.java",
                    "package p1;\n" + "import java.io.*;\n" + "public class TA01twr01 extends FileReader {\n"
                            + "    public TA01twr01(String fileName) throws IOException {\n"
                            + "        super(fileName);\n" + "    }\n" + "    @Override\n"
                            + "    public void close() {\n" + "        try {\n" + "            super.close();\n"
                            + "            System.out.println(\"closed\");\n"
                            + "        } catch (IOException ioe) {\n" + "            ioe.printStackTrace();\n"
                            + "        }\n" + "    }\n" + "}", },
            "----------\n" + "1. WARNING in p1\\TeamA01twr01.java (at line 14)\n"
                    + "   try (ReaderRole r = new ReaderRole(bfr)) {\n"
                    + "                       ^^^^^^^^^^^^^^^^^^^\n"
                    + "Argument to lifting constructor ReaderRole(TA01twr01) is not a freshly created base object (of type p1.TA01twr01); may cause a DuplicateRoleException at runtime (OTJLD 2.4.1(c)).\n"
                    + "----------\n",
            "Hello Reader\n" + "closed", "", null);
}

From source file:org.eclipse.objectteams.otdt.tests.otjld.other.Java7.java

License:Open Source License

@SuppressWarnings("unchecked")
public void testA01_tryWithResources02() {
    String fileName = OUTPUT_DIR + "/p1/data.txt";
    new File(OUTPUT_DIR + "/p1").mkdirs();
    Util.writeToFile("Hello Reader", fileName);
    Map options = getCompilerOptions();
    options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, JavaCore.ERROR);
    runTest(new String[] { "p1/TeamA01twr01.java", "package p1;\n" + "import java.io.*;\n"
            + "public team class TeamA01twr01 {\n"
            + "    protected class ReaderRole implements AutoCloseable playedBy TA01twr01 {\n"
            + "        public char[] content;\n" + "        protected void read12() throws IOException {\n"
            + "            content = new char[12];\n" + "            read(content);\n" + "        }\n"
            + "        void read(char[] chars) -> int read(char[] chars);\n" + "        close -> close;\n"
            + "    }\n" + "    void test(String filename) throws Exception {\n"
            + "        try (ReaderRole r = new ReaderRole(new TA01twr01(filename))) {\n"
            + "            r.read12();\n" + "            System.out.println(String.valueOf(r.content));\n"
            + "        }\n" + "    } \n" + "    public static void main(String[] args) throws Exception {\n"
            + "        new TeamA01twr01().test(\"" + fileName + "\");\n" + "    }\n" + "}", "p1/TA01twr01.java",
            "package p1;\n" + "import java.io.*;\n" + "public class TA01twr01 extends FileReader {\n"
                    + "    public TA01twr01(String fileName) throws IOException {\n"
                    + "        super(fileName);\n" + "    }\n" + "    @Override\n"
                    + "    public void close() {\n" + "        try {\n" + "            super.close();\n"
                    + "            System.out.println(\"closed\");\n" + "        } catch (IOException ioe) {\n"
                    + "            ioe.printStackTrace();\n" + "        }\n" + "    }\n" + "}", },
            false, // no comp err
            "", "Hello Reader\n" + "closed", "", true, // force exec
            null, // libs
            false, // should not flush
            null, // vm args
            options, null, // requestor
            true);// skip javac
}