Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(682)

Side by Side Diff: dart/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/cleanup/migration/Migrate_1M1_library_CleanUp.java

Issue 11233061: Revert "Parts must start with 'part of'" and "Attempt to fix VM build" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012, the Dart project authors. 2 * Copyright (c) 2012, the Dart project authors.
3 * 3 *
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except
5 * in compliance with the License. You may obtain a copy of the License at 5 * in compliance with the License. You may obtain a copy of the License at
6 * 6 *
7 * http://www.eclipse.org/legal/epl-v10.html 7 * http://www.eclipse.org/legal/epl-v10.html
8 * 8 *
9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License 9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express
(...skipping 10 matching lines...) Expand all
21 import com.google.dart.compiler.util.apache.StringUtils; 21 import com.google.dart.compiler.util.apache.StringUtils;
22 import com.google.dart.tools.core.model.DartLibrary; 22 import com.google.dart.tools.core.model.DartLibrary;
23 import com.google.dart.tools.core.utilities.general.SourceRangeFactory; 23 import com.google.dart.tools.core.utilities.general.SourceRangeFactory;
24 24
25 /** 25 /**
26 * In specification 1.0 M1 new library/import/source syntax is defined. 26 * In specification 1.0 M1 new library/import/source syntax is defined.
27 * 27 *
28 * @coverage dart.editor.ui.cleanup 28 * @coverage dart.editor.ui.cleanup
29 */ 29 */
30 public class Migrate_1M1_library_CleanUp extends AbstractMigrateCleanUp { 30 public class Migrate_1M1_library_CleanUp extends AbstractMigrateCleanUp {
31 private static String mapLibraryName(String name) {
32 name = StringUtils.removeEnd(name, ".dart");
33 name = StringUtils.replace(name, ".", "_");
34 name = StringUtils.replace(name, ":", "_");
35 name = StringUtils.replace(name, "-", "_");
36 name = StringUtils.removeEnd(name, ".dart");
37 return name;
38 }
39
40 @Override 31 @Override
41 protected void createFix() throws Exception { 32 protected void createFix() throws Exception {
42 ensurePartOfDirective(); 33 ensurePartOfDirective();
43 unitNode.accept(new ASTVisitor<Void>() { 34 unitNode.accept(new ASTVisitor<Void>() {
44 @Override 35 @Override
45 @SuppressWarnings("deprecation") 36 @SuppressWarnings("deprecation")
46 public Void visitImportDirective(DartImportDirective node) { 37 public Void visitImportDirective(DartImportDirective node) {
47 if (node.isObsoleteFormat()) { 38 if (node.isObsoleteFormat()) {
48 DartStringLiteral uriNode = node.getLibraryUri(); 39 DartStringLiteral uriNode = node.getLibraryUri();
49 String uriSource = utils.getText(uriNode); 40 String uriSource = utils.getText(uriNode);
50 String source = "import " + uriSource; 41 String source = "import " + uriSource;
51 if (node.getOldPrefix() != null) { 42 if (node.getOldPrefix() != null) {
52 source += " as " + node.getOldPrefix().getValue(); 43 source += " as " + node.getOldPrefix().getValue();
53 } 44 }
54 source += ";"; 45 source += ";";
55 addReplaceEdit(SourceRangeFactory.create(node), source); 46 addReplaceEdit(SourceRangeFactory.create(node), source);
56 } 47 }
57 return super.visitImportDirective(node); 48 return super.visitImportDirective(node);
58 } 49 }
59 50
60 @Override 51 @Override
61 public Void visitLibraryDirective(DartLibraryDirective node) { 52 public Void visitLibraryDirective(DartLibraryDirective node) {
62 if (node.isObsoleteFormat()) { 53 if (node.isObsoleteFormat()) {
63 String name = node.getLibraryName(); 54 String name = node.getLibraryName();
64 name = mapLibraryName(name); 55 name = StringUtils.removeEnd(name, ".dart");
56 name = StringUtils.replace(name, ".", "_");
65 addReplaceEdit(SourceRangeFactory.create(node), "library " + name + "; "); 57 addReplaceEdit(SourceRangeFactory.create(node), "library " + name + "; ");
66 } 58 }
67 return super.visitLibraryDirective(node); 59 return super.visitLibraryDirective(node);
68 } 60 }
69 61
70 @Override 62 @Override
71 public Void visitSourceDirective(DartSourceDirective node) { 63 public Void visitSourceDirective(DartSourceDirective node) {
72 if (utils.getText(node).startsWith("#source")) { 64 if (utils.getText(node).startsWith("#source")) {
73 DartStringLiteral uriNode = node.getSourceUri(); 65 DartStringLiteral uriNode = node.getSourceUri();
74 String uriSource = utils.getText(uriNode); 66 String uriSource = utils.getText(uriNode);
75 addReplaceEdit(SourceRangeFactory.create(node), "part " + uriSource + ";"); 67 addReplaceEdit(SourceRangeFactory.create(node), "part " + uriSource + ";");
76 } 68 }
77 return super.visitSourceDirective(node); 69 return super.visitSourceDirective(node);
78 } 70 }
79
80 }); 71 });
81 } 72 }
82 73
83 private void ensurePartOfDirective() throws Exception { 74 private void ensurePartOfDirective() throws Exception {
84 // "part" should not have directives 75 // "part" should not have directives
85 if (!unitNode.getDirectives().isEmpty()) { 76 if (!unitNode.getDirectives().isEmpty()) {
86 return; 77 return;
87 } 78 }
88 // do insert 79 // do insert
89 DartLibrary library = unit.getLibrary(); 80 DartLibrary library = unit.getLibrary();
90 if (library != null) { 81 if (library != null) {
91 String libraryName = library.getLibraryDirectiveName(); 82 String libraryName = library.getLibraryDirectiveName();
92 if (libraryName != null) { 83 if (libraryName != null) {
93 String eol = utils.getEndOfLine(); 84 String eol = utils.getEndOfLine();
94 String source = "part of " + mapLibraryName(libraryName) + ";" + eol + e ol; 85 String source = "part of " + libraryName + ";" + eol + eol;
95 addReplaceEdit(SourceRangeFactory.forStartLength(0, 0), source); 86 addReplaceEdit(SourceRangeFactory.forStartLength(0, 0), source);
96 } 87 }
97 } 88 }
98 } 89 }
99 } 90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698