]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7559) Fixed location information for import declarations 22/1122/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 18 Oct 2017 11:00:38 +0000 (14:00 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 18 Oct 2017 11:00:38 +0000 (14:00 +0300)
Change-Id: I4c8af1bf5cfef9ab7d65e06d95a7fa139b92eab9

bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/Locations.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ImportDeclaration.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLTextEditorEnvironment.java

index f7f745841460bdbfc30aacbd0a35b5174620208f..5a82823a1b27f2d8a200bb8d1c03a8ce8ffc64a6 100644 (file)
@@ -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());
index 3a77cf3250d7c1f58bd17c2e2fcbd8ac164bb9db..70c258b9bab1fa89ae816c97d1bb02d7290441b6 100644 (file)
@@ -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);
+    }
 }
index 21d7104051b133957c17b813a1a2a778ac2334f3..77ac5e78e21bae50d2edf8a175427b35c59758ab 100644 (file)
@@ -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();
index 089f2c26c95469e639176ed9f50136b91a9c46c7..7c3de572f78456db563a65011d64953a26cb546b 100644 (file)
@@ -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<String, ModuleEntry> result = new THashMap<String, ModuleEntry>();
         Collection<ImportFailure> failures = null;
         
-        THashSet<String> originalImports = new THashSet<String>(); 
+        TObjectLongHashMap<String> originalImports = new TObjectLongHashMap<String>(); 
         ArrayList<ImportDeclaration> stack = new ArrayList<ImportDeclaration>(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 {
index de335f0f944c3ba7135b5ba6900398f6cd91b4c5..98b51917744aaa43d7f179a0712e72b23bfdb29a 100644 (file)
@@ -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) {