@Override public boolean met(MPSTreeNode node) { if (!(node instanceof SModelTreeNode)) return false; SModelTreeNode modelNode = (SModelTreeNode) node; SModel modelDescriptor = modelNode.getSModelDescriptor(); SModelReference modelReference = modelDescriptor.getReference(); return modelReference.equals(myModel.getReference()); }
private void fillCacheWithModels(Pair<SModuleReference, String> key, Iterable<SModel> models) { if (!myStubModulesCache.containsKey(key)) { myStubModulesCache.put(key, new HashSet<SModelReference>()); } for (SModel model : models) { if (!model.getReference().getModelName().equals(key.o2)) continue; Set<SModelReference> modelsFromCache = myStubModulesCache.get(key); modelsFromCache.add(model.getReference()); } }
@Override protected void invalidateModel(SModel sModel) { SModelReference mref = sModel.getReference(); List<NodePath> nodePaths = nodePaths(mref); nodePaths.clear(); nodePaths.add(NodePath.EMPTY); }
@Override protected void invalidateNode(SNode sNode) { NodePath affPath = NodePath.forSNode(sNode); SModel containingModel = sNode.getContainingModel(); if (containingModel == null) return; SModelReference mref = containingModel.getReference(); List<NodePath> nodePaths = nodePaths(mref); ListIterator<NodePath> npathIt = nodePaths.listIterator(); while (npathIt.hasNext()) { NodePath path = npathIt.next(); NodePath lcp = affPath.findLowestCommonParent(path); if (lcp != null) { if (lcp.equals(path)) break; // replace with the LCP and stop npathIt.remove(); npathIt.add(lcp); break; } } if (!npathIt.hasNext()) { // not found -> just add nodePaths.add(affPath); } }
private static boolean check_6q36mf_a0a5a0a0a0f93( SModelReference checkedDotOperand, SModel myModel) { if (null != checkedDotOperand) { return checkedDotOperand.equals(myModel.getReference()); } return false; }
@Override public SearchResults find(SearchQuery query, @NotNull ProgressMonitor monitor) { SearchResults<SNode> searchResults = new SearchResults<SNode>(); Object value = query.getObjectHolder().getObject(); SModule module = null; if (value instanceof SModule) { module = ((SModule) value); } else if (value instanceof SModuleReference) { module = query.getScope().resolve(((SModuleReference) value)); } if (!(module instanceof Language)) { return searchResults; } Language language = (Language) module; SModel structureModel = language.getStructureModelDescriptor(); if (structureModel == null) { return searchResults; } if (!(structureModel.getRootNodes().iterator().hasNext())) { return searchResults; } List<SNode> roots = new LinkedList<SNode>(); for (SNode root : structureModel.getRootNodes()) { roots.add(root); } searchResults.getSearchedNodes().addAll(roots); monitor.start("", IterableUtil.asCollection(structureModel.getRootNodes()).size() + 1); try { SearchResults<SModel> modelResults = FindUtils.getSearchResults( monitor.subTask(1), new SearchQuery( structureModel.getReference(), GlobalScopeMinusTransient.getInstance()), new ModelImportsUsagesFinder()); List<SModel> models = new ArrayList<SModel>(); for (SearchResult<SModel> sModelSearchResult : modelResults.getSearchResults()) { models.add(sModelSearchResult.getObject()); } SearchScope scope = new ModelsScope(models.toArray(new SModel[models.size()])); SearchResults<SNode> results = new SearchResults(); for (SNode node : roots) { if (monitor.isCanceled()) { break; } results.addAll( FindUtils.getSearchResults( monitor.subTask(1), node, scope, "jetbrains.mps.lang.structure.findUsages.NodeUsages_Finder")); results.removeDuplicates(); } searchResults.getSearchResults().addAll(results.getSearchResults()); return searchResults; } finally { monitor.done(); } }
@Override public void fileStatusChanged(@NotNull VirtualFile file) { IFile ifile = VirtualFileUtils.toIFile(file); SModel emd = SModelFileTracker.getInstance().findModel(ifile); if (emd != null) { rehighlightFeatureAndDescendants(new ModelFeature(emd.getReference())); } }
/** * @deprecated factory method that requires cast to implementation. why not API way to do the * same? */ @Deprecated @ToRemove(version = 3.3) public SModelReference update() { SModel sm = SModelRepository.getInstance().getModelDescriptor(this); if (sm == null) return this; SModelReference reference = (SModelReference) sm.getReference(); return new SModelReference( reference.getModuleReference(), reference.getModelId(), reference.getModelName()); }
public void beforeModelDisposed(SModel sm) { synchronized (myLock) { for (SNodeReference nodePointer : new ArrayList<SNodeReference>(myTypeCheckingContexts.keySet())) { if (sm.getReference().equals(nodePointer.getModelReference())) { removeContextForNode(nodePointer); } } } }
private static void addImportIfNeed(SModel model, SModel toImport) { if (model == null || toImport == null) { return; } SModelReference ref = toImport.getReference(); if (model == toImport || SModelOperations.getImportedModelUIDs(model).contains(ref)) { return; } ((SModelInternal) model).addModelImport(ref, false); }
public SModel createModel(SModel originalModel) { String originalLong = SNodeOperations.getModelLongName(originalModel); String newModelName = originalLong + "@999"; while (!isValidName(newModelName)) { newModelName += "_"; } SModel result = new TestSModelDescriptor(newModelName, originalModel); myModels.put(result.getReference().getModelName(), result); return result; }
protected String calculateAdditionalText() { if (getNode() == null) { return null; } SModel model = SNodeOperations.getModel(getNode()); if (model == null) { return null; } return model.getReference().getModelName(); }
private static StringBuilder checkModel(final SModel sm) { StringBuilder errorMessages = new StringBuilder(); List<String> validationResult = ModelAccess.instance() .runReadAction( new Computable<List<String>>() { public List<String> compute() { return new ModelValidator(sm).validate(); } }); if (!(validationResult.isEmpty())) { errorMessages.append("errors in model: ").append(sm.getReference().toString()).append("\n"); for (String item : validationResult) { errorMessages.append("\t"); errorMessages.append(item); errorMessages.append("\n"); } } for (SNode node : SNodeUtil.getDescendants(sm)) { // Testbench.LOG.debug("Checking node " + node); if (SModelUtil.findConceptDeclaration(node.getConcept().getQualifiedName()) == null) { errorMessages.append("Unknown concept "); errorMessages.append(node.getConcept().getQualifiedName()); errorMessages.append("\n"); } } for (SNode node : SNodeUtil.getDescendants(sm)) { for (SReference ref : node.getReferences()) { if (jetbrains.mps.smodel.SNodeUtil.hasReferenceMacro(node, ref.getRole())) { continue; } if (SNodeOperations.getTargetNodeSilently(ref) == null) { errorMessages .append("Broken reference in model {") .append(SNodeOperations.getModelLongName(node.getModel())) .append("}") .append(" node ") .append(node.getNodeId().toString()) .append("(") .append(node) .append(")\n"); } } } return errorMessages; }
public void modelsReplaced(Set<SModel> replacedModels) { for (SModel md : replacedModels) { if (!myListeningForModels.contains(md)) { continue; } SModelReference modelRef = md.getReference(); synchronized (myLock) { for (SNodeReference nodePointer : new ArrayList<SNodeReference>(myTypeCheckingContexts.keySet())) { if (nodePointer == null) continue; SNode node = nodePointer.resolve(MPSModuleRepository.getInstance()); if (node == null || !SNodeUtil.isAccessible(node, MPSModuleRepository.getInstance()) || modelRef.equals(nodePointer.getModelReference())) { removeContextForNode(nodePointer); } } } } }
/** Load cache container for the model */ public void loadExisting(@NotNull SModel model, @Nullable IncrementalReporter reporter) { myCache = null; GenerationDependencies dependencies = myIncrementalStrategy.getDependencies(model); if (dependencies == null || !dependencies.isContainsIncrementalInfo()) { return; } GenerationCacheContainer incrementalCacheContainer = myIncrementalStrategy.getContainer(); if (incrementalCacheContainer == null) { if (reporter != null) { reporter.report("No container for incremental caches."); } return; } String oldHash = dependencies.getModelHash(); ModelCacheContainer cacheContainer = incrementalCacheContainer.getCache(model, oldHash, false); if (cacheContainer == null) { if (reporter != null) { reporter.report("No cache for " + model.getReference().toString() + " (" + oldHash + ")"); } return; } IntermediateModelsCache c = IntermediateModelsCache.load(cacheContainer); if (c != null && myPlanSignature.equals(c.getSignature())) { myCache = c; } else if (reporter != null) { if (c == null) { reporter.report("Caches are corrupted for " + oldHash); } else { reporter.report("Plan differs:"); for (String s : DifflibFacade.getSimpleDiff(c.getSignature(), myPlanSignature)) { reporter.report(s); } } } }
@Override public void beforeModelDisposed(SModel model) { SModelReference modelRef = model.getReference(); List<MPSTreeNode> obsoleteTreeNodes = ListSequence.fromList(new ArrayList<MPSTreeNode>()); synchronized (myFeaturesHolder) { for (Feature f : ListSequence.fromList(myFeaturesHolder.getFeaturesByModelReference(modelRef))) { if (!(f instanceof ModelFeature)) { ListSequence.fromList(obsoleteTreeNodes) .addSequence( CollectionSequence.fromCollection(myFeaturesHolder.getNodesByFeature(f))); myFeaturesHolder.removeFeature(f); } } } ListSequence.fromList(obsoleteTreeNodes) .visitAll( new IVisitor<MPSTreeNode>() { public void visit(MPSTreeNode tn) { unhighlightNode(tn); } }); }
protected void addNodeImports(SNode node) { final SModelInternal modelInternal = (SModelInternal) myModel; final AbstractModule module = ((AbstractModule) myModel.getModule()); final Collection<SLanguage> importedLanguages = modelInternal.importedLanguageIds(); for (SNode subNode : ListSequence.fromList( SNodeOperations.getNodeDescendants(node, null, true, new SAbstractConcept[] {}))) { SLanguage usedLanguage = subNode.getConcept().getLanguage(); if (!(importedLanguages.contains(usedLanguage))) { modelInternal.addLanguage(usedLanguage); } for (SReference ref : ListSequence.fromList(SNodeOperations.getReferences(subNode))) { SModel usedModel = SNodeOperations.getModel(SLinkOperations.getTargetNode(ref)); if (usedModel != null && !(modelInternal.importedModels().contains(usedModel))) { modelInternal.addModelImport(usedModel.getReference(), false); module.addDependency( SNodeOperations.getModel(SLinkOperations.getTargetNode(ref)) .getModule() .getModuleReference(), false); } } } }
private void modelDescriptorRemoved(SModel modelDescriptor) { this.removeModelListener(modelDescriptor); this.clearForModel(modelDescriptor.getReference()); }
@Override public void modelRemoved(SModel model) { if (!myModels.contains(model.getReference())) return; myChanged = true; }
@Override public void beforeModelDisposed(SModel model) { clearForModel(model.getReference()); }
@Override public void execute(final EditorContext context) { LOG.assertLog( context.getRepository().getModelAccess().isCommandAction(), "This action must be performed in command"); final EditorComponent editorComponent = (EditorComponent) context.getEditorComponent(); final Selection selection = editorComponent.getSelectionManager().getSelection(); final List<SNode> selectedNodes = selection.getSelectedNodes(); // this is used in case node is in repo to pass it into invokeLater final List<SNodeReference> selectedReferences = new ArrayList<SNodeReference>(); for (SNode node : selectedNodes) { selectedReferences.add(node.getReference()); } final CellInfo pasteTargetCellInfo; final SNode cellNodeSelected; final SNodeReference selectedCellReference; if (selection instanceof SingularSelection) { EditorCell pasteTargetCell = getCellToPasteTo(context.getSelectedCell()); if (pasteTargetCell == null) { return; } pasteTargetCellInfo = APICellAdapter.getCellInfo(pasteTargetCell); cellNodeSelected = pasteTargetCell.getSNode(); selectedCellReference = cellNodeSelected.getReference(); } else { pasteTargetCellInfo = null; cellNodeSelected = null; selectedCellReference = null; } final SModel modelToPaste = selectedNodes.get(0).getModel(); // sometimes model is not in repository (paste in merge dialog) final boolean inRepository = modelToPaste.getReference().resolve(context.getRepository()) != null; // FIXME relationship between Project and Editor needs attention, it's bad to extract final Project mpsProject = ProjectHelper.getProject(context.getRepository()); if (mpsProject == null) { LOG.warning("Paste needs a project to show a dialog for additional imports"); return; } final PasteNodeData pasteNodeData = CopyPasteUtil.getPasteNodeDataFromClipboard(modelToPaste); // FIXME why SwingUtlities? Is it necessary to execute in EDT thread? If yes, use ThreadUtils. // If not, use any other thread than UI, e.g. app's pooled one. SwingUtilities.invokeLater( new Runnable() { @Override public void run() { final Runnable addImportsRunnable = CopyPasteUtil.addImportsWithDialog(pasteNodeData, modelToPaste, mpsProject); context .getRepository() .getModelAccess() .executeCommandInEDT( new Runnable() { @Override public void run() { if (addImportsRunnable != null) { addImportsRunnable.run(); } List<SNode> pasteNodes = pasteNodeData.getNodes(); List<SNode> currentSelectedNodes; if (!inRepository) { currentSelectedNodes = selectedNodes; } else { currentSelectedNodes = new ArrayList<SNode>(); for (SNodeReference ref : selectedReferences) { currentSelectedNodes.add( ref.resolve(MPSModuleRepository.getInstance())); } } NodePaster nodePaster = new NodePaster(pasteNodes); boolean disposed = checkDisposedSelectedNodes(currentSelectedNodes, selectedReferences); boolean canPasteWithRemove = !disposed && nodePaster.canPasteWithRemove(currentSelectedNodes); if (selection instanceof SingularSelection && (selection instanceof EditorCellLabelSelection && !isCompletelySelected((EditorCellLabelSelection) selection) || (selection instanceof EditorCellSelection && !canPasteWithRemove))) { EditorCell selectedCell = pasteTargetCellInfo.findCell(editorComponent); assert selectedCell != null; if (canPasteBefore(selectedCell, pasteNodes)) { SNode selectedNode = inRepository ? selectedCellReference.resolve( MPSModuleRepository.getInstance()) : cellNodeSelected; if (checkDisposed(selectedCellReference, cellNodeSelected)) { return; } new NodePaster(pasteNodes) .pasteRelative(selectedNode, PastePlaceHint.BEFORE_ANCHOR); } else { new NodePaster(pasteNodes).paste(selectedCell); } } else if ((selection instanceof MultipleSelection || selection instanceof EditorCellSelection) && canPasteWithRemove) { nodePaster.pasteWithRemove(currentSelectedNodes); } else { return; } Set<SReference> requireResolveReferences = new HashSet<SReference>(); for (SReference ref : pasteNodeData.getRequireResolveReferences()) { // ref can be detached from modeltoPaste while using copy/paste handlers if (ref.getSourceNode() == null || ref.getSourceNode().getModel() == null) continue; requireResolveReferences.add(ref); } ResolverComponent.getInstance() .resolveScopesOnly(requireResolveReferences, context.getRepository()); // set selection editorComponent.getUpdater().flushModelEvents(); SNode lastNode = pasteNodes.get(pasteNodes.size() - 1); editorComponent .getSelectionManager() .setSelection(lastNode, SelectionManager.LAST_CELL, -1); } }); } }); }