@Override public SNodeReference getReferenceRoleId(SReference reference) { return MapSequence.fromMap(myReferenceRolesToPointers) .get( MultiTuple.<String, String>from( reference.getSourceNode().getConcept().getConceptId(), reference.getRole())); }
private void processReference(SModelReferenceEvent event) { SReference ref = event.getReference(); final SNode sourceNode = ref.getSourceNode(); if (sourceNode.getModel() == null) { return; } final SNodeId nodeId = sourceNode.getNodeId(); final String role = ref.getRole(); runUpdateTask( new _FunctionTypes._void_P0_E0() { public void invoke() { removeChanges( nodeId, SetReferenceChange.class, new _FunctionTypes._return_P1_E0<Boolean, SetReferenceChange>() { public Boolean invoke(SetReferenceChange ch) { return role.equals(ch.getRole()); } }); buildAndAddChanges( new _FunctionTypes._void_P1_E0<ChangeSetBuilder>() { public void invoke(ChangeSetBuilder b) { b.buildForReference(getOldNode(nodeId), sourceNode, role); } }); } }, event.getReference().getSourceNode(), event); }
public Map<SReference, SNode> classifyUsages(Iterable<SReference> usages) { Map<SReference, SNode> result = MapSequence.fromMap(new HashMap<SReference, SNode>()); for (SReference ref : Sequence.fromIterable(usages)) { MapSequence.fromMap(result).put(ref, ref.getTargetNode()); } return result; }
private static void checkModelNodes(@NotNull SModel model, @NotNull final List<String> result) { for (final SNode node : SNodeUtil.getDescendants(model)) { final SConcept concept = node.getConcept(); if (concept == null) { result.add("unknown concept of node: " + SNodeUtil.getDebugText(node)); continue; } for (String name : node.getPropertyNames()) { if (concept.getProperty(name) == null) { result.add("unknown property: `" + name + "' in node " + SNodeUtil.getDebugText(node)); } } for (SReference ref : node.getReferences()) { SAbstractLink link = concept.getLink(ref.getRole()); if (link == null || !(link.isReference())) { result.add( "unknown link role: `" + ref.getRole() + "' in node " + SNodeUtil.getDebugText(node)); } } for (SNode child : node.getChildren()) { String role = child.getRoleInParent(); SAbstractLink link = concept.getLink(role); if (link == null || link.isReference()) { result.add("unknown child role: `" + role + "' in node " + SNodeUtil.getDebugText(node)); } } } }
@Override protected void addReferenceCell(final SReferenceLink referenceLink) { SReference reference = getNode().getReference(referenceLink); if (reference == null) { addLabel("<no target>"); return; } final SNode referentNode = reference.getTargetNode(); if (referentNode == null) { String resolveInfo = ((jetbrains.mps.smodel.SReference) reference).getResolveInfo(); String myErrorText = resolveInfo != null ? resolveInfo : "?" + referenceLink.getName() + "?"; EditorCell_Error errorCell = new EditorCell_Error(getEditorContext(), getNode(), myErrorText); errorCell.setCellId("error_" + referenceLink.getName()); addCell(errorCell); return; } if (referentNode.getModel() == null) { LOG.error("Reference to node which is not inside model. Node: " + referentNode, referentNode); } EditorCell cell = getUpdateSession() .updateReferencedNodeCell( new Computable<EditorCell>() { @Override public EditorCell compute() { return createReferentEditorCell( getEditorContext(), referenceLink, referentNode); } }, referentNode, referenceLink.getName()); setSemanticNodeToCells(cell, getNode()); cell.setCellId("reference_" + referenceLink.getName()); addCell(cell); }
@Override public void referenceRoleRead(SReference reference, SNodeReference linkPointer) { storeAndCheckConsistency( myReferenceRolesToPointers, MultiTuple.<String, String>from( reference.getSourceNode().getConcept().getConceptId(), reference.getRole()), linkPointer); }
public static SNode findLinkDeclaration(SReference reference) { if (reference == null) { return null; } return ((SNode) SModelSearchUtil.findLinkDeclaration( jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations.getConceptDeclaration( ((SNode) reference.getSourceNode())), reference.getRole())); }
private static Map<String, Set<SReference>> createRoleToReferenceMap(SNode expectedNode) { Map<String, Set<SReference>> expRoleToReferenceMap = new HashMap<String, Set<SReference>>(); for (SReference ref : expectedNode.getReferences()) { if (expRoleToReferenceMap.get(ref.getRole()) == null) { expRoleToReferenceMap.put(ref.getRole(), new HashSet<SReference>()); } expRoleToReferenceMap.get(ref.getRole()).add(ref); } return expRoleToReferenceMap; }
@Override public SNodeReference getModifiesSwitch() { SReference ref = mySwitch.getReference(RuleUtil.link_TemplateSwitch_modifiedSwitch); if (ref == null) { return null; } // proceed without resolving (at least for StaticReferences) return ref.toNodePointer(); }
@Override public List<SubstituteAction> createActions() { SConcept concept = mySourceNode.getConcept(); SLanguage primaryLanguage = concept.getLanguage(); if (primaryLanguage == null) { LOG.error( "Couldn't build actions : couldn't get declaring language for concept " + concept.getName()); return Collections.emptyList(); } SReference reference = mySourceNode.getReference(myLink); return createActions(reference == null ? null : reference.getTargetNode()); }
public void execute(SNode node) { SReference ref = node.getReference(((String) makeReferenceStatic_QuickFix.this.getField("role")[0])); SNode target = ref.getTargetNode(); if (target == null) { return; } SReference staticRef = StaticReference.create( ((String) makeReferenceStatic_QuickFix.this.getField("role")[0]), node, target); node.setReference(((String) makeReferenceStatic_QuickFix.this.getField("role")[0]), staticRef); // add model import ((SModelBase) node.getModel()).addModelImport(target.getModel().getReference(), true); }
private void processReference(String prefix, SReference ref, Consumer<SReference> consumer) { if (!(ref instanceof StaticReference)) return; SNodeId target = ref.getTargetNodeId(); if (!(target instanceof Foreign)) return; String targetNodeIdStr = target.toString(); boolean found = false; int idx = targetNodeIdStr.indexOf(prefix); while (idx >= 0) { if (idx == 0) { found = true; break; } char c = targetNodeIdStr.charAt(idx - 1); if (c == '.' || Character.isLetterOrDigit(c)) { idx = targetNodeIdStr.indexOf(prefix, idx + 1); continue; } found = true; break; } if (found) { consumer.consume(ref); } }
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; }
private static void assertReferenceEquals( String errorString, SReference expectedReference, SReference actualReference) { if (expectedReference == null) { assertNull(errorString, actualReference); return; } assertNotNull(errorString, actualReference); // assertIdEqualsOrBothNull(errorString, expectedReference.getTargetNode(), // actualReference.getTargetNode()); assertEquals( errorString, ((jetbrains.mps.smodel.SReference) expectedReference).getResolveInfo(), ((jetbrains.mps.smodel.SReference) actualReference).getResolveInfo()); assertEquals(errorString, expectedReference.getRole(), actualReference.getRole()); assertEquals( errorString, expectedReference.getTargetNodeId(), actualReference.getTargetNodeId()); }
@Override public List<SearchResult<ModelCheckerIssue>> checkModel( SModel model, ProgressMonitor monitor, SRepository repository) { List<SearchResult<ModelCheckerIssue>> results = ListSequence.fromList(new ArrayList<SearchResult<ModelCheckerIssue>>()); monitor.start("adapter usages", 1); for (SNode node : ListSequence.fromList(SModelOperations.getNodes(model, null))) { if (monitor.isCanceled()) { break; } // Check for adapter references for (SReference ref : Sequence.fromIterable(SNodeOperations.getReferences(node))) { SModelReference targetSModelReference = ref.getTargetSModelReference(); if (targetSModelReference != null && SModelStereotype.getStereotype(targetSModelReference.getModelName()) .equals("java_stub")) { SNode target = SLinkOperations.getTargetNode(ref); if ((target != null) && SNodeOperations.isInstanceOf( target, "jetbrains.mps.baseLanguage.structure.ClassConcept")) { String qualifiedName = BehaviorReflection.invokeVirtual( String.class, SNodeOperations.cast( target, "jetbrains.mps.baseLanguage.structure.ClassConcept"), "virtual_getFqName_1213877404258", new Object[] {}); if ("jetbrains.mps.smodel.INodeAdapter".equals(qualifiedName) || "jetbrains.mps.smodel.BaseAdapter".equals(qualifiedName)) { SpecificChecker.addIssue( results, node, "Reference to " + qualifiedName + " in role `" + SLinkOperations.getRole(ref) + "'", ModelChecker.SEVERITY_ERROR, "adapter class usage", null); } if (SModelStereotype.withoutStereotype(targetSModelReference.getModelName()) .endsWith(".structure") && SModelUtil.findConceptDeclaration(qualifiedName) != null) { SpecificChecker.addIssue( results, node, "Using adapter of " + qualifiedName + " concept in role `" + SLinkOperations.getRole(ref) + "'", ModelChecker.SEVERITY_ERROR, "adapter class usage", null); } } } } } monitor.done(); return results; }
public void updateUsage(SReference usage, SNode newTarget) { usage.getSourceNode().setReferenceTarget(usage.getLink(), newTarget); }
public int getModelKind(SModel model, @Nullable SReference reference) { DataSource source = (model != null ? model.getSource() : null); IFile modelFile = (source instanceof FileDataSource ? ((FileDataSource) source).getFile() : null); if (modelFile != null) { String filePath = modelFile.getAbsolutePath().replace('\\', '/'); if (filePath.startsWith(languagesUtilPath)) { return OTHER; } } SModule module = model.getModule(); if (module instanceof Language) { LanguageAspect aspect = Language.getModelAspect(model); if (aspect != null) { switch (aspect) { case ACTIONS: return EDITOR; case BEHAVIOR: return CORE; case CONSTRAINTS: return CORE; case DATA_FLOW: return CORE; case EDITOR: return EDITOR; case FIND_USAGES: return CORE; case INTENTIONS: return EDITOR; case PLUGIN: return WORKBENCH; case REFACTORINGS: return CORE; case SCRIPTS: return CORE; case STRUCTURE: return CORE; case STUBS: return CORE; case TEST: return EDITOR; case TEXT_GEN: return CORE; case TYPESYSTEM: return CORE; default: } } return CORE; } else if (module instanceof Solution) { String moduleFqName = module.getModuleName(); if (moduleFqName.equals("JDK")) { return CORE; } if (moduleFqName.equals("MPS.Core")) { return CORE; } if (moduleFqName.equals("MPS.Editor")) { return EDITOR; } if (moduleFqName.equals("MPS.Workbench")) { return WORKBENCH; } if (moduleFqName.equals("MPS.Classpath")) { SNode refTargetRoot = reference.getTargetNode().getContainingRoot(); if (SNodeOperations.isInstanceOf( refTargetRoot, "jetbrains.mps.baseLanguage.structure.Classifier")) { String cName = SPropertyOperations.getString( SNodeOperations.cast( refTargetRoot, "jetbrains.mps.baseLanguage.structure.Classifier"), "name"); String modelName = model.getModelName(); if (findInModule(coreModule, modelName, cName)) { return CORE; } if (findInModule(editorModule, modelName, cName)) { return EDITOR; } return WORKBENCH; } return OTHER; } Solution sol = (Solution) module; switch (sol.getKind()) { case NONE: return OTHER; case PLUGIN_CORE: return CORE; case PLUGIN_EDITOR: return EDITOR; case PLUGIN_OTHER: return WORKBENCH; default: } } return OTHER; }
public static SNode getTargetNode(SReference reference) { if (reference == null) { return null; } return reference.getTargetNode(); }
public static String getRole(SReference reference) { if (reference == null) { return null; } return reference.getRole(); }