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); }
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 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 void test_setProperty() throws Exception { this.addNodeById("8150353254540236423"); this.addNodeById("8150353254540236549"); this.addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast( this.getNodeById("4195712261513743413"), "jetbrains.mps.baseLanguage.structure.IfStatement"); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.setProperty("forceOneLine", "true"); this.assertMethod( "public void jetbrains.mps.smodel.SNode.setProperty(java.lang.String,java.lang.String)", listener.getResults().o1); }
public void test_putUserObject() throws Exception { this.addNodeById("8150353254540236423"); this.addNodeById("8150353254540236549"); this.addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast( this.getNodeById("8150353254540236424"), "jetbrains.mps.baseLanguage.structure.BlockStatement"); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.putUserObject("test", "test"); this.assertMethod( "public void jetbrains.mps.smodel.SNode.putUserObject(java.lang.Object,java.lang.Object)", listener.getResults().o1); }
public void test_parameterLessMethods() throws Exception { this.addNodeById("8150353254540236423"); this.addNodeById("8150353254540236549"); this.addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast( this.getNodeById("8150353254540236424"), "jetbrains.mps.baseLanguage.structure.BlockStatement"); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); Map<String, Integer> prevCheck = this.getReadAccessMap(); Map<String, Integer> currentCheckChanged = new HashMap<String, Integer>(); Map<String, Integer> currentCheckNew = new HashMap<String, Integer>(); Map<String, Exception> currentException = new HashMap<String, Exception>(); Set<String> contractMethods = this.getISNodeMethodsNames(false); List<Method> methods = new ArrayList<Method>(); methods.addAll(Arrays.asList(SNode.class.getMethods())); // 'delete' must be last checked method for (int i = 0; i < methods.size(); i++) { if (methods.get(i).getName().equals("delete") && i != (methods.size() - 1)) { Collections.swap(methods, i, (methods.size() - 1)); break; } } for (Method method : methods) { if ((method.getModifiers() & (Modifier.PUBLIC | Modifier.PROTECTED)) > 0 && method.getParameterAnnotations().length == 0 && contractMethods.contains(method.getName())) { try { method.invoke(sNode); } catch (Exception e) { currentException.put(method.getName(), e); } finally { Pair<Integer, List<String>> pair = listener.getResults(); listener.resetResults(); if (prevCheck.containsKey(method.toGenericString())) { if (!(this.isReadsCountUnChanged( prevCheck.get(method.toGenericString()).intValue(), pair.o1.intValue()))) { currentCheckChanged.put(method.toGenericString(), pair.o1); } } else { currentCheckNew.put(method.toGenericString(), pair.o1); } } } } StringBuilder error = new StringBuilder("Some changes occured in read access in SNode after last check:"); error.append(System.getProperty("line.separator")); error.append("Methods with changed number of read access:"); error.append(System.getProperty("line.separator")); for (String s : currentCheckChanged.keySet()) { error.append( "In method " + s + " current count " + currentCheckChanged.get(s) + ", prev count " + prevCheck.get(s)); error.append(System.getProperty("line.separator")); } error.append(System.getProperty("line.separator")); error.append("New methods with read access:"); error.append(System.getProperty("line.separator")); for (String s : currentCheckNew.keySet()) { error.append("In method " + s + " read count " + currentCheckNew.get(s)); error.append(System.getProperty("line.separator")); } error.append(System.getProperty("line.separator")); error.append("Methods ended with exception:"); error.append(System.getProperty("line.separator")); for (String s : currentException.keySet()) { error.append( "In method " + s + " was exception " + Arrays.toString(currentException.get(s).getStackTrace())); error.append(System.getProperty("line.separator")); } Assert.assertTrue( error.toString(), currentCheckChanged.isEmpty() && currentCheckNew.isEmpty() && currentException.isEmpty()); }