handle performance issues and corner cases in reporting FileScope errors. Include files and files whose classes had conditional compilation for the class def would also report missing definitions
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/c180dbe4 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/c180dbe4 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/c180dbe4 Branch: refs/heads/develop Commit: c180dbe40a5bf870aebd23ee6f2a3081c71b2cb6 Parents: 5151b51 Author: Alex Harui <[email protected]> Authored: Sat Oct 3 07:39:10 2015 -0700 Committer: Alex Harui <[email protected]> Committed: Sat Oct 3 07:41:11 2015 -0700 ---------------------------------------------------------------------- .../org/apache/flex/compiler/clients/MXMLC.java | 1 + .../internal/parsing/as/BaseASParser.java | 1 + .../parsing/as/ConfigCompilationUnit.java | 7 +++++ .../internal/scopes/ASProjectScope.java | 1 - .../internal/tree/as/ContainerNode.java | 15 +++++++++ .../internal/units/ASCompilationUnit.java | 10 ++++++ .../requests/ASFileScopeRequestResult.java | 33 +++++++++++++++++++- 7 files changed, 66 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c180dbe4/compiler/src/org/apache/flex/compiler/clients/MXMLC.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/clients/MXMLC.java b/compiler/src/org/apache/flex/compiler/clients/MXMLC.java index 51830b1..7a7bfdd 100644 --- a/compiler/src/org/apache/flex/compiler/clients/MXMLC.java +++ b/compiler/src/org/apache/flex/compiler/clients/MXMLC.java @@ -227,6 +227,7 @@ public class MXMLC implements FlexTool if (continueCompilation) { + project.setProblems(problems.getProblems()); compile(); exitCode = printProblems(printer, legacyOutput); reportTargetCompletion(); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c180dbe4/compiler/src/org/apache/flex/compiler/internal/parsing/as/BaseASParser.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/internal/parsing/as/BaseASParser.java b/compiler/src/org/apache/flex/compiler/internal/parsing/as/BaseASParser.java index ca19e78..1d26445 100644 --- a/compiler/src/org/apache/flex/compiler/internal/parsing/as/BaseASParser.java +++ b/compiler/src/org/apache/flex/compiler/internal/parsing/as/BaseASParser.java @@ -2974,6 +2974,7 @@ abstract class BaseASParser extends LLkParser implements IProblemReporter final boolean eval = Boolean.parseBoolean(((LiteralNode)lastChild).getValue()); // remove the configuration condition node containerNode.removeItem((NodeBase)lastChild); + containerNode.setRemovedConditionalCompileNode(true); return eval; } } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c180dbe4/compiler/src/org/apache/flex/compiler/internal/parsing/as/ConfigCompilationUnit.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/internal/parsing/as/ConfigCompilationUnit.java b/compiler/src/org/apache/flex/compiler/internal/parsing/as/ConfigCompilationUnit.java index 4539fc9..21eb080 100644 --- a/compiler/src/org/apache/flex/compiler/internal/parsing/as/ConfigCompilationUnit.java +++ b/compiler/src/org/apache/flex/compiler/internal/parsing/as/ConfigCompilationUnit.java @@ -30,6 +30,7 @@ import org.apache.flex.compiler.internal.tree.as.NilNode; import org.apache.flex.compiler.internal.tree.as.PackageNode; import org.apache.flex.compiler.internal.tree.as.ScopedBlockNode; import org.apache.flex.compiler.internal.units.ASCompilationUnit; +import org.apache.flex.compiler.internal.units.requests.ASFileScopeRequestResult; import org.apache.flex.compiler.tree.as.IASNode; import org.apache.flex.compiler.workspaces.IWorkspace; @@ -87,4 +88,10 @@ class ConfigCompilationUnit extends ASCompilationUnit // Don't try to verify ASTs produced by a ConfigCompilationUnit // because none of the nodes have source location info. } + + @Override + protected void addProblemsToProject(ASFileScopeRequestResult result) + { + // don't do anything here + } } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c180dbe4/compiler/src/org/apache/flex/compiler/internal/scopes/ASProjectScope.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/internal/scopes/ASProjectScope.java b/compiler/src/org/apache/flex/compiler/internal/scopes/ASProjectScope.java index d7859a0..f2195be 100644 --- a/compiler/src/org/apache/flex/compiler/internal/scopes/ASProjectScope.java +++ b/compiler/src/org/apache/flex/compiler/internal/scopes/ASProjectScope.java @@ -2053,7 +2053,6 @@ public class ASProjectScope extends ASScopeBase final IFileScopeRequestResult fileScopeRequestResult = compilationUnit.getFileScopeRequest().get(); actualDefinition = fileScopeRequestResult.getMainDefinition(qname); - Collections.addAll(compilationUnit.getProject().getProblems(), fileScopeRequestResult.getProblems()); } catch (InterruptedException e) { http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c180dbe4/compiler/src/org/apache/flex/compiler/internal/tree/as/ContainerNode.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/internal/tree/as/ContainerNode.java b/compiler/src/org/apache/flex/compiler/internal/tree/as/ContainerNode.java index 3d093d8..5305dd2 100644 --- a/compiler/src/org/apache/flex/compiler/internal/tree/as/ContainerNode.java +++ b/compiler/src/org/apache/flex/compiler/internal/tree/as/ContainerNode.java @@ -50,6 +50,7 @@ public class ContainerNode extends TreeNode implements IContainerNode } private ContainerType containerType = ContainerType.SYNTHESIZED; + private boolean removedConditionalCompileNode = false; // // NodeBase overrides @@ -93,6 +94,20 @@ public class ContainerNode extends TreeNode implements IContainerNode this.containerType = containerType; } + public boolean getRemovedConditionalCompileNode() + { + return removedConditionalCompileNode; + } + + // + // Other methods + // + + public void setRemovedConditionalCompileNode(boolean value) + { + this.removedConditionalCompileNode = value; + } + /** * Adds a node to the list of children (really just a public wrapper around * addChild) http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c180dbe4/compiler/src/org/apache/flex/compiler/internal/units/ASCompilationUnit.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/internal/units/ASCompilationUnit.java b/compiler/src/org/apache/flex/compiler/internal/units/ASCompilationUnit.java index 90d1958..ab60b1f 100644 --- a/compiler/src/org/apache/flex/compiler/internal/units/ASCompilationUnit.java +++ b/compiler/src/org/apache/flex/compiler/internal/units/ASCompilationUnit.java @@ -463,8 +463,18 @@ public class ASCompilationUnit extends CompilationUnitBase Collections.<ICompilerProblem>emptyList(), (ASFileScope)scope, rootSource); stopProfile(Operation.GET_FILESCOPE); + addProblemsToProject(result); return result; } + + protected void addProblemsToProject(ASFileScopeRequestResult result) + { + Collection<ICompilationUnit> units = getProject().getIncludingCompilationUnits(getAbsoluteFilename()); + // an included file often reports an error that it has no definition + if (units != null && units.size() > 0) + return; + Collections.addAll(getProject().getProblems(), result.getProblems()); + } @Override protected IABCBytesRequestResult handleABCBytesRequest() throws InterruptedException http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c180dbe4/compiler/src/org/apache/flex/compiler/internal/units/requests/ASFileScopeRequestResult.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/internal/units/requests/ASFileScopeRequestResult.java b/compiler/src/org/apache/flex/compiler/internal/units/requests/ASFileScopeRequestResult.java index c392c00..a753db9 100644 --- a/compiler/src/org/apache/flex/compiler/internal/units/requests/ASFileScopeRequestResult.java +++ b/compiler/src/org/apache/flex/compiler/internal/units/requests/ASFileScopeRequestResult.java @@ -25,12 +25,19 @@ import java.util.Collections; import org.apache.flex.compiler.common.IDefinitionPriority; import org.apache.flex.compiler.definitions.IDefinition; +import org.apache.flex.compiler.definitions.IPackageDefinition; import org.apache.flex.compiler.filespecs.IFileSpecification; import org.apache.flex.compiler.internal.scopes.ASFileScope; +import org.apache.flex.compiler.internal.scopes.ASScope; +import org.apache.flex.compiler.internal.scopes.PackageScope; +import org.apache.flex.compiler.internal.tree.as.ContainerNode; import org.apache.flex.compiler.internal.units.ASCompilationUnit; import org.apache.flex.compiler.problems.ICompilerProblem; import org.apache.flex.compiler.problems.MultipleExternallyVisibleDefinitionsProblem; import org.apache.flex.compiler.problems.NoMainDefinitionProblem; +import org.apache.flex.compiler.scopes.IDefinitionSet; +import org.apache.flex.compiler.tree.as.IScopedNode; + import com.google.common.collect.Iterables; /** @@ -76,7 +83,31 @@ public class ASFileScopeRequestResult extends FileScopeRequestResultBase } if (!foundMainDefinition) - problems.add(new NoMainDefinitionProblem(fileName, expectedQName)); + { + boolean ignoreMissingMainDefinition = false; + for (final ASFileScope scope : this.getFileScopes()) + { + for (IDefinitionSet defSet : scope.getAllLocalDefinitionSets()) + { + int n = defSet.getSize(); + for (int i = 0; i < n; i++) + { + IDefinition def = defSet.getDefinition(i); + if (def instanceof IPackageDefinition) + { + IPackageDefinition packageDef = (IPackageDefinition)def; + ASScope packageScope = (ASScope)packageDef.getContainedScope(); + IScopedNode scopeNode = packageScope.getScopeNode(); + ContainerNode packageNode = (ContainerNode)scopeNode; + if (packageNode.getRemovedConditionalCompileNode()) + ignoreMissingMainDefinition = true; + } + } + } + } + if (!ignoreMissingMainDefinition) + problems.add(new NoMainDefinitionProblem(fileName, expectedQName)); + } return problems; }
