Skip to content

Commit

Permalink
Removed unnecessary calls to v8.
Browse files Browse the repository at this point in the history
  • Loading branch information
traceyyoshima committed Nov 17, 2023
1 parent 4cd258a commit 261b65d
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.openrewrite.java.JavaTypeSignatureBuilder;
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.javascript.internal.tsc.TSCNode;
import org.openrewrite.javascript.internal.tsc.TSCNodeList;
import org.openrewrite.javascript.internal.tsc.TSCSymbol;
import org.openrewrite.javascript.internal.tsc.TSCType;
import org.openrewrite.javascript.internal.tsc.generated.TSCObjectFlag;
Expand Down Expand Up @@ -58,7 +59,8 @@ public String signature(@Nullable Object object) {
case ClassDeclaration:
case EnumDeclaration:
case InterfaceDeclaration:
return node.hasProperty("typeParameters") && !node.getNodeListProperty("typeParameters").isEmpty() ?
TSCNodeList typeParameters = node.getOptionalNodeListProperty("typeParameters");
return typeParameters != null && !typeParameters.isEmpty() ?
parameterizedSignature(node) : classSignature(node);
case ArrayType:
cached = arraySignature(node);
Expand Down Expand Up @@ -131,8 +133,8 @@ public String genericSignature(Object object) {
StringBuilder s = new StringBuilder("Generic{").append(name);
StringJoiner boundSigs = new StringJoiner(" & ");

if (node.hasProperty("constraint")) {
TSCNode constraint = node.getNodeProperty("constraint");
TSCNode constraint = node.getOptionalNodeProperty("constraint");
if (constraint != null) {
if (constraint.syntaxKind() == TSCSyntaxKind.IntersectionType) {
for (TSCNode type : constraint.getNodeListProperty("types")) {
boundSigs.add(signature(type));
Expand Down Expand Up @@ -232,8 +234,9 @@ public String variableSignature(TSCNode node) {

String name = node.getNodeProperty("name").getText();
String typeSig;
if (node.hasProperty("type")) {
typeSig = signature(node.getNodeProperty("type"));
TSCNode type = node.getOptionalNodeProperty("type");
if (type != null) {
typeSig = signature(type);
} else if (node.syntaxKind() == TSCSyntaxKind.EnumMember) {
typeSig = owner;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.java.tree.TypeUtils;
import org.openrewrite.javascript.internal.tsc.TSCNode;
import org.openrewrite.javascript.internal.tsc.TSCNodeList;
import org.openrewrite.javascript.internal.tsc.TSCSymbol;
import org.openrewrite.javascript.internal.tsc.TSCType;
import org.openrewrite.javascript.internal.tsc.generated.TSCObjectFlag;
Expand Down Expand Up @@ -171,8 +172,9 @@ private JavaType.FullyQualified classType(@Nullable TSCNode node, String signatu
List<TSCNode> propertyNodes = null;
List<TSCNode> methodNodes = null;
List<TSCNode> enumNodes = null;
if (node.hasProperty("members")) {
for (TSCNode member : node.getNodeListProperty("members")) {
TSCNodeList memberNodes = node.getOptionalNodeListProperty("members");
if (memberNodes != null) {
for (TSCNode member : memberNodes) {
if (member.syntaxKind() == TSCSyntaxKind.CallSignature ||
member.syntaxKind() == TSCSyntaxKind.Constructor ||
member.syntaxKind() == TSCSyntaxKind.ConstructSignature ||
Expand Down Expand Up @@ -228,15 +230,15 @@ private JavaType.FullyQualified classType(@Nullable TSCNode node, String signatu
clazz.unsafeSet(null, supertype, owner, mapAnnotations(modifiers), interfaces, members, methods);
}

if (node.hasProperty("typeParameters")) {
TSCNodeList typeParamNodes = node.getOptionalNodeListProperty("typeParameters");
if (typeParamNodes != null) {
JavaType jt = typeCache.get(signature);
if (jt == null) {
JavaType.Parameterized pt = new JavaType.Parameterized(null, null, null);
typeCache.put(signature, pt);

List<TSCNode> paramNodes = node.getNodeListProperty("typeParameters");
List<JavaType> typeParams = new ArrayList<>(paramNodes.size());
for (TSCNode paramNode : paramNodes) {
List<JavaType> typeParams = new ArrayList<>(typeParamNodes.size());
for (TSCNode paramNode : typeParamNodes) {
typeParams.add(type(paramNode));
}
pt.unsafeSet(clazz, typeParams);
Expand All @@ -255,8 +257,8 @@ public JavaType.GenericTypeVariable generic(TSCNode node, String signature) {
List<JavaType> bounds = null;
JavaType.GenericTypeVariable.Variance variance = INVARIANT;

if (node.hasProperty("constraint")) {
TSCNode constraint = node.getNodeProperty("constraint");
TSCNode constraint = node.getOptionalNodeProperty("constraint");
if (constraint != null) {
if (constraint.syntaxKind() == TSCSyntaxKind.IntersectionType) {
List<TSCNode> types = constraint.getNodeListProperty("types");
bounds = new ArrayList<>(types.size());
Expand Down Expand Up @@ -297,11 +299,12 @@ public JavaType.Method methodDeclarationType(TSCNode node, @Nullable JavaType.Fu

boolean isConstructor = node.syntaxKind() == TSCSyntaxKind.Constructor;
List<TSCNode> modifiers = node.getOptionalNodeListProperty("modifiers");
TSCNode nodeName = node.getOptionalNodeProperty("name");
JavaType.Method method = new JavaType.Method(
null,
mapModifiers(modifiers),
null,
isConstructor ? "<constructor>" : node.hasProperty("name") ? node.getNodeProperty("name").getText() : "{anonymous}",
isConstructor ? "<constructor>" : nodeName != null ? nodeName.getText() : "{anonymous}",
null,
paramNames,
null, null, null,
Expand Down
Loading

0 comments on commit 261b65d

Please sign in to comment.