Skip to content

Commit

Permalink
Merge branch 'dev' into fix-cyclic-references-instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
PalumboN committed Nov 23, 2020
2 parents ac0d4cb + dae2ba9 commit 9b6478b
Show file tree
Hide file tree
Showing 22 changed files with 102 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.uqbar.project.wollok.debugger.server.rmi.XDebugStackFrameVariable
import org.uqbar.project.wollok.interpreter.WollokInterpreter
import org.uqbar.project.wollok.interpreter.api.XInterpreterListener
import static extension org.uqbar.project.wollok.model.WMethodContainerExtensions.*
import static extension org.uqbar.project.wollok.utils.XTextExtensions.*

class WollokRemoteContextStateListener implements XInterpreterListener {

Expand Down Expand Up @@ -49,7 +50,8 @@ class WollokRemoteContextStateListener implements XInterpreterListener {
override aboutToEvaluate(EObject element) {}

override evaluated(EObject element) {
if (singleTest === null) {
// be careful, can be null or false
if (singleTest === null || !singleTest) {
singleTest = element.isSingleTest
}
if (!forRepl && singleTest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class WollokPerspectiveListener implements IPerspectiveListener {
val bindingService = PlatformUI.workbench.getAdapter(typeof(IBindingService)) as IBindingService
bindingService.bindings.forEach [
if (unwantedKeyBindings.includesCase(parameterizedCommand?.command?.id)) {
parameterizedCommand.command.undefine
parameterizedCommand.command.enabled = false
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Golondrina {
z = y
const w = y

alimento.hacerAlgo(x,y,z,w)
alimento.hacerAlgo(y,z,w)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* XPECT_SETUP org.uqbar.project.wollok.tests.xpect.WollokXPectTest END_SETUP */

object carrito {
const productos = []
method getProductoMasCaro() {
const aleatoriedad = 3
productos.max({ productoMasCaro => productoMasCaro.precio() })
// XPECT errors ---> "Couldn't resolve reference to 'productoMasCaro'." at "productoMasCaro"
return productoMasCaro + aleatoriedad
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* XPECT_SETUP org.uqbar.project.wollok.tests.xpect.WollokXPectTest END_SETUP */
mixin MundoCerrado {
var property a = 2

method noVaAAndar() = a == self.b()
method b()
}

class Mundo {
var property a = ""

method b() = 2
}

class MundoFeliz inherits Mundo {
var property c = true
}

// XPECT errors --> "There are instance variables with the same name in the hierarchy: [a]" at "new MundoFeliz() with MundoCerrado"
const alf = new MundoFeliz() with MundoCerrado
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,17 @@ class TypeSystemConfigurationBlock extends OptionsConfigurationBlock {
restoreSectionExpansionStates = WollokActivator.getInstance.dialogSettings.addNewSection(SETTINGS_SECTION_NAME)
super.dispose
}

override performApply() {
// Hay que hacer esto para que no se rompa Xtext
savePreferences
true
}

override performOk() {
// Hay que hacer esto para que no se rompa Xtext
savePreferences
true
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,21 @@ class TypeSystemPreferencePage extends PropertyAndPreferencePage implements IWor
}

override performOk() {
if (builderConfigurationBlock !== null) {
scheduleCleanerJobIfNecessary(container)
if (!builderConfigurationBlock.performOk)
return false
}
scheduleCleanerJobIfNecessary(container)
builderConfigurationBlock.performOk
super.performOk
}

override performApply() {
if (builderConfigurationBlock !== null) {
scheduleCleanerJobIfNecessary(null)
builderConfigurationBlock.performApply
}
scheduleCleanerJobIfNecessary(null)
builderConfigurationBlock.performApply
super.performApply
}

def scheduleCleanerJobIfNecessary(IPreferencePageContainer preferencePageContainer) {
//TODO: podría ser inteligente y solo buildear si hubo cambios en ciertas propiedades.
// ver BuilderPreferencePage
val c = container as IWorkbenchPreferenceContainer
c.registerUpdateJob(new Job(Messages.WollokTypeSystemPreference_REBUILD_JOB_TITLE) {
(container as IWorkbenchPreferenceContainer).registerUpdateJob(new Job(Messages.WollokTypeSystemPreference_REBUILD_JOB_TITLE) {
override protected run(IProgressMonitor monitor) {
rebuild(monitor)
Status.OK_STATUS
Expand Down
2 changes: 1 addition & 1 deletion org.uqbar.project.wollok.ui.diagrams/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<view
category="org.uqbar.project.wollok.ui.diagrams.category"
class="org.uqbar.project.wollok.ui.diagrams.classes.WollokDslExecutableExtensionFactory:org.uqbar.project.wollok.ui.diagrams.dynamic.DynamicDiagramView"
icon="icons/object_diagram_icon3.png"
icon="icons/object_diagram_icon.png"
id="org.uqbar.project.wollok.ui.diagrams.object"
name="%dynamicDiagramView"
restorable="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.io.InvalidClassException
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
import java.io.Serializable
import java.net.URLDecoder
import java.util.List
import java.util.Map
import java.util.Observable
Expand All @@ -30,20 +31,16 @@ import static extension org.uqbar.project.wollok.model.WollokModelExtensions.*
import static extension org.uqbar.project.wollok.utils.StringUtils.*

@Accessors
abstract class AbstractDiagramConfiguration extends Observable {
abstract class AbstractDiagramConfiguration extends Observable implements Serializable {

/** Notification Events */
public static String CONFIGURATION_CHANGED = "configuration"

/** Internal state */
boolean rememberLocationsAndSizes = true
Map<String, Point> locations
Map<String, Dimension> sizes
protected Map<String, Point> locations = newHashMap
protected Map<String, Dimension> sizes = newHashMap

new() {
init
}

/**
******************************************************
* STATE INITIALIZATION
Expand Down Expand Up @@ -118,7 +115,7 @@ abstract class AbstractDiagramConfiguration extends Observable {
*
*/
@Accessors
class StaticDiagramConfiguration extends AbstractDiagramConfiguration implements Serializable {
class StaticDiagramConfiguration extends AbstractDiagramConfiguration {

/** Internal state */
boolean showVariables = false
Expand Down Expand Up @@ -369,7 +366,7 @@ class StaticDiagramConfiguration extends AbstractDiagramConfiguration implements
}


/**
/**
******************************************************
* CONFIGURATION LOAD & SAVE TO EXTERNAL FILE
*******************************************************
Expand All @@ -395,11 +392,13 @@ class StaticDiagramConfiguration extends AbstractDiagramConfiguration implements
val file = new FileOutputStream(staticDiagramFile)
val oos = new ObjectOutputStream(file)
oos.writeObject(this)
oos.close
file.close
}
}

def getStaticDiagramFile() {
new File(fullPath, staticDiagramFileName)
new File(URLDecoder.decode(fullPath, "UTF-8"), staticDiagramFileName)
}

def getStaticDiagramFileName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import org.eclipse.gef.editparts.AbstractGraphicalEditPart
import org.eclipse.gef.editparts.ScalableFreeformRootEditPart
import org.eclipse.gef.editparts.ZoomManager
import org.eclipse.gef.ui.actions.ActionRegistry
import org.eclipse.gef.ui.actions.ZoomComboContributionItem
import org.eclipse.gef.ui.properties.UndoablePropertySheetPage
import org.eclipse.gef.ui.views.palette.PalettePage
import org.eclipse.jface.action.Separator
Expand Down Expand Up @@ -398,7 +397,7 @@ class StaticDiagramView extends AbstractDiagramView implements IDocumentListener
val clazz = model.getComponent
if (clazz !== null) {
this.selection = new StructuredSelection(clazz)
val selectionChangedEvent = new SelectionChangedEvent(this, this.selection)
val selectionChangedEvent = new SelectionChangedEvent(this, selection)
currentListeners.forEach [ listener |
listener.selectionChanged(selectionChangedEvent)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ abstract class AbstractModel extends Shape {

protected val static TOP_POSITION = 10
protected val static DEFAULT_WIDTH = 120
protected val static ELEMENT_WIDTH = 50
protected val static MAX_ELEMENT_WIDTH = 230
protected val static ELEMENT_WIDTH = 150
protected val static MAX_ELEMENT_WIDTH = 400
protected val static MAX_ELEMENT_HEIGHT = 300
protected val static ELEMENT_HEIGHT = 55
protected val static WIDTH_SEPARATION_BETWEEN_ELEMENTS = 20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class Messages extends NLS {
public static String WollokDslValidator_CYCLIC_HIERARCHY;
public static String WollokDslValidator_DUPLICATED_METHOD;
public static String WollokDslValidator_DUPLICATED_VARIABLE_IN_HIERARCHY;
public static String WollokDslValidator_DUPLICATED_VARIABLE_IN_CONSTRUCTOR_CALL;
public static String WollokDslValidator_DUPLICATED_NAME;
public static String WollokDslValidator_DUPLICATED_REFERENCE_FROM_IMPORTS;
public static String WollokDslValidator_METHOD_ON_THIS_DOESNT_EXIST;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ WollokDslValidator_WCONSTRUCTOR_CALL__ARGUMENTS = Wrong number of arguments. Sho
WollokDslValidator_OBJECT_MUST_CALL_SUPERCLASS_CONSTRUCTOR = Object must explicitly call a superclass constructor: {1}
WollokDslValidator_NO_SUPERCLASS_CONSTRUCTOR = No superclass constructor or wrong number of arguments. You must explicitly call a constructor: {0}
WollokDslValidator_DUPLICATED_VARIABLE_IN_HIERARCHY = There is already an instance variable with this name in the hierarchy
WollokDslValidator_DUPLICATED_VARIABLE_IN_CONSTRUCTOR_CALL = There are instance variables with the same name in the hierarchy: [{0}]
WollokDslValidator_DUPLICATED_REFERENCE_FROM_IMPORTS = This name is already defined (imported from {0})
WollokDslValidator_RETURN_FORGOTTEN = Method produces a value but you are not returning it. Did you forget the return ?
WollokDslValidator_CANT_USE_RETURN_EXPRESSION_IN_ARGUMENT = Can't use 'return' expression as argument. Tip: remove 'return' keyword.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ WollokDslValidator_OBJECT_NAME_MUST_START_LOWERCASE = El nombre del objeto deber

WollokDslValidator_SUPER_INCORRECT_ARGS = N\u00FAmero incorrecto de argumentos a 'super'. Se espera
WollokDslValidator_SUPER_ONLY_IN_CLASSES = S\u00F3lo se puede utilizar 'super' en m\u00E9todos declarados en clases
WollokDslValidator_SUPER_ONLY_OVERRIDING_METHOD = S\u00F3lo se puede utilizar 'super' en un m\u00E9tod que sobrescribe otro
WollokDslValidator_SUPER_ONLY_OVERRIDING_METHOD = S\u00F3lo se puede utilizar 'super' en un m\u00E9todo que sobrescribe otro

WollokDslValidator_INITIALIZATION_VALUE_FOR_VARIABLE_NEVER_USED = El valor inicial definido nunca es utilizado

Expand All @@ -150,6 +150,7 @@ WollokDslValidator_WCONSTRUCTOR_CALL__ARGUMENTS = N\u00FAmero de argumentos inco
WollokDslValidator_NO_SUPERCLASS_CONSTRUCTOR = No existe el constructor de la superclase o cantidad incorrecta de par\u00E1metros. Debe llamar expl\u00EDcitamente a un constructor: {0}

WollokDslValidator_DUPLICATED_VARIABLE_IN_HIERARCHY = Ya existe una variable de instancia con este nombre en la jerarqu\u00EDa
WollokDslValidator_DUPLICATED_VARIABLE_IN_CONSTRUCTOR_CALL = En la jerarqu\u00EDa hay variables de instancia con el mismo nombre: [{0}]
WollokDslValidator_DUPLICATED_REFERENCE_FROM_IMPORTS = Este nombre ya está definido (importado de {0})

WollokDslValidator_RETURN_FORGOTTEN = El cuerpo del m\u00E9todo genera un valor que no se est\u00E1 retornando. Olvidaste el 'return' ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ class WMethodContainerExtensions extends WollokModelExtensions {
}

def static void superClassesIncludingYourselfTopDownDo(WClass cl, (WClass)=>void action) {
if (cl.equals(cl.parent)) return; // avoid stack overflow
if (cl.hasCyclicHierarchy) return;
if (cl.parent !== null) cl.parent.superClassesIncludingYourselfTopDownDo(action)
action.apply(cl)
}
Expand All @@ -550,7 +550,7 @@ class WMethodContainerExtensions extends WollokModelExtensions {

def static dispatch feature(EObject o) { null }
def static dispatch feature(WMemberFeatureCall call) { call.feature }
def static dispatch feature(WSuperInvocation call) { call.method.name }
def static dispatch feature(WSuperInvocation call) { call.method?.name }
def static dispatch feature(WUnaryOperation o) { o.feature }
def static dispatch feature(WBinaryOperation o) { o.feature }
def static dispatch feature(WPostfixOperation o) { o.feature }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ class WollokModelExtensions {
def static dispatch boolean isGlobal(WParameter it) { false }
def static dispatch boolean isGlobal(WCatch it) { false }

def static dispatch boolean hasGlobalDefinitions(WClosure it) { false }
def static dispatch boolean hasGlobalDefinitions(EObject e) { true }

// ************************************************************************
// ** Variable & parameter usage
// ************************************************************************
Expand All @@ -201,7 +204,7 @@ class WollokModelExtensions {
ParameterUsesVisitor.usesOf(parameter, parameter.declarationContext)
}

def static isUsed(WReferenciable ref) { !ref.uses.isEmpty }
def static isUsed(WReferenciable ref) { ref !== null && !ref.uses.isEmpty }

def static indexOfUse(WVariableReference ref) {
ref.ref.uses.indexOf(ref.eContainer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ class WollokDslScopeProvider extends AbstractDeclarativeScopeProvider {
eContainer.scope + parameters
}

def dispatch IScope scope(WClosure it) { eContainer.scope + parameters }

def dispatch IScope scope(WMethodDeclaration it) {
eContainer.scope + parameters
}

def dispatch IScope scope(WClosure it) {
eContainer.scope + parameters
}

def dispatch IScope scope(WCatch it) { eContainer.scope + exceptionVarName }

def dispatch IScope scope(WTest it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class WollokGlobalScopeProvider extends DefaultGlobalScopeProvider {
].map [ r |
resourceDescriptionManager.getResourceDescription(r).exportedObjects
].flatten + objectsFromManifests

importedObjects
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class WollokImportedNamespaceAwareLocalScopeProvider extends AbstractGlobalScope
// ************************************************************************
override getScope(EObject context, EReference reference) {
synchronized(context.eResource)
synchronized(context.eResource.resourceSet)
// synchronized(context.eResource.resourceSet)
context.computeScope(reference)
}

Expand All @@ -69,9 +69,9 @@ class WollokImportedNamespaceAwareLocalScopeProvider extends AbstractGlobalScope
// ** Internal implementation
// ************************************************************************
protected def IScope computeScope(EObject context, EReference reference) {
val IScope parent = if(context.eContainer !== null)
val IScope parent = if (context.eContainer !== null)
context.eContainer.computeScope(reference)
else
else
context.eResource.resourceScope(reference)

context.localElementsScope(parent, reference)
Expand Down Expand Up @@ -144,11 +144,11 @@ class WollokImportedNamespaceAwareLocalScopeProvider extends AbstractGlobalScope
protected def getAllDescriptions(Resource resource) {
val Iterable<EObject> allContents = new Iterable<EObject>() {
override Iterator<EObject> iterator() {
EcoreUtil.getAllContents(resource, false)
EcoreUtil.getAllContents(resource, false).filter [ eContainer === null || eContainer.hasGlobalDefinitions ]
}
}
val allDescriptions = Scopes.scopedElementsFor(allContents, qualifiedNameProvider)
return new MultimapBasedSelectable(allDescriptions)
new MultimapBasedSelectable(allDescriptions)
}

protected def createImportScope(IScope parent, List<ImportNormalizer> namespaceResolvers, ISelectable importFrom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,19 @@ class WollokDslValidator extends AbstractConfigurableDslValidator {
report(WollokDslValidator_DUPLICATED_VARIABLE_IN_HIERARCHY)
]
}


@Check
@DefaultSeverity(ERROR)
@NotConfigurable
def duplicatedVariableInLinearization(WConstructorCall call) {
if (call.mixins.isEmpty) return;
val inheritedVariables = call.mixins.map[variables].flatten
val duplicatedVariables = call.classRef.allVariables.filter[v|inheritedVariables.exists[name == v.name]]
if (!duplicatedVariables.isEmpty) {
report(NLS.bind(WollokDslValidator_DUPLICATED_VARIABLE_IN_CONSTRUCTOR_CALL, duplicatedVariables.map [ name ].join(", ")), call)
}
}

@Check
@DefaultSeverity(WARN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CamionReutilizable inherits Camion {

override method getCosos() = destinos.map{destino => destino.getCosos()}.flatten()

method descargarCamionEn(unLugar) { destino.remove(destinos.detect{destino => destino.getLugar() == unLugar}) }
method descargarCamionEn(unLugar) { destinos.remove(destinos.detect{destino => destino.getLugar() == unLugar}) }

method cargarUnCosoEnDestino(unCoso, unLugar) {
if(self.puedeCargar(unCoso)) {
Expand Down

0 comments on commit 9b6478b

Please sign in to comment.