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

Side by Side Diff: pkg/analysis_server/lib/src/services/kythe/kythe_visitors.dart

Issue 3004273002: Dart Kythe indexer refactoring to gather all variable declaration logic into one method (Closed)
Patch Set: Created 3 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:convert'; 5 import 'dart:convert';
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
9 import 'package:analyzer/dart/ast/syntactic_entity.dart'; 9 import 'package:analyzer/dart/ast/syntactic_entity.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 _safelyVisit(node.documentationComment); 424 _safelyVisit(node.documentationComment);
425 _safelyVisitList(node.metadata); 425 _safelyVisitList(node.metadata);
426 _safelyVisit(node.parameters); 426 _safelyVisit(node.parameters);
427 _safelyVisitList(node.initializers); 427 _safelyVisitList(node.initializers);
428 _safelyVisit(node.body); 428 _safelyVisit(node.body);
429 }); 429 });
430 } 430 }
431 431
432 @override 432 @override
433 visitDeclaredIdentifier(DeclaredIdentifier node) { 433 visitDeclaredIdentifier(DeclaredIdentifier node) {
434 // variable 434 _handleVariableDeclaration(node.element, node.identifier,
435 var variableVName = addNodeAndFacts(schema.VARIABLE_KIND,
436 element: node.element,
437 subKind: schema.LOCAL_SUBKIND, 435 subKind: schema.LOCAL_SUBKIND,
438 completeFact: schema.DEFINITION); 436 type: resolutionMap.elementDeclaredByDeclaredIdentifier(node).type);
439
440 // anchor
441 addAnchorEdgesContainingEdge(
442 syntacticEntity: node.identifier,
443 edges: [
444 schema.DEFINES_BINDING_EDGE,
445 ],
446 target: variableVName,
447 enclosingTarget: _enclosingVName);
448
449 // type
450 addEdge(
451 variableVName,
452 schema.TYPED_EDGE,
453 _vNameFromType(
454 resolutionMap.elementDeclaredByDeclaredIdentifier(node).type));
455 437
456 // no children 438 // no children
457 } 439 }
458 440
459 @override 441 @override
460 visitEnumConstantDeclaration(EnumConstantDeclaration node) { 442 visitEnumConstantDeclaration(EnumConstantDeclaration node) {
461 // constant node 443 // constant node
462 var constDeclVName = 444 var constDeclVName =
463 addNodeAndFacts(schema.CONSTANT_KIND, element: node.element); 445 addNodeAndFacts(schema.CONSTANT_KIND, element: node.element);
464 446
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 @override 594 @override
613 visitImportDirective(ImportDirective node) { 595 visitImportDirective(ImportDirective node) {
614 // uri 596 // uri
615 _handleUriReference(node.uri, node.uriElement); 597 _handleUriReference(node.uri, node.uriElement);
616 598
617 // prefix 599 // prefix
618 var prefixIdentifier = node.prefix; 600 var prefixIdentifier = node.prefix;
619 601
620 if (prefixIdentifier != null) { 602 if (prefixIdentifier != null) {
621 // variable 603 // variable
622 var variableVName = addNodeAndFacts(schema.VARIABLE_KIND, 604 _handleVariableDeclaration(
623 element: prefixIdentifier.staticElement, 605 prefixIdentifier.staticElement, prefixIdentifier);
624 completeFact: schema.DEFINITION);
625
626 // anchor
627 addAnchorEdgesContainingEdge(
628 syntacticEntity: prefixIdentifier,
629 edges: [schema.DEFINES_BINDING_EDGE],
630 target: variableVName,
631 enclosingTarget: _enclosingVName);
632 } 606 }
633 607
634 // visit children 608 // visit children
635 _safelyVisit(node.documentationComment); 609 _safelyVisit(node.documentationComment);
636 _safelyVisitList(node.metadata); 610 _safelyVisitList(node.metadata);
637 _safelyVisitList(node.combinators); 611 _safelyVisitList(node.combinators);
638 _safelyVisitList(node.configurations); 612 _safelyVisitList(node.configurations);
639 _safelyVisit(node.uri); 613 _safelyVisit(node.uri);
640 } 614 }
641 615
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 @override 832 @override
859 visitUriBasedDirective(UriBasedDirective node) { 833 visitUriBasedDirective(UriBasedDirective node) {
860 _handleUriReference(node.uri, node.uriElement); 834 _handleUriReference(node.uri, node.uriElement);
861 835
862 // visit children 836 // visit children
863 super.visitUriBasedDirective(node); 837 super.visitUriBasedDirective(node);
864 } 838 }
865 839
866 @override 840 @override
867 visitVariableDeclaration(VariableDeclaration node) { 841 visitVariableDeclaration(VariableDeclaration node) {
868 // level variable
869 var isLocal = _enclosingVName != _enclosingClassVName && 842 var isLocal = _enclosingVName != _enclosingClassVName &&
870 _enclosingVName != _enclosingFileVName; 843 _enclosingVName != _enclosingFileVName;
871 844
872 // variable 845 // variable
873 var variableVName = addNodeAndFacts(schema.VARIABLE_KIND, 846 _handleVariableDeclaration(node.element, node.name,
874 element: node.element,
875 subKind: isLocal ? schema.LOCAL_SUBKIND : schema.FIELD_SUBKIND, 847 subKind: isLocal ? schema.LOCAL_SUBKIND : schema.FIELD_SUBKIND,
876 completeFact: schema.DEFINITION); 848 type: resolutionMap.elementDeclaredByVariableDeclaration(node).type);
877
878 // anchor
879 addAnchorEdgesContainingEdge(
880 syntacticEntity: node.name,
881 edges: [
882 schema.DEFINES_BINDING_EDGE,
883 ],
884 target: variableVName,
885 enclosingTarget: _enclosingVName);
886
887 // type
888 addEdge(
889 variableVName,
890 schema.TYPED_EDGE,
891 _vNameFromType(
892 resolutionMap.elementDeclaredByVariableDeclaration(node).type));
893 849
894 // visit children 850 // visit children
895 _safelyVisit(node.initializer); 851 _safelyVisit(node.initializer);
896 } 852 }
897 853
898 Element _findNonSyntheticElement(Element element) { 854 Element _findNonSyntheticElement(Element element) {
899 if (element == null || !element.isSynthetic) { 855 if (element == null || !element.isSynthetic) {
900 return element; 856 return element;
901 } 857 }
902 if (element is PropertyAccessorElement) { 858 if (element is PropertyAccessorElement) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 edges: [schema.REF_EDGE], 980 edges: [schema.REF_EDGE],
1025 target: vName); 981 target: vName);
1026 982
1027 // childof from the anchor 983 // childof from the anchor
1028 addEdge(anchorVName, schema.CHILD_OF_EDGE, _enclosingVName); 984 addEdge(anchorVName, schema.CHILD_OF_EDGE, _enclosingVName);
1029 } 985 }
1030 986
1031 // no children to visit 987 // no children to visit
1032 } 988 }
1033 989
990 void _handleVariableDeclaration(
991 Element element, SyntacticEntity syntacticEntity,
992 {String subKind, DartType type}) {
993 // variable
994 var variableVName = addNodeAndFacts(schema.VARIABLE_KIND,
995 element: element, subKind: subKind, completeFact: schema.DEFINITION);
996
997 // anchor
998 addAnchorEdgesContainingEdge(
999 syntacticEntity: syntacticEntity,
1000 edges: [
1001 schema.DEFINES_BINDING_EDGE,
1002 ],
1003 target: variableVName,
1004 enclosingTarget: _enclosingVName);
1005
1006 // type
1007 if (type != null) {
1008 addEdge(variableVName, schema.TYPED_EDGE, _vNameFromType(type));
1009 }
1010 }
1011
1034 /// Add a "ref/imports" edge from the passed [uriNode] location to the 1012 /// Add a "ref/imports" edge from the passed [uriNode] location to the
1035 /// [referencedElement] [Element]. If the passed element is null, the edge is 1013 /// [referencedElement] [Element]. If the passed element is null, the edge is
1036 /// not written out. 1014 /// not written out.
1037 void _handleUriReference(StringLiteral uriNode, Element referencedElement) { 1015 void _handleUriReference(StringLiteral uriNode, Element referencedElement) {
1038 if (referencedElement != null) { 1016 if (referencedElement != null) {
1039 var start = uriNode.offset; 1017 var start = uriNode.offset;
1040 var end = uriNode.end; 1018 var end = uriNode.end;
1041 1019
1042 // The following is the expected and common case. 1020 // The following is the expected and common case.
1043 // The contents between the quotes is used as the location to work well 1021 // The contents between the quotes is used as the location to work well
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 } 1393 }
1416 1394
1417 @override 1395 @override
1418 StringBuffer visitTypeParameterElement(TypeParameterElement e) { 1396 StringBuffer visitTypeParameterElement(TypeParameterElement e) {
1419 // It is legal to have a named constructor with the same name as a type 1397 // It is legal to have a named constructor with the same name as a type
1420 // parameter. So we distinguish them by using '.' between the class (or 1398 // parameter. So we distinguish them by using '.' between the class (or
1421 // typedef) name and the type parameter name. 1399 // typedef) name and the type parameter name.
1422 return e.enclosingElement.accept(this)..write('.')..write(e.name); 1400 return e.enclosingElement.accept(this)..write('.')..write(e.name);
1423 } 1401 }
1424 } 1402 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698