1b293ca775054871164e9e3c83833a2fd4601387cTor Norbye/*
2b293ca775054871164e9e3c83833a2fd4601387cTor Norbye * Copyright (C) 2012 The Android Open Source Project
3b293ca775054871164e9e3c83833a2fd4601387cTor Norbye *
4b293ca775054871164e9e3c83833a2fd4601387cTor Norbye * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5b293ca775054871164e9e3c83833a2fd4601387cTor Norbye * you may not use this file except in compliance with the License.
6b293ca775054871164e9e3c83833a2fd4601387cTor Norbye * You may obtain a copy of the License at
7b293ca775054871164e9e3c83833a2fd4601387cTor Norbye *
8b293ca775054871164e9e3c83833a2fd4601387cTor Norbye *      http://www.eclipse.org/org/documents/epl-v10.php
9b293ca775054871164e9e3c83833a2fd4601387cTor Norbye *
10b293ca775054871164e9e3c83833a2fd4601387cTor Norbye * Unless required by applicable law or agreed to in writing, software
11b293ca775054871164e9e3c83833a2fd4601387cTor Norbye * distributed under the License is distributed on an "AS IS" BASIS,
12b293ca775054871164e9e3c83833a2fd4601387cTor Norbye * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b293ca775054871164e9e3c83833a2fd4601387cTor Norbye * See the License for the specific language governing permissions and
14b293ca775054871164e9e3c83833a2fd4601387cTor Norbye * limitations under the License.
15b293ca775054871164e9e3c83833a2fd4601387cTor Norbye */
16b293ca775054871164e9e3c83833a2fd4601387cTor Norbyepackage com.android.ide.eclipse.adt.internal.refactorings.core;
17b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
1813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbyeimport com.android.annotations.NonNull;
1913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbyeimport com.android.annotations.Nullable;
20b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport com.android.ide.eclipse.adt.AdtUtils;
21b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport com.android.ide.eclipse.adt.internal.editors.layout.refactoring.AdtProjectTest;
22b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport com.google.common.base.Charsets;
23b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport com.google.common.base.Splitter;
24b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport com.google.common.io.ByteStreams;
25b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport com.google.common.io.Files;
26b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
27b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport org.eclipse.core.resources.IFile;
28b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport org.eclipse.core.resources.IProject;
29b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport org.eclipse.core.resources.IResource;
30b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport org.eclipse.core.runtime.NullProgressMonitor;
3113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbyeimport org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange;
32b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange;
33b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport org.eclipse.jface.text.Document;
34b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport org.eclipse.jface.text.IDocument;
35b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport org.eclipse.ltk.core.refactoring.Change;
36b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport org.eclipse.ltk.core.refactoring.CompositeChange;
37b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport org.eclipse.ltk.core.refactoring.Refactoring;
38b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport org.eclipse.ltk.core.refactoring.RefactoringStatus;
39b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport org.eclipse.ltk.core.refactoring.TextChange;
40b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport org.eclipse.ltk.core.refactoring.TextFileChange;
4113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbyeimport org.eclipse.ltk.core.refactoring.resource.MoveResourceChange;
42b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport org.eclipse.ltk.core.refactoring.resource.RenameResourceChange;
43b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport org.eclipse.text.edits.TextEdit;
44b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
45b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport java.io.File;
46b293ca775054871164e9e3c83833a2fd4601387cTor Norbyeimport java.io.IOException;
4713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbyeimport java.util.Arrays;
4813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbyeimport java.util.Collections;
4913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbyeimport java.util.Comparator;
5013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbyeimport java.util.List;
51b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
52b293ca775054871164e9e3c83833a2fd4601387cTor Norbye@SuppressWarnings({"javadoc","restriction"})
53b293ca775054871164e9e3c83833a2fd4601387cTor Norbyepublic abstract class RefactoringTestBase extends AdtProjectTest {
547e3452665f6672c8a42710b799a1f69e26e3d98dTor Norbye    protected void checkRefactoring(Refactoring refactoring, String expected) throws Exception {
557e3452665f6672c8a42710b799a1f69e26e3d98dTor Norbye        checkRefactoring(refactoring, expected, null);
567e3452665f6672c8a42710b799a1f69e26e3d98dTor Norbye    }
577e3452665f6672c8a42710b799a1f69e26e3d98dTor Norbye
582c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye    @Override
592c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye    protected void setUp() throws Exception {
602c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye        // Not calling super.setUp
612c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye    }
622c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye
637e3452665f6672c8a42710b799a1f69e26e3d98dTor Norbye    protected void checkRefactoring(Refactoring refactoring, String expected,
647e3452665f6672c8a42710b799a1f69e26e3d98dTor Norbye            @Nullable String expectedWarnings) throws Exception {
65b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        RefactoringStatus status = refactoring.checkAllConditions(new NullProgressMonitor());
66b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        assertNotNull(status);
677e3452665f6672c8a42710b799a1f69e26e3d98dTor Norbye        if (expectedWarnings == null) {
687e3452665f6672c8a42710b799a1f69e26e3d98dTor Norbye            expectedWarnings = "<OK\n>";
697e3452665f6672c8a42710b799a1f69e26e3d98dTor Norbye        }
702c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye        if (status.toString().trim().startsWith(
712c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye            "<WARNING\n" +
722c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye            "\t\n" +
732c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye            "WARNING: Code modification may not be accurate as affected resource '")) {
742c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye            // Test instability, probably a timing issue with getting the new project
752c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye            // compiled (to recognize Android classpath entries)
762c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye            // Just continue to ensure that the refactoring list matches.
772c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye        } else {
782c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye            assertEquals(status.toString().trim(), expectedWarnings.trim());
792c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye        }
80b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        if (!status.isOK()) {
81b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            return;
82b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        }
83b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        assertTrue(status.toString(), status.isOK());
84b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        Change change = refactoring.createChange(new NullProgressMonitor());
85b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        assertNotNull(change);
86b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        String explanation = "CHANGES:\n-------\n" + describe(change);
87b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        if (!expected.trim().equals(explanation.trim())) { // allow trimming endlines in expected
88b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            assertEquals(expected, explanation);
89b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        }
90b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    }
91b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
922c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye    private IProject mProject;
932c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye
942c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye    @Override
952c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye    protected IProject getProject() {
962c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye        return mProject;
972c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye    }
982c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye
99b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    protected IProject createProject(Object[] testData) throws Exception {
100b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        String name = getName();
101b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        IProject project = createProject(name);
1022c6c42bdffd1f9162c86d63a4b0bdee9a4eb7d59Tor Norbye        mProject = project;
103b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        File projectDir = AdtUtils.getAbsolutePath(project).toFile();
104b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        assertNotNull(projectDir);
105b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        assertTrue(projectDir.getPath(), projectDir.exists());
106b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        createTestDataDir(projectDir, testData);
107b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
108b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
109b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        for (int i = 0; i < testData.length; i+= 2) {
110b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            assertTrue(testData[i].toString(), testData[i] instanceof String);
111b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            String relative = (String) testData[i];
112b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            IResource member = project.findMember(relative);
113b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            assertNotNull(relative, member);
114b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            assertTrue(member.getClass().getSimpleName(), member instanceof IFile);
115b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        }
116b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
117b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        return project;
118b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    }
119b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
120b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    public static String describe(Change change) throws Exception {
121b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        StringBuilder sb = new StringBuilder(1000);
122b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        describe(sb, change, 0);
123b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
124b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        // Trim trailing space
125b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        for (int i = sb.length() - 1; i >= 0; i--) {
126b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            if (!Character.isWhitespace(sb.charAt(i))) {
127b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                sb.setLength(i + 1);
128b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                break;
129b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            }
130b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        }
131b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
132b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        return sb.toString();
133b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    }
134b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
135b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    protected static void describe(StringBuilder sb, Change change, int indent) throws Exception {
136b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        if (change instanceof CompositeChange
137b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                && ((CompositeChange) change).isSynthetic()) {
138b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            // Don't display information about synthetic changes
139b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        } else {
140b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            String changeName = change.getName();
141b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
142b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            if (changeName.contains("MoreUnit")) {
143b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                // If MoreUnit plugin is installed, don't include in unit test results
144b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                return;
145b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            }
146b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
147b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            // Describe this change
148b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            indent(sb, indent);
1498cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye            if (change.isEnabled()) {
1508cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye                sb.append("[x] ");
1518cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye            } else {
1528cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye                sb.append("[ ] ");
1538cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye            }
154b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            sb.append(changeName);
15513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
15613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            IFile file = getFile(change);
15713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            if (file != null) {
158b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                sb.append(" - ");
15913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                sb.append(file.getFullPath());
160b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                sb.append('\n');
161b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            } else {
162b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                sb.append('\n');
163b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            }
16413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
16532654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            if (change instanceof TextFileChange) {
16613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                assertNotNull(file);
16713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                if (file != null) {
16813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                    TextChange tc = (TextChange) change;
16913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                    TextEdit edit = tc.getEdit();
17013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                    byte[] bytes = ByteStreams.toByteArray(file.getContents());
17113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                    String before = new String(bytes, Charsets.UTF_8);
17213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                    IDocument document = new Document();
17313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                    document.replace(0, 0, before);
17413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                    // Make a copy: edits are sometimes destructive when run repeatedly!
17513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                    edit.copy().apply(document);
17613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                    String after = document.get();
17713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
17813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                    String diff = getDiff(before, after);
17913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                    for (String line : Splitter.on('\n').split(diff)) {
18013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                        if (!line.trim().isEmpty()) {
18113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                            indent(sb, indent + 1);
18213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                            sb.append(line);
18313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                        }
18413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                        sb.append('\n');
185b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                    }
186b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                }
18713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            } else if (change instanceof RenameCompilationUnitChange) {
18813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                // Change name, appended above, is adequate
189b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            } else if (change instanceof RenameResourceChange) {
190b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                // Change name, appended above, is adequate
191b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            } else if (change instanceof RenamePackageChange) {
192b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                // Change name, appended above, is adequate
19313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            } else if (change instanceof MoveResourceChange) {
19413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                // Change name, appended above, is adequate
195b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            } else if (change instanceof CompositeChange) {
196b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                // Don't print details about children here; they'll be nested below
197b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            } else {
198b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                indent(sb, indent);
19913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                sb.append("<UNKNOWN CHANGE TYPE " + change.getClass().getName() + ">");
200b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            }
201b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            sb.append('\n');
202b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        }
203b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
204b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        if (change instanceof CompositeChange) {
205b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            CompositeChange composite = (CompositeChange) change;
206b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            Change[] children = composite.getChildren();
20713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            List<Change> sorted = Arrays.asList(children);
20813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            // Process children in a fixed (output-alphabetical) order to ensure stable output
20913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            Collections.sort(sorted, new Comparator<Change>() {
21013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                @Override
21113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                public int compare(Change change1, Change change2) {
21213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                    try {
21313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                        IFile file1 = getFile(change1);
21413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                        IFile file2 = getFile(change2);
21513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                        if (file1 != null && file2 != null) {
21613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                            // Sort in decreasing order. This places the most interesting
21713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                            // files first: res > src > gen
21813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                            int fileDelta = file2.getFullPath().toOSString().compareToIgnoreCase(
21913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                                    file1.getFullPath().toOSString());
22013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                            if (fileDelta != 0) {
22113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                                return fileDelta;
22213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                            }
22313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                        }
22413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
22513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                        int nameDelta = change2.getName().compareTo(change1.getName());
22613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                        if (nameDelta != 0) {
22713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                            return nameDelta;
22813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                        }
22913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
23013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                        // This is pretty inefficient but ensures stable output
23113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                        return describe(change2).compareTo(describe(change1));
23213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                    } catch (Exception e) {
23313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                        fail(e.getLocalizedMessage());
23413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                        return 0;
23513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                    }
23613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye                }
23713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
23813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            });
23913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            for (Change child : sorted) {
240b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                describe(sb, child, indent + (composite.isSynthetic() ? 0 : 1));
241b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            }
242b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        }
243b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    }
244b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
24513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye    @Nullable
24613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye    private static IFile getFile(@NonNull Change change) {
24713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        if (change instanceof TextFileChange) {
24813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            TextFileChange tfc = (TextFileChange) change;
24913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            return tfc.getFile();
25013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        }
25113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
25213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        return null;
25313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye    }
25413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
255b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    protected static void indent(StringBuilder sb, int indent) {
256b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        for (int i = 0; i < indent; i++) {
257b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            sb.append("  ");
258b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        }
259b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    }
260b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
261b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    protected void createTestDataDir(File dir, Object[] data) throws IOException {
262b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        for (int i = 0, n = data.length; i < n; i += 2) {
263b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            assertTrue("Must be a path: " + data[i], data[i] instanceof String);
264b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            String relativePath = ((String) data[i]).replace('/', File.separatorChar);
265b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            File to = new File(dir, relativePath);
266b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            File parent = to.getParentFile();
267b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            if (!parent.exists()) {
268b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                boolean mkdirs = parent.mkdirs();
269b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                assertTrue(to.getPath(), mkdirs);
270b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            }
271b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
272b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            Object o = data[i + 1];
273b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            if (o instanceof String) {
274b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                String contents = (String) o;
275b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                Files.write(contents, to, Charsets.UTF_8);
276b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            } else if (o instanceof byte[]) {
277b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                Files.write((byte[]) o, to);
278b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            } else {
279b293ca775054871164e9e3c83833a2fd4601387cTor Norbye                fail("Data must be a String or a byte[] for " + to);
280b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            }
281b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        }
282b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    }
283b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
284b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    // Test sources
285b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
286b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    protected static final String SAMPLE_MANIFEST =
287b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
288b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" +
289b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    package=\"com.example.refactoringtest\"\n" +
290b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    android:versionCode=\"1\"\n" +
291b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    android:versionName=\"1.0\" >\n" +
292b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
293b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    <uses-sdk\n" +
294b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:minSdkVersion=\"8\"\n" +
295b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:targetSdkVersion=\"17\" />\n" +
296b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
297b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    <application\n" +
298b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:icon=\"@drawable/ic_launcher\"\n" +
299b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:label=\"@string/app_name\"\n" +
300b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:theme=\"@style/AppTheme\" >\n" +
301b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        <activity\n" +
302b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "            android:name=\"com.example.refactoringtest.MainActivity\"\n" +
303b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "            android:label=\"@string/app_name\" >\n" +
304b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "            <intent-filter>\n" +
305b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "                <action android:name=\"android.intent.action.MAIN\" />\n" +
306b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
307b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "                <category android:name=\"android.intent.category.LAUNCHER\" />\n" +
308b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "            </intent-filter>\n" +
309b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        </activity>\n" +
31032654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "        <activity\n" +
31132654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "            android:name=\".MainActivity2\"\n" +
31232654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "            android:label=\"@string/app_name2\" >\n" +
31332654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "        </activity>\n" +
314b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    </application>\n" +
315b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
316b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "</manifest>";
317b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
318b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    protected static final String SAMPLE_MAIN_ACTIVITY =
319b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "package com.example.refactoringtest;\n" +
320b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
321b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "import android.os.Bundle;\n" +
322b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "import android.app.Activity;\n" +
323b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "import android.view.Menu;\n" +
324b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "import android.view.View;\n" +
325b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
326b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "public class MainActivity extends Activity {\n" +
327b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
328b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    @Override\n" +
329b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    protected void onCreate(Bundle savedInstanceState) {\n" +
330b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        super.onCreate(savedInstanceState);\n" +
331b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        setContentView(R.layout.activity_main);\n" +
332b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        View view1 = findViewById(R.id.textView1);\n" +
333b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    }\n" +
334b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
335b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    @Override\n" +
336b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    public boolean onCreateOptionsMenu(Menu menu) {\n" +
337b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        // Inflate the menu; this adds items to the action bar if it is present.\n" +
338b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        getMenuInflater().inflate(R.menu.activity_main, menu);\n" +
339b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        return true;\n" +
340b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    }\n" +
341b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
342b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "}\n";
343b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
34432654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye    protected static final String SAMPLE_MAIN_ACTIVITY2 =
34532654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "package com.example.refactoringtest;\n" +
34632654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "\n" +
34732654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "import android.os.Bundle;\n" +
34832654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "import android.app.Activity;\n" +
34932654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "import android.view.Menu;\n" +
35032654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "import android.view.View;\n" +
35132654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "\n" +
35232654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "public class MainActivity2 extends Activity {\n" +
35332654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "\n" +
35432654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "    @Override\n" +
35532654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "    protected void onCreate(Bundle savedInstanceState) {\n" +
35632654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "        super.onCreate(savedInstanceState);\n" +
35732654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "    }\n" +
35832654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "\n" +
35932654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "}\n";
36032654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye
36132654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye    protected static final String MY_FRAGMENT =
36232654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "package com.example.refactoringtest;\n" +
36332654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "import android.support.v4.app.ListFragment;\n" +
36432654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "\n" +
36532654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "public class MyFragment extends ListFragment {\n" +
36632654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "\n" +
36732654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "}\n";
36832654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye
369b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    protected static final String SAMPLE_LAYOUT =
370b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" +
371b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    xmlns:tools=\"http://schemas.android.com/tools\"\n" +
372b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    android:layout_width=\"match_parent\"\n" +
373b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    android:layout_height=\"match_parent\"\n" +
374b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    tools:context=\".MainActivity\" >\n" +
375b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
376b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    <TextView\n" +
377b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:id=\"@+id/textView1\"\n" +
378b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:layout_width=\"wrap_content\"\n" +
379b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:layout_height=\"wrap_content\"\n" +
380b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:layout_centerVertical=\"true\"\n" +
381b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:layout_toRightOf=\"@+id/button2\"\n" +
382b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:text=\"@string/hello_world\" />\n" +
383b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
384b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    <Button\n" +
385b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:id=\"@+id/button1\"\n" +
386b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:layout_width=\"wrap_content\"\n" +
387b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:layout_height=\"wrap_content\"\n" +
388b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:layout_alignLeft=\"@+id/textView1\"\n" +
389b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:layout_below=\"@+id/textView1\"\n" +
390b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:layout_marginLeft=\"22dp\"\n" +
391b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:layout_marginTop=\"24dp\"\n" +
392b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:text=\"Button\" />\n" +
393b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
394b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    <Button\n" +
395b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:id=\"@+id/button2\"\n" +
396b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:layout_width=\"wrap_content\"\n" +
397b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:layout_height=\"wrap_content\"\n" +
398b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:layout_alignParentLeft=\"true\"\n" +
399b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:layout_alignParentTop=\"true\"\n" +
400b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:text=\"Button\" />\n" +
401b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
40232654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "    <fragment android:name=\"com.example.refactoringtest.MyFragment\"/>" +
40332654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "\n" +
404b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "</RelativeLayout>";
405b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
406b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    protected static final String SAMPLE_LAYOUT_2 =
407b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" +
408b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    xmlns:tools=\"http://schemas.android.com/tools\"\n" +
409b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    android:layout_width=\"match_parent\"\n" +
410b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    android:layout_height=\"match_parent\"\n" +
411b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    tools:context=\".MainActivity\" >\n" +
412b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
41332654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "    <ListView\n" +
41432654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "        android:layout_width=\"match_parent\"\n" +
41532654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "        android:layout_height=\"wrap_content\"\n" +
41632654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "        tools:listitem=\"@layout/preview\" >\n" +
41732654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "    </ListView>\n" +
41832654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "\n" +
41932654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "    <fragment\n" +
42032654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "        android:name=\"android.support.v4.app.ListFragment\"\n" +
42132654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "        android:layout_width=\"wrap_content\"\n" +
42232654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "        android:layout_height=\"wrap_content\"\n" +
42332654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "        tools:layout=\"@layout/preview\" />\n" +
42432654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye            "\n" +
425b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
426b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "</RelativeLayout>";
427b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
428b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
429b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    protected static final String SAMPLE_MENU =
430b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "<menu xmlns:android=\"http://schemas.android.com/apk/res/android\" >\n" +
431b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
432b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    <item\n" +
433b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:id=\"@+id/menu_settings\"\n" +
434b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:orderInCategory=\"100\"\n" +
435b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:showAsAction=\"never\"\n" +
436b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        android:title=\"@string/menu_settings\"/>\n" +
437b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
438b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "</menu>";
439b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
440b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    protected static final String SAMPLE_STRINGS =
441b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
442b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "<resources>\n" +
443b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
444b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    <string name=\"app_name\">RefactoringTest</string>\n" +
445b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    <string name=\"hello_world\">Hello world!</string>\n" +
446b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    <string name=\"menu_settings\">Settings</string>\n" +
447b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
448b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "</resources>";
449b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
450b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    protected static final String SAMPLE_STYLES =
451b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "<resources>\n" +
452b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
453b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    <!--\n" +
454b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        Base application theme, dependent on API level. This theme is replaced\n" +
455b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.\n" +
456b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    -->\n" +
457b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    <style name=\"AppBaseTheme\" parent=\"android:Theme.Light\">\n" +
458b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        <!--\n" +
459b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "            Theme customizations available in newer API levels can go in\n" +
460b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "            res/values-vXX/styles.xml, while customizations related to\n" +
461b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "            backward-compatibility can go here.\n" +
462b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        -->\n" +
463b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    </style>\n" +
464b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
465b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    <!-- Application theme. -->\n" +
466b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    <style name=\"AppTheme\" parent=\"AppBaseTheme\">\n" +
467b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        <!-- All customizations that are NOT specific to a particular API-level can go here. -->\n" +
468b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    </style>\n" +
469b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
470b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "</resources>";
471b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
472b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    protected static final String SAMPLE_R =
473b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "/* AUTO-GENERATED FILE.  DO NOT MODIFY.\n" +
474b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            " *\n" +
475b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            " * This class was automatically generated by the\n" +
476b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            " * aapt tool from the resource data it found.  It\n" +
477b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            " * should not be modified by hand.\n" +
478b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            " */\n" +
479b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
480b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "package com.example.refactoringtest;\n" +
481b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
482b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "public final class R {\n" +
483b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    public static final class attr {\n" +
484b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    }\n" +
485b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    public static final class drawable {\n" +
486b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        public static final int ic_launcher=0x7f020000;\n" +
487b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    }\n" +
488b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    public static final class id {\n" +
489b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        public static final int button1=0x7f070002;\n" +
490b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        public static final int button2=0x7f070001;\n" +
491b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        public static final int menu_settings=0x7f070003;\n" +
492b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        public static final int textView1=0x7f070000;\n" +
493b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    }\n" +
494b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    public static final class layout {\n" +
495b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        public static final int activity_main=0x7f030000;\n" +
496b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    }\n" +
497b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    public static final class menu {\n" +
498b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        public static final int activity_main=0x7f060000;\n" +
499b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    }\n" +
500b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    public static final class string {\n" +
501b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        public static final int app_name=0x7f040000;\n" +
502b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        public static final int hello_world=0x7f040001;\n" +
503b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        public static final int menu_settings=0x7f040002;\n" +
504b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    }\n" +
505b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    public static final class style {\n" +
506b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        /** \n" +
507b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        Base application theme, dependent on API level. This theme is replaced\n" +
508b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.\n" +
509b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    \n" +
510b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
511b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "            Theme customizations available in newer API levels can go in\n" +
512b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "            res/values-vXX/styles.xml, while customizations related to\n" +
513b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "            backward-compatibility can go here.\n" +
514b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        \n" +
515b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
516b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        Base application theme for API 11+. This theme completely replaces\n" +
517b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        AppBaseTheme from res/values/styles.xml on API 11+ devices.\n" +
518b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    \n" +
519b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            " API 11 theme customizations can go here. \n" +
520b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "\n" +
521b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        Base application theme for API 14+. This theme completely replaces\n" +
522b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        AppBaseTheme from BOTH res/values/styles.xml and\n" +
523b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        res/values-v11/styles.xml on API 14+ devices.\n" +
524b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    \n" +
525b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            " API 14 theme customizations can go here. \n" +
526b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "         */\n" +
527b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        public static final int AppBaseTheme=0x7f050000;\n" +
528b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        /**  Application theme. \n" +
529b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            " All customizations that are NOT specific to a particular API-level can go here. \n" +
530b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "         */\n" +
531b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "        public static final int AppTheme=0x7f050001;\n" +
532b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "    }\n" +
533b293ca775054871164e9e3c83833a2fd4601387cTor Norbye            "}\n";
534b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
535b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    protected static final Object[] TEST_PROJECT = new Object[] {
536b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        "AndroidManifest.xml",
537b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        SAMPLE_MANIFEST,
538b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
539b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        "src/com/example/refactoringtest/MainActivity.java",
540b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        SAMPLE_MAIN_ACTIVITY,
541b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
54232654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye        "src/com/example/refactoringtest/MainActivity2.java",
54332654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye        SAMPLE_MAIN_ACTIVITY2,
54432654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye
545b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        "gen/com/example/refactoringtest/R.java",
546b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        SAMPLE_R,
547b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
548b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        "res/drawable-xhdpi/ic_launcher.png",
549b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        new byte[] { 0 },
550b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        "res/drawable-hdpi/ic_launcher.png",
551b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        new byte[] { 0 },
552b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        "res/drawable-ldpi/ic_launcher.png",
553b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        new byte[] { 0 },
554b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        "res/drawable-mdpi/ic_launcher.png",
555b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        new byte[] { 0 },
556b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
557b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        "res/layout/activity_main.xml",
558b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        SAMPLE_LAYOUT,
559b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
560b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        "res/layout-land/activity_main.xml",
561b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        SAMPLE_LAYOUT_2,
562b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
563b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        "res/menu/activity_main.xml",
564b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        SAMPLE_MENU,
565b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
566b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        "res/values/strings.xml",   // file 3
567b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        SAMPLE_STRINGS,
568b293ca775054871164e9e3c83833a2fd4601387cTor Norbye
569b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        "res/values/styles.xml",   // file 3
570b293ca775054871164e9e3c83833a2fd4601387cTor Norbye        SAMPLE_STYLES,
571b293ca775054871164e9e3c83833a2fd4601387cTor Norbye    };
57213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
57313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye    // More test data
57413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
57513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye    protected static final String CUSTOM_VIEW_1 =
57613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "package com.example.refactoringtest;\n" +
57713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "\n" +
57813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "import android.content.Context;\n" +
57913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "import android.widget.Button;\n" +
58013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "\n" +
58113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "public class CustomView1 extends Button {\n" +
58213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "    public CustomView1(Context context) {\n" +
58313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "        super(context);\n" +
58413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "    }\n" +
58513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "}\n";
58613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
5878cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye    protected static final String CUSTOM_VIEW_1_STYLES =
5888cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye            "<resources>\n" +
5898cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye            "\n" +
5908cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye            "    <!-- Aattributes for the custom view -->\n" +
5918cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye            "    <declare-styleable name=\"CustomView1\">\n" +
5928cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye            "        <attr name=\"exampleString\" format=\"string\" />\n" +
5938cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye            "        <attr name=\"exampleDimension\" format=\"dimension\" />\n" +
5948cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye            "        <attr name=\"exampleColor\" format=\"color\" />\n" +
5958cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye            "        <attr name=\"exampleDrawable\" format=\"color|reference\" />\n" +
5968cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye            "    </declare-styleable>\n" +
5978cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye            "\n" +
5988cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye            "</resources>";
5998cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye
60013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye    protected static final String CUSTOM_VIEW_2 =
60113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "package com.example.refactoringtest.subpackage;\n" +
60213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "\n" +
60313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "import android.content.Context;\n" +
60413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "import android.widget.Button;\n" +
60513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "\n" +
60613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "public class CustomView2 extends Button {\n" +
60713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "    public CustomView2(Context context) {\n" +
60813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "        super(context);\n" +
60913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "    }\n" +
61013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "}\n";
61113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
61213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye    protected static final String CUSTOM_VIEW_LAYOUT =
61313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
61413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" +
61513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "    xmlns:tools=\"http://schemas.android.com/tools\"\n" +
61613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "    android:layout_width=\"match_parent\"\n" +
61713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "    android:layout_height=\"match_parent\"\n" +
61813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "    android:orientation=\"vertical\"\n" +
61913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "    tools:ignore=\"HardcodedText\" >\n" +
62013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "\n" +
62113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "    <com.example.refactoringtest.CustomView1\n" +
62213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "        android:id=\"@+id/customView1\"\n" +
62313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "        android:layout_width=\"wrap_content\"\n" +
62413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "        android:layout_height=\"wrap_content\"\n" +
62513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "        android:text=\"CustomView1\" />\n" +
62613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "\n" +
62713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "    <com.example.refactoringtest.subpackage.CustomView2\n" +
62813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "        android:id=\"@+id/customView2\"\n" +
62913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "        android:layout_width=\"wrap_content\"\n" +
63013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "        android:layout_height=\"wrap_content\"\n" +
63113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "        android:text=\"CustomView2\" />\n" +
63213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "\n" +
63313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye            "</LinearLayout>";
63413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
63513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye    protected static final Object[] TEST_PROJECT2 = new Object[] {
63613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "AndroidManifest.xml",
63713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        SAMPLE_MANIFEST,
63813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
63913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "src/com/example/refactoringtest/MainActivity.java",
64013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        SAMPLE_MAIN_ACTIVITY,
64113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
64213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "src/com/example/refactoringtest/CustomView1.java",
64313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        CUSTOM_VIEW_1,
64413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
6458cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye        "res/values/attrs_custom_view.xml",
6468cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye        CUSTOM_VIEW_1_STYLES,
6478cf21be14c49245cb4bc967e81d8d7bc798179b7Tor Norbye
64813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "src/com/example/refactoringtest/subpackage/CustomView2.java",
64913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        CUSTOM_VIEW_2,
65013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
65132654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye        "src/com/example/refactoringtest/MyFragment.java",
65232654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye        MY_FRAGMENT,
65332654dfbd134559fbf6bec4542d6a4a8105897c9Tor Norbye
65413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "gen/com/example/refactoringtest/R.java",
65513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        SAMPLE_R,
65613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
65713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "res/drawable-xhdpi/ic_launcher.png",
65813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        new byte[] { 0 },
65913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "res/drawable-hdpi/ic_launcher.png",
66013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        new byte[] { 0 },
66113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "res/drawable-ldpi/ic_launcher.png",
66213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        new byte[] { 0 },
66313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "res/drawable-mdpi/ic_launcher.png",
66413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        new byte[] { 0 },
66513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
66613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "res/layout/activity_main.xml",
66713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        SAMPLE_LAYOUT,
66813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
66913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "res/layout-land/activity_main.xml",
67013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        SAMPLE_LAYOUT_2,
67113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
67213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "res/layout/customviews.xml",
67313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        CUSTOM_VIEW_LAYOUT,
67413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
67513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "res/layout-land/customviews.xml",
67613945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        CUSTOM_VIEW_LAYOUT,
67713945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
67813945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "res/menu/activity_main.xml",
67913945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        SAMPLE_MENU,
68013945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
68113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "res/values/strings.xml",   // file 3
68213945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        SAMPLE_STRINGS,
68313945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye
68413945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        "res/values/styles.xml",   // file 3
68513945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye        SAMPLE_STYLES,
6867e3452665f6672c8a42710b799a1f69e26e3d98dTor Norbye
6877e3452665f6672c8a42710b799a1f69e26e3d98dTor Norbye        // Just a gen file, should not be refactored
6887e3452665f6672c8a42710b799a1f69e26e3d98dTor Norbye        "bin/AndroidManifest.xml",
6897e3452665f6672c8a42710b799a1f69e26e3d98dTor Norbye        SAMPLE_MANIFEST,
6907e3452665f6672c8a42710b799a1f69e26e3d98dTor Norbye
69113945169f077dcd1260fae9c532d9c1e57cb98e3Tor Norbye    };
692be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye
693be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye
694be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye    protected static final String MANIFEST =
695be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "/* AUTO-GENERATED FILE.  DO NOT MODIFY.\n" +
696be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            " *\n" +
697be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            " * This class was automatically generated by the\n" +
698be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            " * aapt tool from the resource data it found.  It\n" +
699be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            " * should not be modified by hand.\n" +
700be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            " */\n" +
701be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "\n" +
702be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "package com.example.refactoringtest;\n" +
703be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "\n" +
704be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "public final class Manifest {\n" +
705be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "    public static final class permission {\n" +
706be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "        public static final String WRITE_SCHEDULE=\"com.example.refactoringtest.permission.WRITE_SCHEDULE\";\n" +
707be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "    }\n" +
708be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "}";
709be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye
710be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye    protected static final String BUILD_CONFIG =
711be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "/** Automatically generated file. DO NOT MODIFY */\n" +
712be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "package com.example.refactoringtest;\n" +
713be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "\n" +
714be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "public final class BuildConfig {\n" +
715be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "    public final static boolean DEBUG = true;\n" +
716be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "}";
717be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye
718be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye    protected static final String MORE_CODE_JAVA =
719be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "package com.example.refactoringtest.subpkg;\n" +
720be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "\n" +
721be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "import android.os.Bundle;\n" +
722be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "import android.app.Activity;\n" +
723be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "import android.view.Menu;\n" +
724be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "import android.view.View;\n" +
725be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "import com.example.refactoringtest.BuildConfig;\n" +
726be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "import com.example.refactoringtest.Manifest;\n" +
727be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "import com.example.refactoringtest.R;\n" +
728be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "\n" +
729be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "public class MoreCode extends Activity {\n" +
730be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "\n" +
731be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "    protected void code() {\n" +
732be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "        if (BuildConfig.DEBUG) {\n" +
733be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "            System.out.println(Manifest.permission);\n" +
734be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "        }" +
735be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "        System.out.println(com.example.refactoringtest.BuildConfig.DEBUG);\n" +
736be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "    }\n" +
737be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "\n" +
738be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye            "}\n";
739be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye
740be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye    /** Project which includes references to BuildConfig, Manifest, and R */
741be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye    protected static final Object[] TEST_PROJECT3;
742be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye    static {
743be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye        Object[] additional = new Object[] {
744be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye                "src/com/example/refactoringtest/subpkg/MoreCode.java",
745be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye                MORE_CODE_JAVA,
746be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye
747be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye                "gen/com/example/refactoringtest/BuildConfig.java",
748be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye                BUILD_CONFIG,
749be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye
750be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye                "gen/com/example/refactoringtest/Manifest.java",
751be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye                MANIFEST,
752be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye        };
753be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye        TEST_PROJECT3 = new Object[TEST_PROJECT2.length + additional.length];
754be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye        System.arraycopy(TEST_PROJECT2, 0, TEST_PROJECT3, 0, TEST_PROJECT2.length);
755be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye        System.arraycopy(additional, 0, TEST_PROJECT3, TEST_PROJECT2.length, additional.length);
756be33998c0a03941ae968675128dacace85ac1fd1Tor Norbye    };
757b293ca775054871164e9e3c83833a2fd4601387cTor Norbye}
758