private static String asString(MappingConfig_AbstractRef mappingRef, boolean moreDetails) { if (mappingRef instanceof MappingConfig_RefAllLocal) { return "*"; } if (mappingRef instanceof MappingConfig_RefAllGlobal) { return "[*:*]"; } if (mappingRef instanceof MappingConfig_RefSet) { String s = "{"; int count = ((MappingConfig_RefSet) mappingRef).getMappingConfigs().size(); for (MappingConfig_AbstractRef mappingSimpleRef : ((MappingConfig_RefSet) mappingRef).getMappingConfigs()) { count--; s = s + asString(mappingSimpleRef, moreDetails); if (count > 0) s += ", "; } return s + "}"; } if (mappingRef instanceof MappingConfig_SimpleRef) { final String modelUID = ((MappingConfig_SimpleRef) mappingRef).getModelUID(); final String nodeID = ((MappingConfig_SimpleRef) mappingRef).getNodeID(); final SModelReference modelReference = PersistenceFacade.getInstance().createModelReference(modelUID); String modelName = moreDetails ? SModelStereotype.withoutStereotype(modelReference.getModelName()) : NameUtil.shortNameFromLongName( SModelStereotype.withoutStereotype(modelReference.getModelName())); StringBuilder sb = new StringBuilder(); sb.append(modelName); sb.append('.'); if (nodeID.equals("*")) { return sb.append('*').toString(); } else { SModel refModel = SModelRepository.getInstance().getModelDescriptor(modelReference); if (refModel != null) { SNodeId nodeId = PersistenceFacade.getInstance().createNodeId(nodeID); assert nodeId != null : "wrong node id string"; SNode mappingConfig = refModel.getNode(nodeId); if (mappingConfig != null) { return sb.append(mappingConfig.getName()).toString(); } } } return sb.append(nodeID).append("!unresolved!").toString(); } if (mappingRef instanceof MappingConfig_ExternalRef) { SModuleReference generatorRef = ((MappingConfig_ExternalRef) mappingRef).getGenerator(); MappingConfig_AbstractRef extMappingRef = ((MappingConfig_ExternalRef) mappingRef).getMappingConfig(); return "[" + asString(generatorRef) + ":" + asString(extMappingRef, moreDetails) + "]"; } return "???"; }
private TestSModelDescriptor(String modelName, SModel toCopy) { super( PersistenceFacade.getInstance() .createModelReference(null, jetbrains.mps.smodel.SModelId.generate(), modelName)); myLongName = SModelStereotype.withoutStereotype(modelName); myToCopy = toCopy; }
private void openRule(String ruleModel, final String ruleID) { if (ruleModel == null || ruleID == null) return; final SModelReference modelUID = PersistenceFacade.getInstance().createModelReference(ruleModel); final SModel modelDescriptor = SModelRepository.getInstance() .getModelDescriptor(SModelStereotype.withoutStereotype(modelUID.getModelName())); if (modelDescriptor == null) { LOG.error("can't find rule's model " + ruleModel); return; } ModelAccess.instance() .runWriteInEDT( new Runnable() { @Override public void run() { jetbrains.mps.smodel.SNodeId nodeId = jetbrains.mps.smodel.SNodeId.fromString(ruleID); assert nodeId != null : "wrong node id string"; SNode rule = modelDescriptor.getNode(nodeId); if (rule == null) { LOG.error( "can't find rule with id " + ruleID + " in the model " + modelDescriptor); return; } NavigationSupport.getInstance() .openNode( myOperationContext, rule, true, !(rule.getModel() != null && rule.getParent() == null)); } }); }
@Override public SModel resolveInDependencies(SModelId reference) { boolean own = reference.getModelName() != null && myModels .keySet() .contains(SModelStereotype.withoutStereotype(reference.getModelName())); if (!own) return super.resolveInDependencies(reference); return myModels.get(reference.getModelName()); }
public static void warnIfUnitNameInvalid(String unitName, SNode node) { String longName = SModelStereotype.withoutStereotype(node.getModel().getReference().getModelName()); if (!(unitName.startsWith(longName))) { LOG.warning( "Unit name has to start with model fqName. Fix " + unitName + " in " + longName + ".", node); } else if (unitName.length() <= longName.length() + 1 || !(unitName.substring(longName.length()).startsWith(".")) || unitName.substring(longName.length() + 1).contains(".")) { LOG.warning( "Unit name has to match \"modelFqName.shortUnitName\" where short unit name does not contain dots. Fix " + unitName + " in " + longName + ".", node); } }
@Override public List<String> getErrors() { List<String> errors = new ArrayList<String>(super.getErrors()); for (SModuleReference lang : myModule.getExtendedLanguageRefs()) { if (MPSModuleRepository.getInstance().getModule(lang) == null) { errors.add("Can't find extended language: " + lang.getModuleName()); } } checkBehaviorAspectPresence(myModule, errors); for (SModuleReference mr : myModule.getRuntimeModulesReferences()) { SModule runtimeModule = MPSModuleRepository.getInstance().getModule(mr); if (runtimeModule == null) continue; if (!(runtimeModule instanceof Solution)) { errors.add("Runtime module " + runtimeModule + " is not a solution"); } } for (SModelReference accessory : myModule.getModuleDescriptor().getAccessoryModels()) { // this check is wrong in common as we don't know what the user wants to do with the acc model // in build. // but I'll not delete it until accessories removal just to have some warning on project // consistency org.jetbrains.mps.openapi.model.SModel accModel = accessory.resolve(MPSModuleRepository.getInstance()); if (accModel == null) continue; if (!VisibilityUtil.isVisible(myModule, accModel)) { errors.add( "Can't find accessory model: " + SModelStereotype.withoutStereotype(accessory.getModelName())); } } for (SModuleReference ref : myModule.getModuleDescriptor().getRuntimeModules()) { if (MPSModuleRepository.getInstance().getModule(ref) == null) { errors.add("Can't find runtime module: " + ref.getModuleName()); } } return errors; }
@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; }