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

Side by Side Diff: pkg/analysis_server/lib/src/computer/element.dart

Issue 628023003: Move Engine to Server element / error converters into protocol_server.dart (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library computer.element;
6
7 import 'package:analysis_server/src/protocol_server.dart';
8 import 'package:analyzer/src/generated/element.dart' as engine;
9 import 'package:analyzer/src/generated/utilities_dart.dart' as engine;
10
11
12 Element elementFromEngine(engine.Element element) {
13 String name = element.displayName;
14 String elementParameters = _getParametersString(element);
15 String elementReturnType = _getReturnTypeString(element);
16 return new Element(
17 newElementKind_fromEngine(element.kind),
18 name,
19 Element.makeFlags(
20 isPrivate: element.isPrivate,
21 isDeprecated: element.isDeprecated,
22 isAbstract: _isAbstract(element),
23 isConst: _isConst(element),
24 isFinal: _isFinal(element),
25 isStatic: _isStatic(element)),
26 location: newLocation_fromElement(element),
27 parameters: elementParameters,
28 returnType: elementReturnType);
29 }
30
31 String _getParametersString(engine.Element element) {
32 // TODO(scheglov) expose the corresponding feature from ExecutableElement
33 if (element is engine.ExecutableElement) {
34 var sb = new StringBuffer();
35 String closeOptionalString = '';
36 for (var parameter in element.parameters) {
37 if (sb.isNotEmpty) {
38 sb.write(', ');
39 }
40 if (closeOptionalString.isEmpty) {
41 if (parameter.kind == engine.ParameterKind.NAMED) {
42 sb.write('{');
43 closeOptionalString = '}';
44 }
45 if (parameter.kind == engine.ParameterKind.POSITIONAL) {
46 sb.write('[');
47 closeOptionalString = ']';
48 }
49 }
50 sb.write(parameter.toString());
51 }
52 sb.write(closeOptionalString);
53 return '(' + sb.toString() + ')';
54 } else {
55 return null;
56 }
57 }
58
59 String _getReturnTypeString(engine.Element element) {
60 if (element is engine.ExecutableElement) {
61 if (element.kind == engine.ElementKind.SETTER) {
62 return null;
63 } else {
64 return element.returnType.toString();
65 }
66 } else {
67 return null;
68 }
69 }
70
71 bool _isAbstract(engine.Element element) {
72 // TODO(scheglov) add isAbstract to Element API
73 if (element is engine.ClassElement) {
74 return element.isAbstract;
75 }
76 if (element is engine.MethodElement) {
77 return element.isAbstract;
78 }
79 if (element is engine.PropertyAccessorElement) {
80 return element.isAbstract;
81 }
82 return false;
83 }
84
85 bool _isConst(engine.Element element) {
86 // TODO(scheglov) add isConst to Element API
87 if (element is engine.ConstructorElement) {
88 return element.isConst;
89 }
90 if (element is engine.VariableElement) {
91 return element.isConst;
92 }
93 return false;
94 }
95
96 bool _isFinal(engine.Element element) {
97 // TODO(scheglov) add isFinal to Element API
98 if (element is engine.VariableElement) {
99 return element.isFinal;
100 }
101 return false;
102 }
103
104 bool _isStatic(engine.Element element) {
105 // TODO(scheglov) add isStatic to Element API
106 if (element is engine.ExecutableElement) {
107 return element.isStatic;
108 }
109 if (element is engine.PropertyInducingElement) {
110 return element.isStatic;
111 }
112 return false;
113 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/protocol_server.dart » ('j') | pkg/analysis_server/lib/src/protocol_server.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698