Skip to content
This repository was archived by the owner on Jun 20, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions analyzer_plugin/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ linter:
- always_require_non_null_named_parameters
- annotate_overrides
- avoid_annotating_with_dynamic
- avoid_catches_without_on_clauses
- avoid_catching_errors
- avoid_classes_with_only_static_members
- avoid_empty_else
- avoid_init_to_null
- avoid_null_checks_in_equality_operators
- avoid_positional_boolean_parameters
- avoid_return_types_on_setters
- avoid_returning_this
- avoid_setters_without_getters
- avoid_slow_async_io
- avoid_types_on_closure_parameters
Expand Down
5 changes: 3 additions & 2 deletions analyzer_plugin/lib/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:angular_analyzer_plugin/src/model.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:meta/meta.dart';

enum ExpressionBoundType { input, twoWay, attr, clazz, style }

Expand Down Expand Up @@ -341,10 +342,10 @@ class ElementInfo extends NodeInfo implements HasDirectives {
this.closingSpan,
this.openingNameSpan,
this.closingNameSpan,
this.isTemplate,
this.attributes,
this.templateAttribute,
this.parent) {
this.parent,
{@required this.isTemplate}) {
if (!isSynthetic) {
childNodesMaxEnd = offset + length;
}
Expand Down
16 changes: 12 additions & 4 deletions analyzer_plugin/lib/src/angular_driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:analysis_server/plugin/protocol/protocol_dart.dart' as protocol;
import 'package:analysis_server/src/protocol_server.dart' as protocol;
import 'package:analyzer/error/error.dart';
import 'package:analyzer/src/dart/analysis/driver.dart';
import 'package:analyzer/src/summary/api_signature.dart';
import 'package:front_end/src/base/api_signature.dart';
import 'package:angular_analyzer_plugin/tasks.dart';
import 'package:angular_analyzer_plugin/src/file_tracker.dart';
import 'package:angular_analyzer_plugin/src/from_file_prefixed_error.dart';
Expand Down Expand Up @@ -86,6 +86,8 @@ class AngularDriver
// TODO analyze these files first
}

List<String> get priorityFiles => [];

