-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detached ruleset unlocked from mixin did not worked right (did not seen
mixins parameters). Putting body scope joiner on one place to find out how to refactor them. #186
- Loading branch information
jurcovicovam
committed
Jul 1, 2014
1 parent
aef9cff
commit 28d4897
Showing
11 changed files
with
141 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
...in/java/com/github/sommeri/less4j/core/compiler/scopes/FullDetachedRulesetDefinition.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/com/github/sommeri/less4j/core/compiler/scopes/ScopeManipulation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.github.sommeri.less4j.core.compiler.scopes; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.github.sommeri.less4j.core.compiler.scopes.view.ScopeView; | ||
|
||
public class ScopeManipulation { | ||
|
||
//FIXME !!!! refactor and clean, unify with references solver joiner | ||
public ScopeView constructImportedBodyScope(IScope importTargetScope, IScope bodyToBeImportedScope) { | ||
ScopeView newScope = null; | ||
// locally defined mixin does not require any other action | ||
boolean isLocalImport = bodyToBeImportedScope.seesAllDataOf(importTargetScope); | ||
|
||
if (isLocalImport) { | ||
// we need to copy the whole tree, because this runs inside referenced mixin scope | ||
// snapshot and imported mixin needs to remember the scope as it is now | ||
newScope = ScopeFactory.createJoinedScopesView(null, bodyToBeImportedScope); | ||
newScope.saveLocalDataForTheWholeWayUp(); | ||
} else { | ||
// since this is non-local import, we need to join reference scope and imported mixins scope | ||
// imported mixin needs to have access to variables defined in caller | ||
newScope = ScopeFactory.createJoinedScopesView(importTargetScope, bodyToBeImportedScope); | ||
newScope.saveLocalDataForTheWholeWayUp(); | ||
} | ||
return newScope; | ||
} | ||
|
||
public IScope calculateBodyWorkingScope(IScope callerScope, IScope bodyScope) { | ||
//FIXME !!!!!! find the case where this is needed for mixins and create test case for it | ||
// locally defined mixin does not require any other action | ||
boolean isLocallyDefined = bodyScope.seesAllDataOf(callerScope); | ||
|
||
if (isLocallyDefined) { | ||
return bodyScope; | ||
} | ||
|
||
//join scopes | ||
IScope result = ScopeFactory.createJoinedScopesView(callerScope, bodyScope); | ||
return result; | ||
} | ||
|
||
//FIXME: !!! evaluate need for this | ||
public IScope calculateMixinsWorkingScope(IScope callerScope, IScope arguments, IScope mixinScope) { | ||
// add arguments | ||
IScope mixinDeclarationScope = mixinScope.getParent(); | ||
mixinDeclarationScope.add(arguments); | ||
|
||
// locally defined mixin does not require any other action | ||
boolean isLocallyDefined = mixinDeclarationScope.seesLocalDataOf(callerScope); | ||
if (isLocallyDefined) { | ||
return mixinScope; | ||
} | ||
|
||
//join scopes | ||
IScope result = ScopeFactory.createJoinedScopesView(callerScope, mixinScope); | ||
return result; | ||
} | ||
|
||
public List<FullMixinDefinition> mixinsToImport(IScope referenceScope, IScope referencedMixinScope, List<FullMixinDefinition> unmodifiedMixinsToImport) { | ||
List<FullMixinDefinition> result = new ArrayList<FullMixinDefinition>(); | ||
for (FullMixinDefinition mixinToImport : unmodifiedMixinsToImport) { | ||
boolean isLocalImport = mixinToImport.getScope().seesLocalDataOf(referenceScope); | ||
if (isLocalImport) { | ||
// we need to copy the whole tree, because this runs inside referenced mixin scope | ||
// snapshot and imported mixin needs to remember the scope as it is now | ||
ScopeView newWay = ScopeFactory.createJoinedScopesView(null, mixinToImport.getScope()); | ||
newWay.saveLocalDataForTheWholeWayUp(); | ||
result.add(new FullMixinDefinition(mixinToImport.getMixin(), newWay)); | ||
} else { | ||
// since this is non-local import, we need to join reference scope and imported mixins scope | ||
// imported mixin needs to have access to variables defined in caller | ||
ScopeView newWay = ScopeFactory.createJoinedScopesView(referencedMixinScope, mixinToImport.getScope()); | ||
newWay.saveLocalDataForTheWholeWayUp(); | ||
result.add(new FullMixinDefinition(mixinToImport.getMixin(), newWay)); | ||
} | ||
|
||
} | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.