Search in sources :

Example 21 with URI

use of org.eclipse.emf.common.util.URI in project xtext-xtend by eclipse.

the class XtendReferenceFinder method addReferenceIfTarget.

protected void addReferenceIfTarget(final EObject candidate, final Predicate<URI> targetURISet, final EObject sourceElement, final EReference reference, final IReferenceFinder.Acceptor acceptor) {
    final URI candidateURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(candidate);
    boolean _apply = targetURISet.apply(candidateURI);
    if (_apply) {
        final URI sourceURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(sourceElement);
        acceptor.accept(sourceElement, sourceURI, reference, (-1), candidate, candidateURI);
    }
}
Also used : URI(org.eclipse.emf.common.util.URI)

Example 22 with URI

use of org.eclipse.emf.common.util.URI in project xtext-xtend by eclipse.

the class AbstractFileSystemSupport method getURI.

protected URI getURI(final Path path) {
    if (((path == null) || Objects.equal(path, Path.ROOT))) {
        return null;
    }
    final IProjectConfig projectConfig = this.projectConfigProvider.getProjectConfig(this.context);
    if ((projectConfig == null)) {
        return null;
    }
    final URI projectURI = projectConfig.getPath();
    final String projectName = IterableExtensions.<String>head(path.getSegments());
    String _name = projectConfig.getName();
    boolean _notEquals = (!Objects.equal(projectName, _name));
    if (_notEquals) {
        return null;
    }
    final Iterable<String> segments = IterableExtensions.<String>tail(path.getSegments());
    boolean _isEmpty = IterableExtensions.isEmpty(segments);
    if (_isEmpty) {
        return projectURI;
    }
    final URI relativeURI = URI.createURI(IterableExtensions.<String>head(segments)).appendSegments(((String[]) Conversions.unwrapArray(IterableExtensions.<String>tail(segments), String.class)));
    final URI uri = relativeURI.resolve(projectURI);
    Boolean _isFolder = this.isFolder(uri);
    if ((_isFolder).booleanValue()) {
        return UriUtil.toFolderURI(uri);
    }
    return uri;
}
Also used : IProjectConfig(org.eclipse.xtext.workspace.IProjectConfig) URI(org.eclipse.emf.common.util.URI)

Example 23 with URI

use of org.eclipse.emf.common.util.URI in project xtext-xtend by eclipse.

the class AbstractFileSystemSupport method setContents.

@Override
public void setContents(final Path path, final CharSequence contents) {
    final URI uri = this.getURI(path);
    if ((uri == null)) {
        throw new IllegalArgumentException(("The file cannot be found: " + path));
    }
    CharSequence _elvis = null;
    CharSequence _postProcess = null;
    if (this.postProcessor != null) {
        _postProcess = this.postProcessor.postProcess(uri, contents);
    }
    if (_postProcess != null) {
        _elvis = _postProcess;
    } else {
        _elvis = contents;
    }
    final CharSequence processedContents = _elvis;
    try {
        String _string = processedContents.toString();
        String _charset = this.getCharset(path);
        StringInputStream _stringInputStream = new StringInputStream(_string, _charset);
        this.setContentsAsStream(path, _stringInputStream);
    } catch (final Throwable _t) {
        if (_t instanceof UnsupportedEncodingException) {
            final UnsupportedEncodingException exc = (UnsupportedEncodingException) _t;
            String _message = exc.getMessage();
            throw new IllegalArgumentException(_message, exc);
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URI(org.eclipse.emf.common.util.URI)

Example 24 with URI

use of org.eclipse.emf.common.util.URI in project xtext-xtend by eclipse.

the class XAnnotationExtensions method isProcessed.

/**
 * Checks whether this annotation is pointing to a processed annotation, without resolving the proxy
 */
public boolean isProcessed(final XAnnotation it) {
    Object _eGet = it.eGet(XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, false);
    final Object proxy = _eGet;
    boolean _matched = false;
    if (proxy instanceof EObject) {
        boolean _eIsProxy = ((EObject) proxy).eIsProxy();
        if (_eIsProxy) {
            _matched = true;
            final URI uri = ((InternalEObject) proxy).eProxyURI();
            boolean _isCrossLinkFragment = this.encoder.isCrossLinkFragment(it.eResource(), uri.fragment());
            if (_isCrossLinkFragment) {
                final Triple<EObject, EReference, INode> triple = this.encoder.decode(it.eResource(), uri.fragment());
                final List<EObject> candidates = this.linkingService.getLinkedObjects(triple.getFirst(), triple.getSecond(), triple.getThird());
                boolean _isEmpty = candidates.isEmpty();
                boolean _not = (!_isEmpty);
                if (_not) {
                    final EObject head = IterableExtensions.<EObject>head(candidates);
                    if ((head instanceof JvmAnnotationType)) {
                        return this.isActiveAnnotation(((JvmAnnotationType) head));
                    }
                }
            }
        }
    }
    if (!_matched) {
        if (proxy instanceof JvmAnnotationType) {
            _matched = true;
            return this.isActiveAnnotation(((JvmAnnotationType) proxy));
        }
    }
    return false;
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) INode(org.eclipse.xtext.nodemodel.INode) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) URI(org.eclipse.emf.common.util.URI) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EReference(org.eclipse.emf.ecore.EReference)

Example 25 with URI

use of org.eclipse.emf.common.util.URI in project xtext-xtend by eclipse.

the class XtendBatchCompiler method createIssueMessage.

private StringBuilder createIssueMessage(Issue issue) {
    StringBuilder issueBuilder = new StringBuilder("\n");
    issueBuilder.append(issue.getSeverity()).append(": \t");
    URI uriToProblem = issue.getUriToProblem();
    if (uriToProblem != null) {
        URI resourceUri = uriToProblem.trimFragment();
        issueBuilder.append(resourceUri.lastSegment()).append(" - ");
        if (resourceUri.isFile()) {
            issueBuilder.append(resourceUri.toFileString());
        }
    }
    issueBuilder.append("\n").append(issue.getLineNumber()).append(": ").append(issue.getMessage());
    return issueBuilder;
}
Also used : URI(org.eclipse.emf.common.util.URI)

Aggregations

URI (org.eclipse.emf.common.util.URI)305 Resource (org.eclipse.emf.ecore.resource.Resource)85 Test (org.junit.Test)79 EObject (org.eclipse.emf.ecore.EObject)55 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)37 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)33 XtextResource (org.eclipse.xtext.resource.XtextResource)32 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)26 BuildRequest (org.eclipse.xtext.build.BuildRequest)23 File (java.io.File)20 AbstractIncrementalBuilderTest (org.eclipse.xtext.testing.builder.AbstractIncrementalBuilderTest)20 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)19 IOException (java.io.IOException)18 InternalEObject (org.eclipse.emf.ecore.InternalEObject)18 EPackage (org.eclipse.emf.ecore.EPackage)15 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)15 InputStream (java.io.InputStream)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ArrayList (java.util.ArrayList)13 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13