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

Unified Diff: pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Issue 1161333002: Issue 23239. Fix for 'Create Class' Quick Fix i case of prefixed names. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/correction/fix_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/correction/fix_internal.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
index bd00f6cd170da38a4895c3829a5d0b65783166c1..783e4e90773e1dc1d6d73e9648f05a3d99a52f92 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -372,39 +372,79 @@ class FixProcessor {
}
void _addFix_createClass() {
- if (!_mayBeTypeIdentifier(node)) {
+ Element prefixElement = null;
+ String name = null;
+ if (node is SimpleIdentifier) {
+ AstNode parent = node.parent;
+ if (parent is PrefixedIdentifier) {
+ PrefixedIdentifier prefixedIdentifier = parent;
+ prefixElement = prefixedIdentifier.prefix.staticElement;
+ parent = prefixedIdentifier.parent;
+ name = prefixedIdentifier.identifier.name;
+ } else {
+ name = (node as SimpleIdentifier).name;
+ }
+ if (parent is! TypeName) {
+ return;
+ }
+ } else {
return;
}
- String name = (node as SimpleIdentifier).name;
// prepare environment
- CompilationUnitMember enclosingMember =
- node.getAncestor((node) => node.parent is CompilationUnit);
- if (enclosingMember == null) {
- return;
- }
- int offset = enclosingMember.end;
+ Element targetUnit;
+ SourceBuilder sb;
String prefix = '';
+ String suffix = '';
+ if (prefixElement == null) {
+ targetUnit = unitElement;
+ CompilationUnitMember enclosingMember =
+ node.getAncestor((node) => node.parent is CompilationUnit);
+ if (enclosingMember == null) {
+ return;
+ }
+ int offset = enclosingMember.end;
+ sb = new SourceBuilder(file, offset);
+ prefix = '$eol$eol';
+ } else {
+ for (ImportElement import in unitLibraryElement.imports) {
+ if (prefixElement is PrefixElement && import.prefix == prefixElement) {
+ targetUnit = import.importedLibrary.definingCompilationUnit;
+ Source targetSource = targetUnit.source;
+ int offset = targetSource.contents.data.length;
+ sb = new SourceBuilder(targetSource.fullName, offset);
+ prefix = '$eol';
+ suffix = '$eol';
+ break;
+ }
+ }
+ if (sb == null) {
+ return;
+ }
+ }
// prepare source
- SourceBuilder sb = new SourceBuilder(file, offset);
{
- sb.append('$eol$eol');
sb.append(prefix);
// "class"
sb.append('class ');
// append name
- {
+ if (prefixElement == null) {
sb.startPosition('NAME');
sb.append(name);
sb.endPosition();
+ } else {
+ sb.append(name);
}
// no members
sb.append(' {');
sb.append(eol);
sb.append('}');
+ sb.append(suffix);
}
// insert source
- _insertBuilder(sb, unitElement);
- _addLinkedPosition('NAME', sb, rf.rangeNode(node));
+ _insertBuilder(sb, targetUnit);
+ if (prefixElement == null) {
+ _addLinkedPosition('NAME', sb, rf.rangeNode(node));
+ }
// add proposal
_addFix(DartFixKind.CREATE_CLASS, [name]);
}
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/correction/fix_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698