Skip to content

Commit

Permalink
Add Feedback object that holds common error msgs
Browse files Browse the repository at this point in the history
Future error reporting would be more sophisticated because ideally we
want to report concise error messages with good contextual information.

This commit takes the first step by putting common error messages in
an object `Feedback` stored into `GlobalHelpers`. Temporary error
messages have not been added since they will be removed in future
commits (things like `super` not being handled in `ExtractAPI`, for instance).
  • Loading branch information
jvican committed Feb 7, 2017
1 parent c1f821b commit e288c18
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
20 changes: 5 additions & 15 deletions internal/compiler-bridge/src/main/scala/xsbt/Dependency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
dependencyExtractor.localInheritanceDependencies foreach processDependency(context = LocalDependencyByInheritance)
processTopLevelImportDependencies(dependencyExtractor.topLevelImportDependencies)
} else {
throw new UnsupportedOperationException("Turning off name hashing is not supported in class-based dependency trackging.")
throw new UnsupportedOperationException(Feedback.NameHashingDisabled)
}
/*
* Registers top level import dependencies as coming from a first top level class/trait/object declared
Expand All @@ -75,13 +75,7 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
deps foreach { dep =>
processDependency(context = DependencyByMemberRef)(ClassDependency(firstClassSymbol, dep))
}
case None =>
reporter.warning(
unit.position(0),
"""|Found top level imports but no class, trait or object is defined in the compilation unit.
|The incremental compiler cannot record the dependency information in such case.
|Some errors like unused import referring to a non-existent class might not be reported.""".stripMargin
)
case None => reporter.warning(unit.position(0), Feedback.OrphanTopLevelImports)
}
}
/*
Expand Down Expand Up @@ -163,10 +157,7 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
}
}
private def addClassDependency(deps: HashSet[ClassDependency], fromClass: Symbol, dep: Symbol): Unit = {
assert(
fromClass.isClass,
s"The ${fromClass.fullName} defined at ${fromClass.fullLocationString} is not a class symbol."
)
assert(fromClass.isClass, Feedback.expectedClassSymbol(fromClass))
val depClass = enclOrModuleClass(dep)
if (fromClass.associatedFile != depClass.associatedFile) {
deps += ClassDependency(fromClass, depClass)
Expand All @@ -191,10 +182,9 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
}
private def addDependency(dep: Symbol): Unit = {
val fromClass = resolveDependencySource().fromClass
if (fromClass == NoSymbol || fromClass.hasPackageFlag) {
if (ignoredSymbol(fromClass) || fromClass.hasPackageFlag) {
if (inImportNode) addTopLevelImportDependency(dep)
else
devWarning(s"No enclosing class. Discarding dependency on $dep (currentOwner = $currentOwner).")
else devWarning(Feedback.missingEnclosingClass(dep, currentOwner))
} else {
addClassDependency(_memberRefDependencies, fromClass, dep)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@ class ExtractUsedNames[GlobalType <: CallbackGlobal](val global: GlobalType) ext
val firstClassName = className(firstClassSymbol)
traverser.usedNamesFromClass(firstClassName) ++= namesUsedAtTopLevel.map(decodeName)
case None =>
reporter.warning(
unit.position(0),
"""|Found names used at the top level but no class, trait or object is defined in the compilation unit.
|The incremental compiler cannot record used names in such case.
|Some errors like unused import referring to a non-existent class might not be reported.""".stripMargin
)
reporter.warning(unit.position(0), Feedback.OrphanNames)
}
}

Expand Down
17 changes: 17 additions & 0 deletions internal/compiler-bridge/src/main/scala/xsbt/GlobalHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,21 @@ trait GlobalHelpers {
}.headOption
}
}

/** Define common error messages for error reporting and assertions. */
object Feedback {
val NameHashingDisabled = "Turning off name hashing is not supported in class-based dependency trackging."
val OrphanTopLevelImports = noTopLevelMember("top level imports")
val OrphanNames = noTopLevelMember("names")

def expectedClassSymbol(culprit: Symbol): String =
s"The ${culprit.fullName} defined at ${culprit.fullLocationString} is not a class symbol."
def missingEnclosingClass(culprit: Symbol, owner: Symbol): String =
s"No enclosing class. Discarding dependency on $culprit (currentOwner = $owner)."
def noTopLevelMember(found: String) = s"""
|Found $found but no class, trait or object is defined in the compilation unit.
|The incremental compiler cannot record the dependency information in such case.
|Some errors like unused import referring to a non-existent class might not be reported.
""".stripMargin
}
}

0 comments on commit e288c18

Please sign in to comment.