-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is not necessary after all but it's much cleaner and avoids duplication of bindings in nested scopes.
- Loading branch information
Showing
8 changed files
with
85 additions
and
72 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
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
41 changes: 41 additions & 0 deletions
41
independent-projects/qute/core/src/main/java/io/quarkus/qute/Scope.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,41 @@ | ||
package io.quarkus.qute; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Scope { | ||
|
||
public static final Scope EMPTY = new Scope(null) { | ||
@Override | ||
public void put(String binding, String type) { | ||
throw new UnsupportedOperationException("Immutable empty scope"); | ||
} | ||
}; | ||
|
||
private Scope parentScope; | ||
private Map<String, String> bindings; | ||
|
||
public Scope(Scope parentScope) { | ||
this.parentScope = parentScope; | ||
} | ||
|
||
public void put(String binding, String type) { | ||
if (bindings == null) | ||
bindings = new HashMap<>(); | ||
bindings.put(binding, type); | ||
} | ||
|
||
public String getBindingType(String binding) { | ||
// we can contain null types to override outer scopes | ||
if (bindings != null | ||
&& bindings.containsKey(binding)) | ||
return bindings.get(binding); | ||
return parentScope != null ? parentScope.getBindingType(binding) : null; | ||
} | ||
|
||
public String getBindingTypeOrDefault(String binding, String defaultValue) { | ||
String type = getBindingType(binding); | ||
return type != null ? type : defaultValue; | ||
} | ||
|
||
} |
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