/// Notify the driver that the client is going to stop using it.
@override
void dispose() {
Expand Down Expand Up @@ -416,7 +418,9 @@ class AngularDriver
final unit = (await dartDriver.getUnitElement(dartPath)).element;
final htmlSource = _sourceFactory.forUri('file:$htmlPath');

if (unit == null) return null;
if (unit == null) {
return null;
}
final context = unit.context;
final dartSource = _sourceFactory.forUri('file:$dartPath');
final htmlContent = getFileContent(htmlPath);
Expand Down Expand Up @@ -534,7 +538,9 @@ class AngularDriver

Future pushDartErrors(String path) async {
final result = await resolveDart(path);
if (result == null) return;
if (result == null) {
return;
}
final errors = result.errors;
final lineInfo = new LineInfo.fromContent(getFileContent(path));
final serverErrors = protocol.doAnalysisError_listFromEngine(
Expand Down Expand Up @@ -585,7 +591,9 @@ class AngularDriver
final result = await getDirectives(path);
final directives = result.directives;
final unit = (await dartDriver.getUnitElement(path)).element;
if (unit == null) return null;
if (unit == null) {
return null;
}
final context = unit.context;
final source = unit.source;

Expand Down
31 changes: 19 additions & 12 deletions analyzer_plugin/lib/src/converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:angular_analyzer_plugin/src/strings.dart';
import 'package:angular_analyzer_plugin/tasks.dart';
import 'package:html/dom.dart' as html;
import 'package:html/parser.dart' as html;
import 'package:meta/meta.dart';
import 'package:source_span/source_span.dart';

html.Element firstElement(html.Node node) {
Expand Down Expand Up @@ -52,10 +53,10 @@ class HtmlTreeConverter {
closingSpan,
openingNameSpan,
closingNameSpan,
isTemplate,
attributes,
findTemplateAttribute(attributes),
parent);
parent,
isTemplate: isTemplate);

for (final attribute in attributes) {
attribute.parent = element;
Expand Down Expand Up @@ -132,7 +133,7 @@ class HtmlTreeConverter {
valueOffset,
dartParser.findMustaches(value, valueOffset)));
}
} on IgnorableHtmlInternalError {
} on IgnorableHtmlInternalException {
// See https://github.com/dart-lang/html/issues/44, this error will
// be thrown looking for nameOffset. Catch it so that analysis else
// where continues.
Expand Down Expand Up @@ -235,13 +236,14 @@ class HtmlTreeConverter {
valueOffset,
origName,
origNameOffset,
dartParser.parseDartExpression(valueOffset, value, true),
dartParser.parseDartExpression(valueOffset, value,
detectTrailing: true),
bound);
}

List<NodeInfo> _convertChildren(html.Element node, ElementInfo parent) {
final children = <NodeInfo>[];
for (html.Node child in node.nodes) {
for (final child in node.nodes) {
final childNode = convert(child, parent: parent);
if (childNode != null) {
children.add(childNode);
Expand Down Expand Up @@ -285,7 +287,7 @@ class HtmlTreeConverter {
AttributeSpanContainer.generateAttributeSpans(element);
return container.attributeSpans[name].start.offset;
} catch (e) {
throw new IgnorableHtmlInternalError(e);
throw new IgnorableHtmlInternalException(e);
}
}
}
Expand All @@ -304,7 +306,7 @@ class HtmlTreeConverter {
: null;
}
} catch (e) {
throw new IgnorableHtmlInternalError(e);
throw new IgnorableHtmlInternalException(e);
}
}

Expand All @@ -325,7 +327,8 @@ class EmbeddedDartParser {
this.templateSource, this.errorListener, this.errorReporter);

/// Parse the given Dart [code] that starts at [offset].
Expression parseDartExpression(int offset, String code, bool detectTrailing) {
Expression parseDartExpression(int offset, String code,
{@required bool detectTrailing}) {
if (code == null) {
return null;
}
Expand Down Expand Up @@ -471,8 +474,8 @@ class EmbeddedDartParser {
}
// resolve
final code = text.substring(exprBegin, exprEnd);
final expression =
parseDartExpression(fileOffset + exprBegin, code, detectTrailing);
final expression = parseDartExpression(fileOffset + exprBegin, code,
detectTrailing: detectTrailing);

final offset = fileOffset + begin;

Expand Down Expand Up @@ -638,6 +641,10 @@ class EmbeddedDartParser {
_tokenMatchesBuiltInIdentifier(token);
}

class IgnorableHtmlInternalError extends StateError {
IgnorableHtmlInternalError(String msg) : super(msg);
class IgnorableHtmlInternalException implements Exception {
String msg;
IgnorableHtmlInternalException(this.msg);

@override
String toString() => "IgnorableHtmlInternalException: $msg";
}
9 changes: 3 additions & 6 deletions analyzer_plugin/lib/src/directive_extraction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,9 @@ class DirectiveExtractor extends AnnotationProcessorMixin {
final isComponent = isAngularAnnotation(node, 'Component');
final isDirective = isAngularAnnotation(node, 'Directive');
if (isComponent || isDirective) {
var selector = _parseSelector(node);
if (selector == null) {
// empty selector. Don't fail to create a Component just because of a
// broken or missing selector, that results in cascading errors.
selector = new AndSelector([]);
}
// Don't fail to create a Component just because of a broken or missing
// selector, that results in cascading errors.
final selector = _parseSelector(node) ?? new AndSelector([]);
final exportAs = _parseExportAs(node);
final inputElements = <InputElement>[];
final outputElements = <OutputElement>[];
Expand Down
8 changes: 6 additions & 2 deletions analyzer_plugin/lib/src/directive_linking.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class DirectiveLinker {
// is this correct lookup?
final setter =
classElem.lookUpSetter(inputSum.propName, classElem.library);
if (setter == null) continue;
if (setter == null) {
continue;
}
inputs.add(new InputElement(
inputSum.name,
inputSum.nameOffset,
Expand All @@ -85,7 +87,9 @@ class DirectiveLinker {
// is this correct lookup?
final getter =
classElem.lookUpGetter(outputSum.propName, classElem.library);
if (getter == null) continue;
if (getter == null) {
continue;
}
outputs.add(new OutputElement(
outputSum.name,
outputSum.nameOffset,
Expand Down
3 changes: 2 additions & 1 deletion analyzer_plugin/lib/src/file_tracker.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:collection';

import 'package:analyzer/src/summary/api_signature.dart';
import 'package:front_end/src/base/api_signature.dart';

abstract class FileHasher {
ApiSignature getContentHash(String path);
Expand Down Expand Up @@ -33,6 +33,7 @@ class FileTracker {
void setDartHtmlTemplates(String dartPath, List<String> htmlPaths) =>
_dartToHtml.setFileReferencesFiles(dartPath, htmlPaths);

// ignore: avoid_positional_boolean_parameters
void setDartHasTemplate(String dartPath, bool hasTemplate) {
if (hasTemplate) {
_dartFilesWithDartTemplates.add(dartPath);
Expand Down
2 changes: 1 addition & 1 deletion analyzer_plugin/lib/src/ng_expr_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NgExprParser extends Parser {
Token beforePipeToken;
expression = parseBitwiseXorExpression();
while (_currentToken.type == TokenType.BAR) {
if (beforePipeToken == null) beforePipeToken = _currentToken.previous;
beforePipeToken ??= _currentToken.previous;
getAndAdvance();
parsePipeExpression();
}
Expand Down
53 changes: 22 additions & 31 deletions analyzer_plugin/lib/src/resolver.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
library angular2.src.analysis.analyzer_plugin.src.resolver;

import 'dart:collection';
import 'package:meta/meta.dart';

import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
Expand Down Expand Up @@ -198,10 +199,8 @@ class _DartReferencesRecorder extends RecursiveAstVisitor {
void visitSimpleIdentifier(SimpleIdentifier node) {
final dartElement = node.bestElement;
if (dartElement != null) {
var angularElement = dartToAngularMap[dartElement];
if (angularElement == null) {
angularElement = new DartElement(dartElement);
}
final angularElement =
dartToAngularMap[dartElement] ?? new DartElement(dartElement);
final range = new SourceRange(node.offset, node.length);
template.addRange(range, angularElement);
}
Expand Down Expand Up @@ -472,10 +471,7 @@ class PrepareScopeVisitor extends AngularScopeVisitor {
offset += prefixLen;

// prepare internal variable name
var internalName = attribute.value;
if (internalName == null) {
internalName = r'$implicit';
}
final internalName = attribute.value ?? r'$implicit';

// maybe an internal variable reference
DartType type;
Expand All @@ -498,9 +494,7 @@ class PrepareScopeVisitor extends AngularScopeVisitor {
}

// any unmatched values should be dynamic to prevent secondary errors
if (type == null) {
type = typeProvider.dynamicType;
}
type ??= typeProvider.dynamicType;

// add a new local variable with type
final localVariableElement =
Expand Down Expand Up @@ -553,8 +547,8 @@ class DartVariableManager {
// ensure artificial Dart elements in the template source
if (htmlMethodElement == null) {
htmlCompilationUnitElement =
new CompilationUnitElementImpl(templateSource.fullName);
htmlCompilationUnitElement.source = templateSource;
new CompilationUnitElementImpl(templateSource.fullName)
..source = templateSource;
htmlClassElement = new ClassElementImpl('AngularTemplateClass', -1);
htmlCompilationUnitElement.types = <ClassElement>[htmlClassElement];
htmlMethodElement = new MethodElementImpl('angularTemplateMethod', -1);
Expand Down Expand Up @@ -842,8 +836,8 @@ class ComponentContentResolver extends AngularAstVisitor {
}

if (!tagIsStandard) {
checkTransclusionsContentChildren(
component, element.childNodes, tagIsStandard);
checkTransclusionsContentChildren(component, element.childNodes,
tagIsStandard: tagIsStandard);
}

for (final child in element.childNodes) {
Expand All @@ -852,7 +846,8 @@ class ComponentContentResolver extends AngularAstVisitor {
}

void checkTransclusionsContentChildren(
Component component, List<NodeInfo> children, bool tagIsStandard) {
Component component, List<NodeInfo> children,
{@required bool tagIsStandard}) {
if (component?.ngContents == null) {
return;
}
Expand Down Expand Up @@ -1346,7 +1341,8 @@ class SingleScopeResolver extends AngularScopeVisitor {
astNode.accept(visitor);
}
final resolver = new AngularResolverVisitor(
library, templateSource, typeProvider, errorListener, acceptAssignment);
library, templateSource, typeProvider, errorListener,
acceptAssignment: acceptAssignment);
// fill the name scope
final classScope = new ClassScope(resolver.nameScope, classElement);
final localScope = new EnclosedScope(classScope);
Expand All @@ -1358,8 +1354,9 @@ class SingleScopeResolver extends AngularScopeVisitor {
// do resolve
astNode.accept(resolver);
// verify
final verifier = new AngularErrorVerifier(errorReporter, library,
typeProvider, new InheritanceManager(library), acceptAssignment);
final verifier = new AngularErrorVerifier(
errorReporter, library, typeProvider, new InheritanceManager(library),
acceptAssignment: acceptAssignment);
astNode.accept(verifier);
}

Expand Down Expand Up @@ -1431,12 +1428,9 @@ class AngularResolverVisitor extends _IntermediateResolverVisitor
with ReportUnacceptableNodesMixin {
final bool acceptAssignment;

AngularResolverVisitor(
LibraryElement library,
Source source,
TypeProvider typeProvider,
AnalysisErrorListener errorListener,
this.acceptAssignment)
AngularResolverVisitor(LibraryElement library, Source source,
TypeProvider typeProvider, AnalysisErrorListener errorListener,
{@required this.acceptAssignment})
: super(library, source, typeProvider, errorListener);

@override
Expand Down Expand Up @@ -1514,12 +1508,9 @@ class AngularErrorVerifier extends ErrorVerifier
@override
TypeProvider typeProvider;

AngularErrorVerifier(
ErrorReporter errorReporter,
LibraryElement library,
TypeProvider typeProvider,
InheritanceManager inheritanceManager,
this.acceptAssignment)
AngularErrorVerifier(ErrorReporter errorReporter, LibraryElement library,
TypeProvider typeProvider, InheritanceManager inheritanceManager,
{@required this.acceptAssignment})
: errorReporter = errorReporter,
typeProvider = typeProvider,
super(errorReporter, library, typeProvider, inheritanceManager, false);
Expand Down
Loading