-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1205 from HubSpot/fix-macro-child-scope-reconstru…
…ction Overhaul current path reconstruction in eager execution
- Loading branch information
Showing
46 changed files
with
509 additions
and
336 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
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
52 changes: 52 additions & 0 deletions
52
src/main/java/com/hubspot/jinjava/interpret/MetaContextVariables.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,52 @@ | ||
package com.hubspot.jinjava.interpret; | ||
|
||
import com.google.common.annotations.Beta; | ||
import java.util.Objects; | ||
|
||
@Beta | ||
public class MetaContextVariables { | ||
|
||
public static final String TEMPORARY_META_CONTEXT_PREFIX = "__temp_meta_"; | ||
private static final String TEMPORARY_IMPORT_ALIAS_PREFIX = | ||
TEMPORARY_META_CONTEXT_PREFIX + "import_alias_"; | ||
|
||
private static final String TEMPORARY_IMPORT_ALIAS_FORMAT = | ||
TEMPORARY_IMPORT_ALIAS_PREFIX + "%d__"; | ||
private static final String TEMP_CURRENT_PATH_PREFIX = | ||
TEMPORARY_META_CONTEXT_PREFIX + "current_path_"; | ||
private static final String TEMP_CURRENT_PATH_FORMAT = | ||
TEMP_CURRENT_PATH_PREFIX + "%d__"; | ||
|
||
public static boolean isMetaContextVariable(String varName, Context context) { | ||
if (isTemporaryMetaContextVariable(varName)) { | ||
return true; | ||
} | ||
return ( | ||
context.getMetaContextVariables().contains(varName) && | ||
!context.getNonMetaContextVariables().contains(varName) | ||
); | ||
} | ||
|
||
private static boolean isTemporaryMetaContextVariable(String varName) { | ||
return varName.startsWith(TEMPORARY_META_CONTEXT_PREFIX); | ||
} | ||
|
||
public static boolean isTemporaryImportAlias(String varName) { | ||
// This is just faster than checking a regex | ||
return varName.startsWith(TEMPORARY_IMPORT_ALIAS_PREFIX); | ||
} | ||
|
||
public static String getTemporaryImportAlias(String fullAlias) { | ||
return String.format( | ||
TEMPORARY_IMPORT_ALIAS_FORMAT, | ||
Math.abs(Objects.hashCode(fullAlias)) | ||
); | ||
} | ||
|
||
public static String getTemporaryCurrentPathVarName(String newPath) { | ||
return String.format( | ||
TEMP_CURRENT_PATH_FORMAT, | ||
Math.abs(Objects.hash(newPath, TEMPORARY_META_CONTEXT_PREFIX) >> 1) | ||
); | ||
} | ||
} |
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
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
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
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.