protected void replaceAndReparse(String model, int offset, int length, String change, String expectedReparseRegion) throws Exception { IParseResult parseResult = getParseResult(model); PartialParsingPointers parsingPointers = getPartialParser().calculatePartialParsingPointers(parseResult, offset, length); String reparseRegion = getPartialParser().insertChangeIntoReplaceRegion(parsingPointers .getDefaultReplaceRootNode(), new ReplaceRegion(offset, length, change)); assertEquals(expectedReparseRegion, reparseRegion); final Wrapper<Boolean> unloaded = Wrapper.wrap(Boolean.FALSE); getPartialParser().setUnloader(new IReferableElementsUnloader() { @Override public void unloadRoot(EObject root) { unloaded.set(Boolean.TRUE); } }); IParseResult partiallyReparse = reparse(parseResult, offset, length, change); assertTrue("unloaded", unloaded.get()); assertFalse(partiallyReparse.getRootNode().getText(), partiallyReparse.hasSyntaxErrors()); String expectedReparseModel = model.substring(0, offset) + change + model.substring(offset + length); assertEquals(expectedReparseModel, partiallyReparse.getRootNode().getText()); }
protected void replaceAndReparse(String model, int offset, int length, String change, String expectedReparseRegion) throws Exception { IParseResult parseResult = getParseResultAndExpect(model, UNKNOWN_EXPECTATION); PartialParsingPointers parsingPointers = getPartialParser().calculatePartialParsingPointers(parseResult, offset, length); String reparseRegion = getPartialParser().insertChangeIntoReplaceRegion(parsingPointers .getDefaultReplaceRootNode(), new ReplaceRegion(offset, length, change)); assertEquals(expectedReparseRegion, reparseRegion); final Wrapper<Boolean> unloaded = Wrapper.wrap(Boolean.FALSE); getPartialParser().setUnloader(new IReferableElementsUnloader() { @Override public void unloadRoot(EObject root) { unloaded.set(Boolean.TRUE); } }); IParseResult partiallyReparse = reparse(parseResult, offset, length, change); assertTrue("unloaded", unloaded.get()); String expectedReparseModel = model.substring(0, offset) + change + model.substring(offset + length); assertEquals(expectedReparseModel, partiallyReparse.getRootNode().getText()); compareWithFullParse(model, offset, length, change); }
@Override protected Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> getDeclaratorParameterMapping() { final Wrapper<Map<JvmTypeParameter, LightweightMergedBoundTypeArgument>> receiverTypeParameterMapping = Wrapper.wrap(Collections.<JvmTypeParameter, LightweightMergedBoundTypeArgument>emptyMap()); XExpression receiver = getReceiver(); if (receiver != null) { LightweightTypeReference receiverType = getReceiverType(); if (receiverType == null) { throw new IllegalStateException("Cannot determine type of receiver "+ getReceiver()); } JvmIdentifiableElement feature = getFeature(); if (feature instanceof JvmFeature) { JvmDeclaredType declaringType = ((JvmFeature) feature).getDeclaringType(); final LightweightTypeReference declaringTypeReference = receiverType.getOwner().newParameterizedTypeReference(declaringType); final TypeConformanceComputationArgument rawConformanceCheck = new TypeConformanceComputationArgument(true, false, false, false, false, false); if (declaringTypeReference.isAssignableFrom(receiverType, rawConformanceCheck)) { receiverTypeParameterMapping.set(new DeclaratorTypeArgumentCollector().getTypeParameterMapping(receiverType)); } else { CommonTypeComputationServices services = receiverType.getOwner().getServices(); SynonymTypesProvider synonymProvider = services.getSynonymTypesProvider(); synonymProvider.collectSynonymTypes(receiverType, new SynonymTypesProvider.Acceptor() { @Override protected boolean accept(LightweightTypeReference synonym, int hints) { if (declaringTypeReference.isAssignableFrom(synonym, rawConformanceCheck)) { receiverTypeParameterMapping.set(new DeclaratorTypeArgumentCollector().getTypeParameterMapping(synonym)); return false; } return true; } }); } } else { receiverTypeParameterMapping.set(new DeclaratorTypeArgumentCollector().getTypeParameterMapping(receiverType)); } } return receiverTypeParameterMapping.get(); }
protected <T extends Object> void genericTestInitializeSafely(final Function3<? super EObject, ? super String, ? super Procedure1<? super T>, ? extends EObject> create) { final XNullLiteral expr = XbaseFactory.eINSTANCE.createXNullLiteral(); final Wrapper<Boolean> initialized = new Wrapper<Boolean>(Boolean.valueOf(false)); final Procedure1<T> _function = (T it) -> { initialized.set(Boolean.valueOf(true)); throw new RuntimeException(); }; final EObject element = create.apply(expr, "foo", _function); Assert.assertTrue((initialized.get()).booleanValue()); Assert.assertNotNull(element); }
public FragmentFakingEcoreResource(final URI uri, final Wrapper<Boolean> isSaving) { super(uri); this.isSaving = isSaving; this.encoding = "UTF-8"; this.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.valueOf(true)); this.getDefaultSaveOptions().put(XMLResource.OPTION_LINE_WIDTH, Integer.valueOf(80)); Map<Object, Object> _defaultSaveOptions = this.getDefaultSaveOptions(); URIHandlerImpl.PlatformSchemeAware _platformSchemeAware = new URIHandlerImpl.PlatformSchemeAware(); _defaultSaveOptions.put(XMLResource.OPTION_URI_HANDLER, _platformSchemeAware); }
public <STATE> String format(Nfa<STATE> nfa) { Map<STATE, Integer> names = Maps.newLinkedHashMap(); List<Node> nodes = Lists.newArrayList(); nodes.add(createNodes(nfa, nfa.getStart(), names, new Wrapper<Integer>(0))); StringBuilder result = new StringBuilder(); STATE starts = nfa.getStart(); STATE stops = nfa.getStop(); for (Map.Entry<STATE, Integer> e : names.entrySet()) { result.append(e.getValue() + ": " + e.getKey()); if (starts == e.getKey()) result.append(" (start)"); if (stops == e.getKey()) result.append(" (stop)"); if (!new NfaUtil().canReachFinalState(nfa, e.getKey())) result.append(" (no connection to final state!)"); result.append("\n"); } Canvas canvas = new Canvas(); int width = 0; for (Node n : nodes) { n.draw(canvas, 0, width, n.getMinWidth()); width += n.getMinWidth(); } // result.append(n.getNameLine() + " "); // result.append("\n"); // for (Node n : nodes) // result.append(n.getBranchLine() + " "); // result.append("\n"); // List<Node> children = Lists.newArrayList(); // for (Node n : nodes) // children.addAll(n.children); // nodes = children; // } result.append(canvas); return result.toString(); }
protected <STATE> Node createNodes(Nfa<STATE> nfa, STATE state, Map<STATE, Integer> names, Wrapper<Integer> lastName) { Integer name = names.get(state); if (name != null) return new Node(String.valueOf(name), true); lastName.set(lastName.get() + 1); names.put(state, lastName.get()); Node node = new Node(String.valueOf(lastName.get()), false); for (STATE follower : nfa.getFollowers(state)) node.children.add(createNodes(nfa, follower, names, lastName)); return node; }
@Test public void testMergeIntoCommaSeparatedList() throws Exception { LinkedHashSet<String> toMerge = new LinkedHashSet<String>(); toMerge.add("foo"); toMerge.add("bar"); toMerge.add("baz"); assertEquals("bar,foo,baz", removeWS(MergeableManifest.mergeIntoCommaSeparatedList("bar", toMerge, Wrapper.wrap(false), NL))); assertEquals("bar,x,foo,baz", removeWS(MergeableManifest.mergeIntoCommaSeparatedList("bar , x", toMerge, Wrapper.wrap(false), NL))); assertEquals("baz,bar,foo", removeWS(MergeableManifest.mergeIntoCommaSeparatedList("baz,bar,foo", toMerge, Wrapper.wrap(false), NL))); assertEquals("foo,bar,baz", removeWS(MergeableManifest.mergeIntoCommaSeparatedList("", toMerge, Wrapper.wrap(false), NL))); assertEquals("foo,bar,baz", removeWS(MergeableManifest.mergeIntoCommaSeparatedList(null, toMerge, Wrapper.wrap(false), NL))); }
@Test public void testMergeIntoCommaSeparatedListWithParams() throws Exception { LinkedHashSet<String> toMerge = new LinkedHashSet<String>(); toMerge.add("foo"); toMerge.add("bar"); toMerge.add("baz"); assertEquals("bar;version=\"0.7.0\",foo,baz", removeWS(MergeableManifest.mergeIntoCommaSeparatedList( "bar;version=\"0.7.0\"", toMerge, Wrapper.wrap(false), NL))); assertEquals("bar;special=foo,x,foo,baz", removeWS(MergeableManifest.mergeIntoCommaSeparatedList( "bar;special=foo , x", toMerge, Wrapper.wrap(false), NL))); }
@Test public void testMergeIntoCommaSeparatedListWithCommaSeparatedParams() throws Exception { LinkedHashSet<String> toMerge = new LinkedHashSet<String>(); toMerge.add("foo"); toMerge.add("bar"); toMerge.add("baz"); assertEquals("bar;x-friends=\"xxx,foo,bar,zzz\",foo,baz", removeWS(MergeableManifest.mergeIntoCommaSeparatedList( "bar;x-friends=\"xxx,foo,bar,zzz\"", toMerge, Wrapper.wrap(false), NL))); }
@Test public void testUnloadReferables() throws Exception { resource.reparse(simpleModel); final Wrapper<Boolean> unloaded = Wrapper.wrap(Boolean.FALSE); resource.setUnloader(new IReferableElementsUnloader() { @Override public void unloadRoot(EObject root) { unloaded.set(Boolean.TRUE); } }); resource.reparse(simpleModel); assertTrue("unloaded", unloaded.get()); }
@Override public boolean isRecursive() { if ((this.recursive == null)) { this.recursive = Wrapper.<Boolean>wrap(Boolean.valueOf(this.internalIsRecursive())); } return (this.recursive.get()).booleanValue(); }
public FactoryImpl(final Wrapper<Boolean> isSaving) { super(); this.isSaving = isSaving; }
protected void writeGrammar() { final Wrapper<Boolean> isSaving = Wrapper.<Boolean>wrap(Boolean.valueOf(false)); final ResourceSet cloneInto = new ResourceSetImpl(); Map<String, Object> _extensionToFactoryMap = cloneInto.getResourceFactoryRegistry().getExtensionToFactoryMap(); FragmentFakingEcoreResource.FactoryImpl _factoryImpl = new FragmentFakingEcoreResource.FactoryImpl(isSaving); _extensionToFactoryMap.put( FragmentFakingEcoreResource.FactoryImpl.ECORE_SUFFIX, _factoryImpl); final ResourceSet resourceSet = EcoreUtil2.<ResourceSet>clone(cloneInto, this.getLanguage().getGrammar().eResource().getResourceSet()); EObject _head = IterableExtensions.<EObject>head(resourceSet.getResource(this.getLanguage().getGrammar().eResource().getURI(), true).getContents()); final Grammar copy = ((Grammar) _head); String _xifexpression = null; if ((this.xmlVersion == null)) { _xifexpression = GrammarUtil.getClasspathRelativePathToBinGrammar(copy); } else { String _xblockexpression = null; { String _simpleName = GrammarAccessFragment2.class.getSimpleName(); String _plus = ("The property \'xmlVersion\' has been specified for this " + _simpleName); String _plus_1 = (_plus + ". Therefore, the grammar is persisted as XMI and not as binary. This can be a performance drawback."); GrammarAccessFragment2.LOG.warn(_plus_1); _xblockexpression = GrammarUtil.getClasspathRelativePathToXmi(copy); } _xifexpression = _xblockexpression; } final String path = _xifexpression; final URI uri = this.getProjectConfig().getRuntime().getSrcGen().getURI(path); final Resource resource = resourceSet.createResource(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE); HashSet<Grammar> _hashSet = new HashSet<Grammar>(); this.addAllGrammarsToResource(resource, copy, _hashSet); isSaving.set(Boolean.valueOf(true)); final Map<String, Object> saveOptions = CollectionLiterals.<String, Object>newHashMap(); if ((resource instanceof XMLResource)) { String _elvis = null; if (this.xmlVersion != null) { _elvis = this.xmlVersion; } else { _elvis = "1.0"; } ((XMLResource)resource).setXMLVersion(_elvis); } else { if ((resource instanceof BinaryResourceImpl)) { saveOptions.put(BinaryResourceImpl.OPTION_VERSION, BinaryResourceImpl.BinaryIO.Version.VERSION_1_1); saveOptions.put(BinaryResourceImpl.OPTION_STYLE_DATA_CONVERTER, Boolean.valueOf(true)); } } try { resource.save(saveOptions); } catch (final Throwable _t) { if (_t instanceof IOException) { final IOException e = (IOException)_t; GrammarAccessFragment2.LOG.error(e.getMessage(), e); } else { throw Exceptions.sneakyThrow(_t); } } finally { isSaving.set(Boolean.valueOf(false)); } }
@Test public void testMergeIntoCommaSeparatedListValidParam() throws Exception { LinkedHashSet<String> toMerge = new LinkedHashSet<String>(); toMerge.add("foo;foo=version"); assertEquals("bar,foo;foo=version", removeWS(MergeableManifest.mergeIntoCommaSeparatedList( "bar", toMerge, Wrapper.wrap(false), NL))); }
@Test public void testMergeIntoCommaSeparatedListSkipWhenParamExists() throws Exception { LinkedHashSet<String> toMerge = new LinkedHashSet<String>(); toMerge.add("foo;foo=other"); assertEquals("foo;version=\"0.7.0\"", removeWS(MergeableManifest.mergeIntoCommaSeparatedList( "foo;version=\"0.7.0\"", toMerge, Wrapper.wrap(false), NL))); }
@Test public void testMergeIntoCommaSeparatedListAddParam() throws Exception { LinkedHashSet<String> toMerge = new LinkedHashSet<String>(); toMerge.add("foo;version=\"0.7.0\""); assertEquals("foo;version=\"0.7.0\"", removeWS(MergeableManifest.mergeIntoCommaSeparatedList( "foo", toMerge, Wrapper.wrap(false), NL))); }