private SNode convertLanguage(LanguageDescriptor source) { SNode result = SConceptOperations.createNewNode("jetbrains.mps.lang.project.structure.Language", null); result.setId(SNodeId.fromString("~root")); SModelOperations.addRootNode(myModel, result); fill(result, source); SPropertyOperations.set(result, "doNotGenerateAdapters", "" + source.isDoNotGenerateAdapters()); SPropertyOperations.set(result, "genPath", source.getGenPath()); SPropertyOperations.set(result, "languagePath", myFile.getPath()); for (SModelReference ref : source.getAccessoryModels()) { SLinkOperations.getTargets(result, "accessoryModels", true).add(convert(ref)); } for (GeneratorDescriptor descriptor : source.getGenerators()) { SLinkOperations.getTargets(result, "generator", true).add(convert(descriptor)); } for (ModuleReference ref : source.getExtendedLanguages()) { SLinkOperations.getTargets(result, "extendedLanguages", true).add(convert(ref)); } for (Dependency dep : source.getRuntimeModules()) { SLinkOperations.getTargets(result, "runtimeModules", true).add(convert(dep)); } for (ModelRoot entry : source.getRuntimeStubModels()) { SLinkOperations.getTargets(result, "runtimeStubModels", true).add(convert(entry)); } for (StubSolution sol : source.getStubSolutions()) { SLinkOperations.getTargets(result, "stubSolutions", true).add(convert(sol)); } collectModels(result, source); return result; }
public void test_removeChild() throws Exception { this.addNodeById("8150353254540236423"); this.addNodeById("8150353254540236549"); this.addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast( this.getNodeById("8150353254540236424"), "jetbrains.mps.baseLanguage.structure.BlockStatement"); SNode child = SNodeOperations.cast( this.getNodeById("8150353254540236551"), "jetbrains.mps.baseLanguage.structure.LocalVariableDeclarationStatement"); child.getParent().removeChild(child); sNode.addChild("", child); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.removeChild(child); this.assertMethod( "public void jetbrains.mps.smodel.SNode.removeChild(org.jetbrains.mps.openapi.model.SNode)", listener.getResults().o1); }
public SNode resolveClass(PsiClassType t) { PsiClass cls = t.resolve(); // TODO q: handle this case? create dynamic reference? if (cls == null) { return null; } System.out.println("Class resolved: " + cls.getQualifiedName()); PsiElement e = cls; do { e = e.getParent(); if (!(e instanceof PsiClass) && !(e instanceof PsiJavaFile)) { return null; } } while (!(e instanceof PsiJavaFile)); PsiJavaFile file = (PsiJavaFile) e; String packageName = file.getPackageName(); SModelReference modelRef = SModelReference.fromString(packageName); SNode clsType = SConceptOperations.createNewNode( "jetbrains.mps.baseLanguage.structure.ClassifierType", null); clsType.setReference( "classifier", new DynamicReference("classifier", clsType, modelRef, t.getClassName())); System.out.println("Class type: " + t.getClassName()); return clsType; }
public void execute(final SNode node, final EditorContext editorContext) { String name = CreateFromUsageUtil.getText(editorContext); if (name == null || name.length() == 0) { name = "default_" + SPropertyOperations.getString(node, "name"); } SNode t = SNodeFactoryOperations.createNewRootNode( SNodeOperations.getModel(node), "jetbrains.mps.lang.generator.structure.TemplateDeclaration", null); SPropertyOperations.set(t, "name", name); t.setProperty( SModelTreeNode.PACK, SPropertyOperations.getString( SNodeOperations.cast( SNodeOperations.getContainingRoot(node), "jetbrains.mps.lang.core.structure.BaseConcept"), "virtualPackage")); // make reference SNode tr = SNodeFactoryOperations.createNewNode( "jetbrains.mps.lang.generator.structure.TemplateDeclarationReference", null); SLinkOperations.setTarget(tr, "template", t, false); SLinkOperations.setTarget(node, "defaultConsequence", tr, true); }
private String getNodeName(SNode node, boolean isLast) throws ArtifactsRelativePathHelper.RelativePathException { if (SNodeOperations.isInstanceOf(node, "jetbrains.mps.build.structure.BuildLayout_Folder")) { return getBSName( SLinkOperations.getTarget( SNodeOperations.cast(node, "jetbrains.mps.build.structure.BuildLayout_Folder"), "containerName", true)); } else if (SNodeOperations.isInstanceOf(node, "jetbrains.mps.build.structure.BuildLayout_Copy") && isLast) { SNode fileset = SLinkOperations.getTarget( SNodeOperations.cast(node, "jetbrains.mps.build.structure.BuildLayout_Copy"), "fileset", true); if (SNodeOperations.isInstanceOf( fileset, "jetbrains.mps.build.structure.BuildInputSingleFile")) { return BuildSourcePath_Behavior.call_getLastSegment_1368030936106771141( SLinkOperations.getTarget( SNodeOperations.cast(fileset, "jetbrains.mps.build.structure.BuildInputSingleFile"), "path", true), null); } else { throw new ArtifactsRelativePathHelper.RelativePathException( "cannot build relative path for copy, fileset is " + node.getConceptShortName()); } } throw new ArtifactsRelativePathHelper.RelativePathException( "cannot build relative path for " + node.getConceptShortName()); }
public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) { try { NodeHighlightManager highlightManager = ((EditorComponent) MapSequence.fromMap(_params).get("editorComponent")) .getHighlightManager(); EditorMessageOwner messageOwner = ((EditorComponent) MapSequence.fromMap(_params).get("editorComponent")) .getHighlightMessagesOwner(); Set<SNode> usages = FindUsagesManager.getInstance() .findUsages( Collections.singleton( SNodeOperations.getConceptDeclaration( ((SNode) MapSequence.fromMap(_params).get("node")))), SearchType.INSTANCES, new ModelsOnlyScope( ((SModelDescriptor) MapSequence.fromMap(_params).get("model"))), null); for (SNode ref : SetSequence.fromSet(usages)) { if (ref.getContainingRoot() == ((EditorComponent) MapSequence.fromMap(_params).get("editorComponent")) .getRootCell() .getSNode() .getContainingRoot()) { highlightManager.mark(ref, HighlightConstants.INSTANCES_COLOR, "usage", messageOwner); } } highlightManager.repaintAndRebuildEditorMessages(); } catch (Throwable t) { if (log.isErrorEnabled()) { log.error("User's action execute method failed. Action:" + "HighlightInstances", t); } } }
public List<String> createAvailableTypes() { if (this.myType == null) { List<String> result = ListSequence.fromList(new ArrayList<String>()); return result; } SubtypingManager manager = TypeChecker.getInstance().getSubtypingManager(); StructuralNodeSet<?> frontier = new StructuralNodeSet(); List<SNode> found = new ArrayList<SNode>(); frontier.add(this.myType); while (!(frontier.isEmpty())) { StructuralNodeSet<?> ancestors = new StructuralNodeSet(); for (SNode node : SetSequence.fromSet(frontier)) { ancestors.addAllStructurally(manager.collectImmediateSupertypes(node, false)); ListSequence.fromList(found).addElement(node); } for (SNode passed : ListSequence.fromList(found)) { ancestors.removeStructurally(passed); } frontier = ancestors; } List<String> result = ListSequence.fromList(new ArrayList<String>()); for (SNode node : ListSequence.fromList(found)) { ListSequence.fromList(result).addElement(node.toString()); MapSequence.fromMap(this.myTypesMap).put(node.toString(), node); } return result; }
public void test_setReference() throws Exception { this.addNodeById("8150353254540236423"); this.addNodeById("8150353254540236549"); this.addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast( this.getNodeById("4195712261513781536"), "jetbrains.mps.baseLanguage.structure.LocalVariableReference"); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.setReference( "localVariableDeclaration", SNodeOperations.getReference( SNodeOperations.cast( this.getNodeById("4195712261513781536"), "jetbrains.mps.baseLanguage.structure.LocalVariableReference"), SLinkOperations.findLinkDeclaration( "jetbrains.mps.baseLanguage.structure.LocalVariableReference", "localVariableDeclaration"))); this.assertMethod( "public void jetbrains.mps.smodel.SNode.setReference(java.lang.String,org.jetbrains.mps.openapi.model.SReference)", listener.getResults().o1); }
private void addLocationBreakpoint(ILocationBreakpoint breakpoint) { SNode node = breakpoint.getLocation().getSNode(); if (node != null) { SNode root = node.getContainingRoot(); if (root != null) { SNodePointer rootPointer = new SNodePointer(root); Set<ILocationBreakpoint> breakpointsForRoot = myRootsToBreakpointsMap.get(rootPointer); if (breakpointsForRoot == null) { breakpointsForRoot = new HashSet<ILocationBreakpoint>(); myRootsToBreakpointsMap.put(rootPointer, breakpointsForRoot); } // check the following assumption: one breakpoint for one node for (ILocationBreakpoint breakpointForRoot : breakpointsForRoot) { if (breakpointForRoot .getLocation() .getNodePointer() .equals(breakpoint.getLocation().getNodePointer())) { LOG.error( "Trying to add a second breakpoint for node", breakpointForRoot.getLocation().getSNode()); break; } } breakpointsForRoot.add(breakpoint); } } }
private static SNode _quotation_createNode_qzfpnd_a0a0c0a(Object parameter_1) { SNode quotedNode_2 = null; SNode quotedNode_3 = null; SNode quotedNode_4 = null; quotedNode_2 = SModelUtil_new.instantiateConceptDeclaration( "jetbrains.mps.baseLanguage.closures.structure.FunctionType", null, null, GlobalScope.getInstance(), false); quotedNode_3 = SModelUtil_new.instantiateConceptDeclaration( "jetbrains.mps.baseLanguage.collections.structure.SequenceType", null, null, GlobalScope.getInstance(), false); quotedNode_4 = (SNode) parameter_1; if (quotedNode_4 != null) { quotedNode_3.addChild("elementType", HUtil.copyIfNecessary(quotedNode_4)); } quotedNode_2.addChild("resultType", quotedNode_3); return quotedNode_2; }
public SNode createNode(final TypeCheckingContext typeCheckingContext) { SNode result = null; Set<SNode> _parameterValues_129834374 = new HashSet<SNode>(); SNode quotedNode_1 = null; SNode quotedNode_2 = null; { quotedNode_1 = SModelUtil_new.instantiateConceptDeclaration( "jetbrains.mps.baseLanguage.collections.structure.ListType", null, GlobalScope.getInstance(), false); SNode quotedNode1_3 = quotedNode_1; { quotedNode_2 = SModelUtil_new.instantiateConceptDeclaration( "jetbrains.mps.lang.smodel.structure.SNodeType", null, GlobalScope.getInstance(), false); SNode quotedNode1_4 = quotedNode_2; quotedNode_1.addChild("elementType", quotedNode1_4); } result = quotedNode1_3; } return result; }
public SNode createNode() { SNode result = null; Set<SNode> _parameterValues_129834374 = new HashSet<SNode>(); SNode quotedNode_1 = null; { quotedNode_1 = SModelUtil_new.instantiateConceptDeclaration( "jetbrains.mps.baseLanguage.structure.StaticMethodCall", null, GlobalScope.getInstance(), false); SNode quotedNode1_2 = quotedNode_1; quotedNode1_2.addReference( SReference.create( "classConcept", quotedNode1_2, SModelReference.fromString( "f:java_stub#jetbrains.mps.refactoring.framework.paramchooser.mps(jetbrains.mps.refactoring.framework.paramchooser.mps@java_stub)"), SNodeId.fromString("~MPSChooserFactory"))); quotedNode1_2.addReference( SReference.create( "baseMethodDeclaration", quotedNode1_2, SModelReference.fromString( "f:java_stub#jetbrains.mps.refactoring.framework.paramchooser.mps(jetbrains.mps.refactoring.framework.paramchooser.mps@java_stub)"), SNodeId.fromString( "~MPSChooserFactory.createNodeChooser(jetbrains.mps.refactoring.framework.RefactoringContext,java.lang.String,jetbrains.mps.refactoring.framework.paramchooser.mps.IChooserSettings):jetbrains.mps.refactoring.framework.paramchooser.IChooser"))); result = quotedNode1_2; } return result; }
@Override protected void handleAttribute(Object resultObject, String name, String value) throws SAXException { SNode result = (SNode) resultObject; if ("type".equals(name)) { return; } if ("typeId".equals(name)) { fieldlinkMap.addTypeLocation(fieldhelper.readLinkId(value), result); return; } if ("role".equals(name)) { result.setRoleInParent(fieldhelper.readRole(value)); return; } if ("roleId".equals(name)) { fieldlinkMap.addRoleLocation(fieldhelper.readLinkId(value), result); return; } if ("id".equals(name)) { SNodeId id = SNodeId.fromString(value); if (id == null) { throw new SAXParseException("bad node ID", null); } result.setId(id); return; } super.handleAttribute(resultObject, name, value); }
public SNode createNode(Object parameter_5, final TypeCheckingContext typeCheckingContext) { SNode result = null; Set<SNode> _parameterValues_129834374 = new HashSet<SNode>(); SNode quotedNode_1 = null; SNode quotedNode_2 = null; { quotedNode_1 = SModelUtil_new.instantiateConceptDeclaration( "jetbrains.mps.baseLanguage.collections.structure.SequenceType", null, GlobalScope.getInstance(), false); SNode quotedNode1_3 = quotedNode_1; { quotedNode_2 = (SNode) parameter_5; SNode quotedNode1_4; if (_parameterValues_129834374.contains(quotedNode_2)) { quotedNode1_4 = HUtil.copyIfNecessary(quotedNode_2, typeCheckingContext); } else { _parameterValues_129834374.add(quotedNode_2); quotedNode1_4 = quotedNode_2; } if (quotedNode1_4 != null) { quotedNode_1.addChild( "elementType", HUtil.copyIfNecessary(quotedNode1_4, typeCheckingContext)); } } result = quotedNode1_3; } return result; }
// todo: this method can be called from inference rules - by calling behavior methods, // todo: in which there are no typechecking context( public static SNode copyIfNecessary(SNode node) { if (node != null && (node.getParent() != null || node.getModel() != null && node.getModel().isRoot(node))) { // this copies all the atributes, because can be used in migration scripts SNode copy = CopyUtil.copy(node, new THashMap<SNode, SNode>(1), true); return copy; } else { return node; } }
public SNode createChildNode(Object parameterObject, SModel model, String pattern) { SNode childNode = SModelUtil_new.instantiateConceptDeclaration( NameUtil.nodeFQName(mySmartConcept), model, GlobalScope.getInstance()); String referentRole = SModelUtil.getGenuineLinkRole(mySmartReference); childNode.setReferenceTarget(referentRole, myReferentNode); NodeFactoryManager.setupNode( mySmartConcept, childNode, myCurrentChild, myParentNode, model, getScope()); return childNode; }
public static SNode findProperty(SNode node, String name) { boolean cpt = eq_yzaoi3_a0a0a0g( node.getConcept().getId(), "jetbrains.mps.lang.structure.structure.ConceptDeclaration") || eq_yzaoi3_a0a0a0g_0( node.getConcept().getId(), "jetbrains.mps.lang.structure.structure.InterfaceConceptDeclaration"); SNode conceptNode = (cpt ? ((SNode) node) : SNodeOperations.getConceptDeclaration(node)); return SModelSearchUtil.findConceptProperty(conceptNode, name); }
private static SNode _quotation_createNode_w9106s_a0a2a5(Object parameter_1) { SNode quotedNode_2 = null; quotedNode_2 = SModelUtil_new.instantiateConceptDeclaration( "jetbrains.mps.lang.smodel.structure.SNodeType", null, null, GlobalScope.getInstance(), false); quotedNode_2.setReferenceTarget("concept", (SNode) parameter_1); return quotedNode_2; }
private SNode convertSolution(SolutionDescriptor source) { SNode result = SConceptOperations.createNewNode("jetbrains.mps.lang.project.structure.Solution", null); result.setId(SNodeId.fromString("~root")); SModelOperations.addRootNode(myModel, result); fill(result, source); SPropertyOperations.set(result, "dontLoadClasses", "" + source.isDontLoadClasses()); SPropertyOperations.set(result, "outputPath", source.getOutputPath()); SPropertyOperations.set(result, "solutionPath", myFile.getPath()); collectModels(result, source); return result; }
public static void innerClassifiers(SNode concept, final SNodeTextGen textGen) { for (SNode classifier : SLinkOperations.getTargets(concept, "staticInnerClassifiers", true)) { TextGenManager.instance() .appendNodeText( textGen.getContext(), textGen.getBuffer(), classifier, textGen.getSNode()); if (!(classifier.equals( ListSequence.fromList(SLinkOperations.getTargets(concept, "staticInnerClassifiers", true)) .last()))) { textGen.appendNewLine(); } } }
private static SNode _quotation_createNode_89tbzo_a0b0a(Object parameter_1) { SNode quotedNode_2 = null; quotedNode_2 = SModelUtil_new.instantiateConceptDeclaration( "jetbrains.mps.execution.settings.structure.PersistentConfigurationType", null, null, GlobalScope.getInstance(), false); quotedNode_2.setReferenceTarget("persistentConfiguration", (SNode) parameter_1); return quotedNode_2; }
public static GenerationDependencies fromIncremental( Map<SNode, SNode> currentToOriginalMap, RootDependenciesBuilder[] roots, String modelHash, String parametersHash, IOperationContext operationContext, IncrementalGenerationStrategy incrementalStrategy, int skippedCount, int fromCacheCount) { Map<String, List<String>> generatedFiles = getGeneratedFiles(currentToOriginalMap); List<GenerationRootDependencies> unchanged = null; List<GenerationRootDependencies> rootDependencies = new ArrayList<GenerationRootDependencies>(roots.length); Map<String, String> externalHashes = new HashMap<String, String>(); for (RootDependenciesBuilder l : roots) { SNode originalRoot = l.getOriginalRoot(); List<String> files = generatedFiles.get(originalRoot != null ? originalRoot.getId() : ""); if (files == null) { files = Collections.emptyList(); } GenerationRootDependencies dep; if (l.isUnchanged()) { dep = l.getSavedDependencies(); if (unchanged == null) { unchanged = new ArrayList<GenerationRootDependencies>(); } unchanged.add(dep); } else { dep = GenerationRootDependencies.fromData(l, files); } rootDependencies.add(dep); for (String modelReference : dep.getExternal()) { if (!externalHashes.containsKey(modelReference)) { SModelDescriptor sm = SModelRepository.getInstance() .getModelDescriptor(SModelReference.fromString(modelReference)); Map<String, String> hashes = incrementalStrategy.getModelHashes(sm, operationContext); String value = hashes != null ? hashes.get(ModelDigestHelper.FILE) : null; externalHashes.put(modelReference, value); } } } return new GenerationDependencies( rootDependencies, modelHash, parametersHash, externalHashes, unchanged == null ? Collections.<GenerationRootDependencies>emptyList() : unchanged, skippedCount, fromCacheCount); }
@Override protected void handleChild(Object resultObject, String tagName, Object value) throws SAXException { SNode result = (SNode) resultObject; if ("node".equals(tagName)) { SNode child = (SNode) value; if (child != null) { result.addChild(child.getRole_(), child); } return; } super.handleChild(resultObject, tagName, value); }
private void removeLocationBreakpoint(ILocationBreakpoint breakpoint) { SNode node = breakpoint.getLocation().getSNode(); if (node != null) { SNode root = node.getContainingRoot(); if (root != null) { SNodePointer rootPointer = new SNodePointer(root); Set<ILocationBreakpoint> breakpointsForRoot = myRootsToBreakpointsMap.get(rootPointer); if (breakpointsForRoot != null) { breakpointsForRoot.remove(breakpoint); } } } }
@Override public boolean contains(SNode node) { if (!(SNodeOperations.isInstanceOf(node, "jetbrains.mps.lang.core.structure.INamedConcept")) || !(node.isInstanceOfConcept(kindConceptFqName))) { return false; } if (scope.contains(node)) { return true; } if (SetSequence.fromSet(names).contains(node.getName())) { return false; } return parentScope.contains(node); }
private boolean canPasteBefore(EditorCell selectedCell, List<SNode> pasteNodes) { if (!selectedCell.isFirstPositionInBigCell()) return false; SNode anchor = selectedCell.getSNode(); if (anchor.getParent() == null) return false; NodeAndRole nodeAndRole = new NodePaster(pasteNodes).getActualAnchorNode(anchor, anchor.getRoleInParent()); if (nodeAndRole == null) return false; EditorCell targetCell = selectedCell.getEditor().findNodeCell(nodeAndRole.myNode); return targetCell != null && targetCell.getFirstLeaf(CellConditions.SELECTABLE) == selectedCell && new NodePaster(pasteNodes).canPasteRelative(nodeAndRole.myNode); }
public boolean canExecute(final KeyEvent keyEvent, final EditorContext editorContext) { EditorCell contextCell = editorContext.getContextCell(); if ((contextCell == null)) { return false; } SNode contextNode = contextCell.getSNode(); if (contextNode == null) { return false; } if (contextNode.isInstanceOfConcept("jetbrains.mps.build.packaging.structure.Module")) { return true; } return false; }
public SNode coerceSubTypingNew( final SNode subtype, final IMatchingPattern pattern, final boolean isWeak, final State state) { if (subtype == null) return null; if (pattern.match(subtype)) return subtype; if (!CoerceUtil.canBeCoerced(subtype, pattern.getConceptFQName())) return null; if ("jetbrains.mps.lang.typesystem.structure.MeetType".equals(subtype.getConceptFqName())) { List<SNode> children = subtype.getChildren("argument"); for (SNode child : children) { SNode result = coerceSubTypingNew(child, pattern, isWeak, state); if (result != null) return result; } return null; } final TypeCheckingContextNew typeCheckingContext = state == null ? null : state.getTypeCheckingContext(); if ("jetbrains.mps.lang.typesystem.structure.JoinType".equals(subtype.getConceptFqName())) { List<SNode> children = subtype.getChildren("argument"); SNode lcs = mySubTyping.createLCS(children, typeCheckingContext); return coerceSubTypingNew(lcs, pattern, isWeak, state); } // asking the cache return NodeReadAccessCasterInEditor.runReadTransparentAction( new Computable<SNode>() { public SNode compute() { Pair<Boolean, SNode> answer = getCoerceCacheAnswer(subtype, pattern, isWeak); if (answer != null && answer.o1) { return answer.o2; } CoercionMatcher coercionMatcher = new CoercionMatcher(pattern); SNode result = searchInSuperTypes(subtype, coercionMatcher, isWeak); // writing to the cache SubtypingCache subtypingCache = myTypeChecker.getSubtypingCache(); if (subtypingCache != null) { subtypingCache.cacheCoerce(subtype, pattern, result, isWeak); } subtypingCache = myTypeChecker.getGlobalSubtypingCache(); if (subtypingCache != null) { subtypingCache.cacheCoerce(subtype, pattern, result, isWeak); } return result; } }); }
public boolean canExecute(final KeyEvent keyEvent, final EditorContext editorContext) { EditorCell contextCell = editorContext.getContextCell(); if ((contextCell == null)) { return false; } SNode contextNode = contextCell.getSNode(); if (contextNode == null) { return false; } if (contextNode.isInstanceOfConcept("jetbrains.mps.lang.quotation.structure.Quotation")) { return this.canExecute_internal( keyEvent, editorContext, contextNode, this.getSelectedNodes(editorContext)); } return false; }
public boolean canExecute(final KeyEvent keyEvent, final EditorContext editorContext) { EditorCell contextCell = editorContext.getContextCell(); if ((contextCell == null)) { return false; } SNode contextNode = contextCell.getSNode(); if (contextNode == null) { return false; } if (contextNode.isInstanceOfConcept( "jetbrains.mps.baseLanguage.structure.ParenthesizedExpression")) { return true; } return false; }