Skip to content

Commit

Permalink
Refactoring validation - extract constant
Browse files Browse the repository at this point in the history
  • Loading branch information
PalumboN committed Dec 14, 2023
1 parent a5f8a7d commit 8ee734e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const WOLLOK_EXTRA_STACK_TRACE_HEADER = 'Derived from TypeScript stack'

export const WOLLOK_BASE_PACKAGE = 'wollok.'
export const WOLLOK_BASE_PACKAGE = 'wollok.'

export const INITIALIZE_METHOD_NAME = 'initialize'
6 changes: 3 additions & 3 deletions src/interpreter/runtimeModel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { WOLLOK_BASE_PACKAGE, WOLLOK_EXTRA_STACK_TRACE_HEADER } from '../constants'
import { v4 as uuid } from 'uuid'
import { INITIALIZE_METHOD_NAME, WOLLOK_BASE_PACKAGE, WOLLOK_EXTRA_STACK_TRACE_HEADER } from '../constants'
import { getPotentiallyUninitializedLazy } from '../decorators'
import { get, is, last, List, match, raise, when } from '../extensions'
import { Assignment, Body, Catch, Describe, Environment, Entity, Expression, Id, If, Literal, LiteralValue, Method, Module, Name, New, Node, Package, Program, Reference, Return, Self, Send, Singleton, Super, Test, Throw, Try, Variable } from '../model'
import { Assignment, Body, Catch, Describe, Entity, Environment, Expression, Id, If, Literal, LiteralValue, Method, Module, Name, New, Node, Package, Program, Reference, Return, Self, Send, Singleton, Super, Test, Throw, Try, Variable } from '../model'
import { Interpreter } from './interpreter'

const { isArray } = Array
Expand Down Expand Up @@ -675,7 +675,7 @@ export class Evaluation {
instance.set(field.name, initialValue)
}

yield * this.send('initialize', instance)
yield * this.send(INITIALIZE_METHOD_NAME, instance)

if(!instance.module.name || instance.module.is(Describe))
for (const field of instance.module.allFields)
Expand Down
12 changes: 7 additions & 5 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
// - Level could be different for the same Expectation on different nodes
// - Problem could know how to convert to string, receiving the interpolation function (so it can be translated). This could let us avoid having parameters.
// - Good default for simple problems, but with a config object for more complex, so we know what is each parameter
import { WOLLOK_BASE_PACKAGE } from './constants'
import { count, TypeDefinition, duplicates, is, isEmpty, last, List, match, notEmpty, when } from './extensions'
import { INITIALIZE_METHOD_NAME, WOLLOK_BASE_PACKAGE } from './constants'
import { count, duplicates, is, isEmpty, last, List, match, notEmpty, TypeDefinition, when } from './extensions'
// - Unified problem type
import { Assignment, Body, Catch, Class, Code, Describe, Entity, Expression, Field, If, Import,
import {
Assignment, Body, Catch, Class, Code, Describe, Entity, Expression, Field, If, Import,
Level, Literal, Method, Mixin, Module, NamedArgument, New, Node, Package, Parameter, ParameterizedType, Problem,
Program, Reference, Return, Self, Send, Sentence, Singleton, SourceIndex, SourceMap, Super, Test, Throw, Try, Variable } from './model'
Program, Reference, Return, Self, Send, Sentence, Singleton, SourceIndex, SourceMap, Super, Test, Throw, Try, Variable
} from './model'

const { entries } = Object

Expand Down Expand Up @@ -184,7 +186,7 @@ export const shouldOnlyInheritFromMixin = error<Mixin>(node => node.supertypes.e
}))

export const shouldUseOverrideKeyword = warning<Method>(node =>
!(!node.isOverride && superclassMethod(node) && !['initialize'].includes(node.name))
node.isOverride || !superclassMethod(node) || node.name == INITIALIZE_METHOD_NAME
)

export const possiblyReturningBlock = warning<Method>(node => {
Expand Down

0 comments on commit 8ee734e

Please sign in to comment.