package jetbrains.mps.idea.java.psiStubs; /*Generated by MPS */ import org.jetbrains.mps.openapi.util.Consumer; import jetbrains.mps.util.Pair; import org.jetbrains.mps.openapi.model.SNode; import com.intellij.psi.PsiElement; import java.util.Set; import com.intellij.psi.PsiClass; import jetbrains.mps.baseLanguage.closures.runtime.Wrappers; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SConceptOperations; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import org.jetbrains.mps.openapi.language.SAbstractConcept; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations; import com.intellij.psi.PsiClassType; import jetbrains.mps.internal.collections.runtime.ListSequence; import jetbrains.mps.internal.collections.runtime.Sequence; import jetbrains.mps.internal.collections.runtime.IWhereFilter; import jetbrains.mps.internal.collections.runtime.ISelector; import jetbrains.mps.internal.collections.runtime.IVisitor; import com.intellij.psi.PsiField; import com.intellij.psi.PsiEnumConstant; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiModifier; import com.intellij.psi.PsiAnnotationMethod; import com.intellij.psi.PsiParameter; import jetbrains.mps.smodel.SNodeId; import com.intellij.psi.PsiType; import com.intellij.psi.PsiPrimitiveType; import com.intellij.psi.PsiArrayType; import com.intellij.psi.PsiWildcardType; import com.intellij.psi.PsiTypeParameter; import com.intellij.psi.PsiExpression; import com.intellij.psi.PsiLiteralExpression; import com.intellij.psi.impl.source.PsiClassReferenceType; import com.intellij.psi.impl.source.tree.JavaSourceUtil; import jetbrains.mps.smodel.DynamicReference; import com.intellij.psi.PsiAnnotation; import com.intellij.psi.impl.light.LightElement; import com.intellij.psi.PsiModifierListOwner; import com.intellij.psi.PsiTypeParameterListOwner; import com.intellij.psi.PsiNameValuePair; import java.util.Map; import jetbrains.mps.internal.collections.runtime.MapSequence; import java.util.HashMap; import jetbrains.mps.internal.collections.runtime.SetSequence; import jetbrains.mps.smodel.SReference; import com.intellij.psi.PsiTypeElement; import org.jetbrains.mps.openapi.persistence.PersistenceFacade; import jetbrains.mps.smodel.SModelUtil_new; import jetbrains.mps.lang.typesystem.runtime.HUtil; import org.jetbrains.mps.openapi.model.SNodeAccessUtil; public class ASTConverter { private final ASTConverter.State myState; protected final Consumer<Pair<SNode, PsiElement>> myMps2PsiMapper; public ASTConverter() { myState = new ASTConverter.State(); myMps2PsiMapper = null; } public ASTConverter(Consumer<Pair<SNode, PsiElement>> mps2psiMapper) { myState = new ASTConverter.State(); myMps2PsiMapper = mps2psiMapper; } public ASTConverter(Consumer<Pair<SNode, PsiElement>> mps2psiMapper, ASTConverter.State state) { myState = state; myMps2PsiMapper = mps2psiMapper; } private ASTConverter withTypeVarNames(Set<String> typeVarNames) { return new ASTConverter(myMps2PsiMapper, new ASTConverter.State(myState, typeVarNames)); } private ASTConverter withTypeVarDecls(Iterable<SNode> typeVars) { return new ASTConverter(myMps2PsiMapper, new ASTConverter.State(myState, typeVars)); } protected boolean needToSetId() { return true; } public SNode convertClass(PsiClass x) { final Wrappers._T<SNode> classifier = new Wrappers._T<SNode>(); if (x.isAnnotationType()) { classifier.value = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x114a69dc80cL, "jetbrains.mps.baseLanguage.structure.Annotation")); } else if (x.isEnum()) { classifier.value = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfc367070a5L, "jetbrains.mps.baseLanguage.structure.EnumClass")); } else if (x.isInterface()) { classifier.value = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101edd46144L, "jetbrains.mps.baseLanguage.structure.Interface")); } else { classifier.value = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca66L, "jetbrains.mps.baseLanguage.structure.ClassConcept")); } final SAbstractConcept ourConcept = SNodeOperations.getConcept(classifier.value); SPropertyOperations.set(classifier.value, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name"), "" + (x.getName())); SLinkOperations.setTarget(classifier.value, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x112670d273fL, 0x112670d886aL, "visibility"), getVisibility(x)); addAnnotations(x, classifier.value); if (needToSetId() && isNotEmptyString(SPropertyOperations.getString(classifier.value, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name")))) { ((jetbrains.mps.smodel.SNode) classifier.value).setId(JavaForeignIdBuilder.computeNodeId(x)); } final ASTConverter currConverter = addTypeParams(x, classifier.value); // class's super types and implemented ifaces PsiClassType[] extendz = x.getExtendsListTypes(); PsiClassType[] implementz = x.getImplementsListTypes(); { final SNode reallyClass = classifier.value; if (SNodeOperations.isInstanceOf(reallyClass, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca66L, "jetbrains.mps.baseLanguage.structure.ClassConcept"))) { if (extendz.length != 0) { SLinkOperations.setTarget(reallyClass, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca66L, 0x10f6353296dL, "superclass"), currConverter.resolveClass(extendz[0])); } ListSequence.fromList(SLinkOperations.getChildren(reallyClass, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca66L, 0xff2ac0b419L, "implementedInterface"))).addSequence(Sequence.fromIterable(Sequence.fromArray(implementz)).where(new IWhereFilter<PsiClassType>() { public boolean accept(PsiClassType it) { return isNotLight(it); } }).select(new ISelector<PsiClassType, SNode>() { public SNode select(PsiClassType it) { return currConverter.resolveClass(it); } })); SPropertyOperations.set(reallyClass, MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca66L, 0x11c6af4b284L, "isFinal"), "" + (isFinal(x))); SPropertyOperations.set(reallyClass, MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca66L, 0x451f9e9f920b7f7dL, "isStatic"), "" + (isStatic(x))); } } // interface's super intefaces // isNotLight is needed, for example, for annotations as they have an implicit extended interface: // java.lang.annotations.Annotation { final SNode iface = classifier.value; if (SNodeOperations.isInstanceOf(iface, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101edd46144L, "jetbrains.mps.baseLanguage.structure.Interface"))) { ListSequence.fromList(SLinkOperations.getChildren(iface, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101edd46144L, 0x101eddadad7L, "extendedInterface"))).addSequence(Sequence.fromIterable(Sequence.fromArray(extendz)).where(new IWhereFilter<PsiClassType>() { public boolean accept(PsiClassType it) { return isNotLight(it); } }).select(new ISelector<PsiClassType, SNode>() { public SNode select(PsiClassType it) { return currConverter.resolveClass(it); } })); } } Sequence.fromIterable(Sequence.fromArray(x.getFields())).visitAll(new IVisitor<PsiField>() { public void visit(PsiField it) { if (it instanceof PsiEnumConstant) { // in BL it's not a field, it's a separate thing if (!(SNodeOperations.isInstanceOf(classifier.value, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfc367070a5L, "jetbrains.mps.baseLanguage.structure.EnumClass")))) { return; } SNode cnst = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfc367388b3L, "jetbrains.mps.baseLanguage.structure.EnumConstantDeclaration")); SPropertyOperations.set(cnst, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name"), "" + (it.getName())); if (needToSetId() && SPropertyOperations.getString(cnst, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name")) != null) { ((jetbrains.mps.smodel.SNode) cnst).setId(JavaForeignIdBuilder.computeNodeId(it)); } // TODO maybe we must not touch expressions here (they may be not in the psi index) // <node> ListSequence.fromList(SLinkOperations.getChildren(SNodeOperations.cast(classifier.value, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfc367070a5L, "jetbrains.mps.baseLanguage.structure.EnumClass")), MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfc367070a5L, 0xfc367503acL, "enumConstant"))).addElement(cnst); } // normal field SNode node = currConverter.convertField(it, ourConcept); if (SNodeOperations.isInstanceOf(node, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf93c84351fL, "jetbrains.mps.baseLanguage.structure.StaticFieldDeclaration")) || SNodeOperations.isInstanceOf(node, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca68L, "jetbrains.mps.baseLanguage.structure.FieldDeclaration"))) { ListSequence.fromList(SLinkOperations.getChildren(classifier.value, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101d9d3ca30L, 0x4a9a46de59132803L, "member"))).addElement(SNodeOperations.cast(node, MetaAdapterFactory.getInterfaceConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x112574373bdL, "jetbrains.mps.baseLanguage.structure.ClassifierMember"))); } } }); Sequence.fromIterable(Sequence.fromArray(x.getMethods())).visitAll(new IVisitor<PsiMethod>() { public void visit(PsiMethod it) { SNode node = currConverter.convertMethod(it, ourConcept); if (SNodeOperations.isInstanceOf(node, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b21dL, "jetbrains.mps.baseLanguage.structure.InstanceMethodDeclaration")) || SNodeOperations.isInstanceOf(node, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfbbebabf0aL, "jetbrains.mps.baseLanguage.structure.StaticMethodDeclaration")) || SNodeOperations.isInstanceOf(node, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b204L, "jetbrains.mps.baseLanguage.structure.ConstructorDeclaration"))) { ListSequence.fromList(SLinkOperations.getChildren(classifier.value, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101d9d3ca30L, 0x4a9a46de59132803L, "member"))).addElement(SNodeOperations.cast(node, MetaAdapterFactory.getInterfaceConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x112574373bdL, "jetbrains.mps.baseLanguage.structure.ClassifierMember"))); } } }); ListSequence.fromList(SLinkOperations.getChildren(classifier.value, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101d9d3ca30L, 0x4a9a46de59132803L, "member"))).addSequence(Sequence.fromIterable(Sequence.fromArray(x.getInnerClasses())).select(new ISelector<PsiClass, SNode>() { public SNode select(PsiClass it) { return currConverter.convertClass(it); } })); if (myMps2PsiMapper != null) { myMps2PsiMapper.consume(new Pair<SNode, PsiElement>(classifier.value, x)); } return classifier.value; } public SNode convertField(PsiField x, SAbstractConcept parentConcept) { SNode field; if (isStatic(x) || SConceptOperations.isSubConceptOf(SNodeOperations.asSConcept(parentConcept), MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101edd46144L, "jetbrains.mps.baseLanguage.structure.Interface"))) { field = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf93c84351fL, "jetbrains.mps.baseLanguage.structure.StaticFieldDeclaration")); } else { field = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca68L, "jetbrains.mps.baseLanguage.structure.FieldDeclaration")); SPropertyOperations.set(SNodeOperations.cast(field, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca68L, "jetbrains.mps.baseLanguage.structure.FieldDeclaration")), MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca68L, 0x120c4a208a1L, "isVolatile"), "" + (x.hasModifierProperty(PsiModifier.VOLATILE))); SPropertyOperations.set(SNodeOperations.cast(field, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca68L, "jetbrains.mps.baseLanguage.structure.FieldDeclaration")), MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca68L, 0x776fe644792f90adL, "isTransient"), "" + (x.hasModifierProperty(PsiModifier.TRANSIENT))); } SPropertyOperations.set(field, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name"), "" + (x.getName())); SLinkOperations.setTarget(SNodeOperations.cast(field, MetaAdapterFactory.getInterfaceConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x112574373bdL, "jetbrains.mps.baseLanguage.structure.ClassifierMember")), MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x112670d273fL, 0x112670d886aL, "visibility"), getVisibility(x)); SPropertyOperations.set(field, MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c37a7f6eL, 0x111f9e9f00cL, "isFinal"), "" + (isFinal(x))); SLinkOperations.setTarget(field, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x450368d90ce15bc3L, 0x4ed4d318133c80ceL, "type"), convertType(x.getType())); addAnnotations(x, field); if (needToSetId() && SPropertyOperations.getString(field, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name")) != null) { ((jetbrains.mps.smodel.SNode) field).setId(JavaForeignIdBuilder.computeNodeId(x)); } if (myMps2PsiMapper != null) { myMps2PsiMapper.consume(new Pair<SNode, PsiElement>(field, x)); } return field; } public SNode convertMethod(PsiMethod x, SAbstractConcept parentConcept) { SNode method; if (x.isConstructor()) { method = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b204L, "jetbrains.mps.baseLanguage.structure.ConstructorDeclaration")); } else if (x instanceof PsiAnnotationMethod && SConceptOperations.isSubConceptOf(SNodeOperations.asSConcept(parentConcept), MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x114a69dc80cL, "jetbrains.mps.baseLanguage.structure.Annotation"))) { method = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x114a6a17a27L, "jetbrains.mps.baseLanguage.structure.AnnotationMethodDeclaration")); if (((PsiAnnotationMethod) x).getDefaultValue() != null) { SNode str = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf93d565d10L, "jetbrains.mps.baseLanguage.structure.StringLiteral")); SPropertyOperations.set(str, MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf93d565d10L, 0xf93d565d11L, "value"), "TODO: SUPPORT EXPRESSIONS IN PSI STUBS?"); SLinkOperations.setTarget(SNodeOperations.cast(method, MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x114a6a17a27L, "jetbrains.mps.baseLanguage.structure.AnnotationMethodDeclaration")), MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x114a6a17a27L, 0x505a7bf53e13af48L, "defaultValue"), str); } } else if (!(isStatic(x)) || SConceptOperations.isSubConceptOf(SNodeOperations.asSConcept(parentConcept), MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101edd46144L, "jetbrains.mps.baseLanguage.structure.Interface"))) { method = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b21dL, "jetbrains.mps.baseLanguage.structure.InstanceMethodDeclaration")); } else { method = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfbbebabf0aL, "jetbrains.mps.baseLanguage.structure.StaticMethodDeclaration")); } SPropertyOperations.set(method, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name"), "" + (x.getName())); SLinkOperations.setTarget(SNodeOperations.cast(method, MetaAdapterFactory.getInterfaceConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x112574373bdL, "jetbrains.mps.baseLanguage.structure.ClassifierMember")), MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x112670d273fL, 0x112670d886aL, "visibility"), getVisibility(x)); SPropertyOperations.set(method, MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0x113294bffd2L, "isFinal"), "" + (isFinal(x))); SPropertyOperations.set(method, MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0x3b576cda23612c7aL, "isSynchronized"), "" + (x.hasModifierProperty(PsiModifier.SYNCHRONIZED))); ListSequence.fromList(SLinkOperations.getChildren(method, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0x10f383d6949L, "throwsItem"))).addSequence(Sequence.fromIterable(Sequence.fromArray(x.getThrowsList().getReferencedTypes())).where(new IWhereFilter<PsiClassType>() { public boolean accept(PsiClassType it) { return isNotLight(it); } }).select(new ISelector<PsiClassType, SNode>() { public SNode select(PsiClassType it) { SNode typ = resolveClass(it); return typ; } })); final ASTConverter currConverter = addTypeParams(x, method); SLinkOperations.setTarget(method, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0xf8cc56b1fdL, "returnType"), currConverter.convertType(x.getReturnType())); ListSequence.fromList(SLinkOperations.getChildren(method, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0xf8cc56b1feL, "parameter"))).addSequence(Sequence.fromIterable(Sequence.fromArray(x.getParameterList().getParameters())).select(new ISelector<PsiParameter, SNode>() { public SNode select(PsiParameter it) { SNode param = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c77f1e94L, "jetbrains.mps.baseLanguage.structure.ParameterDeclaration")); SPropertyOperations.set(param, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name"), "" + (it.getName())); SLinkOperations.setTarget(param, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x450368d90ce15bc3L, 0x4ed4d318133c80ceL, "type"), currConverter.convertType(it.getType())); SPropertyOperations.set(param, MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c37a7f6eL, 0x111f9e9f00cL, "isFinal"), "" + (isFinal(it))); currConverter.addAnnotations(it, param); return param; } })); // not strictly necessary if (1 > 0) { SLinkOperations.setTarget(method, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0xf8cc56b1ffL, "body"), SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x4975dc2bdcfa0c49L, "jetbrains.mps.baseLanguage.structure.StubStatementList"))); } else { SLinkOperations.setTarget(method, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0xf8cc56b1ffL, "body"), SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b200L, "jetbrains.mps.baseLanguage.structure.StatementList"))); } if (needToSetId()) { SNodeId.Foreign nodeId = JavaForeignIdBuilder.computeNodeId(x); if (nodeId != null) { ((jetbrains.mps.smodel.SNode) method).setId(nodeId); } } if (myMps2PsiMapper != null) { myMps2PsiMapper.consume(new Pair<SNode, PsiElement>(method, x)); } return method; } public SNode convertType(PsiType x) { if (x == null) { return null; } if (x instanceof PsiPrimitiveType) { PsiPrimitiveType t = (PsiPrimitiveType) x; if (x.equals(PsiPrimitiveType.BYTE)) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf940d5b617L, "jetbrains.mps.baseLanguage.structure.ByteType")); } else if (x.equals(PsiPrimitiveType.INT)) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf940d22479L, "jetbrains.mps.baseLanguage.structure.IntegerType")); } else if (x.equals(PsiPrimitiveType.SHORT)) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf940cc380dL, "jetbrains.mps.baseLanguage.structure.ShortType")); } else if (x.equals(PsiPrimitiveType.LONG)) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc67c7f3L, "jetbrains.mps.baseLanguage.structure.LongType")); } else if (x.equals(PsiPrimitiveType.SHORT)) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf940cc380dL, "jetbrains.mps.baseLanguage.structure.ShortType")); } else if (x.equals(PsiPrimitiveType.FLOAT)) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf940d327fdL, "jetbrains.mps.baseLanguage.structure.FloatType")); } else if (x.equals(PsiPrimitiveType.DOUBLE)) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf940d451a6L, "jetbrains.mps.baseLanguage.structure.DoubleType")); } else if (x.equals(PsiPrimitiveType.CHAR)) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf940d4f826L, "jetbrains.mps.baseLanguage.structure.CharType")); } else if (x.equals(PsiPrimitiveType.BOOLEAN)) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf940d6513eL, "jetbrains.mps.baseLanguage.structure.BooleanType")); } else if (x.equals(PsiPrimitiveType.VOID)) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc6bf96dL, "jetbrains.mps.baseLanguage.structure.VoidType")); } else { return null; } } else if (x instanceof PsiClassType) { PsiClassType t = (PsiClassType) x; // ask state if it's a type variable SNode typVarRef = myState.resolveTypeVar(t.getClassName()); if (typVarRef != null) { return typVarRef; } SNode typ = resolveClass(t); return typ; } else if (x instanceof PsiArrayType) { SNode arrType = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf940d819f7L, "jetbrains.mps.baseLanguage.structure.ArrayType")); SLinkOperations.setTarget(arrType, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf940d819f7L, 0xf940d819f8L, "componentType"), convertType(((PsiArrayType) x).getComponentType())); return arrType; } else if (x instanceof PsiWildcardType) { PsiWildcardType t = (PsiWildcardType) x; if (!(t.isBounded())) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x110dae5f4a3L, "jetbrains.mps.baseLanguage.structure.WildCardType")); } SNode bound = convertType(t.getBound()); if (t.isExtends()) { return _quotation_createNode_rbndtb_a0a6a2c0t(bound); } else { return _quotation_createNode_rbndtb_a0a0g0c2a91(bound); } } else { return null; } } public SNode convertTypeParameter(PsiTypeParameter x) { SNode typeVar = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x1024639ed74L, "jetbrains.mps.baseLanguage.structure.TypeVariableDeclaration")); SPropertyOperations.set(typeVar, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name"), "" + (x.getName())); if (x.getExtendsListTypes().length > 0) { Iterable<PsiClassType> extend = Sequence.fromArray(x.getExtendsListTypes()); if (isNotLight(Sequence.fromIterable(extend).first())) { SLinkOperations.setTarget(typeVar, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x1024639ed74L, 0x11ae375bda0L, "bound"), resolveClass(Sequence.fromIterable(extend).first())); } ListSequence.fromList(SLinkOperations.getChildren(typeVar, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x1024639ed74L, 0x11ae913a476L, "auxBounds"))).addSequence(Sequence.fromIterable(extend).skip(1).where(new IWhereFilter<PsiClassType>() { public boolean accept(PsiClassType it) { return isNotLight(it); } }).select(new ISelector<PsiClassType, SNode>() { public SNode select(PsiClassType it) { return resolveClass(it); } })); } return typeVar; } public SNode convertExpression(PsiExpression exp) { if (exp instanceof PsiLiteralExpression) { Object value = ((PsiLiteralExpression) exp).getValue(); if (value instanceof String) { return _quotation_createNode_rbndtb_a0a1a0a12(value.toString()); } else if (value instanceof Integer) { SNode c = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc59b314L, "jetbrains.mps.baseLanguage.structure.IntegerConstant")); SPropertyOperations.set(c, MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc59b314L, 0xf8cc59b315L, "value"), "" + (((Integer) value).intValue())); return c; } } return null; } public SNode resolveClass(PsiClassType t) { assert isNotLight(t) : "resolveClass() must not be applied to LightElements"; SNode clsType = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, "jetbrains.mps.baseLanguage.structure.ClassifierType")); String resolveInfo; if (t instanceof PsiClassReferenceType) { resolveInfo = JavaSourceUtil.getReferenceText(((PsiClassReferenceType) t).getReference()); } else { resolveInfo = t.getClassName(); } clsType.setReference(MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, 0x101de490babL, "classifier"), new DynamicReference(MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, 0x101de490babL, "classifier"), clsType, null, resolveInfo)); ListSequence.fromList(SLinkOperations.getChildren(clsType, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, 0x102419671abL, "parameter"))).addSequence(Sequence.fromIterable(Sequence.fromArray(t.getParameters())).select(new ISelector<PsiType, SNode>() { public SNode select(PsiType it) { return convertType(it); } })); return clsType; } public SNode resolveAnnotation(PsiAnnotation a) { String fqName = a.getQualifiedName(); // TODO q: handle this case? create dynamic reference? if (fqName == null) { return null; } SNode anno = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x114a6b4ccabL, "jetbrains.mps.baseLanguage.structure.AnnotationInstance")); anno.setReference(MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x114a6b4ccabL, 0x114a6b85d40L, "annotation"), new DynamicReference(MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x114a6b4ccabL, 0x114a6b85d40L, "annotation"), anno, null, fqName)); return anno; } private boolean isNotLight(PsiClassType t) { return !((t instanceof PsiClassReferenceType && ((PsiClassReferenceType) t).getReference() instanceof LightElement)); } private SNode getVisibility(PsiModifierListOwner x) { if (x.hasModifierProperty(PsiModifier.PUBLIC)) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x10af9581ff1L, "jetbrains.mps.baseLanguage.structure.PublicVisibility")); } else if (x.hasModifierProperty(PsiModifier.PROTECTED)) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x10af958b686L, "jetbrains.mps.baseLanguage.structure.ProtectedVisibility")); } else if (x.hasModifierProperty(PsiModifier.PRIVATE)) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x10af9586f0cL, "jetbrains.mps.baseLanguage.structure.PrivateVisibility")); } else { return null; } } private boolean isFinal(PsiModifierListOwner x) { return x.hasModifierProperty(PsiModifier.FINAL); } public boolean isStatic(PsiModifierListOwner x) { return x.hasModifierProperty(PsiModifier.STATIC); } private ASTConverter addTypeParams(PsiTypeParameterListOwner from, SNode to) { Iterable<SNode> typeVarDecls = Sequence.fromIterable(Sequence.fromArray(from.getTypeParameters())).select(new ISelector<PsiTypeParameter, SNode>() { public SNode select(PsiTypeParameter it) { return convertTypeParameter(it); } }); ListSequence.fromList(SLinkOperations.getChildren(to, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x102463b447aL, 0x102463bb98eL, "typeVariableDeclaration"))).addSequence(Sequence.fromIterable(typeVarDecls)); return withTypeVarDecls(typeVarDecls); } private void addAnnotations(PsiModifierListOwner from, SNode to) { ListSequence.fromList(SLinkOperations.getChildren(to, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x114a6be947aL, 0x114a6beb0bdL, "annotation"))).addSequence(Sequence.fromIterable(Sequence.fromArray(from.getModifierList().getAnnotations())).select(new ISelector<PsiAnnotation, SNode>() { public SNode select(PsiAnnotation it) { PsiAnnotation psiAnno = it; SNode anno = resolveAnnotation(psiAnno); if ((anno == null)) { return null; } ListSequence.fromList(SLinkOperations.getChildren(anno, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x114a6b4ccabL, 0x114a71c697fL, "value"))).addSequence(Sequence.fromIterable(Sequence.fromArray(psiAnno.getParameterList().getAttributes())).select(new ISelector<PsiNameValuePair, SNode>() { public SNode select(PsiNameValuePair it) { SNode annoParam = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x114a71b1af4L, "jetbrains.mps.baseLanguage.structure.AnnotationInstanceValue")); String paramName = it.getName(); annoParam.setReference(MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x114a71b1af4L, 0x114a71b44e3L, "key"), new DynamicReference(MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x114a71b1af4L, 0x114a71b44e3L, "key"), annoParam, null, paramName)); return annoParam; } })); return anno; } })); } public static class State { private ASTConverter.State parentState; private Map<String, SNode> myTypeVars = MapSequence.fromMap(new HashMap<String, SNode>()); public State() { } public State(ASTConverter.State base, Set<String> typeVarNames) { parentState = base; SetSequence.fromSet(typeVarNames).visitAll(new IVisitor<String>() { public void visit(String it) { MapSequence.fromMap(myTypeVars).put(it, null); } }); } public State(ASTConverter.State base, Iterable<SNode> typeVars) { parentState = base; for (SNode tv : Sequence.fromIterable(typeVars)) { MapSequence.fromMap(myTypeVars).put(SPropertyOperations.getString(tv, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name")), tv); } } protected SNode resolveTypeVar(String name) { if (myTypeVars == null) { return (parentState == null ? null : parentState.resolveTypeVar(name)); } if (myTypeVars == null || !(MapSequence.fromMap(myTypeVars).containsKey(name))) { // Either type var map is not initialized, this means that this State object was created with something else: // e.g. with id prefix. // Or type var is not part of this state return (parentState == null ? null : parentState.resolveTypeVar(name)); } else { // we have this var name SNode typeVar = MapSequence.fromMap(myTypeVars).get(name); SNode typeVarRef = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x102467229d8L, "jetbrains.mps.baseLanguage.structure.TypeVariableReference")); SReference ref; // let's see if var has been parsed already if (typeVar != null) { // FIXME static reference doesn't work here for some reason // <node> ref = new DynamicReference(MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x102467229d8L, 0x1024673a581L, "typeVariableDeclaration"), typeVarRef, null, name); } else { ref = new DynamicReference(MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x102467229d8L, 0x1024673a581L, "typeVariableDeclaration"), typeVarRef, null, name); } typeVarRef.setReference(ref.getLink(), ref); return typeVarRef; } } } public static String typeReferenceId(PsiTypeElement psiTypeElem) { // FIXME a) check it's good for node id, b) try to be the same as binary stubs String str = null; // FIXME doesn't work properly with a very rare case a.b<X,Y>.c.d<V,W> str = psiTypeElem.getText(); int firstBracket = str.indexOf("<"); if (firstBracket > 0) { str = str.substring(0, firstBracket); } PsiType psiType = psiTypeElem.getType(); if (psiType instanceof PsiArrayType && !(str.endsWith("[]"))) { str = str + "[]"; } return str; } private static boolean isNotEmptyString(String str) { return str != null && str.length() > 0; } private static SNode _quotation_createNode_rbndtb_a0a6a2c0t(Object parameter_1) { PersistenceFacade facade = PersistenceFacade.getInstance(); SNode quotedNode_2 = null; SNode quotedNode_3 = null; quotedNode_2 = SModelUtil_new.instantiateConceptDeclaration(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x110daeaa84aL, "jetbrains.mps.baseLanguage.structure.UpperBoundType"), null, null, false); quotedNode_3 = (SNode) parameter_1; if (quotedNode_3 != null) { quotedNode_2.addChild(MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x110daeaa84aL, 0x110daeaa84bL, "bound"), HUtil.copyIfNecessary(quotedNode_3)); } return quotedNode_2; } private static SNode _quotation_createNode_rbndtb_a0a0g0c2a91(Object parameter_1) { PersistenceFacade facade = PersistenceFacade.getInstance(); SNode quotedNode_2 = null; SNode quotedNode_3 = null; quotedNode_2 = SModelUtil_new.instantiateConceptDeclaration(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x110dae9d53dL, "jetbrains.mps.baseLanguage.structure.LowerBoundType"), null, null, false); quotedNode_3 = (SNode) parameter_1; if (quotedNode_3 != null) { quotedNode_2.addChild(MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x110dae9d53dL, 0x110dae9f25bL, "bound"), HUtil.copyIfNecessary(quotedNode_3)); } return quotedNode_2; } private static SNode _quotation_createNode_rbndtb_a0a1a0a12(Object parameter_1) { PersistenceFacade facade = PersistenceFacade.getInstance(); SNode quotedNode_2 = null; quotedNode_2 = SModelUtil_new.instantiateConceptDeclaration(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf93d565d10L, "jetbrains.mps.baseLanguage.structure.StringLiteral"), null, null, false); SNodeAccessUtil.setProperty(quotedNode_2, MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf93d565d10L, 0xf93d565d11L, "value"), (String) parameter_1); return quotedNode_2; } }