public void test_childrenByLinkDeclarationSpecialized() throws Exception { this.addNodeById("8758390115029078425"); this.addNodeById("5815925154349132136"); this.addNodeById("2166349271756548530"); TestUtilities.assertEquals( Sequence.fromArray( new SNode[] { SNodeOperations.cast( this.getNodeById("2600026384779198859"), "jetbrains.mps.lang.smodelTests.structure.GrandChild") }), SNodeOperations.getChildren( SNodeOperations.cast( this.getNodeById("8758390115029078430"), "jetbrains.mps.lang.smodelTests.structure.ChildSubConcept"), SLinkOperations.findLinkDeclaration( "jetbrains.mps.lang.smodelTests.structure.ChildSubConcept", "specializedGranChild_0_1"))); TestUtilities.assertEquals( Sequence.fromArray( new SNode[] { SNodeOperations.cast( this.getNodeById("2600026384779198859"), "jetbrains.mps.lang.smodelTests.structure.GrandChild") }), SNodeOperations.getChildren( SNodeOperations.cast( this.getNodeById("8758390115029078430"), "jetbrains.mps.lang.smodelTests.structure.ChildSubConcept"), SLinkOperations.findLinkDeclaration( "jetbrains.mps.lang.smodelTests.structure.Child", "grandChild_0_1"))); }
public Iterable<ITarget.Name> after() { return Sequence.fromArray( new ITarget.Name[] { new ITarget.Name("jetbrains.mps.baseLanguage.JavaCompile.compile"), new ITarget.Name("jetbrains.mps.baseLanguage.JavaCompile.auxCompile") }); }
public Iterable<IFacet.Name> required() { return Sequence.fromArray( new IFacet.Name[] { new IFacet.Name("jetbrains.mps.baseLanguage.JavaCompile"), new IFacet.Name("jetbrains.mps.lang.core.Make") }); }
public Iterable<ITarget.Name> before() { return Sequence.fromArray( new ITarget.Name[] { new ITarget.Name("jetbrains.mps.lang.core.Make.reconcile"), new ITarget.Name("jetbrains.mps.lang.core.Make.make") }); }
public void test_childContainingRoles() throws Exception { this.addNodeById("8758390115029078425"); this.addNodeById("5815925154349132136"); this.addNodeById("2166349271756548530"); TestUtilities.assertEquals( Sequence.fromArray( new String[] { SPropertyOperations.getString( SLinkOperations.findLinkDeclaration( "jetbrains.mps.lang.smodelTests.structure.Root", "child_1_n"), "role"), SPropertyOperations.getString( SLinkOperations.findLinkDeclaration( "jetbrains.mps.lang.smodelTests.structure.Root", "childSubConcept_0_n"), "role") }), ListSequence.fromList( SNodeOperations.getChildren( SNodeOperations.cast( this.getNodeById("8758390115029078426"), "jetbrains.mps.lang.smodelTests.structure.Root"))) .select( new ISelector<SNode, String>() { public String select(SNode it) { return SNodeOperations.getContainingLinkRole(it); } })); }
public void test_roles() throws Exception { this.addNodeById("2906110183022219846"); this.addNodeById("2906110183022219807"); this.addNodeById("2906110183022219843"); this.addNodeById("2906110183022354865"); this.addNodeById("2906110183022432276"); TestUtilities.assertEquals( Sequence.fromArray( new String[] { SPropertyOperations.getString( SLinkOperations.findLinkDeclaration( "jetbrains.mps.lang.smodelTests.structure.ReferenceContainer", "root"), "role"), SPropertyOperations.getString( SLinkOperations.findLinkDeclaration( "jetbrains.mps.lang.smodelTests.structure.ReferenceContainer", "leftChild"), "role"), SPropertyOperations.getString( SLinkOperations.findLinkDeclaration( "jetbrains.mps.lang.smodelTests.structure.ReferenceContainer", "rightChild"), "role") }), Sequence.fromIterable( SNodeOperations.getReferences( SNodeOperations.cast( this.getNodeById("2906110183022219844"), "jetbrains.mps.lang.smodelTests.structure.ReferenceContainer"))) .select( new ISelector<SReference, String>() { public String select(SReference it) { return SLinkOperations.getRole(it); } })); }
public void test_target() throws Exception { this.addNodeById("2906110183022219846"); this.addNodeById("2906110183022219807"); this.addNodeById("2906110183022219843"); this.addNodeById("2906110183022354865"); this.addNodeById("2906110183022432276"); TestUtilities.assertEquals( Sequence.fromArray( new SNode[] { SNodeOperations.cast( this.getNodeById("2906110183022219847"), "jetbrains.mps.lang.smodelTests.structure.Root"), SNodeOperations.cast( this.getNodeById("2906110183022219848"), "jetbrains.mps.lang.smodelTests.structure.Child"), SNodeOperations.cast( this.getNodeById("2906110183022311236"), "jetbrains.mps.lang.smodelTests.structure.ChildSubConcept") }), Sequence.fromIterable( SNodeOperations.getReferences( SNodeOperations.cast( this.getNodeById("2906110183022219844"), "jetbrains.mps.lang.smodelTests.structure.ReferenceContainer"))) .select( new ISelector<SReference, SNode>() { public SNode select(SReference it) { return SLinkOperations.getTargetNode(it); } })); }
public Iterable<IFacet.Name> required() { return Sequence.fromArray( new IFacet.Name[] { new IFacet.Name("jetbrains.mps.lang.core.Generate"), new IFacet.Name("jetbrains.mps.lang.core.Make") }); }
@Nullable public static ITestNodeWrapper tryToWrap(@NotNull SNode node) { for (TestNodeWrapperFactory factory : Sequence.fromIterable(Sequence.fromArray(TestNodeWrapperFactory.values()))) { if (factory.canWrap(node)) { return factory.wrap(node); } } return null; }
private void addTypeParams(PsiTypeParameterListOwner from, SNode to) { ListSequence.fromList(SLinkOperations.getTargets(to, "typeVariableDeclaration", true)) .addSequence( Sequence.fromIterable(Sequence.fromArray(from.getTypeParameters())) .select( new ISelector<PsiTypeParameter, SNode>() { public SNode select(PsiTypeParameter it) { return convertTypeParameter(it); } })); }
public void test_forSpecializedLink() throws Exception { this.addNodeById("2906110183022219846"); this.addNodeById("2906110183022219807"); this.addNodeById("2906110183022219843"); this.addNodeById("2906110183022354865"); this.addNodeById("2906110183022432276"); TestUtilities.assertEquals( Sequence.fromArray( new SNode[] { SNodeOperations.cast( this.getNodeById("2906110183022311236"), "jetbrains.mps.lang.smodelTests.structure.ChildSubConcept") }), Sequence.fromIterable( SNodeOperations.getReferences( SNodeOperations.cast( this.getNodeById("2906110183022354866"), "jetbrains.mps.lang.smodelTests.structure.ReferenceContainerSubConcept"))) .where( new IWhereFilter<SReference>() { public boolean accept(SReference it) { return SLinkOperations.findLinkDeclaration(it) == SLinkOperations.findLinkDeclaration( "jetbrains.mps.lang.smodelTests.structure.ReferenceContainer", "rightChild"); } }) .select( new ISelector<SReference, SNode>() { public SNode select(SReference it) { return SLinkOperations.getTargetNode(it); } })); Assert.assertTrue( Sequence.fromIterable( SNodeOperations.getReferences( SNodeOperations.cast( this.getNodeById("2906110183022354866"), "jetbrains.mps.lang.smodelTests.structure.ReferenceContainerSubConcept"))) .where( new IWhereFilter<SReference>() { public boolean accept(SReference it) { return SLinkOperations.findLinkDeclaration(it) == SLinkOperations.findLinkDeclaration( "jetbrains.mps.lang.smodelTests.structure.ReferenceContainerSubConcept", "specializedRightChild"); } }) .isEmpty()); }
public SimpleDiffRequest( @NotNull Project project, @Nullable SModel[] models, @NotNull String[] contentTitles) { super(project); myContentTitles = contentTitles; if (models != null) { myContents = Sequence.fromIterable(Sequence.fromArray(models)) .select( new ISelector<SModel, SimpleContent>() { public SimpleContent select(SModel m) { return new SimpleContent( ModelPersistence.modelToString(m), MPSFileTypeFactory.MODEL_FILE_TYPE); } }) .toGenericArray(SimpleContent.class); } }
private static Iterable<SNode> getWrappedConcepts( final _FunctionTypes._return_P1_E0<? extends Boolean, ? super TestNodeWrapperFactory> condition) { return Sequence.fromIterable(Sequence.fromArray(TestNodeWrapperFactory.values())) .where( new IWhereFilter<TestNodeWrapperFactory>() { public boolean accept(TestNodeWrapperFactory it) { return condition.invoke(it); } }) .select( new ISelector<TestNodeWrapperFactory, SNode>() { public SNode select(TestNodeWrapperFactory it) { return it.getWrappedConcept(); } }) .distinct(); }
@NotNull protected static ConfigurationFactory findFactory( ConfigurationType configurationType, @NonNls String configurationFactoryClassName) { for (ConfigurationFactory factory : Sequence.fromIterable(Sequence.fromArray(configurationType.getConfigurationFactories()))) { if (factory.getClass().getName().equals(configurationFactoryClassName)) { return factory; } } if (LOG.isEnabledFor(Priority.WARN)) { LOG.warn( "Cound not find configuration factory for " + configurationFactoryClassName + " in type " + configurationType.getDisplayName() + "."); } return configurationType.getConfigurationFactories()[0]; }
private void addAnnotations(PsiModifierListOwner from, SNode to) { ListSequence.fromList(SLinkOperations.getTargets(to, "annotation", true)) .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.getTargets(anno, "value", true)) .addSequence( Sequence.fromIterable( Sequence.fromArray( psiAnno.getParameterList().getAttributes())) .select( new ISelector<PsiNameValuePair, SNode>() { public SNode select(PsiNameValuePair it) { SNode annoParam = SConceptOperations.createNewNode( "jetbrains.mps.baseLanguage.structure.AnnotationInstanceValue", null); String paramName = it.getName(); annoParam.setReference( "key", new DynamicReference( "key", annoParam, null, paramName)); return annoParam; } })); return anno; } })); }
private void addModelsForDir( PsiDirectory sourceRoot, PsiDirectory dir, Map<PsiJavaStubDataSource, SModel> resultMap) { if (Sequence.fromIterable(Sequence.fromArray(dir.getFiles())) .ofType(PsiJavaFile.class) .isNotEmpty()) { SModelReference modelRef = makeModelReference(sourceRoot, dir); SModel model = SModelRepository.getInstance().getModelDescriptor(modelRef); if (model == null) { model = makeModelDescriptor(modelRef, dir); } assert model instanceof PsiJavaStubModelDescriptor; PsiJavaStubDataSource dataSource = ((PsiJavaStubModelDescriptor) model).getSource(); MapSequence.fromMap(resultMap).put(dataSource, model); } for (PsiDirectory subDir : dir.getSubdirectories()) { addModelsForDir(sourceRoot, subDir, resultMap); } }
public void test_childrenByLinkDeclaration() throws Exception { this.addNodeById("8758390115029078425"); this.addNodeById("5815925154349132136"); this.addNodeById("2166349271756548530"); List<SNode> singleChild = SNodeOperations.getChildren( SNodeOperations.cast( this.getNodeById("8758390115029078426"), "jetbrains.mps.lang.smodelTests.structure.Root"), SLinkOperations.findLinkDeclaration( "jetbrains.mps.lang.smodelTests.structure.Root", "child_1_n")); Assert.assertEquals(1, ListSequence.fromList(singleChild).count()); Assert.assertEquals( SNodeOperations.cast( this.getNodeById("8758390115029078427"), "jetbrains.mps.lang.smodelTests.structure.Child"), ListSequence.fromList(singleChild).first()); List<SNode> twins = SNodeOperations.getChildren( SNodeOperations.cast( this.getNodeById("5815925154349132137"), "jetbrains.mps.lang.smodelTests.structure.Root"), SLinkOperations.findLinkDeclaration( "jetbrains.mps.lang.smodelTests.structure.Root", "child_1_n")); TestUtilities.assertEquals( Sequence.fromArray( new SNode[] { SNodeOperations.cast( this.getNodeById("5815925154349132142"), "jetbrains.mps.lang.smodelTests.structure.Child"), SNodeOperations.cast( this.getNodeById("5815925154349132138"), "jetbrains.mps.lang.smodelTests.structure.Child") }), twins); }
public SNode convertTypeParameter(PsiTypeParameter x) { SNode typeVar = SConceptOperations.createNewNode( "jetbrains.mps.baseLanguage.structure.TypeVariableDeclaration", null); SPropertyOperations.set(typeVar, "name", x.getName()); if (x.getExtendsListTypes().length > 0) { Iterable<PsiClassType> extend = Sequence.fromArray(x.getExtendsListTypes()); SLinkOperations.setTarget( typeVar, "bound", resolveClass(Sequence.fromIterable(extend).first()), true); ListSequence.fromList(SLinkOperations.getTargets(typeVar, "auxBounds", true)) .addSequence( Sequence.fromIterable(extend) .skip(1) .select( new ISelector<PsiClassType, SNode>() { public SNode select(PsiClassType it) { return resolveClass(it); } })); } return typeVar; }
public SNode convertClass(PsiClass x) { final Wrappers._T<SNode> classifier = new Wrappers._T<SNode>(); if (x.isAnnotationType()) { classifier.value = SConceptOperations.createNewNode("jetbrains.mps.baseLanguage.structure.Annotation", null); } else if (x.isEnum()) { classifier.value = SConceptOperations.createNewNode("jetbrains.mps.baseLanguage.structure.EnumClass", null); } else if (x.isInterface()) { classifier.value = SConceptOperations.createNewNode("jetbrains.mps.baseLanguage.structure.Interface", null); } else { classifier.value = SConceptOperations.createNewNode( "jetbrains.mps.baseLanguage.structure.ClassConcept", null); } final SNode ourConcept = SNodeOperations.getConceptDeclaration(classifier.value); SPropertyOperations.set(classifier.value, "name", x.getName()); SLinkOperations.setTarget(classifier.value, "visibility", getVisibility(x), true); SConceptPropertyOperations.setBoolean(classifier.value, "final", isFinal(x)); addTypeParams(x, classifier.value); if (isNotEmpty_rbndtb_a0m0a(SPropertyOperations.getString(classifier.value, "name"))) { String id = SNodeId.Foreign.ID_PREFIX + SPropertyOperations.getString(classifier.value, "name"); classifier.value.setId(new SNodeId.Foreign(id)); } Sequence.fromIterable(Sequence.fromArray(x.getFields())) .visitAll( new IVisitor<PsiField>() { public void visit(PsiField it) { SNode node = convertField(it, ourConcept); if (SNodeOperations.isInstanceOf( node, "jetbrains.mps.baseLanguage.structure.StaticFieldDeclaration")) { ListSequence.fromList( SLinkOperations.getTargets(classifier.value, "staticField", true)) .addElement( SNodeOperations.cast( node, "jetbrains.mps.baseLanguage.structure.StaticFieldDeclaration")); } else if (SNodeOperations.isInstanceOf( node, "jetbrains.mps.baseLanguage.structure.FieldDeclaration")) { ListSequence.fromList( SLinkOperations.getTargets( SNodeOperations.cast( classifier.value, "jetbrains.mps.baseLanguage.structure.ClassConcept"), "field", true)) .addElement( SNodeOperations.cast( node, "jetbrains.mps.baseLanguage.structure.FieldDeclaration")); } } }); Sequence.fromIterable(Sequence.fromArray(x.getMethods())) .visitAll( new IVisitor<PsiMethod>() { public void visit(PsiMethod it) { SNode node = convertMethod(it, ourConcept); if (SNodeOperations.isInstanceOf( node, "jetbrains.mps.baseLanguage.structure.InstanceMethodDeclaration")) { ListSequence.fromList( SLinkOperations.getTargets(classifier.value, "method", true)) .addElement( SNodeOperations.cast( node, "jetbrains.mps.baseLanguage.structure.InstanceMethodDeclaration")); } else if (SNodeOperations.isInstanceOf( node, "jetbrains.mps.baseLanguage.structure.StaticMethodDeclaration")) { ListSequence.fromList( SLinkOperations.getTargets( SNodeOperations.cast( classifier.value, "jetbrains.mps.baseLanguage.structure.ClassConcept"), "staticMethod", true)) .addElement( SNodeOperations.cast( node, "jetbrains.mps.baseLanguage.structure.StaticMethodDeclaration")); } else if (SNodeOperations.isInstanceOf( node, "jetbrains.mps.baseLanguage.structure.ConstructorDeclaration")) { ListSequence.fromList( SLinkOperations.getTargets( SNodeOperations.cast( classifier.value, "jetbrains.mps.baseLanguage.structure.ClassConcept"), "constructor", true)) .addElement( SNodeOperations.cast( node, "jetbrains.mps.baseLanguage.structure.ConstructorDeclaration")); } } }); return classifier.value; }
public SNode convertMethod(PsiMethod x, SNode parentConcept) { SNode method; if (x.isConstructor()) { method = SConceptOperations.createNewNode( "jetbrains.mps.baseLanguage.structure.ConstructorDeclaration", null); } else if (x instanceof PsiAnnotationMethod && SConceptOperations.isSubConceptOf( parentConcept, "jetbrains.mps.baseLanguage.structure.Annotation")) { method = SConceptOperations.createNewNode( "jetbrains.mps.baseLanguage.structure.AnnotationMethodDeclaration", null); if (((PsiAnnotationMethod) x).getDefaultValue() != null) { SNode str = SConceptOperations.createNewNode( "jetbrains.mps.baseLanguage.structure.StringLiteral", null); SPropertyOperations.set(str, "value", "TODO: SUPPORT EXPRESSIONS IN PSI STUBS?"); SLinkOperations.setTarget( SNodeOperations.cast( method, "jetbrains.mps.baseLanguage.structure.AnnotationMethodDeclaration"), "defaultValue", str, true); } } else if (!(isStatic(x)) || SConceptOperations.isSubConceptOf( parentConcept, "jetbrains.mps.baseLanguage.structure.Interface")) { method = SConceptOperations.createNewNode( "jetbrains.mps.baseLanguage.structure.InstanceMethodDeclaration", null); } else { method = SConceptOperations.createNewNode( "jetbrains.mps.baseLanguage.structure.StaticMethodDeclaration", null); } SPropertyOperations.set(method, "name", x.getName()); SLinkOperations.setTarget( SNodeOperations.cast(method, "jetbrains.mps.baseLanguage.structure.ClassifierMember"), "visibility", getVisibility(x), true); SPropertyOperations.set(method, "isFinal", "" + (isFinal(x))); SPropertyOperations.set( method, "isSynchronized", "" + (x.hasModifierProperty(PsiModifier.SYNCHRONIZED))); SLinkOperations.setTarget(method, "returnType", convertType(x.getReturnType()), true); ListSequence.fromList(SLinkOperations.getTargets(method, "parameter", true)) .addSequence( Sequence.fromIterable(Sequence.fromArray(x.getParameterList().getParameters())) .select( new ISelector<PsiParameter, SNode>() { public SNode select(PsiParameter it) { SNode param = SConceptOperations.createNewNode( "jetbrains.mps.baseLanguage.structure.ParameterDeclaration", null); SPropertyOperations.set(param, "name", it.getName()); SLinkOperations.setTarget(param, "type", convertType(it.getType()), true); SPropertyOperations.set(param, "isFinal", "" + (isFinal(it))); addAnnotations(it, param); return param; } })); ListSequence.fromList(SLinkOperations.getTargets(method, "throwsItem", true)) .addSequence( Sequence.fromIterable(Sequence.fromArray(x.getThrowsList().getReferencedTypes())) .select( new ISelector<PsiClassType, SNode>() { public SNode select(PsiClassType it) { SNode typ = resolveClass(it); return typ; } })); addTypeParams(x, method); // not strictly necessary if (x.getBody() != null) { SLinkOperations.setTarget( method, "body", SConceptOperations.createNewNode( "jetbrains.mps.baseLanguage.structure.StubStatementList", null), true); } else { SLinkOperations.setTarget( method, "body", SConceptOperations.createNewNode( "jetbrains.mps.baseLanguage.structure.StatementList", null), true); } return method; }
public Iterable<IFacet.Name> required() { return Sequence.fromArray(new IFacet.Name[] {new IFacet.Name("Maker_")}); }
public Iterable<ITarget.Name> after() { return Sequence.fromArray( new ITarget.Name[] {new ITarget.Name("jetbrains.mps.lang.core.Generate.generate")}); }
public Iterable<Class<? extends IResource>> expectedInput() { return Sequence.fromArray(EXPECTED_INPUT); }
public Iterable<IFacet.Name> extended() { return Sequence.fromArray( new IFacet.Name[] {new IFacet.Name("jetbrains.mps.make.facets.Make")}); }
public List<String> getPropertyValues( SNode node, IScope scope, IOperationContext operationContext, EditorContext editorContext) { return Sequence.fromIterable(Sequence.fromArray(XmlNameUtil.getDefaultEntities())) .toListSequence(); }
public Iterable<ITarget.Name> before() { return Sequence.fromArray(new ITarget.Name[] {new ITarget.Name("Maker_.Make")}); }