From: Hannu Niemistö Date: Wed, 18 Oct 2017 11:00:38 +0000 (+0300) Subject: (refs #7559) Fixed location information for import declarations X-Git-Tag: v1.31.0~113 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F22%2F1122%2F1;p=simantics%2Fplatform.git (refs #7559) Fixed location information for import declarations Change-Id: I4c8af1bf5cfef9ab7d65e06d95a7fa139b92eab9 --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java index f7f745841..5a82823a1 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java @@ -206,9 +206,9 @@ public class Elaboration { try { String absoluteModuleName = ModuleUtils.resolveAbsolutePath(moduleName, relativeImport.moduleName); ImportDeclaration absoluteImport = new ImportDeclaration( + relativeImport.location, absoluteModuleName, relativeImport.localName, relativeImport.reexport, relativeImport.spec); - absoluteImport.location = relativeImport.location; absoluteImports.add(absoluteImport); } catch (InvalidModulePathException e) { errorLog.log(relativeImport.location, e.getMessage()); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/Locations.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/Locations.java index 3a77cf325..70c258b9b 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/Locations.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/Locations.java @@ -48,4 +48,11 @@ public class Locations { localEnd = begin-end; return location(begin+localBegin, begin+localEnd); } + + public static String toString(long location) { + if(location == NO_LOCATION) + return "NO LOCATION"; + else + return beginOf(location) + "-" + endOf(location); + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ImportDeclaration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ImportDeclaration.java index 21d710405..77ac5e78e 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ImportDeclaration.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ImportDeclaration.java @@ -53,6 +53,11 @@ public class ImportDeclaration extends DeclarationAst { this.spec = DEFAULT_SPEC; } + public ImportDeclaration(long location, String moduleName, String localName, boolean reexport, ImportSpec spec) { + this(moduleName, localName, reexport); + this.location = location; + } + public ImportDeclaration(String moduleName, String localName, boolean reexport, ImportSpec spec) { if(spec == null) throw new NullPointerException(); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java index 089f2c26c..7c3de572f 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java @@ -20,6 +20,7 @@ import org.simantics.scl.compiler.errors.CompilationError; import org.simantics.scl.compiler.errors.DoesNotExist; import org.simantics.scl.compiler.errors.Failable; import org.simantics.scl.compiler.errors.Failure; +import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.errors.Success; import org.simantics.scl.compiler.module.ImportDeclaration; import org.simantics.scl.compiler.module.Module; @@ -37,6 +38,7 @@ import org.simantics.scl.compiler.top.ValueNotFound; import org.simantics.scl.compiler.types.Types; import gnu.trove.map.hash.THashMap; +import gnu.trove.map.hash.TObjectLongHashMap; import gnu.trove.procedure.TObjectObjectProcedure; import gnu.trove.set.hash.THashSet; @@ -261,11 +263,11 @@ public class ModuleRepository { THashMap result = new THashMap(); Collection failures = null; - THashSet originalImports = new THashSet(); + TObjectLongHashMap originalImports = new TObjectLongHashMap(); ArrayList stack = new ArrayList(imports.length); for(ImportDeclaration import_ : imports) { stack.add(import_); - originalImports.add(import_.moduleName); + originalImports.put(import_.moduleName, import_.location); } while(!stack.isEmpty()) { ImportDeclaration import_ = stack.remove(stack.size()-1); @@ -278,8 +280,10 @@ public class ModuleRepository { stack.addAll(compilationResult.getResult().getDependencies()); if(originalImport) { String deprecation = compilationResult.getResult().getDeprecation(); - if(deprecation != null && compilationContext != null) - compilationContext.errorLog.logWarning(import_.location, "Deprecated module " + import_.moduleName + (deprecation.isEmpty() ? "." : ": " + deprecation)); + if(deprecation != null && compilationContext != null) { + long location = originalImport ? originalImports.get(import_.moduleName) : Locations.NO_LOCATION; + compilationContext.errorLog.logWarning(location, "Deprecated module " + import_.moduleName + (deprecation.isEmpty() ? "." : ": " + deprecation)); + } } } else { diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLTextEditorEnvironment.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLTextEditorEnvironment.java index de335f0f9..98b519177 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLTextEditorEnvironment.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLTextEditorEnvironment.java @@ -108,6 +108,7 @@ public class SCLTextEditorEnvironment { try { String absoluteModuleName = ModuleUtils.resolveAbsolutePath(moduleName, relativeImport.moduleName); absoluteImports.add(new ImportDeclaration( + relativeImport.location, absoluteModuleName, relativeImport.localName, relativeImport.reexport, relativeImport.spec)); } catch (InvalidModulePathException e) {