Skip to content

Commit

Permalink
Forced push: refactoring to detect non-implicit imports both in scope…
Browse files Browse the repository at this point in the history
… provider & quick fix
  • Loading branch information
fdodino committed Oct 5, 2019
1 parent 14b676d commit 43e5ece
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.uqbar.project.wollok.libraries

import java.util.List
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.resource.IResourceDescription.Manager
Expand All @@ -11,7 +12,15 @@ import org.eclipse.xtext.resource.IResourceDescription.Manager
*/
class WollokLibExtensions {

private static val libsFqn = #["wollok.lang","wollok.lib","wollok.vm","wollok.game","wollok.mirror"]
public static val LANG_LIB = "wollok.lang"
public static val LIB_LIB = "wollok.lib"
public static val VM_LIB = "wollok.vm"
public static val GAME_LIB = "wollok.game"
public static val MIRROR_LIB = "wollok.mirror"

public static val ALL_LIBS = #[LANG_LIB, LIB_LIB, VM_LIB, GAME_LIB, MIRROR_LIB]
public static val IMPLICIT_IMPORTS = #[LIB_LIB, LANG_LIB]
public static val NON_IMPLICIT_IMPORTS = #[GAME_LIB, VM_LIB, MIRROR_LIB]

/**
* loads the objects without cache
Expand Down Expand Up @@ -48,11 +57,16 @@ class WollokLibExtensions {

}

static def boolean isCoreLib(String fqn){
if(fqn === null) return false
val fqnMatches = libsFqn.filter[ String lib | fqn.startsWith(lib)]
return fqnMatches.size() >= 1
static def boolean isCoreLib(String fqn) {
(fqn ?: "").belongsTo(ALL_LIBS)
}

static def boolean importRequired(String fqn) {
!(fqn ?: "").belongsTo(IMPLICIT_IMPORTS)
}

static def boolean belongsTo(String fqn, List<String> libraries) {
libraries.exists [ lib | fqn.startsWith(lib) ]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import org.eclipse.xtext.EcoreUtil2
import org.eclipse.xtext.naming.QualifiedName
import org.eclipse.xtext.nodemodel.INode
import org.eclipse.xtext.nodemodel.util.NodeModelUtils
import org.eclipse.xtext.resource.IEObjectDescription
import org.eclipse.xtext.resource.XtextResource
import org.eclipse.xtext.scoping.IScope
import org.eclipse.xtext.scoping.impl.ImportNormalizer
import org.uqbar.project.wollok.Messages
import org.uqbar.project.wollok.WollokConstants
import org.uqbar.project.wollok.interpreter.WollokClassFinder
import org.uqbar.project.wollok.interpreter.WollokRuntimeException
import org.uqbar.project.wollok.interpreter.core.WollokObject
import org.uqbar.project.wollok.scoping.WollokGlobalScopeProvider
import org.uqbar.project.wollok.sdk.WollokSDK
import org.uqbar.project.wollok.visitors.ParameterUsesVisitor
import org.uqbar.project.wollok.visitors.VariableAssignmentsVisitor
import org.uqbar.project.wollok.visitors.VariableUsesVisitor
Expand Down Expand Up @@ -71,12 +74,10 @@ import wollok.lang.Exception

import static org.uqbar.project.wollok.WollokConstants.*

import static extension org.uqbar.project.wollok.libraries.WollokLibExtensions.*
import static extension org.uqbar.project.wollok.model.ResourceUtils.*
import static extension org.uqbar.project.wollok.model.WMethodContainerExtensions.*
import static extension org.uqbar.project.wollok.visitors.ReturnFinderVisitor.containsReturnExpression
import org.uqbar.project.wollok.sdk.WollokSDK
import org.eclipse.xtext.resource.IEObjectDescription
import org.eclipse.xtext.scoping.IScope

/**
* Extension methods to Wollok semantic model.
Expand Down Expand Up @@ -767,8 +768,7 @@ class WollokModelExtensions {
}

def static isValidImport(String importName) {
!#["wollok.lang", "wollok.lib", "wollok.mirror"].exists[library|importName.startsWith(library)] &&
importName.contains(".") && !#["wollok.game", "wollok.vm"].exists[library|importName.equals(library)]
importName.importRequired && !NON_IMPLICIT_IMPORTS.exists [ it.equals(importName) ]
}

// *******************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import static extension org.uqbar.project.wollok.model.WollokModelExtensions.*
import static extension org.uqbar.project.wollok.scoping.WollokScopeExtensions.*
import static extension org.uqbar.project.wollok.utils.XtendExtensions.*

import static extension org.uqbar.project.wollok.libraries.WollokLibExtensions.*

/**
* @author tesonep
* @author jfernandes
Expand All @@ -41,8 +43,6 @@ class WollokImportedNamespaceAwareLocalScopeProvider extends AbstractGlobalScope
@Inject
IQualifiedNameProvider qualifiedNameProvider

static val IMPLICIT_IMPORTS = #["wollok.lib", "wollok.lang"]

// ************************************************************************
// ** Public interface
// ************************************************************************
Expand Down

0 comments on commit 43e5ece

Please sign in to comment.