org.eclipse.xtext.xbase.resource.BatchLinkableResource Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.resource.BatchLinkableResource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Bug462047Test.java From xtext-eclipse with Eclipse Public License 2.0 | 7 votes |
@Test public void testNoErrors() throws Exception { IResourcesSetupUtil.createFile("bug462047/src/a.bug462047lang", "element CORE ref CORE.b"); IFile file = IResourcesSetupUtil.createFile("bug462047/src/b.bug462047lang", "element b ref CORE.c"); IResourcesSetupUtil.createFile("bug462047/src/c.bug462047lang", "element c"); IResourcesSetupUtil.waitForBuild(); IResourcesSetupUtil.assertNoErrorsInWorkspace(); LoggingTester.captureLogging(Level.ERROR, BatchLinkableResource.class, ()-> { try { XtextEditor editor = openEditor(file); IXtextDocument document = editor.getDocument(); document.readOnly((XtextResource res)->{ EcoreUtil.resolveAll(res); ResourceSet resourceSet = res.getResourceSet(); assertNull(resourceSet.getResource(URI.createURI("java:/Objects/CORE.CORE"), false)); return null; }); } catch (Exception e) { throw new RuntimeException(e); } }).assertNoLogEntries(); }
Example #2
Source File: ResourceStorageTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test(expected = IOException.class) public void testFailedWrite() throws Exception { final XtendFile file = this.file("class C{}"); ByteArrayOutputStream _byteArrayOutputStream = new ByteArrayOutputStream(); Resource _eResource = file.eResource(); new BatchLinkableResourceStorageWritable(_byteArrayOutputStream, false) { @Override protected void writeAssociationsAdapter(final BatchLinkableResource resource, final OutputStream zipOut) throws IOException { final Function1<Adapter, Boolean> _function = (Adapter it) -> { return Boolean.valueOf((it instanceof JvmModelAssociator.Adapter)); }; final Adapter removeMe = IterableExtensions.<Adapter>findFirst(resource.eAdapters(), _function); Assert.assertTrue(resource.eAdapters().remove(removeMe)); super.writeAssociationsAdapter(resource, zipOut); } }.writeResource(((StorageAwareResource) _eResource)); }
Example #3
Source File: XClosureImplCustom.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
private void ensureLinked() { if (!linked) { Resource resource = eResource(); if (resource != null) { if (resource instanceof BatchLinkableResource) { ((BatchLinkableResource) resource).resolveLazyCrossReferences(null); } else { EcoreUtil.resolveAll(resource); } linked = true; } } }
Example #4
Source File: BatchLinkableResourceStorageLoadable.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected void loadEntries(final StorageAwareResource resource, final ZipInputStream zipIn) throws IOException { super.loadEntries(resource, zipIn); if ((resource instanceof BatchLinkableResource)) { this.readAssociationsAdapter(((BatchLinkableResource)resource), zipIn); } }
Example #5
Source File: BatchLinkableResourceStorageWritable.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected void writeEntries(final StorageAwareResource resource, final ZipOutputStream zipOut) throws IOException { super.writeEntries(resource, zipOut); if ((resource instanceof BatchLinkableResource)) { ZipEntry _zipEntry = new ZipEntry("associations"); zipOut.putNextEntry(_zipEntry); final BufferedOutputStream buffOut = new BufferedOutputStream(zipOut); try { this.writeAssociationsAdapter(((BatchLinkableResource)resource), buffOut); } finally { buffOut.flush(); zipOut.closeEntry(); } } }
Example #6
Source File: BeforeLinkingTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testImplicitLambdaParameter() throws Exception { XBlockExpression block = (XBlockExpression) parseHelper.parse("{ val Comparable<String> c = [ length ] c.toString } "); BatchLinkableResource resource = (BatchLinkableResource) block.eResource(); resource.resolveLazyCrossReferences(null); XVariableDeclaration assignment = (XVariableDeclaration) Iterables.getFirst(block.getExpressions(), null); XClosure lambda = (XClosure) assignment.getRight(); JvmFormalParameter implicitParameter = Iterables.getFirst(lambda.getImplicitFormalParameters(), null); Assert.assertEquals("String", implicitParameter.getParameterType().getSimpleName()); resource.update(0, 0, ""); Assert.assertNull(implicitParameter.eResource()); }
Example #7
Source File: BeforeLinkingTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testImplicitReceiver() throws Exception { XBlockExpression block = (XBlockExpression) parseHelper.parse("{ val it = \'\' toString }"); BatchLinkableResource resource = (BatchLinkableResource) block.eResource(); XFeatureCall toString = (XFeatureCall) Iterables.getLast(block.getExpressions(), null); XFeatureCall implicitReceiver = (XFeatureCall) toString.getImplicitReceiver(); Assert.assertEquals("it", implicitReceiver.getFeature().getSimpleName()); resource.update(0, 0, ""); Assert.assertNull(reflectExtensions.get(toString, "implicitReceiver")); Assert.assertNotNull(toString.getImplicitReceiver()); }
Example #8
Source File: BeforeLinkingTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testImplicitFirstArgument() throws Exception { XBlockExpression block = (XBlockExpression) parseHelper.parse("{ val it = newArrayList unmodifiableView }"); BatchLinkableResource resource = (BatchLinkableResource) block.eResource(); XFeatureCall unmodifiableView = (XFeatureCall) Iterables.getLast(block.getExpressions(), null); XFeatureCall implicitFirstArgument = (XFeatureCall) unmodifiableView.getImplicitFirstArgument(); Assert.assertEquals("it", implicitFirstArgument.getFeature().getSimpleName()); resource.update(0, 0, ""); Assert.assertNull(reflectExtensions.get(unmodifiableView, "implicitFirstArgument")); Assert.assertNotNull(unmodifiableView.getImplicitFirstArgument()); }
Example #9
Source File: ConstantExpressionsInterpreterTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testNonConstant() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("class C { "); _builder.newLine(); _builder.append("\t"); _builder.append("public static final Class<?> REF = D.testFoo;"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.newLine(); _builder.append("class D {"); _builder.newLine(); _builder.append("\t"); _builder.append("public static final Class<?> testFoo = Object"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final XtendFile file = this.file(_builder.toString()); Resource _eResource = file.eResource(); ((BatchLinkableResource) _eResource).resolveLazyCrossReferences(null); final XtendField field = IterableExtensions.<XtendField>head(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class)); try { this.interpreter.evaluate(field.getInitialValue(), field.getType()); Assert.fail("exception expected"); } catch (final Throwable _t) { if (_t instanceof ConstantExpressionEvaluationException) { } else { throw Exceptions.sneakyThrow(_t); } } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #10
Source File: XtendBatchCompiler.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.8 */ protected boolean isSourceFile(Resource resource) { if (resource instanceof BatchLinkableResource) { return !((BatchLinkableResource) resource).isLoadedFromStorage(); } return false; }
Example #11
Source File: SarlBatchCompiler.java From sarl with Apache License 2.0 | 5 votes |
/** Change the loggers that are internally used by Xtext. */ protected void overrideXtextInternalLoggers() { final Logger logger = getLogger(); final org.apache.log4j.spi.LoggerFactory factory = new InternalXtextLoggerFactory(logger); final org.apache.log4j.Logger internalLogger = org.apache.log4j.Logger.getLogger( MessageFormat.format(Messages.SarlBatchCompiler_40, logger.getName()), factory); setStaticField(BatchLinkableResourceStorageWritable.class, "LOG", internalLogger); //$NON-NLS-1$ setStaticField(BatchLinkableResource.class, "log", internalLogger); //$NON-NLS-1$ setStaticField(ProcessorInstanceForJvmTypeProvider.class, "logger", internalLogger); //$NON-NLS-1$ }
Example #12
Source File: SarlBatchCompiler.java From sarl with Apache License 2.0 | 5 votes |
/** Replies if the given resource is a script. * * @param resource the resource to test. * @return <code>true</code> if the given resource is a script. */ @SuppressWarnings("static-method") protected boolean isSourceFile(Resource resource) { if (resource instanceof BatchLinkableResource) { return !((BatchLinkableResource) resource).isLoadedFromStorage(); } return false; }
Example #13
Source File: DefaultXbaseRuntimeModule.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override public Class<? extends XtextResource> bindXtextResource() { return BatchLinkableResource.class; }