@Override public void execute(@NotNull String pattern) { SNodeOperations.insertPrevSiblingChild( _context.getNode(), SNodeFactoryOperations.createNewNode( SNodeFactoryOperations.asInstanceConcept( MetaAdapterFactory.getConcept( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x58e59ea713f79f27L, "jetbrains.mps.samples.Kaja.structure.Drop")), null)); }
@Override public void execute(@NotNull String pattern) { SNode inserted = SNodeOperations.insertPrevSiblingChild( _context.getNode(), SNodeFactoryOperations.createNewNode( SNodeFactoryOperations.asInstanceConcept( MetaAdapterFactory.getConcept( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x3cfcda239f1a1049L, "jetbrains.mps.samples.Kaja.structure.Require")), null)); _context.getEditorContext().selectWRTFocusPolicy(inserted); }
public void processCycles() { List<SNode> modules = new ArrayList<SNode>(); ListSequence.fromList(modules) .addSequence( ListSequence.fromList(SLinkOperations.getTargets(project, "parts", true)) .where( new IWhereFilter<SNode>() { public boolean accept(SNode it) { return SNodeOperations.isInstanceOf( it, "jetbrains.mps.build.workflow.structure.BwfJavaModule"); } }) .select( new ISelector<SNode, SNode>() { public SNode select(SNode it) { return SNodeOperations.cast( it, "jetbrains.mps.build.workflow.structure.BwfJavaModule"); } })); for (SNode m : ListSequence.fromList(modules)) { optimizeDependencies(m); } for (SNode jm : modules) { CycleHelper.Module module = new CycleHelper.Module(jm); map.put(jm, module); if (isEmpty_yc0kju_a0c0d0f(SPropertyOperations.getString(jm, "outputFolder"))) { genContext.showErrorMessage(jm, "empty output path"); } else if (SPropertyOperations.getString(jm, "outputFolder").endsWith("/") || SPropertyOperations.getString(jm, "outputFolder").endsWith("\\")) { genContext.showErrorMessage(jm, "output path shouldn't end with slash"); } } Graph<CycleHelper.Module> graph = new Graph(); for (CycleHelper.Module module : map.values()) { graph.add(module); } List<List<CycleHelper.Module>> cycles = Graphs.findStronglyConnectedComponents(graph); Collections.reverse(cycles); List<SNode> cyclesToName = new ArrayList<SNode>(); for (List<CycleHelper.Module> cycle : cycles) { if (cycle.size() < 2) { continue; } final Set<SNode> cycleModules = new HashSet<SNode>(); for (CycleHelper.Module m : cycle) { cycleModules.add(m.getModule()); } Collections.sort( cycle, new Comparator<CycleHelper.Module>() { public int compare(CycleHelper.Module m1, CycleHelper.Module m2) { return new Integer(SNodeOperations.getIndexInParent(m1.getModule())) .compareTo(SNodeOperations.getIndexInParent(m2.getModule())); } }); SNode first = cycle.get(0).getModule(); SModel model = SNodeOperations.getModel(first); SNode cycleX = SModelOperations.createNewNode( model, null, "jetbrains.mps.build.workflow.structure.BwfJavaModule"); cyclesToName.add(cycleX); SNodeOperations.insertPrevSiblingChild(first, cycleX); SPropertyOperations.set(cycleX, "noWarnings", "" + (true)); // build cycle sources & dependencies; trying to avoid duplication (which is not critical) Set<String> seenSources = new HashSet<String>(); List<SNode> sources = new ArrayList<SNode>(); Set<String> seenDependencies = new HashSet<String>(); List<SNode> deps = new ArrayList<SNode>(); Set<SNode> seenModules = new LinkedHashSet<SNode>(); Set<SNode> seenLibraries = new LinkedHashSet<SNode>(); Set<SNode> taskDependency = new LinkedHashSet<SNode>(); int heapSize = 0; for (CycleHelper.Module m : cycle) { SNode module = m.getModule(); heapSize = Math.max(heapSize, SPropertyOperations.getInteger(module, "heapSize")); ListSequence.fromList(SLinkOperations.getTargets(module, "dependencies", true)) .removeWhere( new IWhereFilter<SNode>() { public boolean accept(SNode it) { return SNodeOperations.isInstanceOf( it, "jetbrains.mps.build.workflow.structure.BwfJavaModuleReference") && cycleModules.contains( SLinkOperations.getTarget( SNodeOperations.cast( it, "jetbrains.mps.build.workflow.structure.BwfJavaModuleReference"), "target", false)); } }); for (SNode dep : SLinkOperations.getTargets(module, "dependencies", true)) { if (SNodeOperations.isInstanceOf( dep, "jetbrains.mps.build.workflow.structure.BwfJavaModuleReference")) { seenModules.add( SLinkOperations.getTarget( SNodeOperations.cast( dep, "jetbrains.mps.build.workflow.structure.BwfJavaModuleReference"), "target", false)); } else if (SNodeOperations.isInstanceOf( dep, "jetbrains.mps.build.workflow.structure.BwfJavaLibraryReference")) { seenLibraries.add( SLinkOperations.getTarget( SNodeOperations.cast( dep, "jetbrains.mps.build.workflow.structure.BwfJavaLibraryReference"), "target", false)); } else if (SNodeOperations.isInstanceOf( dep, "jetbrains.mps.build.workflow.structure.BwfJavaClassPath")) { SNode cp = SLinkOperations.getTarget( SNodeOperations.cast( dep, "jetbrains.mps.build.workflow.structure.BwfJavaClassPath"), "classpath", true); XmlSignature s = new XmlSignature().add(cp); String id = (s.hasErrors() ? "dep." + cp.getNodeId().toString() : s.getResult()); if (seenDependencies.add(id)) { deps.add(cp); } } else { genContext.showErrorMessage(dep, "unexpected dependency type"); } } for (SNode task : ListSequence.fromList(SLinkOperations.getTargets(module, "taskDeps", true)) .select( new ISelector<SNode, SNode>() { public SNode select(SNode it) { return SLinkOperations.getTarget(it, "target", false); } })) { if ((task != null)) { taskDependency.add(task); } } SNode mref = SModelOperations.createNewNode( model, null, "jetbrains.mps.build.workflow.structure.BwfJavaModuleReference"); SLinkOperations.setTarget(mref, "target", cycleX, false); ListSequence.fromList(SLinkOperations.getTargets(module, "dependencies", true)) .addElement(mref); for (SNode n : ListSequence.fromList( SLinkOperations.getTargets( SLinkOperations.getTarget(module, "sources", true), "elements", true))) { XmlSignature s = new XmlSignature().add(n); String id = (s.hasErrors() ? "path." + n.getNodeId().toString() : s.getResult()); if (seenSources.add(id)) { sources.add(n); } } } SPropertyOperations.set(cycleX, "heapSize", "" + (heapSize)); SLinkOperations.setNewChild( cycleX, "sources", "jetbrains.mps.build.workflow.structure.BwfFileSet"); ListSequence.fromList( SLinkOperations.getTargets( SLinkOperations.getTarget(cycleX, "sources", true), "elements", true)) .addSequence( Sequence.fromIterable(((Iterable<SNode>) sources)) .select( new ISelector<SNode, SNode>() { public SNode select(SNode it) { return CopyUtil.copy(it); } })); for (SNode dep : deps) { SNode cp = SModelOperations.createNewNode( model, null, "jetbrains.mps.build.workflow.structure.BwfJavaClassPath"); SLinkOperations.setTarget(cp, "classpath", CopyUtil.copy(dep), true); ListSequence.fromList(SLinkOperations.getTargets(cycleX, "dependencies", true)) .addElement(cp); } for (SNode jl : seenLibraries) { SNode mref = SModelOperations.createNewNode( model, null, "jetbrains.mps.build.workflow.structure.BwfJavaLibraryReference"); SLinkOperations.setTarget(mref, "target", jl, false); ListSequence.fromList(SLinkOperations.getTargets(cycleX, "dependencies", true)) .addElement(mref); } for (SNode jm : seenModules) { SNode mref = SModelOperations.createNewNode( model, null, "jetbrains.mps.build.workflow.structure.BwfJavaModuleReference"); SLinkOperations.setTarget(mref, "target", jm, false); ListSequence.fromList(SLinkOperations.getTargets(cycleX, "dependencies", true)) .addElement(mref); } for (SNode task : taskDependency) { SNode dependency = SModelOperations.createNewNode( model, null, "jetbrains.mps.build.workflow.structure.BwfTaskDependency"); SLinkOperations.setTarget(dependency, "target", task, false); ListSequence.fromList(SLinkOperations.getTargets(cycleX, "taskDeps", true)) .addElement(dependency); } } int cycleCounter = 0; Collections.sort( cyclesToName, new Comparator<SNode>() { public int compare(SNode n1, SNode n2) { return new Integer(SNodeOperations.getIndexInParent(n1)) .compareTo(SNodeOperations.getIndexInParent(n2)); } }); for (SNode cycleX : cyclesToName) { SPropertyOperations.set(cycleX, "name", "java.modules.cycle." + ++cycleCounter); SPropertyOperations.set( cycleX, "outputFolder", SPropertyOperations.getString(project, "temporaryFolder") + "/" + SPropertyOperations.getString(cycleX, "name")); } }
@Override public void execute(final SNode node, final EditorContext editorContext) { SNode routineDefinition = SNodeFactoryOperations.createNewNode( SNodeFactoryOperations.asInstanceConcept( MetaAdapterFactory.getConcept( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2de971c785ed6f79L, "jetbrains.mps.samples.Kaja.structure.RoutineDefinition")), null); List<SNode> selectedNodes = editorContext.getSelectedNodes(); ListSequence.fromList( SLinkOperations.getChildren( SLinkOperations.getTarget( SNodeOperations.getNodeAncestor( node, MetaAdapterFactory.getConcept( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2d523c5e4cc45746L, "jetbrains.mps.samples.Kaja.structure.Script"), true, false), MetaAdapterFactory.getContainmentLink( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2d523c5e4cc45746L, 0x2d523c5e4cc4574cL, "body")), MetaAdapterFactory.getContainmentLink( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2de971c785f06a3fL, 0x2de971c785f06a40L, "commands"))) .addElement(routineDefinition); SNode call = SConceptOperations.createNewNode( MetaAdapterFactory.getConcept( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2de971c785ed6f92L, "jetbrains.mps.samples.Kaja.structure.RoutineCall")); SLinkOperations.setTarget( call, MetaAdapterFactory.getReferenceLink( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2de971c785ed6f92L, 0x2de971c785ede3ccL, "definition"), routineDefinition); SNodeOperations.insertPrevSiblingChild(ListSequence.fromList(selectedNodes).first(), call); for (SNode selectedNode : ListSequence.fromList(selectedNodes)) { ListSequence.fromList( SLinkOperations.getChildren( SLinkOperations.getTarget( routineDefinition, MetaAdapterFactory.getContainmentLink( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2de971c785ed6f79L, 0x2de971c785ed6f7cL, "body")), MetaAdapterFactory.getContainmentLink( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2de971c785f06a3fL, 0x2de971c785f06a40L, "commands"))) .addElement( SNodeOperations.getNodeAncestor( selectedNode, MetaAdapterFactory.getConcept( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2d523c5e4cc4574aL, "jetbrains.mps.samples.Kaja.structure.AbstractCommand"), true, false)); } editorContext.selectWRTFocusPolicy(routineDefinition); }
private static NodeCaretPair smartDelete_id7PYAiugbmRz( @NotNull SNode __thisNode__, boolean isBeginning) { SNode line = SNodeOperations.cast( SNodeOperations.getParent(__thisNode__), MetaAdapterFactory.getConcept( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x757ba20a4c87f96cL, "jetbrains.mps.baseLanguage.javadoc.structure.CommentLine")); int index = SNodeOperations.getIndexInParent(__thisNode__); Iterable<SNode> lines = SLinkOperations.getChildren( __thisNode__, MetaAdapterFactory.getContainmentLink( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x5bc4aa08e154b399L, 0x5bc4aa08e154b39bL, "line")); SNode nodeToSelect = null; int caret = -1; if (Sequence.fromIterable(lines).isEmpty()) { SNode prev = SNodeOperations.getPrevSibling(__thisNode__); if (isNotEmptyString( SPropertyOperations.getString( SNodeOperations.cast( prev, MetaAdapterFactory.getConcept( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x7c7f5b2f31990287L, "jetbrains.mps.baseLanguage.javadoc.structure.TextCommentLinePart")), MetaAdapterFactory.getProperty( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x7c7f5b2f31990287L, 0x7c7f5b2f31990288L, "text")))) { caret = SPropertyOperations.getString( SNodeOperations.cast( prev, MetaAdapterFactory.getConcept( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x7c7f5b2f31990287L, "jetbrains.mps.baseLanguage.javadoc.structure.TextCommentLinePart")), MetaAdapterFactory.getProperty( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x7c7f5b2f31990287L, 0x7c7f5b2f31990288L, "text")) .length(); } SNodeOperations.deleteNode(__thisNode__); CommentLine_BehaviorDescriptor.tryMergeToRight_idooaTF_3fF3.invoke(line, index - 1); return new NodeCaretPair(prev, caret); } else { // Merging first line for (SNode part : ListSequence.fromList( SLinkOperations.getChildren( ListSequence.fromList( SLinkOperations.getChildren( __thisNode__, MetaAdapterFactory.getContainmentLink( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x5bc4aa08e154b399L, 0x5bc4aa08e154b39bL, "line"))) .first(), MetaAdapterFactory.getContainmentLink( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x757ba20a4c87f96cL, 0x7c7f5b2f3199028dL, "part")))) { SNodeOperations.insertPrevSiblingChild(__thisNode__, part); } SNodeOperations.deleteNode( ListSequence.fromList( SLinkOperations.getChildren( __thisNode__, MetaAdapterFactory.getContainmentLink( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x5bc4aa08e154b399L, 0x5bc4aa08e154b39bL, "line"))) .first()); if (isBeginning) { nodeToSelect = ListSequence.fromList( SLinkOperations.getChildren( line, MetaAdapterFactory.getContainmentLink( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x757ba20a4c87f96cL, 0x7c7f5b2f3199028dL, "part"))) .getElement(index - 1); caret = SPropertyOperations.getString( SNodeOperations.cast( ListSequence.fromList( SLinkOperations.getChildren( line, MetaAdapterFactory.getContainmentLink( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x757ba20a4c87f96cL, 0x7c7f5b2f3199028dL, "part"))) .getElement(index - 1), MetaAdapterFactory.getConcept( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x7c7f5b2f31990287L, "jetbrains.mps.baseLanguage.javadoc.structure.TextCommentLinePart")), MetaAdapterFactory.getProperty( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x7c7f5b2f31990287L, 0x7c7f5b2f31990288L, "text")) .length(); } CommentLine_BehaviorDescriptor.tryMergeToRight_idooaTF_3fF3.invoke(line, index - 1); // Merging other lines SNode lastElementLine = ListSequence.fromList( SLinkOperations.getChildren( __thisNode__, MetaAdapterFactory.getContainmentLink( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x5bc4aa08e154b399L, 0x5bc4aa08e154b39bL, "line"))) .last(); for (SNode elementLine : ListSequence.fromList( SLinkOperations.getChildren( __thisNode__, MetaAdapterFactory.getContainmentLink( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x5bc4aa08e154b399L, 0x5bc4aa08e154b39bL, "line"))) .reversedList()) { SNodeOperations.insertNextSiblingChild(line, elementLine); } if ((lastElementLine == null)) { index = SNodeOperations.getIndexInParent(__thisNode__); SNodeOperations.deleteNode(__thisNode__); if (!(isBeginning)) { nodeToSelect = ListSequence.fromList( SLinkOperations.getChildren( line, MetaAdapterFactory.getContainmentLink( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x757ba20a4c87f96cL, 0x7c7f5b2f3199028dL, "part"))) .getElement(index - 1); caret = SPropertyOperations.getString( SNodeOperations.cast( ListSequence.fromList( SLinkOperations.getChildren( line, MetaAdapterFactory.getContainmentLink( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x757ba20a4c87f96cL, 0x7c7f5b2f3199028dL, "part"))) .getElement(index - 1), MetaAdapterFactory.getConcept( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x7c7f5b2f31990287L, "jetbrains.mps.baseLanguage.javadoc.structure.TextCommentLinePart")), MetaAdapterFactory.getProperty( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x7c7f5b2f31990287L, 0x7c7f5b2f31990288L, "text")) .length(); } CommentLine_BehaviorDescriptor.tryMergeToRight_idooaTF_3fF3.invoke(line, index - 1); } else { // Merging last line parts index = ListSequence.fromList( SLinkOperations.getChildren( lastElementLine, MetaAdapterFactory.getContainmentLink( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x757ba20a4c87f96cL, 0x7c7f5b2f3199028dL, "part"))) .count() - 1; for (SNode linePart : ListSequence.fromList(SNodeOperations.getNextSiblings(__thisNode__, false))) { ListSequence.fromList( SLinkOperations.getChildren( lastElementLine, MetaAdapterFactory.getContainmentLink( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x757ba20a4c87f96cL, 0x7c7f5b2f3199028dL, "part"))) .addElement( SNodeOperations.cast( linePart, MetaAdapterFactory.getConcept( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x7c7f5b2f31990286L, "jetbrains.mps.baseLanguage.javadoc.structure.CommentLinePart"))); } SNodeOperations.deleteNode(__thisNode__); if (!(isBeginning)) { nodeToSelect = ListSequence.fromList( SLinkOperations.getChildren( lastElementLine, MetaAdapterFactory.getContainmentLink( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x757ba20a4c87f96cL, 0x7c7f5b2f3199028dL, "part"))) .getElement(index); caret = SPropertyOperations.getString( SNodeOperations.cast( ListSequence.fromList( SLinkOperations.getChildren( lastElementLine, MetaAdapterFactory.getContainmentLink( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x757ba20a4c87f96cL, 0x7c7f5b2f3199028dL, "part"))) .getElement(index), MetaAdapterFactory.getConcept( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x7c7f5b2f31990287L, "jetbrains.mps.baseLanguage.javadoc.structure.TextCommentLinePart")), MetaAdapterFactory.getProperty( 0xf280165065d5424eL, 0xbb1b463a8781b786L, 0x7c7f5b2f31990287L, 0x7c7f5b2f31990288L, "text")) .length(); } CommentLine_BehaviorDescriptor.tryMergeToRight_idooaTF_3fF3.invoke(lastElementLine, index); } } return new NodeCaretPair(nodeToSelect, caret); }
@Override public SNode doRefactoring() { this.findDuplicates(); SNode newDeclaration; if (myFieldInitialization == FieldInitializationPlace.FIELD) { newDeclaration = _quotation_createNode_baxqxe_a0a0c0b( myVisibilityLevel.getNode(), SNodeOperations.copyNode(this.getExpressionType()), SNodeOperations.copyNode(this.getExpression()), this.getName()); } else { newDeclaration = _quotation_createNode_baxqxe_a0a0a2a1( myVisibilityLevel.getNode(), SNodeOperations.copyNode(this.getExpressionType()), this.getName()); } if (myIsFinal) { SPropertyOperations.set(newDeclaration, "isFinal", "" + (true)); } SNode classConcept = SNodeOperations.getAncestor( this.getExpression(), "jetbrains.mps.baseLanguage.structure.ClassConcept", false, false); MemberInsertingUtils.insertClassifierMemberInBestPlace(classConcept, newDeclaration); SNode assignStatement = _quotation_createNode_baxqxe_a0g0b( newDeclaration, SNodeOperations.copyNode(this.getExpression())); if (this.myFieldInitialization == FieldInitializationPlace.METHOD) { SNodeOperations.insertPrevSiblingChild( SNodeOperations.getAncestor( this.getExpression(), "jetbrains.mps.baseLanguage.structure.Statement", false, false), SNodeOperations.copyNode(assignStatement)); } if (this.myFieldInitialization == FieldInitializationPlace.CONSTRUCTOR) { SNode declaration = SNodeOperations.getAncestor( this.getExpression(), "jetbrains.mps.baseLanguage.structure.ClassConcept", false, false); for (SNode constructor : Sequence.fromIterable( BehaviorReflection.invokeNonVirtual( (Class<Iterable<SNode>>) ((Class) Object.class), declaration, "jetbrains.mps.baseLanguage.structure.ClassConcept", "call_constructors_5292274854859503373", new Object[] {}))) { List<SNode> statement = SLinkOperations.getTargets( SLinkOperations.getTarget(constructor, "body", true), "statement", true); if (ListSequence.fromList(statement).isNotEmpty()) { SNodeOperations.insertPrevSiblingChild( ListSequence.fromList(statement).first(), SNodeOperations.copyNode(assignStatement)); } else { ListSequence.fromList(statement).addElement(SNodeOperations.copyNode(assignStatement)); } } } replaceNode(this.getExpression(), newDeclaration); if (myIsReplacingAll) { for (SNode duplicate : ListSequence.fromList(myDuplicates)) { replaceNode(duplicate, newDeclaration); } } return newDeclaration; }