mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
Removed compiler/ directory from repository
R=ricow@google.com Review URL: https://codereview.chromium.org//20722006 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@25728 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
95ee996390
commit
cb18d8ba87
1
README
1
README
|
@ -8,7 +8,6 @@ http://code.google.com/p/dart.
|
|||
|
||||
Here's a brief guide to what's in here:
|
||||
|
||||
compiler/ Dart static analyzer.
|
||||
editor/ Eclipse-based standalone Dart IDE.
|
||||
lib/ Libraries that ship with the Dart runtime (core, html, etc.).
|
||||
pkg/ Packages that are not shipped with the core runtime.
|
||||
|
|
|
@ -8,7 +8,6 @@ bin/ Binaries/scripts to compile, run, and manage Dart applications.
|
|||
dart Dart virtual machine
|
||||
dart2js Dart-to-JavaScript compiler
|
||||
dartanalyzer Dart static analyzer
|
||||
dart_analyzer The older, deprecated Dart static analyzer
|
||||
dartdoc Dart documentation generator
|
||||
pub Pub, the Dart package manager
|
||||
|
||||
|
|
41
compiler/.gitignore
vendored
41
compiler/.gitignore
vendored
|
@ -1,41 +0,0 @@
|
|||
/compiler
|
||||
/third_party
|
||||
/compiler_corelib_sources.gypi
|
||||
/compiler_corelib_sources.xml
|
||||
/corelib_sources.gypi
|
||||
/corelib_sources.xml
|
||||
/domlib_sources.gypi
|
||||
/domlib_sources.xml
|
||||
/htmllib_sources.gypi
|
||||
/htmllib_sources.xml
|
||||
/isolatelib_sources.gypi
|
||||
/isolatelib_sources.xml
|
||||
/jsonlib_sources.gypi
|
||||
/jsonlib_sources.xml
|
||||
/sources.gypi
|
||||
/sources.txt
|
||||
/sources.xml
|
||||
/test_sources.gypi
|
||||
/test_sources.txt
|
||||
/test_sources.xml
|
||||
/out
|
||||
/xcodebuild
|
||||
/Debug
|
||||
/DebugARM
|
||||
/DebugIA32
|
||||
/DebugSIMARM
|
||||
/DebugX64
|
||||
/Release
|
||||
/ReleaseARM
|
||||
/ReleaseIA32
|
||||
/ReleaseSIMARM
|
||||
/ReleaseX64
|
||||
/Makefile
|
||||
/*.Makefile
|
||||
/*.sln
|
||||
/*.target.mk
|
||||
/*.vcproj
|
||||
/*.vcxproj
|
||||
/*.vcxproj.filters
|
||||
/*.vcxproj.user
|
||||
/*.xcodeproj
|
|
@ -1,2 +0,0 @@
|
|||
This directory is a placeholder for the eventual Dart compiler.
|
||||
The Dart compiler consists of among others a Dart front-end, a Dart->JS backend, a Dart->Dart backend, tree-shaking tools, minification tools.
|
|
@ -1,5 +0,0 @@
|
|||
library api;
|
||||
// dart:core is implicit
|
||||
import "dart:html";
|
||||
import "dart:json";
|
||||
import "dart:isolate";
|
|
@ -1,185 +0,0 @@
|
|||
<!--
|
||||
Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
for details. All rights reserved. Use of this source code is governed by a
|
||||
BSD-style license that can be found in the LICENSE file.
|
||||
-->
|
||||
<project default="dist">
|
||||
<!--
|
||||
EDIT DARTC.XML FIRST. This file is no longer used to build
|
||||
dartc proper. It is only here to avoid breaking dartium.gyp
|
||||
short term. Change dartc.xml to get everything working,
|
||||
then update this file to match.
|
||||
-->
|
||||
|
||||
<import file="sources.xml"/>
|
||||
<import file="test_sources.xml"/>
|
||||
|
||||
<!--
|
||||
The file build.properties does not exist. If provided, properties can be customized.
|
||||
-->
|
||||
<property file="build.properties" />
|
||||
|
||||
<!--
|
||||
Configuration properties.
|
||||
-->
|
||||
<property name="build.dir" value="out"/>
|
||||
|
||||
<property name="build.classes.dir" value="${build.dir}/classes"/>
|
||||
|
||||
<property name="build.test.classes.dir" value="${build.dir}/test/classes"/>
|
||||
|
||||
<property name="dart_analyzer.jar" value="${build.dir}/dart_analyzer.jar"/>
|
||||
|
||||
<property name="dist.dir" value="${build.dir}/dist"/>
|
||||
|
||||
<property name="test.report.dir" value="${build.dir}/test"/>
|
||||
|
||||
<property name="third_party.dir" value="../third_party"/>
|
||||
|
||||
<property name="test_py" location="../tools/test.py"/>
|
||||
|
||||
<!--
|
||||
Define buildtime and runtime classpaths.
|
||||
-->
|
||||
<path id="classpath.compile">
|
||||
<pathelement location="${third_party.dir}/args4j/2.0.12/args4j-2.0.12.jar"/>
|
||||
<pathelement location="${third_party.dir}/guava/r13/guava-13.0.1.jar"/>
|
||||
<pathelement location="${third_party.dir}/json/r2_20080312/json.jar"/>
|
||||
</path>
|
||||
|
||||
<path id="classpath.runtime">
|
||||
<path refid="classpath.compile"/>
|
||||
</path>
|
||||
|
||||
<path id="classpath.compile.tests">
|
||||
<path refid="classpath.compile"/>
|
||||
<pathelement location="${build.classes.dir}"/>
|
||||
<pathelement location="${third_party.dir}/junit/v4_8_2/junit.jar"/>
|
||||
</path>
|
||||
|
||||
<path id="classpath.run.tests">
|
||||
<path refid="classpath.compile.tests"/>
|
||||
<pathelement location="${build.test.classes.dir}"/>
|
||||
<pathelement location="${third_party.dir}/hamcrest/v1_3/hamcrest-core-1.3.0RC2.jar"/>
|
||||
<pathelement location="${third_party.dir}/hamcrest/v1_3/hamcrest-generator-1.3.0RC2.jar"/>
|
||||
<pathelement location="${third_party.dir}/hamcrest/v1_3/hamcrest-integration-1.3.0RC2.jar"/>
|
||||
<pathelement location="${third_party.dir}/hamcrest/v1_3/hamcrest-library-1.3.0RC2.jar"/>
|
||||
</path>
|
||||
|
||||
<target name="compile" description="Compiles all of the java source and copies resources to the classes directory.">
|
||||
<!--
|
||||
Ensure the necessary subdirectories exist.
|
||||
-->
|
||||
<mkdir dir="${build.classes.dir}"/>
|
||||
|
||||
<javac destdir="${build.classes.dir}"
|
||||
sourcepath=""
|
||||
srcdir="java"
|
||||
includes="${java_sources}"
|
||||
fork="true"
|
||||
debug="true"
|
||||
source="1.6"
|
||||
target="1.6"
|
||||
encoding="UTF-8">
|
||||
<classpath refid="classpath.compile"/>
|
||||
</javac>
|
||||
<!--
|
||||
Copy all non-java resources.
|
||||
-->
|
||||
<copy todir="${build.classes.dir}">
|
||||
<filelist refid="java_resources"/>
|
||||
</copy>
|
||||
|
||||
</target>
|
||||
|
||||
<target name="compile-tests" depends="compile" description="Compiles all of the java tests and copies the resources to the test classes directory." >
|
||||
<mkdir dir="${build.test.classes.dir}"/>
|
||||
<javac destdir="${build.test.classes.dir}"
|
||||
sourcepath=""
|
||||
srcdir="javatests"
|
||||
includes="${javatests_sources}"
|
||||
excludes="com/google/dart/compiler/vm/**"
|
||||
fork="true"
|
||||
debug="true"
|
||||
source="1.6"
|
||||
target="1.6"
|
||||
encoding="UTF-8">
|
||||
<classpath refid="classpath.compile.tests"/>
|
||||
</javac>
|
||||
<!--
|
||||
Copy the non-java resources.
|
||||
-->
|
||||
<copy todir="${build.test.classes.dir}">
|
||||
<filelist refid="javatests_resources"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="dart_analyzer.jar" depends="compile"
|
||||
description="Creates a jar for dartc without bundling the dependencies.">
|
||||
<jar destfile="${dart_analyzer.jar}" basedir="${build.classes.dir}" manifest="dart_analyzer.mf"/>
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="dart_analyzer.jar" description="Creates a directory that contains a standalone distribution.">
|
||||
<!--
|
||||
Ensure the necessary subdirectories exist.
|
||||
-->
|
||||
<mkdir dir="${dist.dir}/bin"/>
|
||||
<mkdir dir="${dist.dir}/util"/>
|
||||
<mkdir dir="${dist.dir}/util/analyzer"/>
|
||||
|
||||
<!--
|
||||
Copy the dart jar to the lib folder.
|
||||
-->
|
||||
<copy file="${dart_analyzer.jar}" todir="${dist.dir}/util/analyzer"/>
|
||||
|
||||
<!--
|
||||
Re-root the classpaths from third_party into the library folder of the distro.
|
||||
-->
|
||||
<pathconvert property="analyzer.classpath.runtime.unix" targetos="unix" refid="classpath.runtime">
|
||||
<regexpmapper from="${third_party.dir}/(.*)" to="$DART_ANALYZER_LIBS/\1"/>
|
||||
</pathconvert>
|
||||
|
||||
<copy file="scripts/dart_analyzer.sh" tofile="${dist.dir}/bin/dart_analyzer">
|
||||
<filterset>
|
||||
<filter token="CLASSPATH" value="$DART_ANALYZER_LIBS/dart_analyzer.jar:${analyzer.classpath.runtime.unix}"/>
|
||||
</filterset>
|
||||
</copy>
|
||||
<chmod file="${dist.dir}/bin/dart_analyzer" perm="a+rx"/>
|
||||
|
||||
<copy file="scripts/dart_analyzer.bat" tofile="${dist.dir}/bin/dart_analyzer.bat">
|
||||
<filterset>
|
||||
<filter token="CLASSPATH" value="$DART_ANALYZER_LIBS/dart_analyzer.jar:${analyzer.classpath.runtime.win}"/>
|
||||
</filterset>
|
||||
</copy>
|
||||
|
||||
<!--
|
||||
TODO: The following files are not strictly due to dist, move them out.
|
||||
-->
|
||||
<copy todir="${build.dir}">
|
||||
<fileset dir="scripts">
|
||||
<include name="analyzer_metrics.sh"/>
|
||||
</fileset>
|
||||
<filterset>
|
||||
<filter token="CLASSPATH" value="$DARTC_LIBS/dart_analyzer.jar:${analyzer.classpath.runtime.unix}"/>
|
||||
</filterset>
|
||||
</copy>
|
||||
<chmod file="${build.dir}/analyzer_metrics.sh" perm="a+rx"/>
|
||||
|
||||
<!--
|
||||
Copy of all of the dependencies to the lib folder.
|
||||
-->
|
||||
<copy todir="${dist.dir}/util/analyzer">
|
||||
<path refid="classpath.runtime"/>
|
||||
<regexpmapper from="${third_party.dir}/(.*)" to="\1"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="clean" description="Deletes the build output directory.">
|
||||
<delete dir="${build.dir}"/>
|
||||
<delete dir="${dist.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="tests.jar" depends="compile-tests">
|
||||
<jar destfile="${build.dir}/tests.jar" basedir="${build.test.classes.dir}"/>
|
||||
</target>
|
||||
</project>
|
|
@ -1,80 +0,0 @@
|
|||
# Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
# for details. All rights reserved. Use of this source code is governed by a
|
||||
# BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
{
|
||||
'includes': [
|
||||
'sources.gypi',
|
||||
'test_sources.gypi',
|
||||
],
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'dart_analyzer',
|
||||
'type': 'none',
|
||||
'conditions': [
|
||||
[ 'OS!="win"', {
|
||||
'variables': {
|
||||
'script_suffix': '',
|
||||
},
|
||||
}],
|
||||
[ 'OS=="win"', {
|
||||
'variables': {
|
||||
'script_suffix': '.bat',
|
||||
},
|
||||
}],
|
||||
],
|
||||
'actions': [
|
||||
{
|
||||
'action_name': 'build_dart_analyzer',
|
||||
'inputs': [
|
||||
'sources.gypi',
|
||||
'test_sources.gypi',
|
||||
'<@(java_sources)',
|
||||
'<@(java_resources)',
|
||||
'<@(javatests_sources)',
|
||||
'<@(javatests_resources)',
|
||||
'dart_analyzer.xml',
|
||||
'scripts/dart_analyzer.sh',
|
||||
'scripts/dart_analyzer.bat',
|
||||
'scripts/analyzer_metrics.sh',
|
||||
'../third_party/args4j/2.0.12/args4j-2.0.12.jar',
|
||||
'../third_party/guava/r13/guava-13.0.1.jar',
|
||||
'../third_party/hamcrest/v1_3/hamcrest-core-1.3.0RC2.jar',
|
||||
'../third_party/hamcrest/v1_3/hamcrest-generator-1.3.0RC2.jar',
|
||||
'../third_party/hamcrest/v1_3/hamcrest-integration-1.3.0RC2.jar',
|
||||
'../third_party/hamcrest/v1_3/hamcrest-library-1.3.0RC2.jar',
|
||||
],
|
||||
'outputs': [
|
||||
'<(INTERMEDIATE_DIR)/<(_target_name)/tests.jar',
|
||||
'<(PRODUCT_DIR)/analyzer/bin/dart_analyzer',
|
||||
'<(PRODUCT_DIR)/analyzer/bin/dart_analyzer.bat',
|
||||
'<(PRODUCT_DIR)/analyzer/util/analyzer/dart_analyzer.jar',
|
||||
'<(PRODUCT_DIR)/analyzer/util/analyzer/args4j/2.0.12/args4j-2.0.12.jar',
|
||||
'<(PRODUCT_DIR)/analyzer/util/analyzer/guava/r13/guava-13.0.1.jar',
|
||||
],
|
||||
'action' : [
|
||||
'../third_party/apache_ant/1.8.4/bin/ant<(script_suffix)',
|
||||
'-f', 'dart_analyzer.xml',
|
||||
'-Dbuild.dir=<(INTERMEDIATE_DIR)/<(_target_name)',
|
||||
'-Ddist.dir=<(PRODUCT_DIR)/analyzer',
|
||||
'clean',
|
||||
'dist',
|
||||
'tests.jar',
|
||||
],
|
||||
'message': 'Building dart_analyzer.',
|
||||
},
|
||||
{
|
||||
'action_name': 'copy_tests',
|
||||
'inputs': [ '<(INTERMEDIATE_DIR)/<(_target_name)/tests.jar' ],
|
||||
'outputs': [ '<(PRODUCT_DIR)/analyzer/dart_analyzer_tests.jar' ],
|
||||
'action': [ 'cp', '<@(_inputs)', '<@(_outputs)' ]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
# GYP won't generate a catch-all target if there's only one target.
|
||||
'target_name': 'dummy',
|
||||
'type': 'none',
|
||||
},
|
||||
],
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
Manifest-Version: 1.0
|
||||
Main-Class: com.google.dart.compiler.DartCompiler
|
||||
Class-Path: deploy_deploy.jar
|
|
@ -1,190 +0,0 @@
|
|||
<!--
|
||||
Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
for details. All rights reserved. Use of this source code is governed by a
|
||||
BSD-style license that can be found in the LICENSE file.
|
||||
-->
|
||||
<project default="dist">
|
||||
<import file="sources.xml"/>
|
||||
<import file="test_sources.xml"/>
|
||||
|
||||
<!--
|
||||
The file build.properties does not exist. If provided, properties can be customized.
|
||||
-->
|
||||
<property file="build.properties" />
|
||||
|
||||
<!--
|
||||
Configuration properties.
|
||||
-->
|
||||
<property name="build.dir" value="out"/>
|
||||
|
||||
<property name="build.classes.dir" value="${build.dir}/classes"/>
|
||||
|
||||
<property name="build.test.classes.dir" value="${build.dir}/test/classes"/>
|
||||
|
||||
<property name="dart_analyzer.jar" value="${build.dir}/dart_analyzer.jar"/>
|
||||
|
||||
<property name="dist.dir" value="${build.dir}/dist"/>
|
||||
|
||||
<property name="test.report.dir" value="${build.dir}/test"/>
|
||||
|
||||
<property name="third_party.dir" value="../third_party"/>
|
||||
|
||||
<property name="test_py" location="../tools/test.py"/>
|
||||
|
||||
<!--
|
||||
Define buildtime and runtime classpaths.
|
||||
-->
|
||||
<path id="classpath.compile">
|
||||
<pathelement location="${third_party.dir}/args4j/2.0.12/args4j-2.0.12.jar"/>
|
||||
<pathelement location="${third_party.dir}/guava/r13/guava-13.0.1.jar"/>
|
||||
<pathelement location="${third_party.dir}/json/r2_20080312/json.jar"/>
|
||||
</path>
|
||||
|
||||
<path id="classpath.runtime">
|
||||
<path refid="classpath.compile"/>
|
||||
</path>
|
||||
|
||||
<path id="classpath.compile.tests">
|
||||
<path refid="classpath.compile"/>
|
||||
<pathelement location="${build.classes.dir}"/>
|
||||
<pathelement location="${third_party.dir}/junit/v4_8_2/junit.jar"/>
|
||||
</path>
|
||||
|
||||
<path id="classpath.run.tests">
|
||||
<path refid="classpath.compile.tests"/>
|
||||
<pathelement location="${build.test.classes.dir}"/>
|
||||
<pathelement location="${third_party.dir}/hamcrest/v1_3/hamcrest-core-1.3.0RC2.jar"/>
|
||||
<pathelement location="${third_party.dir}/hamcrest/v1_3/hamcrest-generator-1.3.0RC2.jar"/>
|
||||
<pathelement location="${third_party.dir}/hamcrest/v1_3/hamcrest-integration-1.3.0RC2.jar"/>
|
||||
<pathelement location="${third_party.dir}/hamcrest/v1_3/hamcrest-library-1.3.0RC2.jar"/>
|
||||
<pathelement location="${third_party.dir}/fest/fest-util-1.1.6.jar"/>
|
||||
<pathelement location="${third_party.dir}/fest/fest-assert-1.4.jar"/>
|
||||
</path>
|
||||
|
||||
<target name="compile" description="Compiles all of the java source and copies resources to the classes directory.">
|
||||
<!--
|
||||
Ensure the necessary subdirectories exist.
|
||||
-->
|
||||
<mkdir dir="${build.classes.dir}"/>
|
||||
|
||||
<javac destdir="${build.classes.dir}"
|
||||
sourcepath=""
|
||||
srcdir="java"
|
||||
includes="${java_sources}"
|
||||
fork="true"
|
||||
debug="true"
|
||||
source="1.6"
|
||||
target="1.6"
|
||||
includeAntRuntime="false">
|
||||
<classpath refid="classpath.compile"/>
|
||||
</javac>
|
||||
<!--
|
||||
Copy all non-java resources.
|
||||
-->
|
||||
<copy todir="${build.classes.dir}">
|
||||
<filelist refid="java_resources"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
We rely on GYP to call these targets when dependencies change, hence this
|
||||
ant file cannot be used standalone.
|
||||
-->
|
||||
<target name="compile-tests" depends="compile" description="Compiles all of the java tests and copies the resources to the test classes directory." >
|
||||
<mkdir dir="${build.test.classes.dir}"/>
|
||||
<javac destdir="${build.test.classes.dir}"
|
||||
sourcepath=""
|
||||
srcdir="javatests"
|
||||
includes="${javatests_sources}"
|
||||
excludes="com/google/dart/compiler/vm/**"
|
||||
fork="true"
|
||||
debug="true"
|
||||
source="1.6"
|
||||
target="1.6"
|
||||
includeAntRuntime="false">
|
||||
<classpath refid="classpath.compile.tests"/>
|
||||
</javac>
|
||||
<!--
|
||||
Copy the non-java resources.
|
||||
-->
|
||||
<copy todir="${build.test.classes.dir}">
|
||||
<filelist refid="javatests_resources"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="dart_analyzer.jar" depends="compile" description="Creates a jar without bundling the dependencies.">
|
||||
<jar destfile="${dart_analyzer.jar}" basedir="${build.classes.dir}"
|
||||
manifest="dart_analyzer.mf"/>
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="dart_analyzer.jar"
|
||||
description="Create a directory with a standalone distribution.">
|
||||
<!--
|
||||
Ensure the necessary subdirectories exist.
|
||||
-->
|
||||
<mkdir dir="${dist.dir}/bin"/>
|
||||
<mkdir dir="${dist.dir}/util"/>
|
||||
<mkdir dir="${dist.dir}/util/analyzer"/>
|
||||
|
||||
<!--
|
||||
Copy the dart jar to the lib folder.
|
||||
-->
|
||||
<copy file="${dart_analyzer.jar}" todir="${dist.dir}/util/analyzer"/>
|
||||
|
||||
<!--
|
||||
Re-root the classpaths from third_party into the util folder of the distro.
|
||||
-->
|
||||
<pathconvert property="analyzer.classpath.runtime.unix" targetos="unix" refid="classpath.runtime">
|
||||
<regexpmapper from="${third_party.dir}/(.*)" to="$DART_ANALYZER_LIBS/\1"/>
|
||||
</pathconvert>
|
||||
|
||||
<pathconvert property="analyzer.classpath.runtime.win" targetos="windows" refid="classpath.runtime">
|
||||
<regexpmapper from="(.*)third_party\\(.*)" to="%DART_ANALYZER_LIBS%\\\2"/>
|
||||
</pathconvert>
|
||||
|
||||
<copy file="scripts/dart_analyzer.sh" tofile="${dist.dir}/bin/dart_analyzer">
|
||||
<filterset>
|
||||
<filter token="CLASSPATH" value="$DART_ANALYZER_LIBS/dart_analyzer.jar:${analyzer.classpath.runtime.unix}"/>
|
||||
</filterset>
|
||||
</copy>
|
||||
<chmod file="${dist.dir}/bin/dart_analyzer" perm="a+rx"/>
|
||||
|
||||
<copy file="scripts/dart_analyzer.bat" tofile="${dist.dir}/bin/dart_analyzer.bat">
|
||||
<filterset>
|
||||
<filter
|
||||
token="CLASSPATH"
|
||||
value="%DART_ANALYZER_LIBS%\dart_analyzer.jar;${analyzer.classpath.runtime.win}"/>
|
||||
</filterset>
|
||||
</copy>
|
||||
|
||||
<!--
|
||||
TODO: The following files are not strictly due to dist, move them out.
|
||||
-->
|
||||
<copy todir="${build.dir}">
|
||||
<fileset dir="scripts">
|
||||
<include name="analyzer_metrics.sh"/>
|
||||
</fileset>
|
||||
<filterset>
|
||||
<filter token="CLASSPATH" value="$DART_ANALYZER_LIBS/dart_analyzer.jar:${analyzer.classpath.runtime.unix}"/>
|
||||
</filterset>
|
||||
</copy>
|
||||
<chmod file="${build.dir}/analyzer_metrics.sh" perm="a+rx"/>
|
||||
|
||||
<!--
|
||||
Copy of all dependencies to the util folder.
|
||||
-->
|
||||
<copy todir="${dist.dir}/util/analyzer">
|
||||
<path refid="classpath.runtime"/>
|
||||
<regexpmapper from="(.*)third_party[/\\](.*)" to="\2"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="clean" description="Deletes the build output directory.">
|
||||
<delete dir="${build.dir}"/>
|
||||
<delete dir="${dist.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="tests.jar" depends="compile-tests">
|
||||
<jar destfile="${build.dir}/tests.jar" basedir="${build.test.classes.dir}"/>
|
||||
</target>
|
||||
</project>
|
|
@ -1,39 +0,0 @@
|
|||
# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
# for details. All rights reserved. Use of this source code is governed by a
|
||||
# BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
# TODO(vsm): Remove this file and use dart.gyp once that can be pulled
|
||||
# into the dartium build.
|
||||
{
|
||||
'includes': [
|
||||
# TODO(mmendez): Add the appropriate gypi includes here.
|
||||
],
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'dartc',
|
||||
'type': 'none',
|
||||
'actions': [
|
||||
{
|
||||
'action_name': 'Build and test',
|
||||
'inputs': [
|
||||
],
|
||||
'outputs': [
|
||||
'dummy_target',
|
||||
],
|
||||
'action' : [
|
||||
'../third_party/apache_ant/1.8.4/bin/ant',
|
||||
'-Dbuild.dir=<(PRODUCT_DIR)/ant-out',
|
||||
'clean',
|
||||
'dist',
|
||||
],
|
||||
'message': 'Building dartc.',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
# GYP won't generate a catch-all target if there's only one target.
|
||||
'target_name': 'dummy',
|
||||
'type': 'none',
|
||||
},
|
||||
],
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
This is an Eclipse workspace for Helios Service Release 2.
|
||||
|
||||
HOW TO
|
||||
|
||||
1. When you open Eclipse the first time, it will ask you to create a
|
||||
workspace or select an existing one. You can use this directory as
|
||||
workspace, or you can choose a different one.
|
||||
|
||||
2. If you're already using Eclipse, you can either switch to a new
|
||||
workspace (File > Switch Workspace) or use your current workspace.
|
||||
|
||||
3. Add the following "Path Variable" to your workspace:
|
||||
(Open Preferences... > General > Workspace > Linked Resources)
|
||||
DART_TRUNK: point to the root of your checkout
|
||||
|
||||
|
||||
4. Add a "Classpath Variable" to your workspace called DART_TRUNK
|
||||
that points to the same directory as your DART_TRUNK path variable.
|
||||
(Open Preferences... > Java > Build Path > Classpath Variables).
|
||||
|
||||
5. Regardless if you're using this directory as a workspace, you have
|
||||
to import the projects (File > Import... > General > Existing
|
||||
Projects into Workspace).
|
||||
|
||||
6. Click "Next >"
|
||||
|
||||
7. Select root directory. Browse to: compiler/eclipse.workspace.
|
||||
|
||||
8. It should find and select two projects (dartc and tests).
|
||||
|
||||
9. Click Finish. (At this point Eclipse may get stuck, if so, exit
|
||||
Eclipse by right-clicking on the dock icon, and restart).
|
||||
|
||||
10. Open Preferences... > Java > Compiler > Errors/Warnings > Potential
|
||||
programming problems. Change "Serializable class without
|
||||
serialVersionUID" to "Ignore".
|
||||
|
||||
11. Import the launch configuration (File > Import... > Run/Debug >
|
||||
Launch Configurations).
|
||||
|
||||
12. Click "Next >"
|
||||
|
||||
13. In SVN, browse to: compiler/eclipse.workspace/tests.
|
||||
|
||||
14. Select "tests".
|
||||
|
||||
15. Click Finish.
|
||||
|
||||
16. Try running the tests: Run > Run History > dartc test suites.
|
|
@ -1,14 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="var" path="DART_TRUNK/third_party/args4j/2.0.12/args4j-2.0.12.jar" sourcepath="/DART_TRUNK/third_party/args4j/2.0.12/args4j-2.0.12-src.jar"/>
|
||||
<classpathentry kind="var" path="DART_TRUNK/third_party/guava/r13/guava-13.0.1.jar" sourcepath="/DART_TRUNK/third_party/guava/r13/guava-13.0.1-sources.zip"/>
|
||||
<classpathentry kind="var" path="DART_TRUNK/third_party/hamcrest/v1_3/hamcrest-core-1.3.0RC2.jar"/>
|
||||
<classpathentry kind="var" path="DART_TRUNK/third_party/hamcrest/v1_3/hamcrest-generator-1.3.0RC2.jar"/>
|
||||
<classpathentry kind="var" path="DART_TRUNK/third_party/hamcrest/v1_3/hamcrest-integration-1.3.0RC2.jar"/>
|
||||
<classpathentry kind="var" path="DART_TRUNK/third_party/hamcrest/v1_3/hamcrest-library-1.3.0RC2.jar"/>
|
||||
<classpathentry kind="var" path="DART_TRUNK/third_party/json/r2_20080312/json.jar"/>
|
||||
<classpathentry kind="var" path="DART_TRUNK/third_party/junit/v4_8_2/junit.jar" sourcepath="/DART_TRUNK/third_party/junit/v4_8_2/junit-src.jar"/>
|
||||
<classpathentry kind="output" path="output"/>
|
||||
</classpath>
|
1
compiler/eclipse.workspace/dartc/.gitignore
vendored
1
compiler/eclipse.workspace/dartc/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
/output
|
|
@ -1,24 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>dartc</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
<linkedResources>
|
||||
<link>
|
||||
<name>src</name>
|
||||
<type>2</type>
|
||||
<locationURI>DART_TRUNK/compiler/java</locationURI>
|
||||
</link>
|
||||
</linkedResources>
|
||||
</projectDescription>
|
|
@ -1,12 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="cases"/>
|
||||
<classpathentry kind="src" path="suites"/>
|
||||
<classpathentry kind="src" path="imported"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/dartc"/>
|
||||
<classpathentry kind="var" path="DART_TRUNK/third_party/args4j/2.0.12/args4j-2.0.12.jar" sourcepath="/DART_TRUNK/third_party/args4j/2.0.12/args4j-2.0.12-src.jar"/>
|
||||
<classpathentry kind="var" path="DART_TRUNK/third_party/junit/v4_8_2/junit.jar"/>
|
||||
<classpathentry kind="var" path="DART_TRUNK/third_party/guava/r13/guava-13.0.1.jar"/>
|
||||
<classpathentry kind="output" path="output"/>
|
||||
</classpath>
|
2
compiler/eclipse.workspace/tests/.gitignore
vendored
2
compiler/eclipse.workspace/tests/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
/output
|
||||
/.settings
|
|
@ -1,118 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>tests</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
<linkedResources>
|
||||
<link>
|
||||
<name>cases</name>
|
||||
<type>2</type>
|
||||
<locationURI>DART_TRUNK/compiler/javatests</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>suites</name>
|
||||
<type>2</type>
|
||||
<locationURI>DART_TRUNK/compiler/javatests</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>test.py</name>
|
||||
<type>1</type>
|
||||
<locationURI>DART_TRUNK/tools/test.py</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>imported/third_party/java_src/dart/corelib/tests</name>
|
||||
<type>2</type>
|
||||
<locationURI>DART_TRUNK/corelib/tests</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>imported/third_party/java_src/dart/execution/runtime/tests</name>
|
||||
<type>2</type>
|
||||
<locationURI>DART_TRUNK/runtime/tests</locationURI>
|
||||
</link>
|
||||
</linkedResources>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1311331907127</id>
|
||||
<name>cases</name>
|
||||
<type>22</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-*Tests.java</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
<filter>
|
||||
<id>1311331781529</id>
|
||||
<name>imported</name>
|
||||
<type>21</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-*.dart</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
<filter>
|
||||
<id>1311331571786</id>
|
||||
<name>jscomp</name>
|
||||
<type>21</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-*OptTests.java</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
<filter>
|
||||
<id>1311331079908</id>
|
||||
<name>suites</name>
|
||||
<type>21</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-true-false-*Tests.java</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
<filter>
|
||||
<id>1311331715338</id>
|
||||
<name>cases/com/google/dart/compiler</name>
|
||||
<type>10</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-vm</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
<filter>
|
||||
<id>1311331633045</id>
|
||||
<name>jscomp/com/google/dart/compiler</name>
|
||||
<type>10</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-vm</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
<filter>
|
||||
<id>1311331190572</id>
|
||||
<name>suites/com/google/dart/compiler</name>
|
||||
<type>10</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-vm</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
<filter>
|
||||
<id>1311331455715</id>
|
||||
<name>suites/com/google/dart/compiler/end2end</name>
|
||||
<type>6</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-*OptTests.java</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/tests/suites/com/google/dart/corelib/SharedTests.java"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="1"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
|
||||
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
|
||||
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
|
||||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
|
||||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
|
||||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.google.dart.corelib.SharedTests"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="tests"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea -Dcom.google.dart.corelib.SharedTests.test_py=${resource_loc:/tests/test.py} "/>
|
||||
</launchConfiguration>
|
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/tests/suites/com/google/dart/corelib/TestSharedTests.java"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="1"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
|
||||
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
|
||||
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
|
||||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
|
||||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
|
||||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.google.dart.corelib.TestSharedTests"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="tests"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea -Dcom.google.dart.corelib.SharedTests.test_py=${resource_loc:/tests/test.py} "/>
|
||||
</launchConfiguration>
|
|
@ -1,22 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/tests/suites"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="2"/>
|
||||
</listAttribute>
|
||||
<mapAttribute key="org.eclipse.debug.core.environmentVariables">
|
||||
</mapAttribute>
|
||||
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
|
||||
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
|
||||
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=tests/suites"/>
|
||||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
|
||||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
|
||||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="tests"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea -Dcom.google.dart.corelib.SharedTests.test_py=${resource_loc:/tests/test.py} "/>
|
||||
</launchConfiguration>
|
|
@ -1,129 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
# for details. All rights reserved. Use of this source code is governed by a
|
||||
# BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
from __future__ import with_statement
|
||||
import StringIO
|
||||
import os
|
||||
import sys
|
||||
|
||||
class GenerateError(Exception):
|
||||
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
def __str__(self):
|
||||
return repr(self.value)
|
||||
|
||||
|
||||
class Generator:
|
||||
|
||||
def __init__(self, base_directory, name, output, path, *excludes):
|
||||
self.base_directory = base_directory
|
||||
self.name = name
|
||||
self.output = output
|
||||
self.path = path
|
||||
self.excludes = set()
|
||||
for x in excludes:
|
||||
self.excludes.add(x)
|
||||
self.sources = []
|
||||
self.resources = []
|
||||
|
||||
def _list_files(self):
|
||||
start_directory = os.path.join(self.base_directory, self.path)
|
||||
for fullpath, dirs, filenames in os.walk(start_directory):
|
||||
path = fullpath[len(start_directory) + 1:]
|
||||
remove_me = [d for d in dirs if d.startswith('.') or
|
||||
d == 'CVS' or
|
||||
(d in self.excludes)]
|
||||
for d in remove_me:
|
||||
dirs.remove(d)
|
||||
for filename in filenames:
|
||||
if (filename.endswith('.java')):
|
||||
self.sources.append(os.path.join(path, filename))
|
||||
elif (filename.endswith('~')):
|
||||
pass
|
||||
elif (filename.endswith('.pyc')):
|
||||
pass
|
||||
else:
|
||||
self.resources.append(os.path.join(path, filename))
|
||||
self.sources.sort()
|
||||
self.resources.sort()
|
||||
|
||||
def _print_gypi_files(self, out, name, files):
|
||||
out.write(" '%s': [\n" % name)
|
||||
for filename in files:
|
||||
out.write(''' r'%s/%s',%s''' % (self.path, filename,'\n'))
|
||||
out.write(" ],\n")
|
||||
|
||||
def _print_txt_files(self, out, files):
|
||||
for filename in files:
|
||||
out.write('%s\n' % os.path.join(self.path, filename))
|
||||
|
||||
def _print_ant_files(self, out, name, files):
|
||||
out.write(" <filelist id='%s' dir='%s'>\n" % (name, self.path))
|
||||
for filename in files:
|
||||
out.write(" <file name='%s'/>\n" % filename)
|
||||
out.write(" </filelist>\n")
|
||||
out.write(" <pathconvert pathsep=',' property='%s' refid='%s'>\n"
|
||||
% (name, name))
|
||||
out.write(" <map from='${basedir}/%s/' to=''/>\n" % self.path)
|
||||
out.write(" </pathconvert>\n")
|
||||
|
||||
def _make_output(self, file_name):
|
||||
if os.path.exists(file_name):
|
||||
return StringIO.StringIO()
|
||||
else:
|
||||
return file(file_name, 'w')
|
||||
|
||||
def _close(self, file_name, output):
|
||||
if not isinstance(output, StringIO.StringIO):
|
||||
output.close()
|
||||
return
|
||||
new_text = output.getvalue()
|
||||
output.close()
|
||||
with open(file_name, 'r') as f:
|
||||
old_text = f.read()
|
||||
if old_text == new_text:
|
||||
return
|
||||
sys.stderr.write('Updating %s\n' % file_name)
|
||||
with open(file_name, 'w') as f:
|
||||
f.write(new_text)
|
||||
|
||||
def generate(self):
|
||||
self._list_files()
|
||||
|
||||
file_name = self.output + '.gypi';
|
||||
gypi = self._make_output(file_name)
|
||||
gypi.write("{\n 'variables': {\n")
|
||||
self._print_gypi_files(gypi, self.name + '_sources', self.sources)
|
||||
self._print_gypi_files(gypi, self.name + '_resources', self.resources)
|
||||
gypi.write(" },\n}\n")
|
||||
self._close(file_name, gypi)
|
||||
|
||||
file_name = self.output + '.xml'
|
||||
ant = self._make_output(file_name)
|
||||
ant.write("<project>\n")
|
||||
self._print_ant_files(ant, self.name + '_sources', self.sources)
|
||||
self._print_ant_files(ant, self.name + '_resources', self.resources)
|
||||
ant.write("</project>\n")
|
||||
self._close(file_name, ant)
|
||||
|
||||
file_name = self.output + '.txt';
|
||||
txt = self._make_output(file_name)
|
||||
self._print_txt_files(txt, self.sources)
|
||||
self._close(file_name, txt)
|
||||
|
||||
|
||||
def Main(script_name = None, name = None, output = None, path = None,
|
||||
*rest):
|
||||
if not path:
|
||||
raise GenerateError("usage: %s NAME OUTPUT PATH EXCLUDE_DIR_NAME ..."
|
||||
% script_name)
|
||||
base_directory = os.path.dirname(output)
|
||||
Generator(base_directory, name, output, path, *rest).generate()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(Main(*sys.argv))
|
|
@ -1,122 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
# for details. All rights reserved. Use of this source code is governed by a
|
||||
# BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
from __future__ import with_statement
|
||||
import StringIO
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
from collections import deque
|
||||
|
||||
class GenerateError(Exception):
|
||||
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
def __str__(self):
|
||||
return repr(self.value)
|
||||
|
||||
|
||||
class Generator:
|
||||
|
||||
def __init__(self, base_directory, name, output, path, *includes):
|
||||
self.base_directory = base_directory
|
||||
self.name = name
|
||||
self.output = output
|
||||
self.path = path
|
||||
self.includes = set()
|
||||
for x in includes:
|
||||
self.includes.add(x)
|
||||
self.sources = []
|
||||
self.resources = []
|
||||
|
||||
def _list_files(self):
|
||||
drain = deque()
|
||||
drain.extend(self.includes)
|
||||
while len(drain) > 0:
|
||||
target = drain.popleft()
|
||||
# Avoid circular dependencies
|
||||
if target in self.resources:
|
||||
continue
|
||||
if (target.startswith("dart:")):
|
||||
continue
|
||||
self.resources.append(target)
|
||||
if (target.endswith(".dart")):
|
||||
with open(os.path.join(self.base_directory,self.path,target),"r") as fobj:
|
||||
text = fobj.read()
|
||||
file_sources = re.findall(r"#source\(['\"](?P<name>.*)['\"]\);",text)
|
||||
file_native = re.findall(r"#native\(['\"](?P<name>.*)['\"]\);",text)
|
||||
file_imports = re.findall(r"#import\(['\"](?P<name>.*)['\"]\);",text)
|
||||
self.resources.extend(file_sources)
|
||||
self.resources.extend(file_native)
|
||||
drain.extend(file_imports)
|
||||
self.sources.sort()
|
||||
self.resources.sort()
|
||||
|
||||
def _print_gypi_files(self, out, name, files):
|
||||
out.write(" '%s': [\n" % name)
|
||||
for filename in files:
|
||||
out.write(" '%s/%s',\n" % (self.path, filename))
|
||||
out.write(" ],\n")
|
||||
|
||||
def _print_ant_files(self, out, name, files):
|
||||
out.write(" <filelist id='%s' dir='%s'>\n" % (name, self.path))
|
||||
for filename in files:
|
||||
out.write(" <file name='%s'/>\n" % filename)
|
||||
out.write(" </filelist>\n")
|
||||
out.write(" <pathconvert pathsep=',' property='%s' refid='%s'>\n"
|
||||
% (name, name))
|
||||
out.write(" <map from='${basedir}/%s/' to=''/>\n" % self.path)
|
||||
out.write(" </pathconvert>\n")
|
||||
|
||||
def _make_output(self, file_name):
|
||||
if os.path.exists(file_name):
|
||||
return StringIO.StringIO()
|
||||
else:
|
||||
return file(file_name, 'w')
|
||||
|
||||
def _close(self, file_name, output):
|
||||
if not isinstance(output, StringIO.StringIO):
|
||||
output.close()
|
||||
return
|
||||
new_text = output.getvalue()
|
||||
output.close()
|
||||
with open(file_name, 'r') as f:
|
||||
old_text = f.read()
|
||||
if old_text == new_text:
|
||||
return
|
||||
sys.stderr.write('Updating %s\n' % file_name)
|
||||
with open(file_name, 'w') as f:
|
||||
f.write(new_text)
|
||||
|
||||
def generate(self):
|
||||
self._list_files()
|
||||
file_name = self.output + '.gypi';
|
||||
gypi = self._make_output(file_name)
|
||||
gypi.write("{\n 'variables': {\n")
|
||||
self._print_gypi_files(gypi, self.name + '_sources', self.sources)
|
||||
self._print_gypi_files(gypi, self.name + '_resources', self.resources)
|
||||
gypi.write(" },\n}\n")
|
||||
self._close(file_name, gypi)
|
||||
file_name = self.output + '.xml'
|
||||
ant = self._make_output(file_name)
|
||||
ant.write("<project>\n")
|
||||
self._print_ant_files(ant, self.name + '_sources', self.sources)
|
||||
self._print_ant_files(ant, self.name + '_resources', self.resources)
|
||||
ant.write("</project>\n")
|
||||
self._close(file_name, ant)
|
||||
|
||||
|
||||
def Main(script_name = None, name = None, output = None, path = None,
|
||||
*rest):
|
||||
if not path:
|
||||
raise GenerateError("usage: %s NAME OUTPUT PATH EXCLUDE_DIR_NAME ..."
|
||||
% script_name)
|
||||
base_directory = os.path.dirname(output)
|
||||
Generator(base_directory, name, output, path, *rest).generate()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(Main(*sys.argv))
|
|
@ -1,347 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.dart.compiler.CompilerConfiguration.ErrorFormat;
|
||||
import com.google.dart.compiler.util.apache.StringUtils;
|
||||
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Options that can be specified on the command line.
|
||||
*/
|
||||
public class CommandLineOptions {
|
||||
|
||||
/**
|
||||
* Command line options accepted by the {@link DartCompiler} entry point.
|
||||
*/
|
||||
public static class CompilerOptions {
|
||||
|
||||
@Option(name = "--batch", aliases = { "-batch" },
|
||||
usage = "Batch mode (for unit testing)")
|
||||
private boolean batch = false;
|
||||
|
||||
@Option(name = "--error_format",
|
||||
usage = "Format errors as normal or machine")
|
||||
private String errorFormat = "";
|
||||
|
||||
@Option(name = "--machine", //
|
||||
usage = "Print errors in a format suitable for parsing")
|
||||
private boolean machineFormat = false;
|
||||
|
||||
@Option(name = "--extended-exit-code",
|
||||
usage = "0 - clean; 1 - has warnings; 2 - has errors")
|
||||
private boolean extendedExitCode = false;
|
||||
|
||||
@Option(name = "--enable_type_checks",
|
||||
usage = "Generate runtime type checks")
|
||||
private boolean developerModeChecks = false;
|
||||
|
||||
@Option(name = "--ignore-unrecognized-flags",
|
||||
usage = "Ignore unrecognized command line flags")
|
||||
private boolean ignoreUnrecognizedFlags = false;
|
||||
|
||||
@Option(name = "--jvm-metrics-detail",
|
||||
usage = "Display summary (default) or\n verbose metrics")
|
||||
private String jvmMetricDetail = "summary";
|
||||
|
||||
@Option(name = "--jvm-metrics-format",
|
||||
usage = "Output metrics in tabular (default)\n or pretty format")
|
||||
private String jvmMetricFormat = "tabular";
|
||||
|
||||
@Option(name = "--jvm-metrics-type",
|
||||
usage = "Comma-separated list to display:\n "
|
||||
+ " all: (default) all stat types\n "
|
||||
+ " gc: show garbage collection stats\n "
|
||||
+ " mem: show memory stats\n "
|
||||
+ " jit: show jit stats")
|
||||
private String jvmMetricType = "all";
|
||||
|
||||
// leave the command line flag for legacy purposes.
|
||||
@SuppressWarnings("unused")
|
||||
@Option(name = "--noincremental",
|
||||
usage = "Disable incremental compilation (default)")
|
||||
private boolean noincremental = true; // not used, just a placeholder for arg parsing
|
||||
|
||||
@Option(name = "--incremental",
|
||||
usage = "Enable incremental compilation")
|
||||
private boolean incremental = false;
|
||||
|
||||
@Option(name = "--work", aliases = { "-out" },
|
||||
usage = "Directory to receive compiler output\n for future incremental builds")
|
||||
private File workDirectory = new File("out");
|
||||
|
||||
@Option(name = "--help", aliases = { "-?", "-help" },
|
||||
usage = "Prints this help message")
|
||||
private boolean showHelp = false;
|
||||
|
||||
@Option(name = "--jvm-metrics",
|
||||
usage = "Print jvm metrics at end of compile")
|
||||
private boolean showJvmMetrics = false;
|
||||
|
||||
@Option(name = "--metrics",
|
||||
usage = "Print compilation metrics")
|
||||
private boolean showMetrics = false;
|
||||
|
||||
@Option(name = "--fatal-type-errors", aliases = { "-fatal-type-errors" },
|
||||
usage = "Treat type errors as fatal")
|
||||
private boolean typeErrorsAreFatal = false;
|
||||
|
||||
@Option(name = "--fatal-warnings", aliases = { "-Werror" },
|
||||
usage = "Treat non-type warnings as fatal")
|
||||
private boolean warningsAreFatal = false;
|
||||
|
||||
@Option(name = "--platform",
|
||||
usage = "Platform libraries to analyze (e.g. dartium, vm, dart2js, any)")
|
||||
private String platformName = PackageLibraryManager.DEFAULT_PLATFORM;
|
||||
|
||||
@Option(name = "--dart-sdk",
|
||||
usage = "Path to dart sdk. (system property com.google.dart.sdk)")
|
||||
private File dartSdkPath = PackageLibraryManager.DEFAULT_SDK_PATH;
|
||||
|
||||
@Option(name = "--package-root",
|
||||
usage = "Root directory used for the package: scheme")
|
||||
private File packageRoot = PackageLibraryManager.DEFAULT_PACKAGE_ROOT;
|
||||
|
||||
@Option(name = "--show-sdk-warnings", usage = "show warnings from SDK source")
|
||||
private boolean showSdkWarnings = false;
|
||||
|
||||
@Option(name = "--source-from-ast",
|
||||
usage = "For debugging, reconstitute source code from the parsed AST.")
|
||||
private boolean showSourceFromAst = false;
|
||||
|
||||
@Option(name = "--resolve-on-parse-error",
|
||||
usage = "For debugging, continue on with resolution even if there are parse errors.")
|
||||
private boolean resolveDespiteParseErrors;
|
||||
|
||||
@Option(name = "--type-checks-for-inferred-types",
|
||||
usage = "[not in spec] Enables 'interface has no method/field' for receivers with inferred types.")
|
||||
private boolean typeChecksForInferredTypes = false;
|
||||
|
||||
@Option(name = "--version",
|
||||
usage = "Show analyzer version")
|
||||
private boolean showVersion = false;
|
||||
|
||||
@Argument
|
||||
private final List<String> sourceFiles = new ArrayList<String>();
|
||||
|
||||
public String getJvmMetricOptions() {
|
||||
if (!showJvmMetrics) {
|
||||
return null;
|
||||
}
|
||||
return jvmMetricDetail + ":" + jvmMetricFormat + ":" + jvmMetricType;
|
||||
}
|
||||
|
||||
public String getPlatformName() {
|
||||
return platformName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the packageRoot
|
||||
*/
|
||||
public File getPackageRoot() {
|
||||
return packageRoot;
|
||||
}
|
||||
|
||||
public File getDartSdkPath() {
|
||||
return dartSdkPath;
|
||||
}
|
||||
|
||||
public boolean extendedExitCode() {
|
||||
return extendedExitCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether warnings from SDK files should be suppressed.
|
||||
*/
|
||||
public boolean suppressSdkWarnings() {
|
||||
return !showSdkWarnings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether inferred types should be used for type checks.
|
||||
*/
|
||||
public boolean typeChecksForInferredTypes() {
|
||||
return this.typeChecksForInferredTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether "no such member" should be reported for classes which implement
|
||||
* "noSuchMethod" method.
|
||||
*/
|
||||
public boolean reportNoMemberWhenHasInterceptor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of files passed to the compiler.
|
||||
*/
|
||||
public List<String> getSourceFiles() {
|
||||
return sourceFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to receive compiler intermediate output.
|
||||
*/
|
||||
public File getWorkDirectory() {
|
||||
return workDirectory;
|
||||
}
|
||||
|
||||
public boolean ignoreUnrecognizedFlags() {
|
||||
return ignoreUnrecognizedFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the compiler should attempt to incrementally recompile.
|
||||
*/
|
||||
public boolean buildIncrementally() {
|
||||
return incremental;
|
||||
}
|
||||
|
||||
public boolean shouldBatch() {
|
||||
return batch;
|
||||
}
|
||||
|
||||
public boolean resolveDespiteParseErrors() {
|
||||
return resolveDespiteParseErrors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the compiler should print it's help message.
|
||||
*/
|
||||
public boolean showHelp() {
|
||||
return showHelp;
|
||||
}
|
||||
|
||||
public boolean showJvmMetrics() {
|
||||
return showJvmMetrics;
|
||||
}
|
||||
|
||||
public boolean showMetrics() {
|
||||
return showMetrics;
|
||||
}
|
||||
|
||||
public boolean showVersion() {
|
||||
return showVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* if <code>true</code>, run the AST back through the DartSourceVisitor to create source
|
||||
* from the parsed AST and print to stdout.
|
||||
*/
|
||||
public boolean showSourceFromAst() {
|
||||
return showSourceFromAst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether type errors are fatal.
|
||||
*/
|
||||
public boolean typeErrorsAreFatal() {
|
||||
return typeErrorsAreFatal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether warnings (excluding type warnings) are fatal.
|
||||
*/
|
||||
public boolean warningsAreFatal() {
|
||||
return warningsAreFatal;
|
||||
}
|
||||
|
||||
public boolean developerModeChecks() {
|
||||
return developerModeChecks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the format to use for printing errors
|
||||
*/
|
||||
public ErrorFormat printErrorFormat() {
|
||||
if (machineFormat) {
|
||||
return ErrorFormat.MACHINE;
|
||||
}
|
||||
|
||||
String lowerError = errorFormat.toLowerCase();
|
||||
|
||||
if ("machine".equals(lowerError)) {
|
||||
return ErrorFormat.MACHINE;
|
||||
}
|
||||
|
||||
return ErrorFormat.NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses command line options, handling the feature to ignore unrecognized
|
||||
* flags.
|
||||
*
|
||||
* If one of the options is 'ignore-unrecognized-flags', then any exceptions
|
||||
* for 'not a valid option' are suppressed.
|
||||
*
|
||||
* @param args Arguments passed from main()
|
||||
* @param parsedOptions [out parameter] parsed options
|
||||
* @throws CmdLineException Thrown if there is a problem parsing the options.
|
||||
*/
|
||||
public static CmdLineParser parse(String[] args, CompilerOptions parsedOptions)
|
||||
throws CmdLineException {
|
||||
// convert new "--name=value" into old "--name value" style
|
||||
{
|
||||
List<String> argList = Lists.newArrayList();
|
||||
for (String arg : args) {
|
||||
String[] parts = StringUtils.split(arg, '=');
|
||||
Collections.addAll(argList, parts);
|
||||
}
|
||||
args = argList.toArray(new String[argList.size()]);
|
||||
}
|
||||
|
||||
boolean ignoreUnrecognized = false;
|
||||
for (String arg : args) {
|
||||
if (arg.equals("--ignore-unrecognized-flags")) {
|
||||
ignoreUnrecognized = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignoreUnrecognized) {
|
||||
CmdLineParser cmdLineParser = new CmdLineParser(parsedOptions);
|
||||
cmdLineParser.parseArgument(args);
|
||||
return cmdLineParser;
|
||||
}
|
||||
CmdLineParser cmdLineParser = new CmdLineParser(parsedOptions);
|
||||
for (int i = 0, len = args.length; i < len; i++) {
|
||||
try {
|
||||
cmdLineParser.parseArgument(args);
|
||||
} catch (CmdLineException e) {
|
||||
String msg = e.getMessage();
|
||||
|
||||
if (e.getMessage().endsWith(" is not a valid option")) {
|
||||
String option = msg.substring(1);
|
||||
int closeQuote = option.indexOf('\"');
|
||||
option = option.substring(0, closeQuote);
|
||||
List<String> newArgs = Lists.newArrayList();
|
||||
for (String arg : args) {
|
||||
if (arg.equals(option)) {
|
||||
System.out.println("(Ignoring unrecognized flag: " + arg + ")");
|
||||
continue;
|
||||
}
|
||||
newArgs.add(arg);
|
||||
}
|
||||
args = newArgs.toArray(new String[newArgs.size()]);
|
||||
cmdLineParser = new CmdLineParser(parsedOptions);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return cmdLineParser;
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.dart.compiler.CommandLineOptions.CompilerOptions;
|
||||
import com.google.dart.compiler.metrics.CompilerMetrics;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A configuration for the Dart compiler specifying which phases will be executed.
|
||||
*/
|
||||
public interface CompilerConfiguration {
|
||||
|
||||
enum ErrorFormat {
|
||||
NORMAL, // Library/File, line, message
|
||||
MACHINE, // All information including severity, subsystem, etc
|
||||
}
|
||||
|
||||
List<DartCompilationPhase> getPhases();
|
||||
|
||||
/**
|
||||
* Indicates whether developer-mode runtime checks are needed.
|
||||
* @return true if developer-mode checks should be inserted, false if not
|
||||
*/
|
||||
boolean developerModeChecks();
|
||||
|
||||
/**
|
||||
* Returns the {@link CompilerMetrics} instance or <code>null</code> if metrics should not be
|
||||
* recorded.
|
||||
*
|
||||
* @return the metrics instance, <code>null</code> if metrics should not be recorded
|
||||
*/
|
||||
CompilerMetrics getCompilerMetrics();
|
||||
|
||||
/**
|
||||
* Returns a comma-separated string list of options for displaying jvm metrics.
|
||||
* Returns <code>null</code> if jvm metrics are not enabled.
|
||||
*/
|
||||
String getJvmMetricOptions();
|
||||
|
||||
boolean typeErrorsAreFatal();
|
||||
|
||||
boolean warningsAreFatal();
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the compiler should try to resolve
|
||||
* even after having seen parse-errors.
|
||||
*/
|
||||
boolean resolveDespiteParseErrors();
|
||||
|
||||
/**
|
||||
* Temporary flag to turn on incremental compilation. This will be removed once we're certain
|
||||
* incremental compilation is correct.
|
||||
*/
|
||||
boolean incremental();
|
||||
|
||||
/**
|
||||
* The work directory where incremental build output is stored between invocations.
|
||||
*/
|
||||
File getOutputDirectory();
|
||||
|
||||
/**
|
||||
* Returns the error formatting the compiler should print with
|
||||
*/
|
||||
ErrorFormat printErrorFormat();
|
||||
|
||||
/**
|
||||
* Return the system library corresponding to the specified "dart:<libname>" spec.
|
||||
*/
|
||||
LibrarySource getSystemLibraryFor(String importSpec);
|
||||
|
||||
/**
|
||||
* Return the system library manager
|
||||
*/
|
||||
PackageLibraryManager getPackageLibraryManager();
|
||||
|
||||
/**
|
||||
* Return {@link CompilerOptions} instance.
|
||||
* @return command line options passed to the compiler.
|
||||
*/
|
||||
CompilerOptions getCompilerOptions();
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* Abstract class that {@link DartCompiler} consumers can use to specify where
|
||||
* generated files are located.
|
||||
*/
|
||||
public abstract class DartArtifactProvider {
|
||||
|
||||
/**
|
||||
* Gets a reader for an artifact associated with the specified source, which
|
||||
* must have been written to {@link #getArtifactWriter(Source, String, String)}. The
|
||||
* caller is responsible for closing the reader. Only one artifact may be
|
||||
* associated with the given extension.
|
||||
*
|
||||
* @param source the source file (not <code>null</code>)
|
||||
* @param part a component of the source file to get a reader for (may be empty).
|
||||
* @param extension the file extension for this artifact (not
|
||||
* <code>null</code>, not empty)
|
||||
* @return the reader, or <code>null</code> if there is no such artifact
|
||||
*/
|
||||
public abstract Reader getArtifactReader(Source source, String part, String extension)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Gets the {@link URI} for an artifact associated with this source.
|
||||
*
|
||||
* @param source the source file (not <code>null</code>)
|
||||
* @param part a component of the source file to get a reader for (may be empty).
|
||||
* @param extension the file extension for this artifact (not
|
||||
* <code>null</code>, not empty)
|
||||
*/
|
||||
public abstract URI getArtifactUri(Source source, String part, String extension);
|
||||
|
||||
/**
|
||||
* Gets a writer for an artifact associated with this source. The caller is
|
||||
* responsible for closing the writer. Only one artifact may be associated
|
||||
* with the given extension.
|
||||
*
|
||||
* @param source the source file (not <code>null</code>)
|
||||
* @param part a component of the source file to get a reader for (may be empty).
|
||||
* @param extension the file extension for this artifact (not
|
||||
* <code>null</code>, not empty)
|
||||
*/
|
||||
public abstract Writer getArtifactWriter(Source source, String part, String extension)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Determines whether an artifact for the specified source is out of date
|
||||
* with respect to some other source.
|
||||
*
|
||||
* @param source the source file to check (not <code>null</code>)
|
||||
* @param base the artifact's base source (not <code>null</code>)
|
||||
* @param extension the file extension for this artifact (not
|
||||
* <code>null</code>, not empty)
|
||||
* @return <code>true</code> if out of date
|
||||
*/
|
||||
public abstract boolean isOutOfDate(Source source, Source base, String extension);
|
||||
}
|
|
@ -1,191 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.dart.compiler.common.HasSourceInfo;
|
||||
import com.google.dart.compiler.common.SourceInfo;
|
||||
import com.google.dart.compiler.parser.DartScanner.Location;
|
||||
|
||||
/**
|
||||
* Information about a compilation error.
|
||||
*
|
||||
* @see DartCompilerListener
|
||||
*/
|
||||
public class DartCompilationError {
|
||||
|
||||
/**
|
||||
* The character offset from the beginning of the source (zero based) where the error occurred.
|
||||
*/
|
||||
private int offset = 0;
|
||||
|
||||
/**
|
||||
* The number of characters from the startPosition to the end of the source which encompasses the
|
||||
* compilation error.
|
||||
*/
|
||||
private int length = 0;
|
||||
|
||||
/**
|
||||
* The line number in the source (one based) where the error occurred or -1 if it is undefined.
|
||||
*/
|
||||
private int lineNumber = -1;
|
||||
|
||||
/**
|
||||
* The column number in the source (one based) where the error occurred or -1 if it is undefined.
|
||||
*/
|
||||
private int columnNumber = -1;
|
||||
|
||||
/**
|
||||
* The error code associated with the error.
|
||||
*/
|
||||
private ErrorCode errorCode;
|
||||
|
||||
/**
|
||||
* The compilation error message.
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* The source in which the error occurred or <code>null</code> if unknown.
|
||||
*/
|
||||
private Source source;
|
||||
|
||||
/**
|
||||
* Compilation error for the specified {@link Source}, without location.
|
||||
*
|
||||
* @param source the {@link Source} for which the exception occurred
|
||||
* @param errorCode the {@link ErrorCode} to be associated with this error
|
||||
* @param arguments the arguments used to build the error message
|
||||
*/
|
||||
public DartCompilationError(Source source, ErrorCode errorCode, Object... arguments) {
|
||||
this.source = source;
|
||||
this.errorCode = errorCode;
|
||||
this.message = String.format(errorCode.getMessage(), arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compilation error at the {@link SourceInfo} from specified {@link HasSourceInfo}.
|
||||
*
|
||||
* @param hasSourceInfo the provider of {@link SourceInfo} where the error occurred
|
||||
* @param errorCode the {@link ErrorCode} to be associated with this error
|
||||
* @param arguments the arguments used to build the error message
|
||||
*/
|
||||
public DartCompilationError(HasSourceInfo hasSourceInfo, ErrorCode errorCode, Object... arguments) {
|
||||
this(hasSourceInfo.getSourceInfo(), errorCode, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compilation error at the specified {@link SourceInfo}.
|
||||
*
|
||||
* @param sourceInfo the {@link SourceInfo} where the error occurred
|
||||
* @param errorCode the {@link ErrorCode} to be associated with this error
|
||||
* @param arguments the arguments used to build the error message
|
||||
*/
|
||||
public DartCompilationError(SourceInfo sourceInfo, ErrorCode errorCode, Object... arguments) {
|
||||
this.source = sourceInfo.getSource();
|
||||
this.lineNumber = sourceInfo.getLine();
|
||||
this.columnNumber = sourceInfo.getColumn();
|
||||
this.offset = sourceInfo.getOffset();
|
||||
this.length = sourceInfo.getLength();
|
||||
this.errorCode = errorCode;
|
||||
this.message = String.format(errorCode.getMessage(), arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate a new instance representing a compilation error at the specified location.
|
||||
*
|
||||
* @param source the source reference
|
||||
* @param location the source range where the error occurred
|
||||
* @param errorCode the error code to be associated with this error
|
||||
* @param arguments the arguments used to build the error message
|
||||
*/
|
||||
public DartCompilationError(Source source,
|
||||
Location location,
|
||||
ErrorCode errorCode,
|
||||
Object... arguments) {
|
||||
this.source = source;
|
||||
this.errorCode = errorCode;
|
||||
this.message = String.format(errorCode.getMessage(), arguments);
|
||||
if (location != null) {
|
||||
offset = location.getBegin();
|
||||
SourceInfo sourceInfo = new SourceInfo(source, offset, 0);
|
||||
lineNumber = sourceInfo.getLine();
|
||||
columnNumber = sourceInfo.getColumn();
|
||||
length = location.getEnd() - offset;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The column number in the source (one based) where the error occurred.
|
||||
*/
|
||||
public int getColumnNumber() {
|
||||
return columnNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the error code associated with the error.
|
||||
*/
|
||||
public ErrorCode getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* The line number in the source (one based) where the error occurred.
|
||||
*/
|
||||
public int getLineNumber() {
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* The compilation error message.
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the source in which the error occurred or <code>null</code> if unknown.
|
||||
*/
|
||||
public Source getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* The character offset from the beginning of the source (zero based) where the error occurred.
|
||||
*/
|
||||
public int getStartPosition() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* The length of the error location.
|
||||
*/
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashCode = offset;
|
||||
hashCode ^= (message != null) ? message.hashCode() : 0;
|
||||
hashCode ^= (source != null) ? source.getName().hashCode() : 0;
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the source in which the error occurred or <code>null</code> if unknown.
|
||||
*/
|
||||
public void setSource(Source source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append((source != null) ? source.getName() : "<unknown source>");
|
||||
sb.append("(" + lineNumber + ":" + columnNumber + "): ");
|
||||
sb.append(message);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.dart.compiler.ast.DartUnit;
|
||||
import com.google.dart.compiler.resolver.CoreTypeProvider;
|
||||
|
||||
/**
|
||||
* A compiler phase that processes a unit and possibly transforms it or reports
|
||||
* compilation errors.
|
||||
*/
|
||||
public interface DartCompilationPhase {
|
||||
|
||||
/**
|
||||
* Execute this phase on a unit.
|
||||
*
|
||||
* @param unit the program to process
|
||||
* @param context context where to report error messages
|
||||
*/
|
||||
DartUnit exec(DartUnit unit, DartCompilerContext context, CoreTypeProvider typeProvider);
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,122 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.dart.compiler.ast.LibraryUnit;
|
||||
import com.google.dart.compiler.metrics.CompilerMetrics;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* An interface used internally by the {@link DartCompiler} for determining where an artifact should
|
||||
* be generated and providing feedback during the compilation process. This is an internal compiler
|
||||
* construct and as such should not be instantiated or implemented by those outside the compiler
|
||||
* itself.
|
||||
*/
|
||||
public interface DartCompilerContext {
|
||||
|
||||
/**
|
||||
* Parse the application being compiled and return the result. The "application unit" is a
|
||||
* library that specifies an entry-point.
|
||||
*
|
||||
* This method will be removed in favor of {@link #getAppLibraryUnit()}.
|
||||
*
|
||||
* @return the parsed result (not <code>null</code>)
|
||||
*/
|
||||
LibraryUnit getApplicationUnit();
|
||||
|
||||
/**
|
||||
* Parse the application being compiled and return the result. The "app" library unit is a
|
||||
* library that specifies an entry-point.
|
||||
*
|
||||
* @return the parsed result (not <code>null</code>)
|
||||
*/
|
||||
LibraryUnit getAppLibraryUnit();
|
||||
|
||||
/**
|
||||
* Parse the specified library and return the result.
|
||||
*
|
||||
* @param lib the library to parse (not <code>null</code>)
|
||||
* @return the parsed result (not <code>null</code>)
|
||||
*/
|
||||
LibraryUnit getLibraryUnit(LibrarySource lib);
|
||||
|
||||
/**
|
||||
* Called by the compiler when a error (fatal or non-fatal) has occurred in a Dart file.
|
||||
*
|
||||
* @param event the event information (not <code>null</code>)
|
||||
*/
|
||||
void onError(DartCompilationError event);
|
||||
|
||||
/**
|
||||
* Gets a reader for an artifact associated with the specified source, which
|
||||
* must have been written to {@link #getArtifactWriter(Source, String, String)}. The
|
||||
* caller is responsible for closing the reader. Only one artifact may be
|
||||
* associated with the given extension.
|
||||
*
|
||||
* @param source the source file (not <code>null</code>)
|
||||
* @param part a component of the source file to get a reader for (may be empty).
|
||||
* @param extension the file extension for this artifact (not
|
||||
* <code>null</code>, not empty)
|
||||
* @return the reader, or <code>null</code> if no such artifact exists
|
||||
*/
|
||||
Reader getArtifactReader(Source source, String part, String extension) throws IOException;
|
||||
|
||||
/**
|
||||
* Gets the {@link URI} for an artifact associated with this source.
|
||||
*
|
||||
* @param source the source file (not <code>null</code>)
|
||||
* @param part a component of the source file to get a reader for (may be empty).
|
||||
* @param extension the file extension for this artifact (not
|
||||
* <code>null</code>, not empty)
|
||||
*/
|
||||
URI getArtifactUri(DartSource source, String part, String extension);
|
||||
|
||||
/**
|
||||
* Gets a writer for an artifact associated with this source. The caller is
|
||||
* responsible for closing the writer. Only one artifact may be associated
|
||||
* with the given extension.
|
||||
*
|
||||
* @param source the source file (not <code>null</code>)
|
||||
* @param part a component of the source file to get a reader for (may be empty).
|
||||
* @param extension the file extension for this artifact (not
|
||||
* <code>null</code>, not empty)
|
||||
*/
|
||||
Writer getArtifactWriter(Source source, String part, String extension) throws IOException;
|
||||
|
||||
/**
|
||||
* Determines whether an artifact for the specified source is out of date
|
||||
* with respect to some other source.
|
||||
*
|
||||
* @param source the source file to check (not <code>null</code>)
|
||||
* @param base the artifact's base source (not <code>null</code>)
|
||||
* @param extension the file extension for this artifact (not
|
||||
* <code>null</code>, not empty)
|
||||
* @return <code>true</code> if out of date
|
||||
*/
|
||||
boolean isOutOfDate(Source source, Source base, String extension);
|
||||
|
||||
/**
|
||||
* Returns the {@link CompilerMetrics} instance or <code>null</code> if we should not record
|
||||
* metrics.
|
||||
*
|
||||
* @return the metrics instance, <code>null</code> if metrics should not be recorded
|
||||
*/
|
||||
CompilerMetrics getCompilerMetrics();
|
||||
|
||||
/**
|
||||
* Returns the {@link CompilerConfiguration} instance.
|
||||
* @return the compiler configuration instance.
|
||||
*/
|
||||
CompilerConfiguration getCompilerConfiguration();
|
||||
|
||||
/**
|
||||
* Return the system library corresponding to the specified "dart:<libname>" spec.
|
||||
*/
|
||||
LibrarySource getSystemLibraryFor(String importSpec);
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
/**
|
||||
* Valid error codes for the errors produced by the Dart compiler.
|
||||
*/
|
||||
public enum DartCompilerErrorCode implements ErrorCode {
|
||||
CONSOLE_WEB_MIX(ErrorSeverity.INFO,
|
||||
"Libraries 'dart:io' (console apps only) and 'dart:html' (web apps only) cannot be used together"),
|
||||
DUPLICATE_IMPORTED_LIBRARY_NAME("a library with name '%s' was already imported: %s"),
|
||||
ENTRY_POINT_METHOD_CANNOT_HAVE_PARAMETERS(ErrorSeverity.WARNING,
|
||||
"Main entry point method cannot have parameters"),
|
||||
ENTRY_POINT_METHOD_MAY_NOT_BE_GETTER(ErrorSeverity.WARNING,
|
||||
"Entry point \"%s\" may not be a getter"),
|
||||
ENTRY_POINT_METHOD_MAY_NOT_BE_SETTER(ErrorSeverity.WARNING,
|
||||
"Entry point \"%s\" may not be a setter"),
|
||||
ILLEGAL_DIRECTIVES_IN_SOURCED_UNIT("This part was included by %s via a "
|
||||
+ "part directive, so cannot itself contain directives other than a 'part of' directive"),
|
||||
IO("Input/Output error: %s"),
|
||||
MIRRORS_NOT_FULLY_IMPLEMENTED(ErrorSeverity.WARNING, "dart:mirrors is not fully implemented yet"),
|
||||
MISSING_LIBRARY_DIRECTIVE_IMPORT("a library which is imported is missing a library directive: %s"),
|
||||
MISSING_LIBRARY_DIRECTIVE_EXPORT("a library which is exported is missing a library directive: %s"),
|
||||
MISSING_SOURCE("Cannot find referenced source: %s"),
|
||||
MISSING_PART_OF_DIRECTIVE("Unit is part of library '%s', but has no 'part of' directive"),
|
||||
UNIT_WAS_ALREADY_INCLUDED("Unit '%s' was already included"),
|
||||
WRONG_PART_OF_NAME(
|
||||
ErrorSeverity.WARNING,
|
||||
"This part was included by '%s' via a 'part' directive, but uses name '%s' in 'part of' directive");
|
||||
private final ErrorSeverity severity;
|
||||
private final String message;
|
||||
|
||||
/**
|
||||
* Initialize a newly created error code to have the given message and ERROR severity.
|
||||
*/
|
||||
private DartCompilerErrorCode(String message) {
|
||||
this(ErrorSeverity.ERROR, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a newly created error code to have the given severity and message.
|
||||
*/
|
||||
private DartCompilerErrorCode(ErrorSeverity severity, String message) {
|
||||
this.severity = severity;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorSeverity getErrorSeverity() {
|
||||
return severity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubSystem getSubSystem() {
|
||||
return SubSystem.COMPILER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsRecompilation() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.dart.compiler.ast.DartUnit;
|
||||
|
||||
/**
|
||||
* Interface that {@link DartCompiler} consumers can use to monitor compilation progress and report
|
||||
* various problems that occur during compilation.
|
||||
*/
|
||||
public interface DartCompilerListener {
|
||||
/**
|
||||
* Called by the compiler when a compilation error has occurred in a Dart file.
|
||||
*
|
||||
* @param event the event information (not <code>null</code>)
|
||||
*/
|
||||
void onError(DartCompilationError event);
|
||||
|
||||
/**
|
||||
* Called by the compiler before parsing given {@link DartSource}.
|
||||
*/
|
||||
void unitAboutToCompile(DartSource source, boolean diet);
|
||||
|
||||
/**
|
||||
* Called by the compiler after the resolution and type analyzer phase for each unit.
|
||||
*
|
||||
* @param unit the {@link DartUnit} having just been compiled (not <code>null</code>)
|
||||
*/
|
||||
void unitCompiled(DartUnit unit);
|
||||
|
||||
/**
|
||||
* Implementation of {@link DartCompilerListener} which does nothing.
|
||||
*/
|
||||
public static class Empty implements DartCompilerListener {
|
||||
@Override
|
||||
public void onError(DartCompilationError event) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unitAboutToCompile(DartSource source, boolean diet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unitCompiled(DartUnit unit) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instance of {@link DartCompilerListener} which does nothing.
|
||||
*/
|
||||
public static final DartCompilerListener EMPTY = new Empty();
|
||||
}
|
|
@ -1,232 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.dart.compiler.ast.DartUnit;
|
||||
import com.google.dart.compiler.ast.LibraryUnit;
|
||||
import com.google.dart.compiler.metrics.CompilerMetrics;
|
||||
import com.google.dart.compiler.parser.DartParser;
|
||||
import com.google.dart.compiler.resolver.Elements;
|
||||
import com.google.dart.compiler.resolver.ResolverErrorCode;
|
||||
import com.google.dart.compiler.resolver.TypeErrorCode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* An overall context for the Dart compiler providing an adapter and forwarding
|
||||
* mechanism for to both {@link DartArtifactProvider} and
|
||||
* {@link DartCompilerListener}. This is an internal compiler construct and as
|
||||
* such should not be instantiated or subclassed by those outside the compiler
|
||||
* itself.
|
||||
*/
|
||||
final class DartCompilerMainContext implements DartCompilerListener, DartCompilerContext {
|
||||
|
||||
private final LibrarySource lib;
|
||||
private final DartArtifactProvider provider;
|
||||
private final DartCompilerListener listener;
|
||||
private final Map<Source, List<DartCompilationError>> errors = Maps.newHashMap();
|
||||
private final AtomicInteger errorCount = new AtomicInteger(0);
|
||||
private final AtomicInteger warningCount = new AtomicInteger(0);
|
||||
private final AtomicInteger typeErrorCount = new AtomicInteger(0);
|
||||
private final AtomicBoolean filesHaveChanged = new AtomicBoolean();
|
||||
// declared volatile for thread-safety
|
||||
private volatile LibraryUnit appLibraryUnit = null;
|
||||
|
||||
private final CompilerConfiguration compilerConfiguration;
|
||||
|
||||
DartCompilerMainContext(LibrarySource lib, DartArtifactProvider provider,
|
||||
DartCompilerListener listener,
|
||||
CompilerConfiguration compilerConfiguration) {
|
||||
this.lib = lib;
|
||||
this.provider = provider;
|
||||
this.listener = listener;
|
||||
this.compilerConfiguration = compilerConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(DartCompilationError event) {
|
||||
// problems in dart:core are not interesting
|
||||
// http://code.google.com/p/dart/issues/detail?id=7128
|
||||
if (Elements.isCoreLibrarySource(event.getSource())) {
|
||||
ErrorCode ec = event.getErrorCode();
|
||||
if (ec == ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER
|
||||
|| ec == TypeErrorCode.ASSERT_BOOL
|
||||
|| ec == TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE
|
||||
|| ec == TypeErrorCode.FOR_IN_WITH_INVALID_ITERATOR_RETURN_TYPE
|
||||
|| ec == TypeErrorCode.OPERATOR_EQUALS_BOOL_RETURN_TYPE
|
||||
|| ec == TypeErrorCode.CANNOT_OVERRIDE_TYPED_MEMBER
|
||||
|| ec == TypeErrorCode.CANNOT_OVERRIDE_METHOD_NOT_SUBTYPE
|
||||
|| ec == TypeErrorCode.OPERATOR_WRONG_OPERAND_TYPE) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Remember error.
|
||||
{
|
||||
Source source = event.getSource();
|
||||
if (source != null) {
|
||||
List<DartCompilationError> sourceErrors = errors.get(source);
|
||||
if (sourceErrors == null) {
|
||||
sourceErrors = Lists.newArrayList();
|
||||
errors.put(source, sourceErrors);
|
||||
}
|
||||
sourceErrors.add(event);
|
||||
}
|
||||
}
|
||||
// Increment counters.
|
||||
if (event.getErrorCode().getSubSystem() == SubSystem.STATIC_TYPE) {
|
||||
incrementTypeErrorCount();
|
||||
}
|
||||
if (event.getErrorCode().getErrorSeverity() == ErrorSeverity.ERROR) {
|
||||
incrementErrorCount();
|
||||
} else if (event.getErrorCode().getErrorSeverity() == ErrorSeverity.WARNING) {
|
||||
incrementWarningCount();
|
||||
}
|
||||
// Notify listener.
|
||||
listener.onError(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibraryUnit getApplicationUnit() {
|
||||
return getAppLibraryUnit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibraryUnit getAppLibraryUnit() {
|
||||
// use double-checked looking pattern with use of volatile
|
||||
if (appLibraryUnit == null) {
|
||||
synchronized (this) {
|
||||
if (appLibraryUnit == null) {
|
||||
try {
|
||||
appLibraryUnit = new DartParser(lib, DartParser.read(lib), false,
|
||||
Sets.<String> newHashSet(), DartCompilerListener.EMPTY, null).preProcessLibraryDirectives(lib);
|
||||
} catch (IOException e) {
|
||||
onError(new DartCompilationError(lib, DartCompilerErrorCode.IO, e.getMessage()));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return appLibraryUnit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader getArtifactReader(Source source, String part, String extension)
|
||||
throws IOException {
|
||||
return provider.getArtifactReader(source, part, extension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getArtifactUri(DartSource source, String part, String extension) {
|
||||
return provider.getArtifactUri(source, part, extension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Writer getArtifactWriter(Source source, String part, String extension)
|
||||
throws IOException {
|
||||
return provider.getArtifactWriter(source, part, extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link DartCompilationError}s found in the given {@link Source}.
|
||||
*/
|
||||
public List<DartCompilationError> getSourceErrors(Source source) {
|
||||
List<DartCompilationError> sourceErrors = errors.get(source);
|
||||
if (sourceErrors != null) {
|
||||
return sourceErrors;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public int getErrorCount() {
|
||||
return errorCount.get();
|
||||
}
|
||||
|
||||
public int getWarningCount() {
|
||||
return warningCount.get();
|
||||
}
|
||||
|
||||
public int getTypeErrorCount() {
|
||||
return typeErrorCount.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibraryUnit getLibraryUnit(LibrarySource libSrc) {
|
||||
if (libSrc == lib) {
|
||||
return getApplicationUnit();
|
||||
}
|
||||
try {
|
||||
return new DartParser(libSrc, DartParser.read(libSrc), false,
|
||||
Sets.<String> newHashSet(), listener, null).preProcessLibraryDirectives(libSrc);
|
||||
} catch (IOException e) {
|
||||
onError(new DartCompilationError(libSrc, DartCompilerErrorCode.IO, e.getMessage()));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutOfDate(Source source, Source base, String extension) {
|
||||
return provider.isOutOfDate(source, base, extension);
|
||||
}
|
||||
|
||||
protected void incrementErrorCount() {
|
||||
errorCount.incrementAndGet();
|
||||
}
|
||||
|
||||
protected void incrementWarningCount() {
|
||||
warningCount.incrementAndGet();
|
||||
}
|
||||
|
||||
protected void incrementTypeErrorCount() {
|
||||
typeErrorCount.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilerMetrics getCompilerMetrics() {
|
||||
return compilerConfiguration.getCompilerMetrics();
|
||||
}
|
||||
|
||||
public void setFilesHaveChanged() {
|
||||
filesHaveChanged.set(true);
|
||||
}
|
||||
|
||||
public boolean getFilesHaveChanged() {
|
||||
return filesHaveChanged.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilerConfiguration getCompilerConfiguration() {
|
||||
return compilerConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the system library corresponding to the specified "dart:<libname>" spec.
|
||||
*/
|
||||
@Override
|
||||
public LibrarySource getSystemLibraryFor(String importSpec) {
|
||||
return compilerConfiguration.getSystemLibraryFor(importSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unitAboutToCompile(DartSource source, boolean diet) {
|
||||
listener.unitAboutToCompile(source, diet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unitCompiled(DartUnit unit) {
|
||||
listener.unitCompiled(unit);
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
/**
|
||||
* Abstract interface to Dart source.
|
||||
*/
|
||||
public interface DartSource extends Source {
|
||||
|
||||
/**
|
||||
* Gets the library with which this Dart source is associated.
|
||||
*/
|
||||
LibrarySource getLibrary();
|
||||
|
||||
/**
|
||||
* Gets the path of this source, relative to its library.
|
||||
*/
|
||||
String getRelativePath();
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.dart.compiler.CommandLineOptions.CompilerOptions;
|
||||
import com.google.dart.compiler.metrics.CompilerMetrics;
|
||||
import com.google.dart.compiler.resolver.CompileTimeConstantAnalyzer;
|
||||
import com.google.dart.compiler.resolver.Resolver;
|
||||
import com.google.dart.compiler.type.TypeAnalyzer;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A configuration for the Dart compiler specifying which phases will be executed.
|
||||
*/
|
||||
public class DefaultCompilerConfiguration implements CompilerConfiguration {
|
||||
|
||||
private final CompilerOptions compilerOptions;
|
||||
|
||||
private final CompilerMetrics compilerMetrics;
|
||||
|
||||
private final PackageLibraryManager packageLibraryManager;
|
||||
|
||||
|
||||
/**
|
||||
* A default configuration.
|
||||
*/
|
||||
public DefaultCompilerConfiguration() {
|
||||
this(new CompilerOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* A new instance with the specified {@link CompilerOptions}.
|
||||
*/
|
||||
public DefaultCompilerConfiguration(CompilerOptions compilerOptions) {
|
||||
this(compilerOptions, new PackageLibraryManager(compilerOptions.getDartSdkPath(),
|
||||
compilerOptions.getPlatformName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* A new instance with the specified options and system library manager.
|
||||
*/
|
||||
public DefaultCompilerConfiguration(CompilerOptions compilerOptions,
|
||||
PackageLibraryManager libraryManager) {
|
||||
this.compilerOptions = compilerOptions;
|
||||
this.compilerMetrics = compilerOptions.showMetrics() ? new CompilerMetrics() : null;
|
||||
this.packageLibraryManager = libraryManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DartCompilationPhase> getPhases() {
|
||||
List<DartCompilationPhase> phases = new ArrayList<DartCompilationPhase>();
|
||||
phases.add(new Resolver.Phase());
|
||||
phases.add(new CompileTimeConstantAnalyzer.Phase());
|
||||
phases.add(new TypeAnalyzer());
|
||||
return phases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean developerModeChecks() {
|
||||
return compilerOptions.developerModeChecks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilerMetrics getCompilerMetrics() {
|
||||
return compilerMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJvmMetricOptions() {
|
||||
return compilerOptions.getJvmMetricOptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean typeErrorsAreFatal() {
|
||||
return compilerOptions.typeErrorsAreFatal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean warningsAreFatal() {
|
||||
return compilerOptions.warningsAreFatal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resolveDespiteParseErrors() {
|
||||
return compilerOptions.resolveDespiteParseErrors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean incremental() {
|
||||
return compilerOptions.buildIncrementally();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getOutputDirectory() {
|
||||
return compilerOptions.getWorkDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibrarySource getSystemLibraryFor(String importSpec) {
|
||||
URI systemUri;
|
||||
try {
|
||||
systemUri = new URI(importSpec);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// Verify the dart system library exists
|
||||
if( null == this.packageLibraryManager.expandRelativeDartUri(systemUri) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Ensure we are using the short form if it exists
|
||||
URI shortUri = packageLibraryManager.getShortUri(systemUri);
|
||||
if (shortUri != null) {
|
||||
systemUri = shortUri;
|
||||
}
|
||||
|
||||
return new UrlLibrarySource(systemUri, this.packageLibraryManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilerOptions getCompilerOptions() {
|
||||
return compilerOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorFormat printErrorFormat() {
|
||||
return compilerOptions.printErrorFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageLibraryManager getPackageLibraryManager() {
|
||||
return packageLibraryManager;
|
||||
}
|
||||
}
|
|
@ -1,235 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* A default implementation of {@link DartArtifactProvider} specifying
|
||||
* generated files be placed in the same directory as source files.
|
||||
*/
|
||||
public class DefaultDartArtifactProvider extends DartArtifactProvider {
|
||||
|
||||
private final File outputDirectory;
|
||||
|
||||
public DefaultDartArtifactProvider() {
|
||||
this(new File("out"));
|
||||
}
|
||||
|
||||
public DefaultDartArtifactProvider(File outputDirectory) {
|
||||
this.outputDirectory = outputDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader getArtifactReader(Source source, String part, String extension)
|
||||
throws IOException {
|
||||
if (PackageLibraryManager.isDartUri(source.getUri())) {
|
||||
DartSource bundledSource = getBundledArtifact(source, source, part, extension);
|
||||
if (bundledSource != null) {
|
||||
Reader reader = null;
|
||||
try {
|
||||
reader = bundledSource.getSourceReader();
|
||||
} catch (FileNotFoundException e) {
|
||||
/* thrown if file doesn't exist, which is fine */
|
||||
}
|
||||
if (reader != null) {
|
||||
return new BufferedReader(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
File file = getArtifactFile(source, part, extension);
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
return new BufferedReader(new FileReader(file));
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getArtifactUri(Source source, String part, String extension) {
|
||||
try {
|
||||
return new URI("file", getArtifactFile(source, part, extension).getPath(), null);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Writer getArtifactWriter(Source source, String part, String extension) throws IOException {
|
||||
return new BufferedWriter(new FileWriter(makeDirectories(getArtifactFile(source, part,
|
||||
extension))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutOfDate(Source source, Source base, String extension) {
|
||||
if (PackageLibraryManager.isDartUri(base.getUri())) {
|
||||
Source bundledSource = getBundledArtifact(source, base, "", extension);
|
||||
if (bundledSource != null && bundledSource.exists()) {
|
||||
// Note: Artifacts bundled with sources are always up to date
|
||||
return false;
|
||||
}
|
||||
}
|
||||
File artifactFile = getArtifactFile(base, "", extension);
|
||||
return !artifactFile.exists() || artifactFile.lastModified() < source.getLastModified();
|
||||
}
|
||||
|
||||
// TODO(jbrosenberg): remove 'source' argument from this method, it's not used
|
||||
protected DartSource getBundledArtifact(Source source, Source base, String part, String extension) {
|
||||
LibrarySource library;
|
||||
URI relativeUri;
|
||||
if (base instanceof LibrarySource) {
|
||||
library = (LibrarySource) base;
|
||||
relativeUri = library.getUri().resolve(".").normalize().relativize(base.getUri());
|
||||
} else if (base instanceof DartSource){
|
||||
library = ((DartSource) base).getLibrary();
|
||||
String name = base.getName();
|
||||
URI nameUri = URI.create(name).normalize();
|
||||
relativeUri = library.getUri().resolve(".").normalize().relativize(nameUri);
|
||||
} else {
|
||||
throw new AssertionError(base.getClass().getName());
|
||||
}
|
||||
|
||||
DartSource bundledSource;
|
||||
if (!relativeUri.isAbsolute()) {
|
||||
bundledSource = library.getSourceFor(fullname(relativeUri.getPath(), part, extension));
|
||||
} else {
|
||||
bundledSource = null;
|
||||
}
|
||||
return bundledSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer the artifact file associated with the specified source. Only one
|
||||
* artifact may be associated with the given extension.
|
||||
*
|
||||
* @param source the source file (not <code>null</code>)
|
||||
* @param part a component of the source file to get a reader for (may be empty).
|
||||
* @param extension the file extension for this artifact (not
|
||||
* <code>null</code>, not empty)
|
||||
* @return the artifact file (not <code>null</code>)
|
||||
*/
|
||||
protected File getArtifactFile(Source source, String part, String extension) {
|
||||
String name = source.getName();
|
||||
name = URI.create(name).normalize().toString();
|
||||
name = normalizeArtifactName(name);
|
||||
File file = new File(outputDirectory, fullname(name, part, extension));
|
||||
return file;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes extraneous punctuation and file path syntax.
|
||||
*/
|
||||
private String normalizeArtifactName(String name) {
|
||||
/**
|
||||
* For efficiency, String operations are replaced with a single pass over
|
||||
* the character array data.
|
||||
*
|
||||
* Note: This is a refactor of a previous version which used repeated calls
|
||||
* to String.replace(), which turns out to be unnecessarily expensive. This
|
||||
* particular method has been identified as being called a large number of
|
||||
* times, thus the need for the micro-optimization here.
|
||||
*
|
||||
* This is the original logic being implemented here:
|
||||
*
|
||||
* <code>
|
||||
* name = name.replace("//", File.separator);
|
||||
* name = name.replace(":", "");
|
||||
* name = name.replace("!", "");
|
||||
* name = name.replace("..", "_");
|
||||
* </code>
|
||||
*
|
||||
* Please update the above if the logic being implemented ever changes.
|
||||
*
|
||||
* TODO(jbrosenberg): Figure out a better way such that this normalization
|
||||
* is no longer needed in the first place. Source objects could be built
|
||||
* from pre-normalized prefixes, etc. Or if it can be called less often,
|
||||
* then use pre-compiled Patterns and Matchers instead.
|
||||
*/
|
||||
boolean lastCharWasSlash = false;
|
||||
boolean lastCharWasPeriod = false;
|
||||
boolean madeChanges = false;
|
||||
int nameLen = name.length();
|
||||
char[] newName = new char[nameLen];
|
||||
int idx = 0;
|
||||
for (char ch : name.toCharArray()) {
|
||||
if (lastCharWasPeriod && ch != '.') {
|
||||
// didn't get a second period, so append the one we did get
|
||||
newName[idx++] = '.';
|
||||
lastCharWasPeriod = false;
|
||||
} else if (lastCharWasSlash && ch != '/') {
|
||||
// didn't get a second slash, so append the one we did get
|
||||
newName[idx++] = '/';
|
||||
lastCharWasSlash = false;
|
||||
}
|
||||
|
||||
switch (ch) {
|
||||
case ':':
|
||||
case '!':
|
||||
// replace ':'s and '!'s with empty string
|
||||
madeChanges = true;
|
||||
break;
|
||||
case '/':
|
||||
if (lastCharWasSlash) {
|
||||
// got a second slash, replace with File.separatorChar
|
||||
madeChanges = true;
|
||||
newName[idx++] = File.separatorChar;
|
||||
lastCharWasSlash = false;
|
||||
} else {
|
||||
lastCharWasSlash = true;
|
||||
}
|
||||
break;
|
||||
case '.':
|
||||
if (lastCharWasPeriod) {
|
||||
// got a second period, replace with a '_'
|
||||
madeChanges = true;
|
||||
newName[idx++] = ('_');
|
||||
lastCharWasPeriod = false;
|
||||
} else {
|
||||
lastCharWasPeriod = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
newName[idx++] = ch;
|
||||
lastCharWasSlash = false;
|
||||
lastCharWasPeriod = false;
|
||||
}
|
||||
}
|
||||
if (lastCharWasPeriod) {
|
||||
// didn't get a final second period, so append the one we did get
|
||||
newName[idx++] = '.';
|
||||
} else if (lastCharWasSlash) {
|
||||
// didn't get a final second slash, so append the one we did get
|
||||
newName[idx++] = '/';
|
||||
}
|
||||
|
||||
if (madeChanges) {
|
||||
name = new String(newName, 0, idx);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
private File makeDirectories(File file) {
|
||||
file.getParentFile().mkdirs();
|
||||
return file;
|
||||
}
|
||||
|
||||
private String fullname(String name, String part, String extension) {
|
||||
if (part.isEmpty()) {
|
||||
return name + "." + extension;
|
||||
} else {
|
||||
return name + "$" + part + "." + extension;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.dart.compiler.CompilerConfiguration.ErrorFormat;
|
||||
import com.google.dart.compiler.ast.DartUnit;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
/**
|
||||
* A default implementation of {@link DartCompilerListener} which counts
|
||||
* compilation errors.
|
||||
*/
|
||||
public class DefaultDartCompilerListener implements DartCompilerListener {
|
||||
|
||||
/**
|
||||
* The number of (fatal) problems that occurred during compilation.
|
||||
*/
|
||||
private int errorCount = 0;
|
||||
|
||||
/**
|
||||
* The number of (non-fatal) problems that occurred during compilation.
|
||||
*/
|
||||
private int warningCount = 0;
|
||||
|
||||
/**
|
||||
* The number of (non-fatal) problems that occurred during compilation.
|
||||
*/
|
||||
private int typeErrorCount = 0;
|
||||
|
||||
/**
|
||||
* Formatter used to report error messages. Marked protected so that
|
||||
* subclasses can override it (e.g. for a test server using HTML formatting).
|
||||
*/
|
||||
protected final ErrorFormatter formatter;
|
||||
|
||||
public DefaultDartCompilerListener(ErrorFormat errorFormat) {
|
||||
this(System.err, errorFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param outputStream the {@link PrintStream} to use for {@link ErrorFormatter}.
|
||||
*/
|
||||
public DefaultDartCompilerListener(PrintStream outputStream, ErrorFormat errorFormat) {
|
||||
formatter = new PrettyErrorFormatter(outputStream, useColor(), errorFormat);
|
||||
}
|
||||
|
||||
private boolean useColor() {
|
||||
return String.valueOf(System.getenv("TERM")).startsWith("xterm") && System.console() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer the number of fatal errors that occurred during compilation.
|
||||
*
|
||||
* @return the number of problems
|
||||
*/
|
||||
public int getErrorCount() {
|
||||
return errorCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer the number of non-fatal warnings that occurred during compilation.
|
||||
*
|
||||
* @return the number of problems
|
||||
*/
|
||||
public int getWarningCount() {
|
||||
return warningCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer the number of non-fatal type problems that occurred during compilation.
|
||||
*
|
||||
* @return the number of problems
|
||||
*/
|
||||
public int getTypeErrorCount() {
|
||||
return typeErrorCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the {@link #errorCount} by 1
|
||||
*/
|
||||
protected void incrementErrorCount() {
|
||||
errorCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the {@link #warningCount} by 1
|
||||
*/
|
||||
protected void incrementWarningCount() {
|
||||
warningCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the {@link #typeErrorCount} by 1
|
||||
*/
|
||||
protected void incrementTypeErrorCount() {
|
||||
typeErrorCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(DartCompilationError event) {
|
||||
formatter.format(event);
|
||||
if (event.getErrorCode().getSubSystem() == SubSystem.STATIC_TYPE) {
|
||||
incrementTypeErrorCount();
|
||||
} else if (event.getErrorCode().getErrorSeverity() == ErrorSeverity.ERROR) {
|
||||
incrementErrorCount();
|
||||
} else if (event.getErrorCode().getErrorSeverity() == ErrorSeverity.WARNING) {
|
||||
incrementWarningCount();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unitAboutToCompile(DartSource source, boolean diet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unitCompiled(DartUnit unit) {
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.dart.compiler.CompilerConfiguration.ErrorFormat;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
/**
|
||||
* An error formatter that simply prints the file name with the line and column
|
||||
* location.
|
||||
*/
|
||||
public class DefaultErrorFormatter implements ErrorFormatter {
|
||||
protected final PrintStream outputStream;
|
||||
protected final ErrorFormat errorFormat;
|
||||
|
||||
public DefaultErrorFormatter(PrintStream outputStream, ErrorFormat errorFormat) {
|
||||
this.outputStream = outputStream;
|
||||
this.errorFormat = errorFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void format(DartCompilationError event) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
appendError(buf, event);
|
||||
outputStream.print(buf);
|
||||
outputStream.print("\n");
|
||||
}
|
||||
|
||||
protected void appendError(StringBuilder buf, DartCompilationError error) {
|
||||
Source source = error.getSource();
|
||||
String sourceName = getSourceName(source);
|
||||
int line = error.getLineNumber();
|
||||
int col = error.getColumnNumber();
|
||||
int length = error.getLength();
|
||||
if (errorFormat == ErrorFormat.MACHINE) {
|
||||
buf.append(String.format(
|
||||
"%s|%s|%s|%s|%d|%d|%d|%s",
|
||||
escapePipe(error.getErrorCode().getErrorSeverity().toString()),
|
||||
escapePipe(error.getErrorCode().getSubSystem().toString()),
|
||||
escapePipe(error.getErrorCode().toString()),
|
||||
escapePipe(sourceName),
|
||||
line,
|
||||
col,
|
||||
length,
|
||||
escapePipe(error.getMessage())));
|
||||
} else {
|
||||
String includeFrom = getImportString(source);
|
||||
buf.append(String.format(
|
||||
"%s:%d:%d: %s%s",
|
||||
sourceName,
|
||||
line,
|
||||
col,
|
||||
error.getMessage(),
|
||||
includeFrom));
|
||||
}
|
||||
}
|
||||
|
||||
protected static String getImportString(Source sourceFile) {
|
||||
String includeFrom = "";
|
||||
if (sourceFile instanceof DartSource) {
|
||||
LibrarySource lib = ((DartSource) sourceFile).getLibrary();
|
||||
if (lib != null && !Objects.equal(sourceFile.getUri(), lib.getUri())) {
|
||||
includeFrom = " (sourced from " + lib.getUri() + ")";
|
||||
}
|
||||
}
|
||||
return includeFrom;
|
||||
}
|
||||
|
||||
protected static String getSourceName(Source source) {
|
||||
if (source instanceof UrlDartSource) {
|
||||
return source.getUri().toString();
|
||||
}
|
||||
if (source != null) {
|
||||
return source.getName();
|
||||
}
|
||||
return "<unknown-source-file>";
|
||||
}
|
||||
|
||||
protected static String escapePipe(String input) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (char c : input.toCharArray()) {
|
||||
if (c == '\\' || c == '|') {
|
||||
result.append('\\');
|
||||
}
|
||||
result.append(c);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
|
@ -1,202 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.dart.compiler.util.DartSourceString;
|
||||
import com.google.dart.compiler.util.Lists;
|
||||
import com.google.dart.compiler.util.Paths;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Create a default app library specification when compiling a single dart file.
|
||||
*
|
||||
* @author johnlenz@google.com (John Lenz)
|
||||
*/
|
||||
public class DefaultLibrarySource extends UrlSource implements LibrarySource {
|
||||
private static final String WRAPPED_NAME_PREFIX = "_DefaultLibrarySource.wrapper.";
|
||||
private final File sourceFile;
|
||||
private final Map<String, DartSource> sources;
|
||||
private final Map<String, LibrarySource> imports;
|
||||
private String source;
|
||||
private String wrappedName;
|
||||
|
||||
// TODO: Deprecated
|
||||
public DefaultLibrarySource(List<String> sources, String entryPoint) {
|
||||
this(sources.get(0), Paths.toFiles(sources), entryPoint);
|
||||
}
|
||||
|
||||
// TODO: Deprecated
|
||||
public DefaultLibrarySource(List<String> sources, List<String> imports, String entryPoint) {
|
||||
this(sources.get(0), Paths.toFiles(sources), Paths.toFiles(imports), entryPoint);
|
||||
}
|
||||
|
||||
// TODO: Deprecated
|
||||
public DefaultLibrarySource(File sourceFile, String entryPoint) {
|
||||
this(sourceFile.getName(), Lists.<File> create(sourceFile),
|
||||
Lists.<File> create(), entryPoint);
|
||||
}
|
||||
|
||||
public DefaultLibrarySource(String appName, List<File> sourceFiles, String entryPoint) {
|
||||
this(appName, sourceFiles, Lists.<File> create(), entryPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer a new instance representing a {@link LibrarySource} with the
|
||||
* specified name and that contains the specified imports and source files.
|
||||
*
|
||||
* @param appName the application name (not <code>null</code>, not empty)
|
||||
* @param sourceFiles the source files to be included in the application (not
|
||||
* <code>null</code>, and must contain at least one file)
|
||||
* @param importFiles libraries to be imported into the application (e.g. from
|
||||
* #import directives)
|
||||
* @param entryPoint The name of the static method to call to invoke the
|
||||
* library. A synthetic main() method will be generated which wraps a call to
|
||||
* this method. Pass <code>null</code> to use the default main() method
|
||||
* lookup.
|
||||
*/
|
||||
public DefaultLibrarySource(String appName, List<File> sourceFiles, List<File> importFiles,
|
||||
String entryPoint) {
|
||||
this(sourceFiles.get(0));
|
||||
|
||||
for (File file : sourceFiles) {
|
||||
String relPath = Paths.relativePathFor(sourceFile, file);
|
||||
this.sources.put(relPath, new UrlDartSource(file, this));
|
||||
}
|
||||
for (File file : importFiles) {
|
||||
String relPath = Paths.relativePathFor(sourceFile, file);
|
||||
this.imports.put(relPath, new UrlLibrarySource(file));
|
||||
}
|
||||
wrappedName = WRAPPED_NAME_PREFIX + appName;
|
||||
source = generateSource(wrappedName, sourceFile, importFiles, sourceFiles, entryPoint);
|
||||
this.sources.put(wrappedName, new DartSourceString(wrappedName, source));
|
||||
}
|
||||
|
||||
private DefaultLibrarySource(File sourceFile) {
|
||||
super(sourceFile);
|
||||
|
||||
this.sourceFile = sourceFile;
|
||||
this.sources = new HashMap<String, DartSource>();
|
||||
this.imports = new HashMap<String, LibrarySource>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate source declaring a library. An app library will specify a
|
||||
* non-<code>null</code> entryPoint.
|
||||
*
|
||||
* @param name the name of the application or library
|
||||
* @param imports a collection of relative paths indicating the libraries
|
||||
* imported by this application or library
|
||||
* @param sources a collection of relative paths indicating the dart sources
|
||||
* included in this application or library
|
||||
* @param entryPoint The name of the static method to call to invoke the
|
||||
* library. A synthetic main() method will be generated which wraps a call to
|
||||
* this method. Pass <code>null</code> to use the default main() method
|
||||
* lookup.
|
||||
* @return the source (not <code>null</code>)
|
||||
*/
|
||||
public static String generateSource(String name, List<String> imports,
|
||||
List<String> sources, String entryPoint) {
|
||||
return generateSource(name, new File(name), Paths.toFiles(imports),
|
||||
Paths.toFiles(sources), entryPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate source declaring a library. If an entryPoint is provided a main()
|
||||
* method will be synthesized which wraps a call to the provided entryPoint
|
||||
* method.
|
||||
*
|
||||
* @param name the name of the application or library
|
||||
* @param baseFile the application or library file that will contain this
|
||||
* source or any file in that same directory (not <code>null</code>,
|
||||
* but does not need to exist)
|
||||
* @param importFiles a collection of library files imported by this
|
||||
* application or library
|
||||
* @param sourceFiles a collection of dart source files included in this
|
||||
* application or library
|
||||
* @param entryPoint The name of the static method to call to invoke the
|
||||
* library. A synthetic main() method will be generated which wraps a call to
|
||||
* this method. Pass <code>null</code> to use the default main() method
|
||||
* lookup.
|
||||
* @return the source (not <code>null</code>)
|
||||
*/
|
||||
public static String generateSource(String name, File baseFile, List<File> importFiles,
|
||||
List<File> sourceFiles, String entryPoint) {
|
||||
StringWriter sw = new StringWriter(200);
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
pw.println("library " + name + ";");
|
||||
if (importFiles != null) {
|
||||
for (File file : importFiles) {
|
||||
String relPath = file.getPath();
|
||||
if (!relPath.startsWith("dart:")) {
|
||||
relPath = Paths.relativePathFor(baseFile, file);
|
||||
}
|
||||
if (relPath != null) {
|
||||
pw.println("import '" + relPath + "';");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sourceFiles != null) {
|
||||
for (File file : sourceFiles) {
|
||||
String relPath = Paths.relativePathFor(baseFile, file);
|
||||
if (relPath != null) {
|
||||
pw.println("part '" + relPath + "';");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entryPoint != null) {
|
||||
// synthesize a main method, which wraps the entryPoint method call
|
||||
pw.println();
|
||||
pw.println(DartCompiler.MAIN_ENTRY_POINT_NAME + "() {");
|
||||
pw.println(" " + entryPoint + "();");
|
||||
pw.println("}");
|
||||
}
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader getSourceReader() {
|
||||
return new StringReader(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueIdentifier() {
|
||||
return "string://" + wrappedName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getUri() {
|
||||
try {
|
||||
// A bogus uri (but which ends with our wrappedName)
|
||||
return new URI("string://" + wrappedName);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return wrappedName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibrarySource getImportFor(String relPath) {
|
||||
return imports.get(relPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DartSource getSourceFor(String relPath) {
|
||||
return sources.get(relPath);
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.dart.compiler.CommandLineOptions.CompilerOptions;
|
||||
import com.google.dart.compiler.metrics.CompilerMetrics;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides a way to override a specific method of an existing instance of a CompilerConfiguration.
|
||||
*
|
||||
* @author zundel@google.com (Eric Ayers)
|
||||
*/
|
||||
public class DelegatingCompilerConfiguration implements CompilerConfiguration {
|
||||
|
||||
private CompilerConfiguration delegate;
|
||||
|
||||
public DelegatingCompilerConfiguration(CompilerConfiguration delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean developerModeChecks() {
|
||||
return delegate.developerModeChecks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DartCompilationPhase> getPhases() {
|
||||
return delegate.getPhases();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilerMetrics getCompilerMetrics() {
|
||||
return delegate.getCompilerMetrics();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJvmMetricOptions() {
|
||||
return delegate.getJvmMetricOptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean typeErrorsAreFatal() {
|
||||
return delegate.typeErrorsAreFatal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean warningsAreFatal() {
|
||||
return delegate.warningsAreFatal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resolveDespiteParseErrors() {
|
||||
return delegate.resolveDespiteParseErrors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean incremental() {
|
||||
return delegate.incremental();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getOutputDirectory() {
|
||||
return delegate.getOutputDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibrarySource getSystemLibraryFor(String importSpec) {
|
||||
return delegate.getSystemLibraryFor(importSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilerOptions getCompilerOptions() {
|
||||
return delegate.getCompilerOptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorFormat printErrorFormat() {
|
||||
return delegate.printErrorFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageLibraryManager getPackageLibraryManager() {
|
||||
return delegate.getPackageLibraryManager();
|
||||
}
|
||||
}
|
|
@ -1,225 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.io.CharStreams;
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.dart.compiler.ast.DartNode;
|
||||
import com.google.dart.compiler.ast.DartUnit;
|
||||
import com.google.dart.compiler.ast.LibraryNode;
|
||||
import com.google.dart.compiler.ast.LibraryUnit;
|
||||
import com.google.dart.compiler.metrics.CompilerMetrics;
|
||||
import com.google.dart.compiler.parser.DartParser;
|
||||
import com.google.dart.compiler.resolver.CoreTypeProvider;
|
||||
import com.google.dart.compiler.resolver.CoreTypeProviderImplementation;
|
||||
import com.google.dart.compiler.resolver.Element;
|
||||
import com.google.dart.compiler.resolver.ElementKind;
|
||||
import com.google.dart.compiler.resolver.LibraryElement;
|
||||
import com.google.dart.compiler.resolver.MemberBuilder;
|
||||
import com.google.dart.compiler.resolver.Resolver;
|
||||
import com.google.dart.compiler.resolver.Scope;
|
||||
import com.google.dart.compiler.resolver.SupertypeResolver;
|
||||
import com.google.dart.compiler.resolver.TopLevelElementBuilder;
|
||||
import com.google.dart.compiler.type.TypeAnalyzer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.URI;
|
||||
|
||||
class DeltaAnalyzer {
|
||||
private final SourceDelta delta;
|
||||
private final LibraryElement enclosingLibrary;
|
||||
private final CompilerConfiguration config;
|
||||
private final DartCompilerListener listener;
|
||||
private final CoreTypeProvider typeProvider;
|
||||
private final DartCompilerContext context;
|
||||
|
||||
public DeltaAnalyzer(SourceDelta delta,
|
||||
LibraryElement enclosingLibrary,
|
||||
LibraryElement coreLibrary,
|
||||
DartNode interestNode,
|
||||
int interestStart,
|
||||
int interestLength,
|
||||
CompilerConfiguration config,
|
||||
DartCompilerListener listener) {
|
||||
this.delta = delta;
|
||||
this.enclosingLibrary = enclosingLibrary;
|
||||
this.config = config;
|
||||
this.listener = listener;
|
||||
typeProvider = new CoreTypeProviderImplementation(coreLibrary.getScope(), listener);
|
||||
this.context = new Context();
|
||||
}
|
||||
|
||||
public DartNode analyze() throws IOException {
|
||||
Source originalSource = delta.getSourceBefore();
|
||||
DartUnit unit = delta.getUnitAfter();
|
||||
if (unit == null) {
|
||||
DartSource source = delta.getSourceAfter();
|
||||
unit = getParser(source).parseUnit();
|
||||
}
|
||||
Scope scope = deltaLibraryScope(originalSource, unit);
|
||||
// We have to create supertypes and member elements for the entire unit. For example, if you're
|
||||
// doing code-completion, you are only interested in the current expression, but you may be
|
||||
// code-completing on a type that is defined outside the current class.
|
||||
new SupertypeResolver().exec(unit, context, typeProvider);
|
||||
new MemberBuilder().exec(unit, context, typeProvider);
|
||||
|
||||
// The following two phases can be narrowed down to the interest area. We currently ignore the
|
||||
// interest area, but long term, we will need to narrow down to the interest area to handle
|
||||
// very large files.
|
||||
new Resolver(context, scope, typeProvider).exec(unit);
|
||||
new TypeAnalyzer().exec(unit, context, typeProvider);
|
||||
return unit;
|
||||
}
|
||||
|
||||
private Scope deltaLibraryScope(Source originalSource, DartUnit unit) {
|
||||
// Create a library unit which holds the new unit.
|
||||
LibraryUnit libraryUnit = new LibraryUnit(makeLibrarySource("delta"));
|
||||
// Copy all the imports
|
||||
for (LibraryNode path : enclosingLibrary.getLibraryUnit().getImportPaths()) {
|
||||
libraryUnit.addImportPath(path);
|
||||
}
|
||||
for (LibraryUnit importUnit : enclosingLibrary.getLibraryUnit().getImportedLibraries()) {
|
||||
libraryUnit.addImport(importUnit, importUnit.getEntryNode());
|
||||
}
|
||||
libraryUnit.putUnit(unit);
|
||||
|
||||
// Create top-level elements for the new unit.
|
||||
new TopLevelElementBuilder().exec(libraryUnit, context);
|
||||
new TopLevelElementBuilder().fillInLibraryScope(libraryUnit, listener);
|
||||
|
||||
// Copy all the elements from the old library, except the ones declared in the original source.
|
||||
Scope scope = libraryUnit.getElement().getScope();
|
||||
for (Element member : enclosingLibrary.getMembers()) {
|
||||
if (member.getSourceInfo().getSource() != originalSource) {
|
||||
String name = member.getName();
|
||||
if (ElementKind.of(member) == ElementKind.LIBRARY) {
|
||||
name = "__library_" + ((LibraryElement) member).getLibraryUnit().getName();
|
||||
}
|
||||
scope.declareElement(name, member);
|
||||
}
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
private LibrarySource makeLibrarySource(final String name) {
|
||||
final URI uri = URI.create(name);
|
||||
return new LibrarySource() {
|
||||
@Override
|
||||
public String getUniqueIdentifier() {
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader getSourceReader() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastModified() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DartSource getSourceFor(String relPath) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibrarySource getImportFor(String relPath) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private DartParser getParser(Source source) throws IOException {
|
||||
Reader r = source.getSourceReader();
|
||||
String sourceString = CharStreams.toString(r);
|
||||
Closeables.close(r, false);
|
||||
return new DartParser(source, sourceString, false, Sets.<String>newHashSet(), listener, null);
|
||||
}
|
||||
|
||||
private class Context implements DartCompilerListener, DartCompilerContext {
|
||||
@Override
|
||||
public LibraryUnit getApplicationUnit() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibraryUnit getAppLibraryUnit() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibraryUnit getLibraryUnit(LibrarySource lib) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader getArtifactReader(Source source, String part, String extension) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getArtifactUri(DartSource source, String part, String extension) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Writer getArtifactWriter(Source source, String part, String extension) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutOfDate(Source source, Source base, String extension) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilerMetrics getCompilerMetrics() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilerConfiguration getCompilerConfiguration() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibrarySource getSystemLibraryFor(String importSpec) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(DartCompilationError event) {
|
||||
listener.onError(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unitAboutToCompile(DartSource source, boolean diet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unitCompiled(DartUnit unit) {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.dart.compiler.util.apache.StringUtils;
|
||||
|
||||
/**
|
||||
* The behavior common to objects representing error codes associated with
|
||||
* {@link DartCompilationError Dart compilation errors}.
|
||||
*/
|
||||
public interface ErrorCode {
|
||||
/**
|
||||
* Return the message template used to create the message to be displayed for this error.
|
||||
*/
|
||||
String getMessage();
|
||||
|
||||
/**
|
||||
* @return the {@link ErrorSeverity} of this error.
|
||||
*/
|
||||
ErrorSeverity getErrorSeverity();
|
||||
|
||||
/**
|
||||
* @return the {@link SubSystem} which issued this error.
|
||||
*/
|
||||
SubSystem getSubSystem();
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if this {@link ErrorCode} should cause recompilation of the source
|
||||
* during next incremental compilation.
|
||||
*/
|
||||
boolean needsRecompilation();
|
||||
|
||||
public class Helper {
|
||||
/**
|
||||
* @return the "qualified name" of the given {@link ErrorCode} enumeration, good for passing it
|
||||
* to {@link #forQualifiedName(String)}.
|
||||
*/
|
||||
public static String toQualifiedName(ErrorCode errorCode) {
|
||||
return errorCode.getClass().getCanonicalName() + "." + ((Enum<?>) errorCode).name();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link ErrorCode} enumeration constant for string from
|
||||
* {@link #toQualifiedName(ErrorCode)}.
|
||||
*/
|
||||
public static ErrorCode forQualifiedName(String qualifiedName) {
|
||||
try {
|
||||
String className = StringUtils.substringBeforeLast(qualifiedName, ".");
|
||||
String fieldName = StringUtils.substringAfterLast(qualifiedName, ".");
|
||||
Class<?> errorCodeClass = Class.forName(className);
|
||||
return (ErrorCode) errorCodeClass.getField(fieldName).get(null);
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
/**
|
||||
* A class that that helps presenting error messages in the command line.
|
||||
*
|
||||
* @see DefaultErrorFormatter
|
||||
* @see PrettyErrorFormatter
|
||||
*/
|
||||
public interface ErrorFormatter {
|
||||
|
||||
public void format(DartCompilationError event);
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
/**
|
||||
* The severity of {@link ErrorCode}.
|
||||
*/
|
||||
public enum ErrorSeverity {
|
||||
/**
|
||||
* Fatal error.
|
||||
*/
|
||||
ERROR("E"),
|
||||
/**
|
||||
* Warning, may become error with -Werror command line flag.
|
||||
*/
|
||||
WARNING("W"),
|
||||
/**
|
||||
* Info, not considered an official warning
|
||||
*/
|
||||
INFO("I");
|
||||
|
||||
final String name;
|
||||
|
||||
ErrorSeverity(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012, the Dart project authors.
|
||||
*
|
||||
* Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
* or implied. See the License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* A file-based {@link SystemLibraryProvider} that reads dart-sdk/lib/_internal/libraries.dart for
|
||||
* system library information.
|
||||
*/
|
||||
public class FileBasedSystemLibraryProvider extends SystemLibraryProvider {
|
||||
|
||||
private File sdkLibPath;
|
||||
|
||||
/**
|
||||
* Create a {@link FileBasedSystemLibraryProvider} with the given path to the dart SDK.
|
||||
*/
|
||||
public FileBasedSystemLibraryProvider(File sdkPath) {
|
||||
super(new File(sdkPath, "lib").getAbsoluteFile().toURI());
|
||||
//TODO(pquitslund): remove this duplicated file creation
|
||||
sdkLibPath = new File(sdkPath, "lib").getAbsoluteFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SystemLibrariesReader createReader() throws IOException {
|
||||
return new SystemLibrariesReader(sdkLibPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemLibrary createSystemLibrary(String name, String host, String pathToLib,
|
||||
String category, boolean documented, boolean implementation) {
|
||||
|
||||
|
||||
File dir = new File(sdkLibPath, host);
|
||||
|
||||
File libFile = new File(dir, pathToLib);
|
||||
if (!libFile.isFile()) {
|
||||
throw new InternalCompilerException("Error mapping dart:" + host + ", path "
|
||||
+ libFile.getAbsolutePath() + " is not a file.");
|
||||
}
|
||||
|
||||
return new SystemLibrary(
|
||||
name, host, pathToLib, dir, category, documented, implementation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(URI uri) {
|
||||
return new File(uri).exists();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI resolveHost(String host, URI uri) {
|
||||
return new File(sdkLibPath, host).toURI().resolve("." + uri.getPath());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
/**
|
||||
* Exception thrown when the compiler encounters an unexpected internal error.
|
||||
*/
|
||||
public class InternalCompilerException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InternalCompilerException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InternalCompilerException(String message, Throwable t) {
|
||||
super(message, t);
|
||||
}
|
||||
}
|
|
@ -1,313 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.dart.compiler.ast.DartUnit;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Represents a library's dependencies artifact.
|
||||
*/
|
||||
public class LibraryDeps {
|
||||
private static final String VERSION = "v00001";
|
||||
|
||||
/**
|
||||
* Each dependency record contains the library in which it was found, name of the unit in this
|
||||
* library and last-modified timestamp. Any change in the timestamp of the target dependency will
|
||||
* force a recompile of the associated compilation unit.
|
||||
*/
|
||||
public static class Dependency {
|
||||
private final URI libUri;
|
||||
private final String unitName;
|
||||
private final long lastModified;
|
||||
|
||||
public Dependency(URI libUri, String unitName, long lastModified) {
|
||||
this.libUri = libUri;
|
||||
this.unitName = unitName;
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Dependency) {
|
||||
Dependency dep = (Dependency) obj;
|
||||
return Objects.equal(libUri, dep.libUri) && Objects.equal(unitName, dep.unitName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(libUri, unitName);
|
||||
}
|
||||
|
||||
public URI getLibUri() {
|
||||
return libUri;
|
||||
}
|
||||
|
||||
public String getUnitName() {
|
||||
return unitName;
|
||||
}
|
||||
|
||||
public long getLastModified() {
|
||||
return lastModified;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Source {
|
||||
private final Set<Dependency> deps = Sets.newHashSet();
|
||||
private final Set<String> topSymbols = Sets.newHashSet();
|
||||
private final Set<String> allSymbols = Sets.newHashSet();
|
||||
private final Set<String> holes = Sets.newHashSet();
|
||||
private boolean shouldRecompileOnAnyTopLevelChange = false;
|
||||
|
||||
/**
|
||||
* @return the {@link Set} of {@link Dependency}s.
|
||||
*/
|
||||
public Set<Dependency> getDeps() {
|
||||
return deps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the names of top-level elements, such as methods and classes.
|
||||
*/
|
||||
public Set<String> getTopSymbols() {
|
||||
return topSymbols;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the names of all elements in unit, such as names of local variables, fields, etc.
|
||||
*/
|
||||
public Set<String> getAllSymbols() {
|
||||
return allSymbols;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the names of functions, which are invoked without qualifier. So, declaration or
|
||||
* removing function with such name on top-level should cause recompiling.
|
||||
*/
|
||||
public Set<String> getHoles() {
|
||||
return holes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if this unit should be recompiled on any change in the set of
|
||||
* top-level symbols. Typically unit has compilation errors, which potentially may be
|
||||
* fixed, so we should recompile this unit.
|
||||
*/
|
||||
public boolean shouldRecompileOnAnyTopLevelChange() {
|
||||
return shouldRecompileOnAnyTopLevelChange;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new {@link Dependency}.
|
||||
*/
|
||||
public void addDep(Dependency dep) {
|
||||
deps.add(dep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds symbol to the {@link Set} of top symbols.
|
||||
*/
|
||||
public void addTopSymbol(String symbol) {
|
||||
if (!Strings.isNullOrEmpty(symbol)) {
|
||||
topSymbols.add(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds symbol to the {@link Set} of all symbols.
|
||||
*/
|
||||
public void addAllSymbol(String symbol) {
|
||||
allSymbols.add(symbol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new hole for {@link #getHoles()}.
|
||||
*/
|
||||
public void addHole(String hole) {
|
||||
holes.add(hole);
|
||||
}
|
||||
}
|
||||
|
||||
public static LibraryDeps fromReader(Reader reader) {
|
||||
try {
|
||||
return fromReaderEx(reader);
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static LibraryDeps fromReaderEx(Reader reader) throws Exception {
|
||||
LibraryDeps deps = new LibraryDeps();
|
||||
BufferedReader buf = new BufferedReader(reader);
|
||||
// Check version.
|
||||
{
|
||||
String line = buf.readLine();
|
||||
if (!Objects.equal(line, VERSION)) {
|
||||
return deps;
|
||||
}
|
||||
}
|
||||
// Read units dependencies.
|
||||
String relPath;
|
||||
while (null != (relPath = buf.readLine())) {
|
||||
Source source = new Source();
|
||||
// Read flags.
|
||||
source.shouldRecompileOnAnyTopLevelChange = Boolean.parseBoolean(buf.readLine());
|
||||
// Read top symbols.
|
||||
{
|
||||
String line = buf.readLine();
|
||||
Iterable<String> topSymbols = Splitter.on(' ').omitEmptyStrings().split(line);
|
||||
Iterables.addAll(source.topSymbols, topSymbols);
|
||||
}
|
||||
// Read all symbols.
|
||||
{
|
||||
String line = buf.readLine();
|
||||
Iterable<String> allSymbols = Splitter.on(' ').omitEmptyStrings().split(line);
|
||||
Iterables.addAll(source.allSymbols, allSymbols);
|
||||
}
|
||||
// Read holes.
|
||||
{
|
||||
String line = buf.readLine();
|
||||
Iterable<String> holes = Splitter.on(' ').omitEmptyStrings().split(line);
|
||||
Iterables.addAll(source.holes, holes);
|
||||
}
|
||||
// Read dependencies.
|
||||
while (true) {
|
||||
String line = buf.readLine();
|
||||
// Blank line: next unit.
|
||||
if (line.length() == 0) {
|
||||
break;
|
||||
}
|
||||
// Parse line.
|
||||
String[] parts = line.split(" ");
|
||||
source.deps.add(new Dependency(new URI(parts[0]), parts[1], Long.parseLong(parts[2])));
|
||||
}
|
||||
// Remember dependencies for current unit.
|
||||
deps.sources.put(relPath, source);
|
||||
}
|
||||
return deps;
|
||||
}
|
||||
|
||||
private final Map<String, Source> sources = Maps.newHashMap();
|
||||
|
||||
public LibraryDeps() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the relative paths of all units with remembered dependencies.
|
||||
*/
|
||||
public Set<String> getUnitPaths() {
|
||||
return sources.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all {@link Source} descriptions for all units in this library.
|
||||
*/
|
||||
public Iterable<Source> getSources() {
|
||||
return sources.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link Source} description of the unit with given path.
|
||||
*/
|
||||
public Source getSource(String relPath) {
|
||||
return sources.get(relPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remembers {@link Dependency}s of the unit with given path.
|
||||
*/
|
||||
public void putSource(String relPath, Source source) {
|
||||
sources.put(relPath, source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the library dependencies to reflect this unit's classes.
|
||||
*/
|
||||
public void update(DartCompilerMainContext context, DartUnit unit) {
|
||||
Source source = new Source();
|
||||
DartSource unitSource = (DartSource) unit.getSourceInfo().getSource();
|
||||
String relPath = unitSource.getRelativePath();
|
||||
putSource(relPath, source);
|
||||
// Remember dependencies.
|
||||
LibraryDepsVisitor.exec(unit, source);
|
||||
// Fill Source with symbols.
|
||||
for (String name : unit.getDeclarationNames()) {
|
||||
source.addAllSymbol(name);
|
||||
}
|
||||
for (String name : unit.getTopDeclarationNames()) {
|
||||
source.addTopSymbol(name);
|
||||
}
|
||||
// Analyze errors and see if any of them should force recompilation.
|
||||
List<DartCompilationError> sourceErrors = context.getSourceErrors(unitSource);
|
||||
for (DartCompilationError error : sourceErrors) {
|
||||
if (error.getErrorCode().needsRecompilation()) {
|
||||
source.shouldRecompileOnAnyTopLevelChange = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void write(Writer writer) throws IOException {
|
||||
// Write version.
|
||||
writer.write(VERSION);
|
||||
writer.write('\n');
|
||||
// Write entries.
|
||||
for (Entry<String, Source> entry : sources.entrySet()) {
|
||||
String relPath = entry.getKey();
|
||||
Source source = entry.getValue();
|
||||
// Unit name.
|
||||
writer.write(relPath);
|
||||
writer.write('\n');
|
||||
// Flags.
|
||||
writer.write(Boolean.toString(source.shouldRecompileOnAnyTopLevelChange));
|
||||
writer.write('\n');
|
||||
// Write top symbols.
|
||||
for (String symbol : source.topSymbols) {
|
||||
writer.write(symbol);
|
||||
writer.write(' ');
|
||||
}
|
||||
writer.write('\n');
|
||||
// Write all symbols.
|
||||
for (String symbol : source.allSymbols) {
|
||||
writer.write(symbol);
|
||||
writer.write(' ');
|
||||
}
|
||||
writer.write('\n');
|
||||
// Write holes.
|
||||
for (String hole : source.holes) {
|
||||
writer.write(hole);
|
||||
writer.write(' ');
|
||||
}
|
||||
writer.write('\n');
|
||||
// Write dependencies.
|
||||
for (Dependency dep : source.deps) {
|
||||
writer.write(dep.libUri.toString());
|
||||
writer.write(' ');
|
||||
writer.write(dep.unitName);
|
||||
writer.write(' ');
|
||||
writer.write(Long.toString(dep.lastModified));
|
||||
writer.write('\n');
|
||||
}
|
||||
// Empty line after each unit.
|
||||
writer.write('\n');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,168 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.dart.compiler.ast.ASTVisitor;
|
||||
import com.google.dart.compiler.ast.DartClass;
|
||||
import com.google.dart.compiler.ast.DartIdentifier;
|
||||
import com.google.dart.compiler.ast.DartMethodInvocation;
|
||||
import com.google.dart.compiler.ast.DartParameterizedTypeNode;
|
||||
import com.google.dart.compiler.ast.DartPropertyAccess;
|
||||
import com.google.dart.compiler.ast.DartTypeNode;
|
||||
import com.google.dart.compiler.ast.DartUnit;
|
||||
import com.google.dart.compiler.resolver.Element;
|
||||
import com.google.dart.compiler.resolver.ElementKind;
|
||||
import com.google.dart.compiler.type.InterfaceType;
|
||||
import com.google.dart.compiler.type.Type;
|
||||
import com.google.dart.compiler.type.TypeKind;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* A visitor that fills in {@link LibraryDeps} for a compilation unit.
|
||||
*/
|
||||
public class LibraryDepsVisitor extends ASTVisitor<Void> {
|
||||
/**
|
||||
* Fill in {@link LibraryDeps} from a {@link DartUnit}.
|
||||
*/
|
||||
static void exec(DartUnit unit, LibraryDeps.Source source) {
|
||||
LibraryDepsVisitor v = new LibraryDepsVisitor(source);
|
||||
unit.accept(v);
|
||||
}
|
||||
|
||||
private final LibraryDeps.Source source;
|
||||
private Element currentClass;
|
||||
|
||||
private LibraryDepsVisitor(LibraryDeps.Source source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitIdentifier(DartIdentifier node) {
|
||||
Element target = node.getElement();
|
||||
ElementKind kind = ElementKind.of(target);
|
||||
// Add dependency on the field or method.
|
||||
switch (kind) {
|
||||
case FIELD:
|
||||
case METHOD: {
|
||||
Element enclosing = target.getEnclosingElement();
|
||||
addHoleIfUnqualifiedSuper(node, enclosing);
|
||||
if (enclosing.getKind().equals(ElementKind.LIBRARY)) {
|
||||
addElementDependency(target);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Add dependency on the computed type of identifiers.
|
||||
switch (kind) {
|
||||
case NONE:
|
||||
source.addHole(node.getName());
|
||||
break;
|
||||
case DYNAMIC:
|
||||
break;
|
||||
default: {
|
||||
Type type = target.getType();
|
||||
if (type != null) {
|
||||
Element element = type.getElement();
|
||||
if (ElementKind.of(element).equals(ElementKind.CLASS)) {
|
||||
addElementDependency(element);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitPropertyAccess(DartPropertyAccess node) {
|
||||
if (node.getQualifier() instanceof DartIdentifier) {
|
||||
DartIdentifier qualifier = (DartIdentifier) node.getQualifier();
|
||||
Element target = qualifier.getElement();
|
||||
if (target != null && target.getKind() == ElementKind.LIBRARY) {
|
||||
// Handle library prefixes normally.
|
||||
// The prefix part of the qualifier doesn't contain any resolvable library source info.
|
||||
return super.visitPropertyAccess(node);
|
||||
}
|
||||
}
|
||||
// Skip rhs of property accesses, so that all identifiers we visit will be unqualified.
|
||||
if (node.isCascade()) {
|
||||
return null;
|
||||
}
|
||||
return node.getQualifier().accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitClass(DartClass node) {
|
||||
currentClass = node.getElement();
|
||||
node.visitChildren(this);
|
||||
currentClass = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitParameterizedTypeNode(DartParameterizedTypeNode node) {
|
||||
if (TypeKind.of(node.getType()).equals(TypeKind.INTERFACE)) {
|
||||
addElementDependency(((InterfaceType) node.getType()).getElement());
|
||||
}
|
||||
node.visitChildren(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitTypeNode(DartTypeNode node) {
|
||||
if (TypeKind.of(node.getType()).equals(TypeKind.INTERFACE)) {
|
||||
addElementDependency(((InterfaceType) node.getType()).getElement());
|
||||
}
|
||||
node.visitChildren(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a 'hole' for the given identifier, if its declaring class is a superclass of the current
|
||||
* class. A 'hole' dependency specifies a name that, if filled by something in the library scope,
|
||||
* would require this unit to be recompiled.
|
||||
*
|
||||
* This situation occurs because names in the library scope bind more strongly than unqualified
|
||||
* superclass members.
|
||||
*/
|
||||
private void addHoleIfUnqualifiedSuper(DartIdentifier node, Element holder) {
|
||||
if (isQualified(node)) {
|
||||
return;
|
||||
}
|
||||
if (ElementKind.of(holder) == ElementKind.CLASS && holder != currentClass) {
|
||||
source.addHole(node.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a direct dependency on the unit providing given {@link Element}.
|
||||
*/
|
||||
private void addElementDependency(Element element) {
|
||||
DartSource elementSource = (DartSource) element.getSourceInfo().getSource();
|
||||
if (elementSource != null) {
|
||||
LibrarySource library = elementSource.getLibrary();
|
||||
if (library != null) {
|
||||
URI libUri = library.getUri();
|
||||
LibraryDeps.Dependency dep = new LibraryDeps.Dependency(libUri, elementSource.getName(),
|
||||
elementSource.getLastModified());
|
||||
source.addDep(dep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if given {@link DartIdentifier} is "name" part of qualified property
|
||||
* access or method invocation.
|
||||
*/
|
||||
private static boolean isQualified(DartIdentifier node) {
|
||||
if (node.getParent() instanceof DartPropertyAccess) {
|
||||
return ((DartPropertyAccess) node.getParent()).getName() == node;
|
||||
}
|
||||
if (node.getParent() instanceof DartMethodInvocation) {
|
||||
return ((DartMethodInvocation) node.getParent()).getFunctionName() == node;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Abstract interface to library source.
|
||||
*
|
||||
* TODO(jgw): Consider requiring implementors to intern LibrarySource instances so that users can
|
||||
* depend upon reference equality to avoid cycles (or require them to use .equals()). As it is,
|
||||
* there are two pieces of code in {@link DartCompiler} that do this manually, and it's a little
|
||||
* tricky.
|
||||
*/
|
||||
public interface LibrarySource extends Source {
|
||||
|
||||
/**
|
||||
* Answer the {@link LibrarySource} for the path specified in the receiver's
|
||||
* imports declaration
|
||||
*
|
||||
* @param relPath path to the {@link LibrarySource} relative to the receiver
|
||||
* @return the dart source or <code>null</code> if could not be found
|
||||
*/
|
||||
LibrarySource getImportFor(String relPath) throws IOException;
|
||||
|
||||
/**
|
||||
* Answer the {@link DartSource} for the path specified in the receiver's
|
||||
* sources declaration
|
||||
*
|
||||
* @param relPath the path to the {@link DartSource} relative to the receiver
|
||||
* @return the dart source or <code>null</code> if could not be found
|
||||
*/
|
||||
DartSource getSourceFor(String relPath);
|
||||
}
|
|
@ -1,346 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Manages the collection of {@link SystemLibrary}s.
|
||||
*/
|
||||
public class PackageLibraryManager {
|
||||
|
||||
public static class NotADartShortUriException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public NotADartShortUriException(String uriString) {
|
||||
super("Expected dart:<short name>, got: " + uriString);
|
||||
}
|
||||
|
||||
public NotADartShortUriException(URI uri) {
|
||||
super("Expected dart:<short name>, got: " + uri.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The "any" platform is meant to have definitions for all known dart system libraries.
|
||||
* Other implementations may only contain a subset.
|
||||
*/
|
||||
public static final String DEFAULT_PLATFORM = "any";
|
||||
public static final File DEFAULT_SDK_PATH = new File(System.getProperty(
|
||||
"com.google.dart.sdk", "../"));
|
||||
|
||||
public static final File DEFAULT_PACKAGE_ROOT = new File("packages");
|
||||
public static final List<File> DEFAULT_PACKAGE_ROOTS = Arrays.asList(new File[] {DEFAULT_PACKAGE_ROOT});
|
||||
|
||||
public static final String PACKAGE_SCHEME = "package";
|
||||
public static final String PACKAGE_SCHEME_SPEC = "package:";
|
||||
|
||||
public static final String DART_SCHEME = "dart";
|
||||
public static final String DART_SCHEME_SPEC = "dart:";
|
||||
|
||||
|
||||
/**
|
||||
* Answer <code>true</code> if the string is a dart spec
|
||||
*/
|
||||
public static boolean isDartSpec(String spec) {
|
||||
return spec != null && spec.startsWith(DART_SCHEME_SPEC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer <code>true</code> if the specified URI has a "dart" scheme
|
||||
*/
|
||||
public static boolean isDartUri(URI uri) {
|
||||
return uri != null && DART_SCHEME.equals(uri.getScheme());
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer <code>true</code> if the string is a package spec
|
||||
*/
|
||||
public static boolean isPackageSpec(String spec) {
|
||||
return spec != null && spec.startsWith(PACKAGE_SCHEME_SPEC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer <code>true</code> if the specified URI has a "package" scheme
|
||||
*/
|
||||
public static boolean isPackageUri(URI uri) {
|
||||
return uri != null && PACKAGE_SCHEME.equals(uri.getScheme());
|
||||
}
|
||||
|
||||
private static SystemLibraryManager SDK_LIBRARY_MANAGER;
|
||||
|
||||
private List<File> packageRoots = new ArrayList<File>();
|
||||
private List<URI> packageRootsUri = new ArrayList<URI>();
|
||||
|
||||
public PackageLibraryManager() {
|
||||
this(DEFAULT_SDK_PATH, DEFAULT_PLATFORM);
|
||||
}
|
||||
|
||||
public PackageLibraryManager(File sdkPath, String platformName) {
|
||||
this(new FileBasedSystemLibraryProvider(sdkPath));
|
||||
}
|
||||
|
||||
public PackageLibraryManager(SystemLibraryProvider libraryProvider) {
|
||||
initLibraryManager(libraryProvider);
|
||||
setPackageRoots(DEFAULT_PACKAGE_ROOTS);
|
||||
}
|
||||
|
||||
protected void initLibraryManager(SystemLibraryProvider libraryProvider) {
|
||||
if (SDK_LIBRARY_MANAGER == null) {
|
||||
SDK_LIBRARY_MANAGER = new SystemLibraryManager(libraryProvider);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expand a relative or short URI (e.g. "dart:html") which is implementation independent to its
|
||||
* full URI (e.g. "dart://html/com/google/dart/htmllib/html.dart").
|
||||
*
|
||||
* @param uri the relative URI
|
||||
* @return the expanded URI
|
||||
* or the original URI if it could not be expanded
|
||||
* or null if the uri is of the form "dart:<libname>" but does not correspond to a system library
|
||||
*/
|
||||
public URI expandRelativeDartUri(URI uri) throws AssertionError {
|
||||
if (isDartUri(uri)) {
|
||||
return SDK_LIBRARY_MANAGER.expandRelativeDartUri(uri);
|
||||
}
|
||||
if (isPackageUri(uri)){
|
||||
String host = uri.getHost();
|
||||
if (host == null) {
|
||||
String spec = uri.getSchemeSpecificPart();
|
||||
if (!spec.startsWith("//")){
|
||||
try {
|
||||
if (spec.startsWith("/")){
|
||||
// TODO(keertip): fix to handle spaces
|
||||
uri = new URI(PACKAGE_SCHEME + ":/" + spec);
|
||||
} else {
|
||||
uri = new URI(PACKAGE_SCHEME + "://" + spec);
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Given an absolute file URI (e.g. "file:/some/install/directory/dart-sdk/lib/core/bool.dart"),
|
||||
* answer the corresponding dart: URI (e.g. "dart://core/bool.dart") for that file URI,
|
||||
* or <code>null</code> if the file URI does not map to a dart: URI
|
||||
* @param fileUri the file URI
|
||||
* @return the dart URI or <code>null</code>
|
||||
*/
|
||||
public URI getRelativeUri(URI fileUri) {
|
||||
// TODO (danrubel): does not convert dart: libraries outside the dart-sdk/lib directory
|
||||
if (fileUri == null || !fileUri.getScheme().equals("file")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
URI relativeUri = SDK_LIBRARY_MANAGER.getRelativeUri(fileUri);
|
||||
if (relativeUri != null){
|
||||
return relativeUri;
|
||||
}
|
||||
|
||||
for (URI rootUri : packageRootsUri){
|
||||
relativeUri = rootUri.relativize(fileUri);
|
||||
if (relativeUri.getScheme() == null) {
|
||||
try {
|
||||
return new URI(null, null, "package://" + relativeUri.getPath(), null, null);
|
||||
} catch (URISyntaxException e) {
|
||||
//$FALL-THROUGH$
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a package URI (package:foo/foo.dart), convert it into a file system URI.
|
||||
*/
|
||||
public URI resolvePackageUri(String packageUriRef) {
|
||||
if (packageUriRef.startsWith(PACKAGE_SCHEME_SPEC)) {
|
||||
String relPath = packageUriRef.substring(PACKAGE_SCHEME_SPEC.length());
|
||||
if (relPath.startsWith("/")){
|
||||
relPath = relPath.replaceAll("^\\/+", "");
|
||||
}
|
||||
for (URI rootUri : packageRootsUri){
|
||||
URI fileUri = rootUri.resolve(relPath);
|
||||
File file = new File(fileUri);
|
||||
if (file.exists()){
|
||||
try {
|
||||
return file.getCanonicalFile().toURI();
|
||||
} catch (IOException e) {
|
||||
file.toURI();
|
||||
}
|
||||
}
|
||||
}
|
||||
// don't return null for package scheme
|
||||
return packageRootsUri.get(0).resolve(relPath);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer the original "dart:<libname>" URI for the specified resolved URI or <code>null</code> if
|
||||
* it does not map to a short URI.
|
||||
*/
|
||||
public URI getShortUri(URI uri) {
|
||||
URI shortUri = SDK_LIBRARY_MANAGER.getShortUri(uri);
|
||||
if (shortUri != null){
|
||||
return shortUri;
|
||||
}
|
||||
shortUri = getRelativeUri(uri);
|
||||
if (shortUri != null){
|
||||
try {
|
||||
if (shortUri.getHost() != null){
|
||||
return new URI(null, null, shortUri.getScheme() + ":" + shortUri.getHost() + shortUri.getPath(),null, null);
|
||||
}
|
||||
else {
|
||||
return new URI(null, null, shortUri.getScheme() + ":" + shortUri.getSchemeSpecificPart(), null, null);
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand a relative or short URI (e.g. "dart:html") which is implementation independent to its
|
||||
* full URI (e.g. "dart://html/com/google/dart/htmllib/html.dart") and then translate that URI to
|
||||
* a "file:" URI (e.g.
|
||||
* "file:/some/install/directory/com/google/dart/htmllib/html.dart").
|
||||
*
|
||||
* @param uri the original URI
|
||||
* @return the expanded and translated URI, which may be <code>null</code> and may not exist
|
||||
* @exception RuntimeException if the URI is a "dart" scheme, but does not map to a defined system
|
||||
* library
|
||||
*/
|
||||
public URI resolveDartUri(URI uri) {
|
||||
return translateDartUri(expandRelativeDartUri(uri));
|
||||
}
|
||||
|
||||
|
||||
public List<File> getPackageRoots(){
|
||||
return packageRoots;
|
||||
}
|
||||
|
||||
|
||||
public void setPackageRoots(List<File> roots){
|
||||
if (roots == null || roots.isEmpty()){
|
||||
roots = DEFAULT_PACKAGE_ROOTS;
|
||||
}
|
||||
packageRoots.clear();
|
||||
for (File file : roots){
|
||||
packageRoots.add(file.getAbsoluteFile());
|
||||
}
|
||||
packageRootsUri.clear();
|
||||
for (File file : roots){
|
||||
packageRootsUri.add(file.toURI());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the URI from dart://[host]/[pathToLib] (e.g. dart://html/html.dart)
|
||||
* to a "file:" URI (e.g. "file:/some/install/directory/html.dart")
|
||||
*
|
||||
* @param uri the original URI
|
||||
* @return the translated URI, which may be <code>null</code> and may not exist
|
||||
* @exception RuntimeException if the URI is a "dart" scheme,
|
||||
* but does not map to a defined system library
|
||||
*/
|
||||
public URI translateDartUri(URI uri) {
|
||||
if (isDartUri(uri)) {
|
||||
return SDK_LIBRARY_MANAGER.translateDartUri(uri);
|
||||
}
|
||||
if (isPackageUri(uri)){
|
||||
URI fileUri;
|
||||
for (URI rootUri : packageRootsUri){
|
||||
fileUri = getResolvedPackageUri(uri, rootUri);
|
||||
File file = new File(fileUri);
|
||||
if (file.exists()){
|
||||
try {
|
||||
return file.getCanonicalFile().toURI();
|
||||
} catch (IOException e) {
|
||||
return file.toURI();
|
||||
}
|
||||
}
|
||||
}
|
||||
// resolve against first package root
|
||||
fileUri = getResolvedPackageUri(uri, packageRootsUri.get(0));
|
||||
return fileUri;
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given a uri, resolve against the list of package roots, used to find generated files
|
||||
* @return uri - resolved uri if file exists, else return given uri
|
||||
*/
|
||||
public URI findExistingFileInPackages(URI fileUri){
|
||||
|
||||
URI resolvedUri = getRelativeUri(fileUri);
|
||||
if (isPackageUri(resolvedUri)){
|
||||
resolvedUri = resolvePackageUri(resolvedUri.toString());
|
||||
return resolvedUri;
|
||||
}
|
||||
return fileUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the given uri against the package root uri
|
||||
*/
|
||||
private URI getResolvedPackageUri(URI uri, URI packageRootUri) {
|
||||
URI fileUri;
|
||||
// TODO(keertip): Investigate further
|
||||
// if uri.getHost() returns null, then it is resolved right
|
||||
// so use uri.getAuthority to resolve
|
||||
// package://third_party/dart_lang/lib/unittest/unittest.dart
|
||||
if (uri.getHost() != null){
|
||||
fileUri = packageRootUri.resolve(uri.getHost() + uri.getPath());
|
||||
} else {
|
||||
fileUri = packageRootUri.resolve(uri.getAuthority() + uri.getPath());
|
||||
}
|
||||
return fileUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer a collection of all bundled library URL specs (e.g. "dart:html").
|
||||
*
|
||||
* @return a collection of specs (not <code>null</code>, contains no <code>null</code>s)
|
||||
*/
|
||||
public Collection<String> getAllLibrarySpecs() {
|
||||
return SDK_LIBRARY_MANAGER.getAllLibrarySpecs();
|
||||
}
|
||||
|
||||
protected SystemLibrary[] getDefaultLibraries() {
|
||||
return SDK_LIBRARY_MANAGER.getDefaultLibraries();
|
||||
}
|
||||
|
||||
public Collection<SystemLibrary> getSystemLibraries(){
|
||||
return SDK_LIBRARY_MANAGER.getAllSystemLibraries();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this URI denotes a patch file.
|
||||
*/
|
||||
public static boolean isPatchFile(File file) {
|
||||
return SDK_LIBRARY_MANAGER.isPatchFile(file.toURI());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,156 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.dart.compiler.CompilerConfiguration.ErrorFormat;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.Reader;
|
||||
|
||||
/**
|
||||
* An error formatter that scans the source file and prints the error line and
|
||||
* some context around it. This formatter has two modes: with or without color.
|
||||
* When using colors, it prints the error message in red, and it highlights the
|
||||
* portion of the line containing the error in red. Without colors, it prints an
|
||||
* extra line underlying the portion of the line containing the error.
|
||||
*/
|
||||
public class PrettyErrorFormatter extends DefaultErrorFormatter {
|
||||
public static final String ERROR_BOLD_COLOR = "\033[31;1m";
|
||||
public static final String ERROR_COLOR = "\033[31m";
|
||||
|
||||
// Mix ANSI with xterm colors, giving ANSI priority. The terminal should ignore xterm codes
|
||||
// if it doesn't support them.
|
||||
public static final String WARNING_BOLD_COLOR = "\033[33;1m\033[38;5;202m";
|
||||
public static final String WARNING_COLOR = "\033[33m\033[38;5;208m";
|
||||
|
||||
public static final String NO_COLOR = "\033[0m";
|
||||
|
||||
private final boolean useColor;
|
||||
|
||||
public PrettyErrorFormatter(PrintStream outputStream,
|
||||
boolean useColor,
|
||||
ErrorFormat errorFormat) {
|
||||
super(outputStream, errorFormat);
|
||||
this.useColor = useColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void format(DartCompilationError event) {
|
||||
Source sourceFile = event.getSource();
|
||||
|
||||
// if this is an unknown source type, default to the basic error formatter
|
||||
if (!(sourceFile instanceof DartSource) && !(sourceFile instanceof LibrarySource)) {
|
||||
super.format(event);
|
||||
return;
|
||||
}
|
||||
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
Reader sourceReader = sourceFile.getSourceReader();
|
||||
if (sourceReader != null) {
|
||||
reader = new BufferedReader(sourceReader);
|
||||
}
|
||||
|
||||
// get the error line and the line above it (note: line starts at 1)
|
||||
int line = event.getLineNumber();
|
||||
String lineBefore = null;
|
||||
String lineText = null;
|
||||
|
||||
if (reader != null) {
|
||||
lineBefore = getLineAt(reader, line - 1);
|
||||
lineText = getLineAt(reader, 1);
|
||||
}
|
||||
|
||||
// if there is no line to highlight, default to the basic error formatter
|
||||
if (lineText == null) {
|
||||
super.format(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// get column/length and ensure they are within the line limits.
|
||||
int col = event.getColumnNumber() - 1;
|
||||
int length = event.getLength();
|
||||
col = between(col, 0, lineText.length());
|
||||
length = between(length, 0, lineText.length() - col);
|
||||
length = length == 0 ? lineText.length() - col : length;
|
||||
|
||||
// print the error message
|
||||
StringBuilder buf = new StringBuilder();
|
||||
if (useColor) {
|
||||
buf.append(event.getErrorCode().getErrorSeverity() == ErrorSeverity.WARNING
|
||||
? WARNING_BOLD_COLOR : ERROR_BOLD_COLOR);
|
||||
}
|
||||
appendError(buf, event);
|
||||
if (useColor) {
|
||||
buf.append(NO_COLOR);
|
||||
}
|
||||
buf.append("\n");
|
||||
// show the previous line for context
|
||||
if (lineBefore != null) {
|
||||
buf.append(String.format("%6d: %s\n", line - 1, lineBefore));
|
||||
}
|
||||
|
||||
if (useColor) {
|
||||
// highlight error in red
|
||||
buf.append(String.format("%6d: %s%s%s%s%s\n",
|
||||
line,
|
||||
lineText.substring(0, col),
|
||||
event.getErrorCode().getErrorSeverity() == ErrorSeverity.WARNING
|
||||
? WARNING_COLOR : ERROR_COLOR,
|
||||
lineText.substring(col, col + length),
|
||||
NO_COLOR,
|
||||
lineText.substring(col + length)));
|
||||
} else {
|
||||
// print the error line without formatting
|
||||
buf.append(String.format("%6d: %s\n", line, lineText));
|
||||
|
||||
// underline error portion
|
||||
buf.append(" ");
|
||||
for (int i = 0; i < col; ++i) {
|
||||
buf.append(' ');
|
||||
}
|
||||
buf.append('~');
|
||||
if (length > 1) {
|
||||
for (int i = 0; i < length - 2; ++i) {
|
||||
buf.append('~');
|
||||
}
|
||||
buf.append('~');
|
||||
}
|
||||
buf.append('\n');
|
||||
}
|
||||
|
||||
outputStream.print(buf.toString());
|
||||
} catch (IOException ex) {
|
||||
super.format(event);
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
Closeables.closeQuietly(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getLineAt(BufferedReader reader, int line) throws IOException {
|
||||
if (line <= 0) {
|
||||
return null;
|
||||
}
|
||||
String currentLine = null;
|
||||
// TODO(sigmund): do something more efficient - we currently do a linear
|
||||
// scan of the file every time an error is reported. This will not scale
|
||||
// when many errors are reported on the same file.
|
||||
while ((currentLine = reader.readLine()) != null && line-- > 1){}
|
||||
return currentLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the closest value in {@code [start,end]} to the given value. If
|
||||
* the given range is entirely empty, then {@code start} is returned.
|
||||
*/
|
||||
private static int between(int val, int start, int end) {
|
||||
return Math.max(start, Math.min(val, end));
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Abstract interface to a source file.
|
||||
*/
|
||||
public interface Source {
|
||||
|
||||
/**
|
||||
* Determines whether the given source exists.
|
||||
*/
|
||||
boolean exists();
|
||||
|
||||
/**
|
||||
* Returns the last-modified timestamp for this source, using the same units as
|
||||
* {@link Date#getTime()}.
|
||||
*/
|
||||
long getLastModified();
|
||||
|
||||
/**
|
||||
* Gets the name of this source.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets a reader for the dart file's source code. The caller is responsible for closing the
|
||||
* returned reader.
|
||||
*/
|
||||
Reader getSourceReader() throws IOException;
|
||||
|
||||
/**
|
||||
* Return an identifier that will uniquely identify this source.
|
||||
*
|
||||
* @return the unique identifier for this source.
|
||||
*/
|
||||
String getUniqueIdentifier();
|
||||
|
||||
/**
|
||||
* Gets the identifier for this source. This is used to uniquely identify the
|
||||
* source, but should not be used to obtain the source content. Use
|
||||
* {@link #getSourceReader()} to obtain the source content.
|
||||
*/
|
||||
URI getUri();
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.dart.compiler.ast.DartUnit;
|
||||
|
||||
/**
|
||||
* Representation of changes to source.
|
||||
*/
|
||||
public abstract class SourceDelta {
|
||||
public abstract Source getSourceBefore();
|
||||
|
||||
public abstract DartSource getSourceAfter();
|
||||
|
||||
public abstract DartUnit getUnitAfter();
|
||||
|
||||
public final SourceDelta after(DartSource sourceAfter) {
|
||||
return new BeforeAfter(getSourceBefore(), sourceAfter, null);
|
||||
}
|
||||
|
||||
public final SourceDelta after(DartUnit nodeAfter) {
|
||||
return new BeforeAfter(getSourceBefore(), null, nodeAfter);
|
||||
}
|
||||
|
||||
public static SourceDelta before(final DartSource sourceBefore) {
|
||||
return new BeforeAfter(sourceBefore, sourceBefore, null);
|
||||
}
|
||||
|
||||
private static class BeforeAfter extends SourceDelta {
|
||||
private final Source sourceBefore;
|
||||
private final DartSource sourceAfter;
|
||||
private final DartUnit nodeAfter;
|
||||
|
||||
BeforeAfter(Source sourceBefore, DartSource sourceAfter, DartUnit nodeAfter) {
|
||||
this.sourceBefore = sourceBefore;
|
||||
this.sourceAfter = sourceAfter;
|
||||
this.nodeAfter = nodeAfter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Source getSourceBefore() {
|
||||
return sourceBefore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DartSource getSourceAfter() {
|
||||
return sourceAfter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DartUnit getUnitAfter() {
|
||||
return nodeAfter;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
/**
|
||||
* Subsystem of compiler.
|
||||
*/
|
||||
public enum SubSystem {
|
||||
COMPILER, PARSER, STATIC_TYPE, RESOLVER
|
||||
}
|
|
@ -1,264 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012, the Dart project authors.
|
||||
*
|
||||
* Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
* or implied. See the License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.io.CharStreams;
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.dart.compiler.CompilerConfiguration.ErrorFormat;
|
||||
import com.google.dart.compiler.ast.ASTVisitor;
|
||||
import com.google.dart.compiler.ast.DartBooleanLiteral;
|
||||
import com.google.dart.compiler.ast.DartExpression;
|
||||
import com.google.dart.compiler.ast.DartFieldDefinition;
|
||||
import com.google.dart.compiler.ast.DartIdentifier;
|
||||
import com.google.dart.compiler.ast.DartMapLiteralEntry;
|
||||
import com.google.dart.compiler.ast.DartNamedExpression;
|
||||
import com.google.dart.compiler.ast.DartNewExpression;
|
||||
import com.google.dart.compiler.ast.DartNode;
|
||||
import com.google.dart.compiler.ast.DartStringLiteral;
|
||||
import com.google.dart.compiler.ast.DartUnit;
|
||||
import com.google.dart.compiler.metrics.CompilerMetrics;
|
||||
import com.google.dart.compiler.parser.DartParser;
|
||||
import com.google.dart.compiler.util.DartSourceString;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A reader that parses and reads the libraries dart-sdk/lib/_internal/libraries.dart file for
|
||||
* system library information library information is in the format final Map<String, LibraryInfo>
|
||||
* LIBRARIES = const <LibraryInfo> { // Used by VM applications "builtin": const LibraryInfo(
|
||||
* "builtin/builtin_runtime.dart", category: "Server", platforms: VM_PLATFORM), "compiler": const
|
||||
* LibraryInfo( "compiler/compiler.dart", category: "Tools", platforms: 0), };
|
||||
*/
|
||||
public class SystemLibrariesReader {
|
||||
|
||||
@VisibleForTesting
|
||||
public class DartLibrary {
|
||||
|
||||
private String shortName = null;
|
||||
private String path = null;
|
||||
private String category = "Shared";
|
||||
private boolean documented = true;
|
||||
private boolean implementation = false;
|
||||
private int platforms = 0;
|
||||
|
||||
DartLibrary(String name) {
|
||||
this.shortName = name;
|
||||
}
|
||||
|
||||
public String getShortName() {
|
||||
return shortName;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public boolean isDocumented() {
|
||||
return documented;
|
||||
}
|
||||
|
||||
public void setDocumented(boolean documented) {
|
||||
this.documented = documented;
|
||||
}
|
||||
|
||||
public boolean isImplementation() {
|
||||
return implementation;
|
||||
}
|
||||
|
||||
public void setImplementation(boolean implementation) {
|
||||
this.implementation = implementation;
|
||||
}
|
||||
|
||||
public boolean isDart2JsLibrary() {
|
||||
return (platforms & DART2JS_PLATFORM) != 0;
|
||||
}
|
||||
|
||||
public boolean isVmLibrary() {
|
||||
return (platforms & VM_PLATFORM) != 0;
|
||||
}
|
||||
|
||||
public void setPlatforms(int platforms) {
|
||||
this.platforms = platforms;
|
||||
}
|
||||
}
|
||||
|
||||
class LibrariesFileAstVistor extends ASTVisitor<Void> {
|
||||
|
||||
@Override
|
||||
public Void visitMapLiteralEntry(DartMapLiteralEntry node) {
|
||||
|
||||
String keyString = null;
|
||||
DartExpression key = node.getKey();
|
||||
if (key instanceof DartStringLiteral) {
|
||||
keyString = "dart:" + ((DartStringLiteral) key).getValue();
|
||||
}
|
||||
DartExpression value = node.getValue();
|
||||
if (value instanceof DartNewExpression) {
|
||||
DartLibrary library = new DartLibrary(keyString);
|
||||
List<DartExpression> args = ((DartNewExpression) value).getArguments();
|
||||
for (DartExpression arg : args) {
|
||||
if (arg instanceof DartStringLiteral) {
|
||||
library.setPath(((DartStringLiteral) arg).getValue());
|
||||
}
|
||||
if (arg instanceof DartNamedExpression) {
|
||||
String name = ((DartNamedExpression) arg).getName().getName();
|
||||
DartExpression expression = ((DartNamedExpression) arg).getExpression();
|
||||
if (name.equals(CATEGORY)) {
|
||||
library.setCategory(((DartStringLiteral) expression).getValue());
|
||||
} else if (name.equals(IMPLEMENTATION)) {
|
||||
library.setImplementation(((DartBooleanLiteral) expression).getValue());
|
||||
} else if (name.equals(DOCUMENTED)) {
|
||||
library.setDocumented(((DartBooleanLiteral) expression).getValue());
|
||||
} else if (name.equals(PATCH_PATH)) {
|
||||
String path = ((DartStringLiteral) expression).getValue();
|
||||
URI uri = sdkLibPath.resolve(URI.create(path));
|
||||
patchPaths.add(uri);
|
||||
} else if (name.equals(PLATFORMS)) {
|
||||
if (expression instanceof DartIdentifier) {
|
||||
String identifier = ((DartIdentifier) expression).getName();
|
||||
if (identifier.equals("VM_PLATFORM")) {
|
||||
library.setPlatforms(VM_PLATFORM);
|
||||
} else {
|
||||
library.setPlatforms(DART2JS_PLATFORM);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
librariesMap.put(keyString, library);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final String LIBRARIES_FILE = "libraries.dart";
|
||||
public static final String INTERNAL_DIR = "_internal";
|
||||
|
||||
private static final String IMPLEMENTATION = "implementation";
|
||||
private static final String DOCUMENTED = "documented";
|
||||
private static final String CATEGORY = "category";
|
||||
private static final String PATCH_PATH = "dart2jsPatchPath";
|
||||
private static final String PLATFORMS = "platforms";
|
||||
|
||||
private static final int DART2JS_PLATFORM = 1;
|
||||
private static final int VM_PLATFORM = 2;
|
||||
|
||||
private final URI sdkLibPath;
|
||||
private final Map<String, DartLibrary> librariesMap = new HashMap<String, DartLibrary>();
|
||||
private final List<URI> patchPaths = new ArrayList<URI>();
|
||||
|
||||
public SystemLibrariesReader(URI sdkLibPath, Reader sdkFileReader) {
|
||||
this.sdkLibPath = sdkLibPath;
|
||||
loadLibraryInfo(sdkFileReader);
|
||||
}
|
||||
|
||||
public SystemLibrariesReader(File sdkLibPath) throws IOException {
|
||||
this(sdkLibPath.getAbsoluteFile().toURI(), new InputStreamReader(new FileInputStream(
|
||||
getLibrariesFile(sdkLibPath)), Charset.forName("UTF8")));
|
||||
}
|
||||
|
||||
public Map<String, DartLibrary> getLibrariesMap() {
|
||||
return librariesMap;
|
||||
}
|
||||
|
||||
public List<URI> getPatchPaths() {
|
||||
return patchPaths;
|
||||
}
|
||||
|
||||
private void loadLibraryInfo(Reader sdkFileReader) {
|
||||
|
||||
DartUnit unit = getDartUnit(sdkFileReader);
|
||||
|
||||
List<DartNode> nodes = unit.getTopLevelNodes();
|
||||
for (DartNode node : nodes) {
|
||||
if (node instanceof DartFieldDefinition) {
|
||||
node.accept(new LibrariesFileAstVistor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given dart file and return the AST
|
||||
*
|
||||
* @param fileReader the dart file reader
|
||||
* @return the parsed AST
|
||||
*/
|
||||
private DartUnit getDartUnit(Reader fileReader) {
|
||||
|
||||
String srcCode = getSource(fileReader);
|
||||
DartSourceString dartSource = new DartSourceString(LIBRARIES_FILE, srcCode);
|
||||
DefaultDartCompilerListener listener = new DefaultDartCompilerListener(ErrorFormat.NORMAL);
|
||||
DartParser parser = new DartParser(
|
||||
dartSource,
|
||||
srcCode,
|
||||
false,
|
||||
new HashSet<String>(),
|
||||
listener,
|
||||
new CompilerMetrics());
|
||||
return parser.parseUnit();
|
||||
}
|
||||
|
||||
private String getSource(Reader reader) {
|
||||
String srcCode = null;
|
||||
boolean failed = true;
|
||||
try {
|
||||
srcCode = CharStreams.toString(reader);
|
||||
failed = false;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
Closeables.close(reader, failed);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return srcCode;
|
||||
}
|
||||
|
||||
private static File getLibrariesFile(File sdkLibDir) {
|
||||
File file = new File(new File(sdkLibDir, INTERNAL_DIR), LIBRARIES_FILE);
|
||||
if (!file.exists()) {
|
||||
throw new InternalCompilerException("Failed to find " + file.toString()
|
||||
+ ". Is dart-sdk path correct?");
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* A library accessible via the "dart:<libname>.lib" protocol.
|
||||
*/
|
||||
public class SystemLibrary {
|
||||
|
||||
private final String shortName;
|
||||
private final String host;
|
||||
private final String pathToLib;
|
||||
private final File dirOrZip;
|
||||
private String category;
|
||||
private boolean documented;
|
||||
private boolean implementation;
|
||||
|
||||
/**
|
||||
* Define a new system library such that dart:[shortLibName] will automatically be expanded to
|
||||
* dart://[host]/[pathToLib]. For example this call
|
||||
*
|
||||
* <pre>
|
||||
* new SystemLibrary("html.lib", "html", "dart_html.lib");
|
||||
* </pre>
|
||||
*
|
||||
* will define a new system library such that "dart:html.lib" to automatically be expanded to
|
||||
* "dart://html/dart_html.lib". The dirOrZip argument is either the root directory or a zip file
|
||||
* containing all files for this library.
|
||||
*/
|
||||
public SystemLibrary(String shortName, String host, String pathToLib, File dirOrZip, String category,
|
||||
boolean documented, boolean implementation) {
|
||||
this.shortName = shortName;
|
||||
this.host = host;
|
||||
this.pathToLib = pathToLib;
|
||||
this.dirOrZip = dirOrZip;
|
||||
this.category = category;
|
||||
this.documented = documented;
|
||||
this.implementation = implementation;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public boolean isDocumented() {
|
||||
return documented;
|
||||
}
|
||||
|
||||
public boolean isImplementation() {
|
||||
return implementation;
|
||||
}
|
||||
|
||||
public boolean isShared(){
|
||||
return category.equals("Shared");
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public String getPathToLib() {
|
||||
return pathToLib;
|
||||
}
|
||||
|
||||
public String getShortName() {
|
||||
return shortName;
|
||||
}
|
||||
|
||||
public File getLibraryDir() {
|
||||
return dirOrZip;
|
||||
}
|
||||
|
||||
public URI translateUri(URI dartUri) {
|
||||
if (!dirOrZip.exists()) {
|
||||
throw new RuntimeException("System library for " + dartUri + " does not exist: " + dirOrZip.getPath());
|
||||
}
|
||||
try {
|
||||
URI dirOrZipURI = dirOrZip.toURI();
|
||||
if (dirOrZip.isFile()) {
|
||||
return new URI("jar", "file:" + dirOrZipURI.getPath() + "!" + dartUri.getPath(), null);
|
||||
} else {
|
||||
return dirOrZipURI.resolve("." + dartUri.getPath());
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return this.dirOrZip;
|
||||
}
|
||||
}
|
|
@ -1,241 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.dart.compiler.SystemLibrariesReader.DartLibrary;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* A Library manager that manages system libraries
|
||||
*/
|
||||
public class SystemLibraryManager {
|
||||
|
||||
private HashMap<String, String> expansionMap;
|
||||
private Map<String, SystemLibrary> hostMap;
|
||||
private final URI sdkLibPathUri;
|
||||
|
||||
private Map<URI, URI> longToShortUriMap;
|
||||
|
||||
private List<SystemLibrary> libraries;
|
||||
private final SystemLibraryProvider libraryProvider;
|
||||
|
||||
public SystemLibraryManager(File sdkPath) {
|
||||
this(new FileBasedSystemLibraryProvider(sdkPath));
|
||||
}
|
||||
|
||||
public SystemLibraryManager(SystemLibraryProvider libraryProvider) {
|
||||
this.libraryProvider = libraryProvider;
|
||||
this.sdkLibPathUri = libraryProvider.getSdkLibPathUri();
|
||||
setLibraries(getDefaultLibraries());
|
||||
}
|
||||
|
||||
public URI expandRelativeDartUri(URI uri) throws AssertionError {
|
||||
String host = uri.getHost();
|
||||
if (host == null && uri.getAuthority() == null) {
|
||||
String spec = uri.getSchemeSpecificPart();
|
||||
String replacement = expansionMap.get(spec);
|
||||
if (replacement != null) {
|
||||
try {
|
||||
uri = new URI(PackageLibraryManager.DART_SCHEME + ":" + replacement);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
public URI getRelativeUri(URI fileUri) {
|
||||
|
||||
if (fileUri == null || !fileUri.getScheme().equals("file")){
|
||||
return null;
|
||||
}
|
||||
|
||||
URI relativeUri = sdkLibPathUri.relativize(fileUri);
|
||||
if (relativeUri.getScheme() == null) {
|
||||
try {
|
||||
return new URI(null, null, "dart://" + relativeUri.getPath(), null, null);
|
||||
} catch (URISyntaxException e) {
|
||||
//$FALL-THROUGH$
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public URI getShortUri(URI uri) {
|
||||
URI shortUri = longToShortUriMap.get(uri);
|
||||
if (shortUri != null){
|
||||
return shortUri;
|
||||
}
|
||||
shortUri = getRelativeUri(uri);
|
||||
if (shortUri != null){
|
||||
try {
|
||||
return new URI(null, null, shortUri.getScheme() + ":" + shortUri.getHost() + shortUri.getPath(),null, null);
|
||||
} catch (URISyntaxException e) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public URI translateDartUri(URI uri) {
|
||||
|
||||
String host = uri.getHost();
|
||||
|
||||
SystemLibrary library = hostMap.get(host);
|
||||
if (library != null) {
|
||||
return library.translateUri(uri);
|
||||
}
|
||||
if (host != null) {
|
||||
return libraryProvider.resolveHost(host, uri);
|
||||
}
|
||||
String authorithy = uri.getAuthority();
|
||||
if (authorithy != null){
|
||||
return libraryProvider.resolveHost(authorithy, uri);
|
||||
}
|
||||
throw new RuntimeException("No system library defined for " + uri);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Collection<String> getAllLibrarySpecs() {
|
||||
Collection<String> result = new ArrayList<String>(libraries.size());
|
||||
for (SystemLibrary lib : libraries) {
|
||||
result.add("dart:" + lib.getShortName());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Collection<SystemLibrary> getAllSystemLibraries(){
|
||||
return libraries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the libraries listed out in the libraries.dart files as read by the {@link SystemLibrariesReader}
|
||||
*/
|
||||
protected SystemLibrary[] getDefaultLibraries() {
|
||||
libraries = new ArrayList<SystemLibrary>();
|
||||
longToShortUriMap = new HashMap<URI, URI>();
|
||||
|
||||
// Cycle through the import.config, extracting explicit mappings and searching directories
|
||||
URI base = this.sdkLibPathUri;
|
||||
|
||||
Map<String, DartLibrary> declaredLibraries = libraryProvider.getLibraryMap();
|
||||
|
||||
HashSet<String> explicitShortNames = new HashSet<String>();
|
||||
|
||||
for (Entry<String, DartLibrary> entry : declaredLibraries.entrySet()) {
|
||||
if (entry.getValue().getCategory().equals("Internal")
|
||||
// TODO(8365): the following line allows dart:_collection-dev to
|
||||
// be imported even though it's a hidden library.
|
||||
&& !entry.getKey().equals("dart:_collection-dev")) {
|
||||
continue;
|
||||
}
|
||||
String shortName = entry.getKey().trim();
|
||||
DartLibrary library = entry.getValue();
|
||||
String path = library.getPath();
|
||||
URI libFileUri;
|
||||
try {
|
||||
libFileUri = base.resolve(new URI(null, null, path, null, null)).normalize();
|
||||
} catch (URISyntaxException e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!libraryProvider.exists(libFileUri)) {
|
||||
throw new InternalCompilerException("Can't find system library dart:" + shortName
|
||||
+ " at " + libFileUri);
|
||||
}
|
||||
|
||||
int index = shortName.indexOf(':');
|
||||
if (index == -1) {
|
||||
continue;
|
||||
}
|
||||
explicitShortNames.add(shortName);
|
||||
String scheme = shortName.substring(0, index + 1);
|
||||
String name = shortName.substring(index + 1);
|
||||
|
||||
String relPath = sdkLibPathUri.relativize(libFileUri).getPath();
|
||||
index = relPath.indexOf('/');
|
||||
if (index == -1) {
|
||||
continue;
|
||||
}
|
||||
String host = relPath.substring(0, index);
|
||||
String pathToLib = relPath.substring(index + 1);
|
||||
|
||||
addLib(scheme,
|
||||
host,
|
||||
name,
|
||||
pathToLib,
|
||||
library.getCategory(),
|
||||
library.isDocumented(),
|
||||
library.isImplementation());
|
||||
|
||||
}
|
||||
return libraries.toArray(new SystemLibrary[libraries.size()]);
|
||||
}
|
||||
|
||||
protected boolean addLib(String scheme, String host, String name, String pathToLib,
|
||||
String category, boolean documented, boolean implementation)
|
||||
throws AssertionError {
|
||||
|
||||
SystemLibrary lib = libraryProvider.createSystemLibrary(name, host, pathToLib, category, documented, implementation);
|
||||
libraries.add(lib);
|
||||
|
||||
String libSpec = scheme + name;
|
||||
URI libUri;
|
||||
URI expandedUri;
|
||||
try {
|
||||
libUri = new URI(libSpec);
|
||||
expandedUri = new URI("dart:" + "//" + host + "/" + pathToLib);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
URI resolvedUri = lib.translateUri(expandedUri);
|
||||
longToShortUriMap.put(resolvedUri, libUri);
|
||||
longToShortUriMap.put(expandedUri, libUri);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register system libraries for the "dart:" protocol such that dart:[shortLibName] (e.g.
|
||||
* "dart:html") will automatically be expanded to dart://[host]/[pathToLib] (e.g.
|
||||
* dart://html/html.dart)
|
||||
*/
|
||||
private void setLibraries(SystemLibrary[] newLibraries) {
|
||||
libraries = new ArrayList<SystemLibrary>();
|
||||
hostMap = new HashMap<String, SystemLibrary>();
|
||||
expansionMap = new HashMap<String, String>();
|
||||
for (SystemLibrary library : newLibraries) {
|
||||
String host = library.getHost();
|
||||
SystemLibrary existingLib = hostMap.get(host);
|
||||
if (existingLib != null) {
|
||||
libraries.remove(existingLib);
|
||||
}
|
||||
libraries.add(library);
|
||||
hostMap.put(host, library);
|
||||
expansionMap.put(library.getShortName(),
|
||||
"//" + host + "/" + library.getPathToLib());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this URI denotes a patch file.
|
||||
*/
|
||||
public boolean isPatchFile(URI uri) {
|
||||
return libraryProvider.isPatchFile(uri);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012, the Dart project authors.
|
||||
*
|
||||
* Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
* or implied. See the License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import com.google.dart.compiler.SystemLibrariesReader.DartLibrary;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A provider for System libraries.
|
||||
*/
|
||||
public abstract class SystemLibraryProvider {
|
||||
|
||||
private final URI sdkLibPathUri;
|
||||
private SystemLibrariesReader reader;
|
||||
|
||||
/**
|
||||
* Create a {@link SystemLibraryProvider} with the given path to the dart SDK.
|
||||
*/
|
||||
public SystemLibraryProvider(URI sdkLibPathUri) {
|
||||
this.sdkLibPathUri = sdkLibPathUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define a new system library.
|
||||
*
|
||||
* @param name the short name of the library
|
||||
* @param host the host
|
||||
* @param pathToLib the path to the library
|
||||
* @param category the library category
|
||||
* @param documented <code>true</code> if documented, <code>false</code> otherwise
|
||||
* @param implementation <code>true</code> if an implementation library, <code>false</code>
|
||||
* otherwise
|
||||
* @return the resulting {@link SystemLibrary}
|
||||
*/
|
||||
public abstract SystemLibrary createSystemLibrary(String name, String host, String pathToLib,
|
||||
String category, boolean documented, boolean implementation);
|
||||
|
||||
/**
|
||||
* Tests whether the resource denoted by this abstract URI exists.
|
||||
*
|
||||
* @param uri the URI to test
|
||||
* @return <code>true</code> if and only if the resource denoted by this URI exists;
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
public abstract boolean exists(URI uri);
|
||||
|
||||
/**
|
||||
* Get a URI describing the root of the SDK.
|
||||
*/
|
||||
public URI getSdkLibPathUri() {
|
||||
return sdkLibPathUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mapping of symbolic names (e.g., "dart:html") to {@link DartLibrary}s.
|
||||
*/
|
||||
public Map<String, DartLibrary> getLibraryMap() {
|
||||
return getReader().getLibrariesMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this URI denotes a patch file.
|
||||
*/
|
||||
public boolean isPatchFile(URI uri) {
|
||||
return getReader().getPatchPaths().contains(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new URI by parsing the given host string and then resolving it against this URI.
|
||||
*
|
||||
* @param host the host string
|
||||
* @param uri the uri to resolve against
|
||||
* @return the resulting URI
|
||||
*/
|
||||
public abstract URI resolveHost(String host, URI uri);
|
||||
|
||||
/**
|
||||
* Create the system libraries reader.
|
||||
*
|
||||
* @return a reader for parsing system libraries
|
||||
*/
|
||||
protected abstract SystemLibrariesReader createReader() throws IOException;
|
||||
|
||||
private SystemLibrariesReader getReader() {
|
||||
if (reader == null) {
|
||||
try {
|
||||
reader = createReader();
|
||||
} catch (IOException e) {
|
||||
throw new InternalCompilerException("Unable to create system library reader", e);
|
||||
}
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
|
||||
import com.google.dart.compiler.DartCompiler.Result;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* Provides a framework to read command line options from stdin and feed them to
|
||||
* the {@link DartCompiler}.
|
||||
*
|
||||
*/
|
||||
public class UnitTestBatchRunner {
|
||||
|
||||
public interface Invocation {
|
||||
public Result invoke (String[] args) throws Throwable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the tool in 'batch' mode, receiving command lines through stdin and returning
|
||||
* pass/fail status through stdout. This feature is intended for use in unit testing.
|
||||
*
|
||||
* @param batchArgs command line arguments forwarded from main().
|
||||
*/
|
||||
public static Result runAsBatch(String[] batchArgs, Invocation toolInvocation) throws Throwable {
|
||||
System.out.println(">>> BATCH START");
|
||||
|
||||
// Read command lines in from stdin and create a new compiler for each one.
|
||||
BufferedReader cmdlineReader = new BufferedReader(new InputStreamReader(
|
||||
System.in));
|
||||
long startTime = System.currentTimeMillis();
|
||||
int testsFailed = 0;
|
||||
int totalTests = 0;
|
||||
Result batchResult = new Result(DartCompiler.RESULT_OK, null);
|
||||
try {
|
||||
String line;
|
||||
for (; (line = cmdlineReader.readLine()) != null; totalTests++) {
|
||||
long testStart = System.currentTimeMillis();
|
||||
// TODO(zundel): These are shell script cmdlines: be smarter about quoted strings.
|
||||
String[] args = line.trim().split("\\s+");
|
||||
Result result = toolInvocation.invoke(args);
|
||||
boolean resultPass = result.code < DartCompiler.RESULT_ERRORS;
|
||||
if (resultPass) {
|
||||
testsFailed++;
|
||||
}
|
||||
batchResult = batchResult.merge(result);
|
||||
// Write stderr end token and flush.
|
||||
System.err.println(">>> EOF STDERR");
|
||||
System.err.flush();
|
||||
System.out.println(">>> TEST " + (resultPass ? "PASS" : "FAIL") + " "
|
||||
+ (System.currentTimeMillis() - testStart) + "ms");
|
||||
System.out.flush();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
System.err.println(">>> EOF STDERR");
|
||||
System.err.flush();
|
||||
System.out.println(">>> TEST CRASH");
|
||||
System.out.flush();
|
||||
throw e;
|
||||
}
|
||||
long elapsed = System.currentTimeMillis() - startTime;
|
||||
System.out.println(">>> BATCH END (" + (totalTests - testsFailed) + "/"
|
||||
+ totalTests + ") " + elapsed + "ms");
|
||||
System.out.flush();
|
||||
return batchResult;
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* A {@link DartSource} backed by a URL.
|
||||
*/
|
||||
public class UrlDartSource extends UrlSource implements DartSource {
|
||||
|
||||
private final LibrarySource lib;
|
||||
private final String relPath;
|
||||
|
||||
protected UrlDartSource(URI uri, String relPath, LibrarySource lib, PackageLibraryManager slm) {
|
||||
super(uri,slm);
|
||||
this.relPath = relPath;
|
||||
this.lib = lib;
|
||||
}
|
||||
|
||||
protected UrlDartSource(URI uri, String relPath, LibrarySource lib) {
|
||||
this(uri, relPath, lib, null);
|
||||
}
|
||||
|
||||
public UrlDartSource(File file, LibrarySource lib) {
|
||||
super(file);
|
||||
this.relPath = file.getPath();
|
||||
this.lib = lib;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibrarySource getLibrary() {
|
||||
return lib;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
try {
|
||||
String uriSafeName = new URI(null, null, relPath, null).toString();
|
||||
return lib.getName() + "/" + uriSafeName;
|
||||
} catch (URISyntaxException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRelativePath() {
|
||||
return relPath;
|
||||
}
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* A {@link LibrarySource} backed by a URL.
|
||||
*/
|
||||
public class UrlLibrarySource extends UrlSource implements LibrarySource {
|
||||
|
||||
public UrlLibrarySource(URI uri, PackageLibraryManager slm) {
|
||||
super(uri, slm);
|
||||
}
|
||||
|
||||
public UrlLibrarySource(URI uri) {
|
||||
this(uri, null);
|
||||
}
|
||||
|
||||
public UrlLibrarySource(File file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getUri().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibrarySource getImportFor(String relPath) {
|
||||
if (relPath == null || relPath.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
// Force the creation of an escaped relative URI to deal with spaces, etc.
|
||||
URI uri = getUri().resolve(new URI(null, null, relPath, null, null)).normalize();
|
||||
String path = uri.getPath();
|
||||
// Resolve relative reference out of one system library into another
|
||||
if (PackageLibraryManager.isDartUri(uri)) {
|
||||
if (path != null && path.startsWith("/..")) {
|
||||
URI fileUri = packageLibraryManager.resolveDartUri(uri);
|
||||
URI shortUri = packageLibraryManager.getShortUri(fileUri);
|
||||
if (shortUri != null) {
|
||||
uri = shortUri;
|
||||
}
|
||||
}
|
||||
} else if (PackageLibraryManager.isPackageUri(uri)) {
|
||||
URI fileUri = packageLibraryManager.resolveDartUri(uri);
|
||||
if (fileUri != null) {
|
||||
uri = fileUri;
|
||||
}
|
||||
} else if (!resourceExists(uri)) {
|
||||
// resolve against package root directories to find file
|
||||
uri = packageLibraryManager.findExistingFileInPackages(uri);
|
||||
}
|
||||
|
||||
return createLibrarySource(uri, packageLibraryManager);
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DartSource getSourceFor(final String relPath) {
|
||||
if (relPath == null || relPath.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
// Force the creation of an escaped relative URI to deal with spaces, etc.
|
||||
URI uri = getUri().resolve(new URI(null, null, relPath, null, null)).normalize();
|
||||
if (PackageLibraryManager.isPackageUri(uri)) {
|
||||
URI fileUri = packageLibraryManager.resolveDartUri(uri);
|
||||
if (fileUri != null) {
|
||||
uri = fileUri;
|
||||
}
|
||||
}
|
||||
return createDartSource(uri, relPath, this, packageLibraryManager);
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a URL library source.
|
||||
*
|
||||
* (Clients can override.)
|
||||
*
|
||||
* @param uri the URI of the library
|
||||
* @param relPath relative path to the dart source
|
||||
* @param libSource the library source
|
||||
* @param packageManager the package library manager
|
||||
* @return the resulting dart source
|
||||
*/
|
||||
protected UrlDartSource createDartSource(URI uri, String relPath, UrlLibrarySource libSource, PackageLibraryManager packageManager) {
|
||||
return new UrlDartSource(uri, relPath, libSource, packageManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a URL library source.
|
||||
*
|
||||
* (Clients can override.)
|
||||
*
|
||||
* @param uri the URI of the library
|
||||
* @return the resulting library source
|
||||
*/
|
||||
protected UrlLibrarySource createLibrarySource(URI uri, PackageLibraryManager packageManager) {
|
||||
return new UrlLibrarySource(uri, packageManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a resource exists at this URI.
|
||||
*
|
||||
* (Clients can override.)
|
||||
*
|
||||
* @param uri the URI to test
|
||||
* @return <code>true</code> if a resource exists at this URI, <code>false</code> otherwise
|
||||
*/
|
||||
protected boolean resourceExists(URI uri) {
|
||||
String path = uri.getPath();
|
||||
return path == null || new File(path).exists();
|
||||
}
|
||||
}
|
|
@ -1,205 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.jar.JarEntry;
|
||||
|
||||
/**
|
||||
* A {@link Source} backed by a URL (or optionally by a file).
|
||||
*/
|
||||
public abstract class UrlSource implements Source {
|
||||
|
||||
private final static String FILE_PROTOCOL = "file";
|
||||
private final static String JAR_PROTOCOL = "jar";
|
||||
private final static URI CURRENT_DIR = new File(".").toURI().normalize();
|
||||
private final static Charset UTF8 = Charset.forName("UTF8");
|
||||
private final static URI BASE_URI = CURRENT_DIR;
|
||||
|
||||
private final URI uri;
|
||||
private final URI absoluteUri;
|
||||
private final URI translatedUri;
|
||||
private final boolean shouldCareAboutLastModified;
|
||||
private volatile boolean exists = false;
|
||||
private volatile long lastModified = -1;
|
||||
private volatile boolean propertiesInitialized = false;
|
||||
|
||||
// generally, one or the other of these will be non-null after properties are initialized
|
||||
private volatile File sourceFile = null;
|
||||
private volatile JarURLConnection jarConn = null;
|
||||
|
||||
protected final PackageLibraryManager packageLibraryManager;
|
||||
|
||||
protected UrlSource(URI uri) {
|
||||
this(uri,null);
|
||||
}
|
||||
|
||||
protected UrlSource(URI uri, PackageLibraryManager slm) {
|
||||
URI expanded = slm != null ? slm.expandRelativeDartUri(uri) : uri;
|
||||
if (expanded == null) {
|
||||
// import("dart:typo") case
|
||||
expanded = uri;
|
||||
}
|
||||
this.uri = BASE_URI.relativize(expanded.normalize());
|
||||
this.absoluteUri = BASE_URI.resolve(expanded);
|
||||
this.packageLibraryManager = slm;
|
||||
if (PackageLibraryManager.isDartUri(this.uri) || PackageLibraryManager.isPackageUri(this.uri)) {
|
||||
assert slm != null;
|
||||
this.shouldCareAboutLastModified = false;
|
||||
this.translatedUri = slm.resolveDartUri(this.absoluteUri);
|
||||
} else {
|
||||
this.shouldCareAboutLastModified = true;
|
||||
this.translatedUri = this.absoluteUri;
|
||||
}
|
||||
}
|
||||
|
||||
protected UrlSource(File file) {
|
||||
URI uri = file.toURI().normalize();
|
||||
if (!file.exists()) {
|
||||
// TODO(jgw): This is a bit ugly, but some of the test infrastructure depends upon
|
||||
// non-existant relative files being looked up as classpath resources. This was
|
||||
// previously embedded in DartSourceFile.getSourceReader().
|
||||
URL url = getClass().getClassLoader().getResource(file.getPath());
|
||||
if (url != null) {
|
||||
uri = URI.create(url.toString());
|
||||
}
|
||||
}
|
||||
|
||||
this.uri = BASE_URI.relativize(uri);
|
||||
this.translatedUri = this.absoluteUri = BASE_URI.resolve(uri);
|
||||
this.packageLibraryManager = null;
|
||||
this.shouldCareAboutLastModified = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
initProperties();
|
||||
return exists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastModified() {
|
||||
initProperties();
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader getSourceReader() throws IOException {
|
||||
initProperties();
|
||||
if (sourceFile != null) {
|
||||
return new InputStreamReader(new FileInputStream(sourceFile), UTF8);
|
||||
} else if (jarConn != null) {
|
||||
return new InputStreamReader(jarConn.getInputStream(), UTF8);
|
||||
}
|
||||
// fall back case
|
||||
if (translatedUri != null) {
|
||||
InputStream stream = translatedUri.toURL().openStream();
|
||||
if (stream != null) {
|
||||
return new InputStreamReader(stream, UTF8);
|
||||
}
|
||||
}
|
||||
throw new FileNotFoundException(getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueIdentifier() {
|
||||
return absoluteUri.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translated URI for this source.
|
||||
*
|
||||
* @return the translated URI
|
||||
*/
|
||||
public URI getTranslatedUri() {
|
||||
return translatedUri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getUri() {
|
||||
return absoluteUri;
|
||||
}
|
||||
|
||||
private void initProperties() {
|
||||
synchronized (this) {
|
||||
if (!propertiesInitialized) {
|
||||
try {
|
||||
initPropertiesEx();
|
||||
} catch (Throwable e) {
|
||||
} finally {
|
||||
propertiesInitialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link #initProperties()} which can throw exceptions.
|
||||
*/
|
||||
private void initPropertiesEx() throws Exception {
|
||||
URI resolvedUri = BASE_URI.resolve(translatedUri);
|
||||
String scheme = resolvedUri.getScheme();
|
||||
if (scheme == null || FILE_PROTOCOL.equals(scheme)) {
|
||||
File file = new File(resolvedUri);
|
||||
lastModified = file.lastModified();
|
||||
exists = file.exists();
|
||||
sourceFile = file;
|
||||
} else {
|
||||
URL url = translatedUri.toURL();
|
||||
if (JAR_PROTOCOL.equals(url.getProtocol())) {
|
||||
getJarEntryProperties(url);
|
||||
} else {
|
||||
/*
|
||||
* TODO(jbrosenberg): Flesh out the support for other
|
||||
* protocols, like http, etc. Note, calling
|
||||
* URLConnection.getLastModified() can be dangerous, some
|
||||
* URLConnection sub-classes don't have a way to close a
|
||||
* connection opened by this call. Return 0 for now.
|
||||
*/
|
||||
lastModified = 0;
|
||||
// Default this to true for now.
|
||||
exists = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getJarEntryProperties(URL url) {
|
||||
try {
|
||||
jarConn = (JarURLConnection) url.openConnection();
|
||||
// useCaches is usually set to true by default, but make sure here
|
||||
jarConn.setUseCaches(true);
|
||||
// See if our entry exists
|
||||
JarEntry jarEntry = jarConn.getJarEntry();
|
||||
if (jarEntry != null) {
|
||||
exists = true;
|
||||
if (!shouldCareAboutLastModified) {
|
||||
lastModified = 0;
|
||||
return;
|
||||
}
|
||||
// TODO(jbrosenberg): Note the time field for a jarEntry can be
|
||||
// unreliable, and is not always required in a jar file. Consider using
|
||||
// the timestamp on the jar file itself.
|
||||
lastModified = jarEntry.getTime();
|
||||
}
|
||||
if (!exists) {
|
||||
lastModified = -1;
|
||||
return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
exists = false;
|
||||
lastModified = -1;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,411 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A visitor for abstract syntax tree.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* public R visitArrayAccess(DartArrayAccess node) {
|
||||
* // Actions before visiting subnodes.
|
||||
* node.visitChildren(this);
|
||||
* // Actions after visiting subnodes.
|
||||
* return node;
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* In addition, this visitor takes advantage of the AST-node class hierarchy and makes it easy to
|
||||
* perform an action for, for example, all statements:
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* public R visitStatement(DartStatement node) {
|
||||
* // Action that must be performed for all statements.
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
public class ASTVisitor<R> {
|
||||
|
||||
public R visitNode(DartNode node) {
|
||||
node.visitChildren(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
public R visitNodeWithMetadata(DartNodeWithMetadata node) {
|
||||
return visitNode(node);
|
||||
}
|
||||
|
||||
public R visitDirective(DartDirective node) {
|
||||
return visitNodeWithMetadata(node);
|
||||
}
|
||||
|
||||
public R visitInvocation(DartInvocation node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitExportDirective(DartExportDirective node) {
|
||||
return visitDirective(node);
|
||||
}
|
||||
|
||||
public R visitExpression(DartExpression node) {
|
||||
return visitNode(node);
|
||||
}
|
||||
|
||||
public R visitStatement(DartStatement node) {
|
||||
return visitNode(node);
|
||||
}
|
||||
|
||||
public R visitLiteral(DartLiteral node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitGotoStatement(DartGotoStatement node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitSwitchMember(DartSwitchMember node) {
|
||||
return visitNode(node);
|
||||
}
|
||||
|
||||
public R visitDeclaration(DartDeclaration<?> node) {
|
||||
return visitNodeWithMetadata(node);
|
||||
}
|
||||
|
||||
public R visitClassMember(DartClassMember<?> node) {
|
||||
return visitDeclaration(node);
|
||||
}
|
||||
|
||||
public R visitComment(DartComment node) {
|
||||
return visitNode(node);
|
||||
}
|
||||
|
||||
public R visitCommentNewName(DartCommentNewName node) {
|
||||
return visitNode(node);
|
||||
}
|
||||
|
||||
public R visitCommentRefName(DartCommentRefName node) {
|
||||
return visitNode(node);
|
||||
}
|
||||
|
||||
public R visitAnnotation(DartAnnotation node) {
|
||||
return visitNode(node);
|
||||
}
|
||||
|
||||
public R visitArrayAccess(DartArrayAccess node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitArrayLiteral(DartArrayLiteral node) {
|
||||
return visitTypedLiteral(node);
|
||||
}
|
||||
|
||||
public R visitBinaryExpression(DartBinaryExpression node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitBlock(DartBlock node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitReturnBlock(DartReturnBlock node) {
|
||||
return visitBlock(node);
|
||||
}
|
||||
|
||||
public R visitBooleanLiteral(DartBooleanLiteral node) {
|
||||
return visitLiteral(node);
|
||||
}
|
||||
|
||||
public R visitAssertStatement(DartAssertStatement node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitBreakStatement(DartBreakStatement node) {
|
||||
return visitGotoStatement(node);
|
||||
}
|
||||
|
||||
public R visitFunctionObjectInvocation(DartFunctionObjectInvocation node) {
|
||||
return visitInvocation(node);
|
||||
}
|
||||
|
||||
public R visitMethodInvocation(DartMethodInvocation node) {
|
||||
return visitInvocation(node);
|
||||
}
|
||||
|
||||
public R visitUnqualifiedInvocation(DartUnqualifiedInvocation node) {
|
||||
return visitInvocation(node);
|
||||
}
|
||||
|
||||
public R visitSuperConstructorInvocation(DartSuperConstructorInvocation node) {
|
||||
return visitInvocation(node);
|
||||
}
|
||||
|
||||
public R visitCascadeExpression(DartCascadeExpression node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitCase(DartCase node) {
|
||||
return visitSwitchMember(node);
|
||||
}
|
||||
|
||||
public R visitClass(DartClass node) {
|
||||
return visitDeclaration(node);
|
||||
}
|
||||
|
||||
public R visitConditional(DartConditional node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitContinueStatement(DartContinueStatement node) {
|
||||
return visitGotoStatement(node);
|
||||
}
|
||||
|
||||
public R visitDefault(DartDefault node) {
|
||||
return visitSwitchMember(node);
|
||||
}
|
||||
|
||||
public R visitDoubleLiteral(DartDoubleLiteral node) {
|
||||
return visitLiteral(node);
|
||||
}
|
||||
|
||||
public R visitDoWhileStatement(DartDoWhileStatement node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitEmptyStatement(DartEmptyStatement node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitExprStmt(DartExprStmt node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitField(DartField node) {
|
||||
return visitClassMember(node);
|
||||
}
|
||||
|
||||
public R visitFieldDefinition(DartFieldDefinition node) {
|
||||
return visitNodeWithMetadata(node);
|
||||
}
|
||||
|
||||
public R visitForInStatement(DartForInStatement node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitForStatement(DartForStatement node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitFunction(DartFunction node) {
|
||||
return visitNode(node);
|
||||
}
|
||||
|
||||
public R visitFunctionExpression(DartFunctionExpression node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitFunctionTypeAlias(DartFunctionTypeAlias node) {
|
||||
return visitDeclaration(node);
|
||||
}
|
||||
|
||||
public R visitClassTypeAlias(DartClassTypeAlias node) {
|
||||
return visitDeclaration(node);
|
||||
}
|
||||
|
||||
public R visitIdentifier(DartIdentifier node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitIfStatement(DartIfStatement node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitImportCombinator(ImportCombinator node) {
|
||||
return visitNode(node);
|
||||
}
|
||||
|
||||
public R visitImportDirective(DartImportDirective node) {
|
||||
return visitDirective(node);
|
||||
}
|
||||
|
||||
public R visitImportHideCombinator(ImportHideCombinator node) {
|
||||
return visitImportCombinator(node);
|
||||
}
|
||||
|
||||
public R visitImportShowCombinator(ImportShowCombinator node) {
|
||||
return visitImportCombinator(node);
|
||||
}
|
||||
|
||||
public R visitInitializer(DartInitializer node) {
|
||||
return visitNode(node);
|
||||
}
|
||||
|
||||
public R visitIntegerLiteral(DartIntegerLiteral node) {
|
||||
return visitLiteral(node);
|
||||
}
|
||||
|
||||
public R visitLabel(DartLabel node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitLibraryDirective(DartLibraryDirective node) {
|
||||
return visitDirective(node);
|
||||
}
|
||||
|
||||
public R visitTypedLiteral(DartTypedLiteral node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitMapLiteral(DartMapLiteral node) {
|
||||
return visitTypedLiteral(node);
|
||||
}
|
||||
|
||||
public R visitMapLiteralEntry(DartMapLiteralEntry node) {
|
||||
return visitNode(node);
|
||||
}
|
||||
|
||||
public R visitMethodDefinition(DartMethodDefinition node) {
|
||||
return visitClassMember(node);
|
||||
}
|
||||
|
||||
public R visitNativeDirective(DartNativeDirective node) {
|
||||
return visitDirective(node);
|
||||
}
|
||||
|
||||
public R visitNewExpression(DartNewExpression node) {
|
||||
return visitInvocation(node);
|
||||
}
|
||||
|
||||
public R visitNullLiteral(DartNullLiteral node) {
|
||||
return visitLiteral(node);
|
||||
}
|
||||
|
||||
public R visitParameter(DartParameter node) {
|
||||
return visitDeclaration(node);
|
||||
}
|
||||
|
||||
public R visitParameterizedTypeNode(DartParameterizedTypeNode node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitParenthesizedExpression(DartParenthesizedExpression node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitPartOfDirective(DartPartOfDirective node) {
|
||||
return visitDirective(node);
|
||||
}
|
||||
|
||||
public R visitPropertyAccess(DartPropertyAccess node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitTypeNode(DartTypeNode node) {
|
||||
return visitNode(node);
|
||||
}
|
||||
|
||||
public R visitReturnStatement(DartReturnStatement node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitSourceDirective(DartSourceDirective node) {
|
||||
return visitDirective(node);
|
||||
}
|
||||
|
||||
public R visitStringLiteral(DartStringLiteral node) {
|
||||
return visitLiteral(node);
|
||||
}
|
||||
|
||||
public R visitStringInterpolation(DartStringInterpolation node) {
|
||||
return visitLiteral(node);
|
||||
}
|
||||
|
||||
public R visitSuperExpression(DartSuperExpression node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitSwitchStatement(DartSwitchStatement node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitSyntheticErrorExpression(DartSyntheticErrorExpression node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitSyntheticErrorIdentifier(DartSyntheticErrorIdentifier node) {
|
||||
return visitIdentifier(node);
|
||||
}
|
||||
|
||||
public R visitSyntheticErrorStatement(DartSyntheticErrorStatement node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitThisExpression(DartThisExpression node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitThrowExpression(DartThrowExpression node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitCatchBlock(DartCatchBlock node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitTryStatement(DartTryStatement node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitUnaryExpression(DartUnaryExpression node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitUnit(DartUnit node) {
|
||||
return visitNode(node);
|
||||
}
|
||||
|
||||
public R visitVariable(DartVariable node) {
|
||||
return visitDeclaration(node);
|
||||
}
|
||||
|
||||
public R visitVariableStatement(DartVariableStatement node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public R visitWhileStatement(DartWhileStatement node) {
|
||||
return visitStatement(node);
|
||||
}
|
||||
|
||||
public void visit(List<? extends DartNode> nodes) {
|
||||
if (nodes != null) {
|
||||
for (DartNode node : nodes) {
|
||||
node.accept(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public R visitNamedExpression(DartNamedExpression node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitTypeExpression(DartTypeExpression node) {
|
||||
return visitExpression(node);
|
||||
}
|
||||
|
||||
public R visitTypeParameter(DartTypeParameter node) {
|
||||
return visitDeclaration(node);
|
||||
}
|
||||
|
||||
public R visitNativeBlock(DartNativeBlock node) {
|
||||
return visitBlock(node);
|
||||
}
|
||||
|
||||
public R visitRedirectConstructorInvocation(DartRedirectConstructorInvocation node) {
|
||||
return visitInvocation(node);
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Instances of the class {@code DartAnnotation} represent metadata that can be associated with an
|
||||
* AST node.
|
||||
*
|
||||
* <pre>
|
||||
* metadata ::=
|
||||
* annotation*
|
||||
*
|
||||
* annotation ::=
|
||||
* '@' qualified ('.' identifier)? arguments?
|
||||
* </pre>
|
||||
*/
|
||||
public class DartAnnotation extends DartNode {
|
||||
private DartExpression name;
|
||||
|
||||
private NodeList<DartExpression> arguments = NodeList.create(this);
|
||||
|
||||
public DartAnnotation(DartExpression name, List<DartExpression> arguments) {
|
||||
this.name = becomeParentOf(name);
|
||||
if (arguments != null) {
|
||||
this.arguments.addAll(arguments);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitAnnotation(this);
|
||||
}
|
||||
|
||||
public DartExpression getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public NodeList<DartExpression> getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(name, visitor);
|
||||
arguments.accept(visitor);
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import com.google.dart.compiler.resolver.Element;
|
||||
import com.google.dart.compiler.resolver.MethodNodeElement;
|
||||
|
||||
/**
|
||||
* Represents a Dart array access expression (a[b]).
|
||||
*/
|
||||
public class DartArrayAccess extends DartExpression {
|
||||
|
||||
private DartExpression target;
|
||||
private boolean isCascade;
|
||||
private DartExpression key;
|
||||
private MethodNodeElement element;
|
||||
|
||||
public DartArrayAccess(DartExpression target, DartExpression key) {
|
||||
this(target, false, key);
|
||||
}
|
||||
|
||||
public DartArrayAccess(DartExpression target, boolean isCascade, DartExpression key) {
|
||||
this.target = becomeParentOf(target);
|
||||
this.isCascade = isCascade;
|
||||
this.key = becomeParentOf(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isCascade() {
|
||||
return isCascade;
|
||||
}
|
||||
|
||||
public DartExpression getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public DartExpression getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public DartExpression getRealTarget() {
|
||||
if (isCascade) {
|
||||
DartNode ancestor = getParent();
|
||||
while (!(ancestor instanceof DartCascadeExpression)) {
|
||||
if (ancestor == null) {
|
||||
return target;
|
||||
}
|
||||
ancestor = ancestor.getParent();
|
||||
}
|
||||
return ((DartCascadeExpression) ancestor).getTarget();
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(target, visitor);
|
||||
safelyVisitChild(key, visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitArrayAccess(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodNodeElement getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setElement(Element element) {
|
||||
this.element = (MethodNodeElement) element;
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a Dart array literal value.
|
||||
*/
|
||||
public class DartArrayLiteral extends DartTypedLiteral {
|
||||
|
||||
private final NodeList<DartExpression> expressions = NodeList.create(this);
|
||||
|
||||
public DartArrayLiteral(boolean isConst, List<DartTypeNode> typeArguments,
|
||||
List<DartExpression> expressions) {
|
||||
super(isConst, typeArguments);
|
||||
this.expressions.addAll(expressions);
|
||||
}
|
||||
|
||||
public List<DartExpression> getExpressions() {
|
||||
return expressions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
super.visitChildren(visitor);
|
||||
expressions.accept(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitArrayLiteral(this);
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
/**
|
||||
* Represents a Dart 'assert' statement.
|
||||
*/
|
||||
public class DartAssertStatement extends DartStatement {
|
||||
|
||||
private final DartExpression condition;
|
||||
|
||||
public DartAssertStatement(DartExpression condition) {
|
||||
this.condition = becomeParentOf(condition);
|
||||
}
|
||||
|
||||
public DartExpression getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(condition, visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitAssertStatement(this);
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import com.google.dart.compiler.parser.Token;
|
||||
import com.google.dart.compiler.resolver.Element;
|
||||
import com.google.dart.compiler.resolver.MethodNodeElement;
|
||||
|
||||
/**
|
||||
* Represents a Dart binary expression.
|
||||
*/
|
||||
public class DartBinaryExpression extends DartExpression {
|
||||
|
||||
private final Token op;
|
||||
private final int opOffset;
|
||||
private DartExpression arg1;
|
||||
private DartExpression arg2;
|
||||
private MethodNodeElement element;
|
||||
|
||||
public DartBinaryExpression(Token op, int opOffset, DartExpression arg1, DartExpression arg2) {
|
||||
this.opOffset = opOffset;
|
||||
assert op.isBinaryOperator() : op;
|
||||
|
||||
this.op = op;
|
||||
this.arg1 = becomeParentOf(arg1 != null ? arg1 : new DartSyntheticErrorExpression());
|
||||
this.arg2 = becomeParentOf(arg2 != null ? arg2 : new DartSyntheticErrorExpression());
|
||||
}
|
||||
|
||||
public DartExpression getArg1() {
|
||||
return arg1;
|
||||
}
|
||||
|
||||
public DartExpression getArg2() {
|
||||
return arg2;
|
||||
}
|
||||
|
||||
public Token getOperator() {
|
||||
return op;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the character offset of the {@link #getOperator()} token.
|
||||
*/
|
||||
public int getOperatorOffset() {
|
||||
return opOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(arg1, visitor);
|
||||
safelyVisitChild(arg2, visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitBinaryExpression(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodNodeElement getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setElement(Element element) {
|
||||
this.element = (MethodNodeElement) element;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a Dart statement block.
|
||||
*/
|
||||
public class DartBlock extends DartStatement {
|
||||
|
||||
private final NodeList<DartStatement> statements = NodeList.create(this);
|
||||
|
||||
public DartBlock(List<DartStatement> statements) {
|
||||
if (statements != null && !statements.isEmpty()) {
|
||||
this.statements.addAll(statements);
|
||||
}
|
||||
}
|
||||
|
||||
public List<DartStatement> getStatements() {
|
||||
return statements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbruptCompletingStatement() {
|
||||
for (DartStatement stmt : statements) {
|
||||
if (stmt.isAbruptCompletingStatement()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
statements.accept(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitBlock(this);
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
/**
|
||||
* Represents a Dart boolean literal value.
|
||||
*/
|
||||
public class DartBooleanLiteral extends DartLiteral {
|
||||
|
||||
public static DartBooleanLiteral get(boolean value) {
|
||||
return new DartBooleanLiteral(value);
|
||||
}
|
||||
|
||||
private final boolean value;
|
||||
|
||||
private DartBooleanLiteral(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitBooleanLiteral(this);
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
/**
|
||||
* Represents a Dart 'break' statement.
|
||||
*/
|
||||
public class DartBreakStatement extends DartGotoStatement {
|
||||
|
||||
public DartBreakStatement(DartIdentifier label) {
|
||||
super(label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbruptCompletingStatement() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitBreakStatement(this);
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Instances of the class {@code DartCascadeExpression} represent a sequence of cascaded expressions:
|
||||
* expressions that share a common target. There are three kinds of expressions that can be used in
|
||||
* a cascade expression: {@link DartArrayAccess}, {@link DartMethodInvocation} and {@link DartPropertyAccess}.
|
||||
*
|
||||
* <pre>
|
||||
* cascadeExpression ::=
|
||||
* {@link DartExpression conditionalExpression} cascadeSection*
|
||||
*
|
||||
* cascadeSection ::=
|
||||
* '..' (cascadeSelector arguments*) (assignableSelector arguments*)* (assignmentOperator expressionWithoutCascade)?
|
||||
*
|
||||
* cascadeSelector ::=
|
||||
* '[ ' expression '] '
|
||||
* | identifier
|
||||
* </pre>
|
||||
*/
|
||||
public class DartCascadeExpression extends DartExpression {
|
||||
/**
|
||||
* The target of the cascade sections.
|
||||
*/
|
||||
private DartExpression target;
|
||||
|
||||
/**
|
||||
* The cascade sections sharing the common target.
|
||||
*/
|
||||
private NodeList<DartExpression> cascadeSections = new NodeList<DartExpression>(this);
|
||||
|
||||
/**
|
||||
* Initialize a newly created cascade expression.
|
||||
*
|
||||
* @param target the target of the cascade sections
|
||||
* @param cascadeSections the cascade sections sharing the common target
|
||||
*/
|
||||
public DartCascadeExpression(DartExpression target, List<DartExpression> cascadeSections) {
|
||||
this.target = becomeParentOf(target);
|
||||
this.cascadeSections.addAll(cascadeSections);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitCascadeExpression(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cascade sections sharing the common target.
|
||||
*
|
||||
* @return the cascade sections sharing the common target
|
||||
*/
|
||||
public NodeList<DartExpression> getCascadeSections() {
|
||||
return cascadeSections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the target of the cascade sections.
|
||||
*
|
||||
* @return the target of the cascade sections
|
||||
*/
|
||||
public DartExpression getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the target of the cascade sections to the given expression.
|
||||
*
|
||||
* @param target the target of the cascade sections
|
||||
*/
|
||||
public void setTarget(DartExpression target) {
|
||||
this.target = becomeParentOf(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(target, visitor);
|
||||
cascadeSections.accept(visitor);
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a Dart 'case' switch member.
|
||||
*/
|
||||
public class DartCase extends DartSwitchMember {
|
||||
|
||||
private DartExpression expr;
|
||||
|
||||
public DartCase(DartExpression expr, List<DartLabel> labels, List<DartStatement> statements) {
|
||||
super(labels, statements);
|
||||
this.expr = becomeParentOf(expr);
|
||||
}
|
||||
|
||||
public DartExpression getExpr() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(expr, visitor);
|
||||
super.visitChildren(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitCase(this);
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
/**
|
||||
* Represents a Dart 'catch' block.
|
||||
*/
|
||||
public class DartCatchBlock extends DartStatement {
|
||||
private final int onTokenOffset;
|
||||
private final DartParameter exception;
|
||||
private final DartParameter stackTrace;
|
||||
private final DartBlock block;
|
||||
|
||||
public DartCatchBlock(DartBlock block,
|
||||
int onTokenOffset,
|
||||
DartParameter exception,
|
||||
DartParameter stackTrace) {
|
||||
this.block = becomeParentOf(block);
|
||||
this.onTokenOffset = onTokenOffset;
|
||||
this.exception = becomeParentOf(exception);
|
||||
this.stackTrace = becomeParentOf(stackTrace);
|
||||
}
|
||||
|
||||
public int getOnTokenOffset() {
|
||||
return onTokenOffset;
|
||||
}
|
||||
|
||||
public DartParameter getException() {
|
||||
return exception;
|
||||
}
|
||||
|
||||
public DartParameter getStackTrace() {
|
||||
return stackTrace;
|
||||
}
|
||||
|
||||
public DartBlock getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(exception, visitor);
|
||||
safelyVisitChild(stackTrace, visitor);
|
||||
safelyVisitChild(block, visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitCatchBlock(this);
|
||||
}
|
||||
}
|
|
@ -1,204 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import com.google.dart.compiler.resolver.ClassNodeElement;
|
||||
import com.google.dart.compiler.resolver.Element;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a Dart class.
|
||||
*/
|
||||
public class DartClass extends DartDeclaration<DartIdentifier> {
|
||||
|
||||
private ClassNodeElement element;
|
||||
|
||||
private DartTypeNode superclass;
|
||||
|
||||
private final NodeList<DartNode> members = NodeList.create(this);
|
||||
private final NodeList<DartTypeParameter> typeParameters = NodeList.create(this);
|
||||
private final NodeList<DartTypeNode> interfaces = NodeList.create(this);
|
||||
private final NodeList<DartTypeNode> mixins = NodeList.create(this);
|
||||
|
||||
private boolean isInterface;
|
||||
private DartParameterizedTypeNode defaultClass;
|
||||
private final Modifiers modifiers;
|
||||
|
||||
// If the Dart class is implemented by a native JS class the nativeName
|
||||
// points to the JS class. Otherwise it is null.
|
||||
private final DartStringLiteral nativeName;
|
||||
|
||||
private final int tokenOffset;
|
||||
private final int tokenLength;
|
||||
private final int defaultTokenOffset;
|
||||
private final int implementsOffset;
|
||||
private final int openBraceOffset;
|
||||
private final int closeBraceOffset;
|
||||
|
||||
public DartClass(int tokenOffset, int tokenLength, DartIdentifier name,
|
||||
DartStringLiteral nativeName, DartTypeNode superclass, int implementsOffset,
|
||||
List<DartTypeNode> interfaces, List<DartTypeNode> mixins, int defaultTokenOffset,
|
||||
int openBraceOffset, int closeBraceOffset, List<DartNode> members,
|
||||
List<DartTypeParameter> typeParameters, DartParameterizedTypeNode defaultClass,
|
||||
boolean isInterface, Modifiers modifiers) {
|
||||
super(name);
|
||||
this.tokenOffset = tokenOffset;
|
||||
this.tokenLength = tokenLength;
|
||||
this.nativeName = becomeParentOf(nativeName);
|
||||
this.superclass = becomeParentOf(superclass);
|
||||
this.defaultTokenOffset = defaultTokenOffset;
|
||||
this.openBraceOffset = openBraceOffset;
|
||||
this.closeBraceOffset = closeBraceOffset;
|
||||
this.members.addAll(members);
|
||||
this.typeParameters.addAll(typeParameters);
|
||||
this.implementsOffset = implementsOffset;
|
||||
this.interfaces.addAll(interfaces);
|
||||
this.mixins.addAll(mixins);
|
||||
this.defaultClass = becomeParentOf(defaultClass);
|
||||
this.isInterface = isInterface;
|
||||
this.modifiers = modifiers;
|
||||
}
|
||||
|
||||
public boolean isInterface() {
|
||||
return isInterface;
|
||||
}
|
||||
|
||||
public Modifiers getModifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
public boolean isAbstract() {
|
||||
if (modifiers.isAbstract()) {
|
||||
return true;
|
||||
}
|
||||
for (DartNode node : members) {
|
||||
if (node instanceof DartMethodDefinition) {
|
||||
DartMethodDefinition methodDefinition = (DartMethodDefinition) node;
|
||||
if (methodDefinition.getModifiers().isAbstract()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (node instanceof DartFieldDefinition) {
|
||||
DartFieldDefinition fieldDefinition = (DartFieldDefinition) node;
|
||||
for (DartField field : fieldDefinition.getFields()) {
|
||||
if (field.getModifiers().isAbstract()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getTokenOffset() {
|
||||
return tokenOffset;
|
||||
}
|
||||
|
||||
public int getTokenLength() {
|
||||
return tokenLength;
|
||||
}
|
||||
|
||||
public int getDefaultTokenOffset() {
|
||||
return defaultTokenOffset;
|
||||
}
|
||||
|
||||
public int getOpenBraceOffset() {
|
||||
return openBraceOffset;
|
||||
}
|
||||
|
||||
public int getCloseBraceOffset() {
|
||||
return closeBraceOffset;
|
||||
}
|
||||
|
||||
public List<DartNode> getMembers() {
|
||||
return members;
|
||||
}
|
||||
|
||||
public List<DartTypeParameter> getTypeParameters() {
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
public int getImplementsOffset() {
|
||||
return implementsOffset;
|
||||
}
|
||||
|
||||
public List<DartTypeNode> getInterfaces() {
|
||||
return interfaces;
|
||||
}
|
||||
|
||||
public NodeList<DartTypeNode> getMixins() {
|
||||
return mixins;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
if (getName() == null) {
|
||||
return null;
|
||||
}
|
||||
return getName().getName();
|
||||
}
|
||||
|
||||
public DartTypeNode getSuperclass() {
|
||||
return superclass;
|
||||
}
|
||||
|
||||
public DartParameterizedTypeNode getDefaultClass() {
|
||||
return defaultClass;
|
||||
}
|
||||
|
||||
public Element getDefaultSymbol() {
|
||||
if (defaultClass != null) {
|
||||
return defaultClass.getType().getElement();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Element getSuperSymbol() {
|
||||
if (superclass != null) {
|
||||
return superclass.getType().getElement();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassNodeElement getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
public void setDefaultClass(DartParameterizedTypeNode newName) {
|
||||
defaultClass = becomeParentOf(newName);
|
||||
}
|
||||
|
||||
public void setSuperclass(DartTypeNode newName) {
|
||||
superclass = becomeParentOf(newName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setElement(Element element) {
|
||||
this.element = (ClassNodeElement) element;
|
||||
}
|
||||
|
||||
public DartStringLiteral getNativeName() {
|
||||
return nativeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
super.visitChildren(visitor);
|
||||
typeParameters.accept(visitor);
|
||||
safelyVisitChild(superclass, visitor);
|
||||
interfaces.accept(visitor);
|
||||
mixins.accept(visitor);
|
||||
safelyVisitChild(defaultClass, visitor);
|
||||
members.accept(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitClass(this);
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import com.google.dart.compiler.resolver.NodeElement;
|
||||
|
||||
/**
|
||||
* Base class for class members (fields and methods).
|
||||
*/
|
||||
public abstract class DartClassMember<N extends DartExpression> extends DartDeclaration<N> {
|
||||
|
||||
private final Modifiers modifiers;
|
||||
|
||||
protected DartClassMember(N name, Modifiers modifiers) {
|
||||
super(name);
|
||||
this.modifiers = modifiers;
|
||||
}
|
||||
|
||||
public Modifiers getModifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract NodeElement getElement();
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import com.google.dart.compiler.resolver.ClassNodeElement;
|
||||
import com.google.dart.compiler.resolver.Element;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Instances of the class {@code DartClassTypeAlias} represent a class type alias.
|
||||
*/
|
||||
public class DartClassTypeAlias extends DartDeclaration<DartIdentifier> {
|
||||
private final NodeList<DartTypeParameter> typeParameters = NodeList.create(this);
|
||||
private final Modifiers modifiers;
|
||||
private final DartTypeNode superclass;
|
||||
private final NodeList<DartTypeNode> mixins = NodeList.create(this);
|
||||
private final NodeList<DartTypeNode> interfaces = NodeList.create(this);
|
||||
private ClassNodeElement element;
|
||||
|
||||
public DartClassTypeAlias(DartIdentifier name, List<DartTypeParameter> typeParameters,
|
||||
Modifiers modifiers, DartTypeNode superclass, List<DartTypeNode> mixins,
|
||||
List<DartTypeNode> interfaces) {
|
||||
super(name);
|
||||
this.typeParameters.addAll(typeParameters);
|
||||
this.modifiers = modifiers;
|
||||
this.superclass = becomeParentOf(superclass);
|
||||
this.mixins.addAll(mixins);
|
||||
this.interfaces.addAll(interfaces);
|
||||
}
|
||||
|
||||
public List<DartTypeParameter> getTypeParameters() {
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
public Modifiers getModifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
public boolean isAbstract() {
|
||||
return modifiers.isAbstract();
|
||||
}
|
||||
|
||||
public DartTypeNode getSuperclass() {
|
||||
return superclass;
|
||||
}
|
||||
|
||||
public NodeList<DartTypeNode> getMixins() {
|
||||
return mixins;
|
||||
}
|
||||
|
||||
public List<DartTypeNode> getInterfaces() {
|
||||
return interfaces;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
if (getName() == null) {
|
||||
return null;
|
||||
}
|
||||
return getName().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassNodeElement getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setElement(Element element) {
|
||||
this.element = (ClassNodeElement) element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
super.visitChildren(visitor);
|
||||
typeParameters.accept(visitor);
|
||||
superclass.accept(visitor);
|
||||
mixins.accept(visitor);
|
||||
interfaces.accept(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitClassTypeAlias(this);
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import com.google.dart.compiler.Source;
|
||||
import com.google.dart.compiler.common.SourceInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DartComment extends DartNode {
|
||||
private final NodeList<DartCommentRefName> refNames = NodeList.create(this);
|
||||
private final NodeList<DartCommentNewName> newNames = NodeList.create(this);
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final long serialVersionUID = 6066713446767517627L;
|
||||
|
||||
public static enum Style {
|
||||
END_OF_LINE, BLOCK, DART_DOC;
|
||||
}
|
||||
|
||||
private Style style;
|
||||
|
||||
public DartComment(Source source, int start, int length, Style style) {
|
||||
setSourceInfo(new SourceInfo(source, start, length));
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <code>true<code> if this comment is a block comment.
|
||||
*
|
||||
* @return <code>true<code> if this comment is a block comment
|
||||
*/
|
||||
public boolean isBlock() {
|
||||
return style == Style.BLOCK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <code>true<code> if this comment is a DartDoc comment.
|
||||
*
|
||||
* @return <code>true<code> if this comment is a DartDoc comment
|
||||
*/
|
||||
public boolean isDartDoc() {
|
||||
return style == Style.DART_DOC;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <code>true<code> if this comment is an end-of-line comment.
|
||||
*
|
||||
* @return <code>true<code> if this comment is an end-of-line comment
|
||||
*/
|
||||
public boolean isEndOfLine() {
|
||||
return style == Style.END_OF_LINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds <code>[id]</code> reference.
|
||||
*/
|
||||
public void addRefName(DartCommentRefName name) {
|
||||
refNames.add(name);
|
||||
}
|
||||
|
||||
public NodeList<DartCommentRefName> getRefNames() {
|
||||
return refNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds <code>[new Class]</code> or <b>[new Class.name]</b> reference.
|
||||
*/
|
||||
public void addNewName(DartCommentNewName name) {
|
||||
newNames.add(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the <code>[new Class]</code> or <b>[new Class.name]</b> references.
|
||||
*/
|
||||
public List<DartCommentNewName> getNewNames() {
|
||||
return newNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
refNames.accept(visitor);
|
||||
newNames.accept(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitComment(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import com.google.dart.compiler.resolver.ClassElement;
|
||||
import com.google.dart.compiler.resolver.ConstructorElement;
|
||||
import com.google.dart.compiler.util.StringInterner;
|
||||
|
||||
/**
|
||||
* <code>[new Class.name]</code> in {@link DartComment}.
|
||||
*/
|
||||
public final class DartCommentNewName extends DartNode {
|
||||
private final String className;
|
||||
private final int classOffset;
|
||||
private final String constructorName;
|
||||
private ClassElement classElement;
|
||||
private final int constructorOffset;
|
||||
private ConstructorElement constructorElement;
|
||||
|
||||
public DartCommentNewName(String className, int classOffset, String constructorName,
|
||||
int constructorOffset) {
|
||||
assert className != null;
|
||||
assert constructorName != null;
|
||||
this.className = StringInterner.intern(className);
|
||||
this.classOffset = classOffset;
|
||||
this.constructorName = StringInterner.intern(constructorName);
|
||||
this.constructorOffset = constructorOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (constructorName.isEmpty()) {
|
||||
return className;
|
||||
}
|
||||
return className + "." + constructorName;
|
||||
}
|
||||
|
||||
public void setElements(ClassElement classElement, ConstructorElement constructorElement) {
|
||||
this.classElement = classElement;
|
||||
this.constructorElement = constructorElement;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public int getClassOffset() {
|
||||
return classOffset;
|
||||
}
|
||||
|
||||
public ClassElement getClassElement() {
|
||||
return classElement;
|
||||
}
|
||||
|
||||
public String getConstructorName() {
|
||||
return constructorName;
|
||||
}
|
||||
|
||||
public int getConstructorOffset() {
|
||||
return constructorOffset;
|
||||
}
|
||||
|
||||
public ConstructorElement getConstructorElement() {
|
||||
return constructorElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitCommentNewName(this);
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import com.google.dart.compiler.resolver.Element;
|
||||
import com.google.dart.compiler.util.StringInterner;
|
||||
|
||||
/**
|
||||
* <code>[name]</code> in {@link DartComment}.
|
||||
*/
|
||||
public final class DartCommentRefName extends DartNode {
|
||||
private final String name;
|
||||
private Element element;
|
||||
|
||||
public DartCommentRefName(String name) {
|
||||
assert name != null;
|
||||
this.name = StringInterner.intern(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setElement(Element element) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitCommentRefName(this);
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
/**
|
||||
* Represents a Dart conditional expression.
|
||||
*/
|
||||
public class DartConditional extends DartExpression {
|
||||
|
||||
private DartExpression condition;
|
||||
private DartExpression elseExpr;
|
||||
private DartExpression thenExpr;
|
||||
|
||||
public DartConditional(DartExpression condition, DartExpression thenExpr,
|
||||
DartExpression elseExpr) {
|
||||
this.condition = becomeParentOf(condition);
|
||||
this.thenExpr = becomeParentOf(thenExpr);
|
||||
this.elseExpr = becomeParentOf(elseExpr);
|
||||
}
|
||||
|
||||
public DartExpression getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public DartExpression getElseExpression() {
|
||||
return elseExpr;
|
||||
}
|
||||
|
||||
public DartExpression getThenExpression() {
|
||||
return thenExpr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(condition, visitor);
|
||||
safelyVisitChild(thenExpr, visitor);
|
||||
safelyVisitChild(elseExpr, visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitConditional(this);
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
/**
|
||||
* Represents a Dart 'continue' statement.
|
||||
*/
|
||||
public class DartContinueStatement extends DartGotoStatement {
|
||||
|
||||
public DartContinueStatement(DartIdentifier label) {
|
||||
super(label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbruptCompletingStatement() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitContinueStatement(this);
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
/**
|
||||
* Common supertype for most declarations. A declaration introduces a new name in a scope. Certain
|
||||
* tools, such as the IDE, need to know the location of this name, but the name should otherwise be
|
||||
* considered a part of the declaration, not an independent node. So the name is not visited when
|
||||
* traversing the AST.
|
||||
*/
|
||||
public abstract class DartDeclaration<N extends DartExpression> extends DartNodeWithMetadata
|
||||
implements HasObsoleteMetadata {
|
||||
|
||||
private N name; // Not visited.
|
||||
private DartComment dartDoc;
|
||||
private DartObsoleteMetadata obsoleteMetadata = DartObsoleteMetadata.EMPTY;
|
||||
|
||||
protected DartDeclaration(N name) {
|
||||
this.name = becomeParentOf(name);
|
||||
}
|
||||
|
||||
public final N getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public final void setName(N newName) {
|
||||
name = becomeParentOf(newName);
|
||||
}
|
||||
|
||||
public DartComment getDartDoc() {
|
||||
return dartDoc;
|
||||
}
|
||||
|
||||
public void setDartDoc(DartComment dartDoc) {
|
||||
// dartDoc is still parented by the containing DartUnit.
|
||||
this.dartDoc = dartDoc;
|
||||
}
|
||||
|
||||
public DartObsoleteMetadata getObsoleteMetadata() {
|
||||
return obsoleteMetadata;
|
||||
}
|
||||
|
||||
public void setObsoleteMetadata(DartObsoleteMetadata metadata) {
|
||||
this.obsoleteMetadata = metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(dartDoc, visitor);
|
||||
super.visitChildren(visitor);
|
||||
safelyVisitChild(name, visitor);
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a Dart 'default' switch member.
|
||||
*/
|
||||
public class DartDefault extends DartSwitchMember {
|
||||
|
||||
public DartDefault(List<DartLabel> labels, List<DartStatement> statements) {
|
||||
super(labels, statements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitDefault(this);
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import com.google.dart.compiler.resolver.NodeElement;
|
||||
|
||||
/**
|
||||
* Base class for directives.
|
||||
*/
|
||||
public abstract class DartDirective extends DartNodeWithMetadata implements HasObsoleteMetadata {
|
||||
private DartObsoleteMetadata obsoleteMetadata = DartObsoleteMetadata.EMPTY;
|
||||
|
||||
@Override
|
||||
public NodeElement getElement() {
|
||||
throw new UnsupportedOperationException(getClass().getSimpleName());
|
||||
}
|
||||
|
||||
public DartObsoleteMetadata getObsoleteMetadata() {
|
||||
return obsoleteMetadata;
|
||||
}
|
||||
|
||||
public void setObsoleteMetadata(DartObsoleteMetadata metadata) {
|
||||
this.obsoleteMetadata = metadata;
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
/**
|
||||
* Represents a Dart 'do/while' statement.
|
||||
*/
|
||||
public class DartDoWhileStatement extends DartStatement {
|
||||
|
||||
private DartExpression condition;
|
||||
private DartStatement body;
|
||||
|
||||
public DartDoWhileStatement(DartExpression condition, DartStatement body) {
|
||||
this.condition = becomeParentOf(condition);
|
||||
this.body = becomeParentOf(body);
|
||||
}
|
||||
|
||||
public DartStatement getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public DartExpression getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(condition, visitor);
|
||||
safelyVisitChild(body, visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitDoWhileStatement(this);
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
/**
|
||||
* Represents a Dart double literal value.
|
||||
*/
|
||||
public class DartDoubleLiteral extends DartLiteral {
|
||||
|
||||
public static DartDoubleLiteral get(double x) {
|
||||
return new DartDoubleLiteral(x);
|
||||
}
|
||||
|
||||
private final double value;
|
||||
|
||||
private DartDoubleLiteral(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitDoubleLiteral(this);
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
/**
|
||||
* Represents an empty Dart statement.
|
||||
*/
|
||||
public class DartEmptyStatement extends DartStatement {
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitEmptyStatement(this);
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implements the export directive.
|
||||
*/
|
||||
public class DartExportDirective extends DartDirective {
|
||||
private DartStringLiteral libraryUri;
|
||||
|
||||
private NodeList<ImportCombinator> combinators = new NodeList<ImportCombinator>(this);
|
||||
|
||||
public DartExportDirective(DartStringLiteral libraryUri, List<ImportCombinator> combinators) {
|
||||
this.libraryUri = becomeParentOf(libraryUri);
|
||||
this.combinators.addAll(combinators);
|
||||
}
|
||||
|
||||
public DartStringLiteral getLibraryUri() {
|
||||
return libraryUri;
|
||||
}
|
||||
|
||||
public List<ImportCombinator> getCombinators() {
|
||||
return combinators;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
super.visitChildren(visitor);
|
||||
safelyVisitChild(libraryUri, visitor);
|
||||
combinators.accept(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitExportDirective(this);
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
/**
|
||||
* Represents a Dart expression-as-statement.
|
||||
*/
|
||||
public class DartExprStmt extends DartStatement {
|
||||
|
||||
private DartExpression expr;
|
||||
|
||||
public DartExprStmt(DartExpression expr) {
|
||||
this.expr = becomeParentOf(expr);
|
||||
}
|
||||
|
||||
public DartExpression getExpression() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbruptCompletingStatement() {
|
||||
return expr instanceof DartThrowExpression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(expr, visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitExprStmt(this);
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract base class for Dart expressions.
|
||||
*/
|
||||
public abstract class DartExpression extends DartNode {
|
||||
|
||||
private Object invocationParameterId;
|
||||
|
||||
public boolean isAssignable() {
|
||||
// By default you cannot assign to expressions.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ID of parameter, {@link Integer} index of positional, {@link String} name if named.
|
||||
*/
|
||||
public Object getInvocationParameterId() {
|
||||
return invocationParameterId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #getInvocationParameterId()
|
||||
*/
|
||||
public void setInvocationParameterId(Object parameterId) {
|
||||
this.invocationParameterId = parameterId;
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import com.google.dart.compiler.resolver.Element;
|
||||
import com.google.dart.compiler.resolver.FieldNodeElement;
|
||||
|
||||
/**
|
||||
* Represents a single field within a field definition.
|
||||
*/
|
||||
public class DartField extends DartClassMember<DartIdentifier> {
|
||||
|
||||
private DartExpression value;
|
||||
private FieldNodeElement element;
|
||||
private DartMethodDefinition accessor;
|
||||
|
||||
public DartField(DartIdentifier name, Modifiers modifiers, DartMethodDefinition accessor,
|
||||
DartExpression value) {
|
||||
super(name, modifiers);
|
||||
this.accessor = becomeParentOf(accessor);
|
||||
this.value = becomeParentOf(value);
|
||||
}
|
||||
|
||||
public void setValue(DartExpression value) {
|
||||
this.value = becomeParentOf(value);
|
||||
}
|
||||
|
||||
public DartExpression getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setAccessor(DartMethodDefinition accessor) {
|
||||
this.accessor = becomeParentOf(accessor);
|
||||
}
|
||||
|
||||
public DartMethodDefinition getAccessor() {
|
||||
return accessor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldNodeElement getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setElement(Element element) {
|
||||
this.element = (FieldNodeElement) element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
super.visitChildren(visitor);
|
||||
safelyVisitChild(accessor, visitor);
|
||||
safelyVisitChild(value, visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitField(this);
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a Dart field definition.
|
||||
*/
|
||||
public class DartFieldDefinition extends DartNodeWithMetadata {
|
||||
|
||||
private DartTypeNode typeNode;
|
||||
private final NodeList<DartField> fields = NodeList.create(this);
|
||||
|
||||
public DartFieldDefinition(DartTypeNode typeNode, List<DartField> fields) {
|
||||
this.setTypeNode(typeNode);
|
||||
this.fields.addAll(fields);
|
||||
}
|
||||
|
||||
public DartTypeNode getTypeNode() {
|
||||
return typeNode;
|
||||
}
|
||||
|
||||
public void setTypeNode(DartTypeNode typeNode) {
|
||||
this.typeNode = becomeParentOf(typeNode);
|
||||
}
|
||||
|
||||
public List<DartField> getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
super.visitChildren(visitor);
|
||||
safelyVisitChild(typeNode, visitor);
|
||||
fields.accept(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitFieldDefinition(this);
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
/**
|
||||
* Represents a Dart 'for (.. in ..)' statement.
|
||||
*/
|
||||
public class DartForInStatement extends DartStatement {
|
||||
|
||||
private DartStatement setup;
|
||||
private DartExpression iterable;
|
||||
private final int closeParenOffset;
|
||||
private DartStatement body;
|
||||
|
||||
public DartForInStatement(DartStatement setup,
|
||||
DartExpression iterable,
|
||||
int closeParenOffset,
|
||||
DartStatement body) {
|
||||
this.setup = becomeParentOf(setup);
|
||||
this.iterable = becomeParentOf(iterable);
|
||||
this.closeParenOffset = closeParenOffset;
|
||||
this.body = becomeParentOf(body);
|
||||
}
|
||||
|
||||
public int getCloseParenOffset() {
|
||||
return closeParenOffset;
|
||||
}
|
||||
|
||||
public DartStatement getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public DartExpression getIterable() {
|
||||
return iterable;
|
||||
}
|
||||
|
||||
public boolean introducesVariable() {
|
||||
return setup instanceof DartVariableStatement;
|
||||
}
|
||||
|
||||
public DartIdentifier getIdentifier() {
|
||||
assert !introducesVariable();
|
||||
return (DartIdentifier) ((DartExprStmt) setup).getExpression();
|
||||
}
|
||||
|
||||
public DartVariableStatement getVariableStatement() {
|
||||
assert introducesVariable();
|
||||
return (DartVariableStatement) setup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(setup, visitor);
|
||||
safelyVisitChild(iterable, visitor);
|
||||
safelyVisitChild(body, visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitForInStatement(this);
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
/**
|
||||
* Represents a Dart 'for' statement.
|
||||
*/
|
||||
public class DartForStatement extends DartStatement {
|
||||
|
||||
private DartStatement init;
|
||||
private DartExpression condition;
|
||||
private DartExpression increment;
|
||||
private final int closeParenOffset;
|
||||
private DartStatement body;
|
||||
|
||||
public DartForStatement(DartStatement init, DartExpression condition, DartExpression increment,
|
||||
int closeParenOffset, DartStatement body) {
|
||||
this.init = becomeParentOf(init);
|
||||
this.condition = becomeParentOf(condition);
|
||||
this.increment = becomeParentOf(increment);
|
||||
this.closeParenOffset = closeParenOffset;
|
||||
this.body = becomeParentOf(body);
|
||||
}
|
||||
|
||||
public int getCloseParenOffset() {
|
||||
return closeParenOffset;
|
||||
}
|
||||
|
||||
public DartStatement getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public DartExpression getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public DartExpression getIncrement() {
|
||||
return increment;
|
||||
}
|
||||
|
||||
public DartStatement getInit() {
|
||||
return init;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(init, visitor);
|
||||
safelyVisitChild(condition, visitor);
|
||||
safelyVisitChild(increment, visitor);
|
||||
safelyVisitChild(body, visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitForStatement(this);
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a Dart function.
|
||||
*/
|
||||
public class DartFunction extends DartNode {
|
||||
|
||||
private final NodeList<DartParameter> parameters = NodeList.create(this);
|
||||
private final int parametersOpenParen;
|
||||
private final int parametersOptionalOpen;
|
||||
private final int parametersOptionalClose;
|
||||
private final int parametersCloseParen;
|
||||
private DartBlock body;
|
||||
private DartTypeNode returnTypeNode;
|
||||
|
||||
public DartFunction(List<DartParameter> parameters, int parametersOpenParen, int parametersOptionalOpen,
|
||||
int parametersOptionalClose, int parametersCloseParen, DartBlock body,
|
||||
DartTypeNode returnTypeNode) {
|
||||
this.parametersOpenParen = parametersOpenParen;
|
||||
this.parametersOptionalOpen = parametersOptionalOpen;
|
||||
this.parametersOptionalClose = parametersOptionalClose;
|
||||
if (parameters != null && !parameters.isEmpty()) {
|
||||
this.parameters.addAll(parameters);
|
||||
}
|
||||
this.parametersCloseParen = parametersCloseParen;
|
||||
this.body = becomeParentOf(body);
|
||||
this.returnTypeNode = becomeParentOf(returnTypeNode);
|
||||
}
|
||||
|
||||
public DartBlock getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public List<DartParameter> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public int getParametersOptionalOpen() {
|
||||
return parametersOptionalOpen;
|
||||
}
|
||||
|
||||
public int getParametersOptionalClose() {
|
||||
return parametersOptionalClose;
|
||||
}
|
||||
|
||||
public int getParametersOpenParen() {
|
||||
return parametersOpenParen;
|
||||
}
|
||||
|
||||
public int getParametersCloseParen() {
|
||||
return parametersCloseParen;
|
||||
}
|
||||
|
||||
public DartTypeNode getReturnTypeNode() {
|
||||
return returnTypeNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
parameters.accept(visitor);
|
||||
safelyVisitChild(body, visitor);
|
||||
safelyVisitChild(returnTypeNode, visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitFunction(this);
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import com.google.dart.compiler.resolver.Element;
|
||||
import com.google.dart.compiler.resolver.MethodElement;
|
||||
|
||||
/**
|
||||
* Represents a Dart 'function' expression.
|
||||
*/
|
||||
public class DartFunctionExpression extends DartExpression {
|
||||
|
||||
// Not visited. Similar to DartDeclaration, but DartDeclaration shouldn't be
|
||||
// a statement or an expression.
|
||||
private DartIdentifier name;
|
||||
|
||||
private final boolean isStmt;
|
||||
private MethodElement element;
|
||||
private DartFunction function;
|
||||
|
||||
public DartFunctionExpression(DartIdentifier name, DartFunction function, boolean isStmt) {
|
||||
this.name = becomeParentOf(name);
|
||||
this.function = becomeParentOf(function);
|
||||
this.isStmt = isStmt;
|
||||
}
|
||||
|
||||
public DartFunction getFunction() {
|
||||
return function;
|
||||
}
|
||||
|
||||
public String getFunctionName() {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
return name.getName();
|
||||
}
|
||||
|
||||
public DartIdentifier getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodElement getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
public boolean isStatement() {
|
||||
return isStmt;
|
||||
}
|
||||
|
||||
public void setName(DartIdentifier newName) {
|
||||
name = becomeParentOf(newName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setElement(Element element) {
|
||||
this.element = (MethodElement) element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(name, visitor);
|
||||
safelyVisitChild(function, visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitFunctionExpression(this);
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Function-object invocation AST node.
|
||||
*/
|
||||
public class DartFunctionObjectInvocation extends DartInvocation {
|
||||
|
||||
private DartExpression target;
|
||||
|
||||
public DartFunctionObjectInvocation(DartExpression target, List<DartExpression> args) {
|
||||
super(args);
|
||||
this.target = becomeParentOf(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DartExpression getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(target, visitor);
|
||||
visitor.visit(getArguments());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitFunctionObjectInvocation(this);
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import com.google.dart.compiler.resolver.Element;
|
||||
import com.google.dart.compiler.resolver.FunctionAliasElement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Named function-type alias AST node.
|
||||
*/
|
||||
public class DartFunctionTypeAlias extends DartDeclaration<DartIdentifier> {
|
||||
|
||||
private DartTypeNode returnTypeNode;
|
||||
private final NodeList<DartParameter> parameters = NodeList.create(this);
|
||||
private final NodeList<DartTypeParameter> typeParameters = NodeList.create(this);
|
||||
private FunctionAliasElement element;
|
||||
|
||||
public DartFunctionTypeAlias(DartIdentifier name, DartTypeNode returnTypeNode,
|
||||
List<DartParameter> parameters,
|
||||
List<DartTypeParameter> typeParameters) {
|
||||
super(name);
|
||||
this.returnTypeNode = becomeParentOf(returnTypeNode);
|
||||
this.parameters.addAll(parameters);
|
||||
this.typeParameters.addAll(typeParameters);
|
||||
}
|
||||
|
||||
public List<DartParameter> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public DartTypeNode getReturnTypeNode() {
|
||||
return returnTypeNode;
|
||||
}
|
||||
|
||||
public List<DartTypeParameter> getTypeParameters() {
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionAliasElement getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
public void setReturnTypeNode(DartTypeNode newReturnType) {
|
||||
returnTypeNode = becomeParentOf(newReturnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setElement(Element element) {
|
||||
this.element = (FunctionAliasElement) element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
super.visitChildren(visitor);
|
||||
safelyVisitChild(returnTypeNode, visitor);
|
||||
parameters.accept(visitor);
|
||||
typeParameters.accept(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R accept(ASTVisitor<R> visitor) {
|
||||
return visitor.visitFunctionTypeAlias(this);
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package com.google.dart.compiler.ast;
|
||||
|
||||
import com.google.dart.compiler.resolver.Element;
|
||||
import com.google.dart.compiler.resolver.LabelElement;
|
||||
|
||||
/**
|
||||
* Base class of {@link DartBreakStatement} and {@link DartContinueStatement}.
|
||||
*/
|
||||
public abstract class DartGotoStatement extends DartStatement {
|
||||
|
||||
private DartIdentifier label;
|
||||
private LabelElement element;
|
||||
|
||||
public DartGotoStatement(DartIdentifier label) {
|
||||
this.label = becomeParentOf(label);
|
||||
}
|
||||
|
||||
public DartIdentifier getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public String getTargetName() {
|
||||
if (label == null) {
|
||||
return null;
|
||||
}
|
||||
return label.getName();
|
||||
}
|
||||
|
||||
public void setLabel(DartIdentifier newLabel) {
|
||||
label = newLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LabelElement getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setElement(Element element) {
|
||||
this.element = (LabelElement) element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitChildren(ASTVisitor<?> visitor) {
|
||||
safelyVisitChild(label, visitor);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue