Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
11a54dee
Commit
11a54dee
authored
May 06, 2016
by
Phil Quitslund
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3752 from pq/analysis_rework
Analysis re-work to use analyzer APIs.
parents
4d9fdda7
2df43d50
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
366 additions
and
294 deletions
+366
-294
pubspec.yaml
packages/flutter_test/pubspec.yaml
+3
-3
analyze.dart
packages/flutter_tools/lib/src/commands/analyze.dart
+83
-284
analysis.dart
packages/flutter_tools/lib/src/dart/analysis.dart
+275
-0
pubspec.yaml
packages/flutter_tools/pubspec.yaml
+3
-4
analyze_duplicate_names_test.dart
...ages/flutter_tools/test/analyze_duplicate_names_test.dart
+2
-3
No files found.
packages/flutter_test/pubspec.yaml
View file @
11a54dee
...
...
@@ -7,10 +7,10 @@ dependencies:
# here we pin it precisely to avoid version skew across our packages.
test
:
0.12.13+1
# We don't actually depend on 'analyzer', but 'test'
does. We pin the
# version of analyzer we depend on to avoid version skew across our
# We don't actually depend on 'analyzer', but 'test'
and 'flutter_tools' do.
#
We pin the
version of analyzer we depend on to avoid version skew across our
# packages.
analyzer
:
0.27.
2
analyzer
:
0.27.
4-alpha.1
flutter
:
path
:
../flutter
packages/flutter_tools/lib/src/commands/analyze.dart
View file @
11a54dee
This diff is collapsed.
Click to expand it.
packages/flutter_tools/lib/src/dart/analysis.dart
0 → 100644
View file @
11a54dee
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:collection'
;
import
'dart:io'
;
import
'package:analyzer/file_system/file_system.dart'
as
file_system
;
import
'package:analyzer/file_system/file_system.dart'
show
Folder
;
import
'package:analyzer/file_system/physical_file_system.dart'
;
import
'package:analyzer/plugin/options.dart'
;
import
'package:analyzer/source/analysis_options_provider.dart'
;
import
'package:analyzer/source/embedder.dart'
;
import
'package:analyzer/source/error_processor.dart'
;
import
'package:analyzer/source/package_map_provider.dart'
;
import
'package:analyzer/source/package_map_resolver.dart'
;
import
'package:analyzer/source/pub_package_map_provider.dart'
;
import
'package:analyzer/src/generated/engine.dart'
;
import
'package:analyzer/src/generated/error.dart'
;
import
'package:analyzer/src/generated/java_io.dart'
;
import
'package:analyzer/src/generated/sdk.dart'
;
import
'package:analyzer/src/generated/sdk_io.dart'
;
import
'package:analyzer/src/generated/source.dart'
;
import
'package:analyzer/src/generated/source_io.dart'
;
import
'package:analyzer/src/task/options.dart'
;
import
'package:cli_util/cli_util.dart'
as
cli_util
;
import
'package:linter/src/plugin/linter_plugin.dart'
;
import
'package:package_config/packages.dart'
show
Packages
;
import
'package:package_config/packages_file.dart'
as
pkgfile
show
parse
;
import
'package:package_config/src/packages_impl.dart'
show
MapPackages
;
import
'package:path/path.dart'
as
path
;
import
'package:plugin/manager.dart'
;
import
'package:plugin/plugin.dart'
;
class
AnalysisDriver
{
Set
<
Source
>
_analyzedSources
=
new
HashSet
<
Source
>();
AnalysisOptionsProvider
analysisOptionsProvider
=
new
AnalysisOptionsProvider
();
AnalysisContext
context
;
DriverOptions
options
;
AnalysisDriver
(
this
.
options
)
{
AnalysisEngine
.
instance
.
logger
=
new
_StdLogger
(
outSink:
options
.
outSink
,
errorSink:
options
.
errorSink
);
_processPlugins
();
}
String
get
sdkDir
=>
options
.
dartSdkPath
??
cli_util
.
getSdkDir
().
path
;
List
<
AnalysisErrorDescription
>
analyze
(
Iterable
<
File
>
files
)
{
List
<
AnalysisErrorInfo
>
infos
=
_analyze
(
files
);
List
<
AnalysisErrorDescription
>
errors
=
<
AnalysisErrorDescription
>[];
for
(
AnalysisErrorInfo
info
in
infos
)
{
for
(
AnalysisError
error
in
info
.
errors
)
{
if
(!
_isFiltered
(
error
))
{
errors
.
add
(
new
AnalysisErrorDescription
(
error
,
info
.
lineInfo
));
}
}
}
return
errors
;
}
List
<
AnalysisErrorInfo
>
_analyze
(
Iterable
<
File
>
files
)
{
context
=
AnalysisEngine
.
instance
.
createAnalysisContext
();
_processAnalysisOptions
(
context
,
options
);
Packages
packages
=
_getPackageConfig
();
context
.
sourceFactory
=
new
SourceFactory
(
_getResolvers
(
context
,
packages
),
packages
);
List
<
Source
>
sources
=
<
Source
>[];
ChangeSet
changeSet
=
new
ChangeSet
();
for
(
File
file
in
files
)
{
JavaFile
sourceFile
=
new
JavaFile
(
path
.
normalize
(
file
.
absolute
.
path
));
Source
source
=
new
FileBasedSource
(
sourceFile
,
sourceFile
.
toURI
());
Uri
uri
=
context
.
sourceFactory
.
restoreUri
(
source
);
if
(
uri
!=
null
)
{
source
=
new
FileBasedSource
(
sourceFile
,
uri
);
}
sources
.
add
(
source
);
changeSet
.
addedSource
(
source
);
}
context
.
applyChanges
(
changeSet
);
List
<
AnalysisErrorInfo
>
infos
=
<
AnalysisErrorInfo
>[];
for
(
Source
source
in
sources
)
{
context
.
computeErrors
(
source
);
infos
.
add
(
context
.
getErrors
(
source
));
_analyzedSources
.
add
(
source
);
}
return
infos
;
}
Packages
_getPackageConfig
()
{
if
(
options
.
packageConfigPath
!=
null
)
{
String
packageConfigPath
=
options
.
packageConfigPath
;
Uri
fileUri
=
new
Uri
.
file
(
packageConfigPath
);
try
{
File
configFile
=
new
File
.
fromUri
(
fileUri
).
absolute
;
List
<
int
>
bytes
=
configFile
.
readAsBytesSync
();
Map
<
String
,
Uri
>
map
=
pkgfile
.
parse
(
bytes
,
configFile
.
uri
);
return
new
MapPackages
(
map
);
}
catch
(
e
)
{
throw
new
AnalysisDriverException
(
'Unable to create package map.'
);
}
}
return
null
;
}
Map
<
String
,
List
<
file_system
.
Folder
>>
_getPackageMap
(
Packages
packages
)
{
if
(
packages
==
null
)
return
null
;
Map
<
String
,
List
<
file_system
.
Folder
>>
folderMap
=
new
Map
<
String
,
List
<
file_system
.
Folder
>>();
packages
.
asMap
().
forEach
((
String
packagePath
,
Uri
uri
)
{
folderMap
[
packagePath
]
=
<
file_system
.
Folder
>[
PhysicalResourceProvider
.
INSTANCE
.
getFolder
(
path
.
fromUri
(
uri
))
];
});
return
folderMap
;
}
List
<
UriResolver
>
_getResolvers
(
InternalAnalysisContext
context
,
Packages
packages
)
{
DartSdk
sdk
=
new
DirectoryBasedDartSdk
(
new
JavaFile
(
sdkDir
));
List
<
UriResolver
>
resolvers
=
<
UriResolver
>[];
Map
<
String
,
List
<
file_system
.
Folder
>>
packageMap
=
_getPackageMap
(
packages
);
EmbedderYamlLocator
yamlLocator
=
context
.
embedderYamlLocator
;
yamlLocator
.
refresh
(
packageMap
);
EmbedderUriResolver
embedderUriResolver
=
new
EmbedderUriResolver
(
yamlLocator
.
embedderYamls
);
if
(
embedderUriResolver
.
length
==
0
)
{
resolvers
.
add
(
new
DartUriResolver
(
sdk
));
}
else
{
resolvers
.
add
(
embedderUriResolver
);
}
if
(
options
.
packageRootPath
!=
null
)
{
JavaFile
packageDirectory
=
new
JavaFile
(
options
.
packageRootPath
);
resolvers
.
add
(
new
PackageUriResolver
(<
JavaFile
>[
packageDirectory
]));
}
else
{
PubPackageMapProvider
pubPackageMapProvider
=
new
PubPackageMapProvider
(
PhysicalResourceProvider
.
INSTANCE
,
sdk
);
PackageMapInfo
packageMapInfo
=
pubPackageMapProvider
.
computePackageMap
(
PhysicalResourceProvider
.
INSTANCE
.
getResource
(
'.'
));
Map
<
String
,
List
<
Folder
>>
packageMap
=
packageMapInfo
.
packageMap
;
if
(
packageMap
!=
null
)
{
resolvers
.
add
(
new
PackageMapUriResolver
(
PhysicalResourceProvider
.
INSTANCE
,
packageMap
));
}
}
resolvers
.
add
(
new
FileUriResolver
());
return
resolvers
;
}
bool
_isFiltered
(
AnalysisError
error
)
{
ErrorProcessor
processor
=
ErrorProcessor
.
getProcessor
(
context
,
error
);
// Filtered errors are processed to a severity of `null`.
return
processor
!=
null
&&
processor
.
severity
==
null
;
}
void
_processAnalysisOptions
(
AnalysisContext
context
,
AnalysisOptions
analysisOptions
)
{
List
<
OptionsProcessor
>
optionsProcessors
=
AnalysisEngine
.
instance
.
optionsPlugin
.
optionsProcessors
;
try
{
String
optionsPath
=
options
.
analysisOptionsFile
;
if
(
optionsPath
!=
null
)
{
file_system
.
File
file
=
PhysicalResourceProvider
.
INSTANCE
.
getFile
(
optionsPath
);
Map
<
Object
,
Object
>
optionMap
=
analysisOptionsProvider
.
getOptionsFromFile
(
file
);
optionsProcessors
.
forEach
(
(
OptionsProcessor
p
)
=>
p
.
optionsProcessed
(
context
,
optionMap
));
if
(
optionMap
!=
null
)
{
configureContextOptions
(
context
,
optionMap
);
}
}
}
on
Exception
catch
(
e
)
{
optionsProcessors
.
forEach
((
OptionsProcessor
p
)
=>
p
.
onError
(
e
));
}
}
void
_processPlugins
()
{
List
<
Plugin
>
plugins
=
<
Plugin
>[];
plugins
.
addAll
(
AnalysisEngine
.
instance
.
requiredPlugins
);
plugins
.
add
(
AnalysisEngine
.
instance
.
commandLinePlugin
);
plugins
.
add
(
AnalysisEngine
.
instance
.
optionsPlugin
);
plugins
.
add
(
linterPlugin
);
ExtensionManager
manager
=
new
ExtensionManager
();
manager
.
processPlugins
(
plugins
);
}
}
class
AnalysisDriverException
implements
Exception
{
final
String
message
;
AnalysisDriverException
([
this
.
message
]);
@override
String
toString
()
=>
message
==
null
?
'Exception'
:
'Exception:
$message
'
;
}
class
AnalysisErrorDescription
{
static
Directory
cwd
=
Directory
.
current
.
absolute
;
final
AnalysisError
error
;
final
LineInfo
line
;
AnalysisErrorDescription
(
this
.
error
,
this
.
line
);
ErrorCode
get
errorCode
=>
error
.
errorCode
;
String
get
errorType
=>
error
.
errorCode
.
type
.
displayName
;
LineInfo_Location
get
location
=>
line
.
getLocation
(
error
.
offset
);
String
get
path
=>
_shorten
(
cwd
.
path
,
error
.
source
.
fullName
);
Source
get
source
=>
error
.
source
;
String
asString
()
=>
'[
$errorType
]
${error.message}
(
$path
, '
'line
${location.lineNumber}
, col
${location.columnNumber}
)'
;
static
String
_shorten
(
String
root
,
String
path
)
=>
path
.
startsWith
(
root
)
?
path
.
substring
(
root
.
length
+
1
)
:
path
;
}
class
DriverOptions
extends
AnalysisOptionsImpl
{
@override
int
cacheSize
=
512
;
/// The path to the dart SDK.
String
dartSdkPath
;
/// The path to a `.packages` configuration file
String
packageConfigPath
;
/// The path to the package root.
String
packageRootPath
;
/// The path to analysis options.
String
analysisOptionsFile
;
@override
bool
generateSdkErrors
=
false
;
/// Analysis options map.
Map
<
Object
,
Object
>
analysisOptions
;
@override
bool
lint
=
true
;
/// Out sink for logging.
IOSink
outSink
=
stdout
;
/// Error sink for logging.
IOSink
errorSink
=
stderr
;
}
class
_StdLogger
extends
Logger
{
final
IOSink
outSink
;
final
IOSink
errorSink
;
_StdLogger
({
this
.
outSink
,
this
.
errorSink
});
@override
void
logError
(
String
message
,
[
Exception
exception
])
=>
errorSink
.
writeln
(
message
);
@override
void
logInformation
(
String
message
,
[
Exception
exception
])
=>
outSink
.
writeln
(
message
);
}
packages/flutter_tools/pubspec.yaml
View file @
11a54dee
...
...
@@ -15,6 +15,7 @@ dependencies:
http
:
^0.11.3
json_rpc_2
:
^2.0.0
json_schema
:
^1.0.3
linter
:
^0.1.15
mustache4dart
:
^1.0.0
package_config
:
^0.1.3
path
:
^1.3.0
...
...
@@ -33,10 +34,8 @@ dependencies:
# precisely.
test
:
0.12.13+1
# We don't actually depend on 'analyzer', but 'test' does. We pin the
# version of analyzer we depend on to avoid version skew across our
# packages.
analyzer
:
0.27.2
# Pinned in flutter_test as well.
analyzer
:
0.27.4-alpha.1
dev_dependencies
:
mockito
:
^0.11.0
...
...
packages/flutter_tools/test/analyze_duplicate_names_test.dart
View file @
11a54dee
...
...
@@ -38,9 +38,8 @@ void main() {
return
createTestCommandRunner
(
command
).
run
(
<
String
>[
'analyze'
,
'--no-current-package'
,
'--no-current-directory'
,
dartFileA
.
path
,
dartFileB
.
path
]
).
then
((
int
code
)
{
expect
(
code
,
1
);
expect
(
testLogger
.
errorText
,
'[warning] The imported libraries
\'
a.dart
\'
and
\'
b.dart
\'
cannot have the same name
\'
test
\'
(
${dartFileB.path}
)
\n
'
);
expect
(
testLogger
.
statusText
,
'Analyzing 2 entry points...
\n
'
);
expect
(
code
,
0
);
expect
(
testLogger
.
statusText
,
startsWith
(
'Analyzing 2 files...
\n
No analyzer warnings!'
));
});
},
overrides:
<
Type
,
dynamic
>{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment