mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 08:18:55 +00:00
[eclipse/xtext#1679] Refactor more Xtend to java.
Signed-off-by: Arne Deutsch <Arne.Deutsch@itemis.de>
This commit is contained in:
parent
0fd063d73b
commit
9f4bf0fb16
30 changed files with 1163 additions and 2357 deletions
|
@ -0,0 +1,108 @@
|
|||
/**
|
||||
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.findReferences;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.EReference;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.xtext.EcoreUtil2;
|
||||
import org.eclipse.xtext.resource.IEObjectDescription;
|
||||
import org.eclipse.xtext.resource.IReferenceDescription;
|
||||
import org.eclipse.xtext.resource.IResourceServiceProvider;
|
||||
import org.eclipse.xtext.resource.impl.DefaultReferenceDescription;
|
||||
import org.eclipse.xtext.util.IAcceptor;
|
||||
|
||||
/**
|
||||
* For local references, populates an {@link IReferenceDescription} that knows its exported container URI.
|
||||
*
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
* @author kosyakov - Pulled up to the runtime project
|
||||
*/
|
||||
public class ReferenceAcceptor implements IReferenceFinder.Acceptor {
|
||||
private final IResourceServiceProvider.Registry resourceServiceProviderRegistry;
|
||||
|
||||
private final IAcceptor<IReferenceDescription> delegate;
|
||||
|
||||
private Resource currentResource;
|
||||
|
||||
private Map<EObject, URI> exportedContainersInCurrentResource;
|
||||
|
||||
public ReferenceAcceptor(IResourceServiceProvider.Registry resourceServiceProviderRegistry,
|
||||
IAcceptor<IReferenceDescription> delegate) {
|
||||
this.resourceServiceProviderRegistry = resourceServiceProviderRegistry;
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(EObject source, URI sourceURI, EReference eReference, int index, EObject targetOrProxy,
|
||||
URI targetURI) {
|
||||
if (currentResource == null || source.eResource() != currentResource) {
|
||||
computeExportedObjectsMap(source);
|
||||
currentResource = source.eResource();
|
||||
}
|
||||
accept(createReferenceDescription(EcoreUtil2.getFragmentPathURI(source), targetURI, eReference, index,
|
||||
findExportedContainer(source)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(IReferenceDescription description) {
|
||||
delegate.accept(description);
|
||||
}
|
||||
|
||||
protected void computeExportedObjectsMap(EObject source) {
|
||||
Resource resource = source.eResource();
|
||||
IResourceServiceProvider resourceServiceProvider = resourceServiceProviderRegistry
|
||||
.getResourceServiceProvider(resource.getURI());
|
||||
if (resourceServiceProvider != null) {
|
||||
exportedContainersInCurrentResource = new HashMap<>();
|
||||
Iterable<IEObjectDescription> exportedObjects = resourceServiceProvider.getResourceDescriptionManager()
|
||||
.getResourceDescription(resource).getExportedObjects();
|
||||
for (IEObjectDescription description : exportedObjects) {
|
||||
EObject instance = description.getEObjectOrProxy();
|
||||
if (instance.eIsProxy()) {
|
||||
instance = resource.getEObject(description.getEObjectURI().fragment());
|
||||
}
|
||||
exportedContainersInCurrentResource.put(instance, description.getEObjectURI());
|
||||
}
|
||||
} else {
|
||||
exportedContainersInCurrentResource = Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
||||
protected URI findExportedContainer(EObject obj) {
|
||||
if (exportedContainersInCurrentResource.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
EObject source = obj;
|
||||
URI result = exportedContainersInCurrentResource.get(source);
|
||||
while (result == null) {
|
||||
if (exportedContainersInCurrentResource.containsKey(source)) {
|
||||
return result;
|
||||
}
|
||||
source = source.eContainer();
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
result = exportedContainersInCurrentResource.get(source);
|
||||
}
|
||||
exportedContainersInCurrentResource.put(source, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected IReferenceDescription createReferenceDescription(URI sourceURI, URI targetURI, EReference eReference,
|
||||
int index, URI containerURI) {
|
||||
return new DefaultReferenceDescription(sourceURI, targetURI, eReference, index, containerURI);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.findReferences
|
||||
|
||||
import java.util.Map
|
||||
import org.eclipse.emf.common.util.URI
|
||||
import org.eclipse.emf.ecore.EObject
|
||||
import org.eclipse.emf.ecore.EReference
|
||||
import org.eclipse.emf.ecore.resource.Resource
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
|
||||
import org.eclipse.xtext.resource.IReferenceDescription
|
||||
import org.eclipse.xtext.resource.IResourceServiceProvider
|
||||
import org.eclipse.xtext.resource.impl.DefaultReferenceDescription
|
||||
import org.eclipse.xtext.util.IAcceptor
|
||||
import org.eclipse.xtext.EcoreUtil2
|
||||
|
||||
/**
|
||||
* For local references, populates an {@link IReferenceDescription} that knows its exported container URI.
|
||||
*
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
* @author kosyakov - Pulled up to the runtime project
|
||||
*/
|
||||
@FinalFieldsConstructor
|
||||
class ReferenceAcceptor implements IReferenceFinder.Acceptor {
|
||||
|
||||
val IResourceServiceProvider.Registry resourceServiceProviderRegistry
|
||||
val IAcceptor<IReferenceDescription> delegate
|
||||
|
||||
Resource currentResource
|
||||
Map<EObject, URI> exportedContainersInCurrentResource
|
||||
|
||||
override void accept(
|
||||
EObject source,
|
||||
URI sourceURI,
|
||||
EReference eReference,
|
||||
int index,
|
||||
EObject targetOrProxy,
|
||||
URI targetURI
|
||||
) {
|
||||
if (currentResource === null || source.eResource() !== currentResource) {
|
||||
computeExportedObjectsMap(source)
|
||||
currentResource = source.eResource()
|
||||
}
|
||||
accept(createReferenceDescription(EcoreUtil2.getFragmentPathURI(source), targetURI, eReference, index, findExportedContainer(source)))
|
||||
}
|
||||
|
||||
protected def void computeExportedObjectsMap(EObject source) {
|
||||
val resource = source.eResource
|
||||
val resourceServiceProvider = resourceServiceProviderRegistry.getResourceServiceProvider(resource.URI)
|
||||
if (resourceServiceProvider !== null) {
|
||||
val resourceDescription = resourceServiceProvider.resourceDescriptionManager.getResourceDescription(resource)
|
||||
exportedContainersInCurrentResource = newHashMap
|
||||
for (description : resourceDescription.exportedObjects) {
|
||||
var instance = description.EObjectOrProxy
|
||||
if (instance.eIsProxy) {
|
||||
instance = resource.getEObject(description.EObjectURI.fragment)
|
||||
}
|
||||
exportedContainersInCurrentResource.put(instance, description.EObjectURI)
|
||||
}
|
||||
} else {
|
||||
exportedContainersInCurrentResource = emptyMap
|
||||
}
|
||||
}
|
||||
|
||||
protected def URI findExportedContainer(EObject obj) {
|
||||
var source = obj
|
||||
if (exportedContainersInCurrentResource.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
var result = exportedContainersInCurrentResource.get(source)
|
||||
while (result === null) {
|
||||
if (exportedContainersInCurrentResource.containsKey(source)) {
|
||||
return result
|
||||
}
|
||||
source = source.eContainer
|
||||
if (source === null) {
|
||||
return null
|
||||
}
|
||||
result = exportedContainersInCurrentResource.get(source)
|
||||
}
|
||||
exportedContainersInCurrentResource.put(source, result)
|
||||
return result
|
||||
}
|
||||
|
||||
override void accept(IReferenceDescription description) {
|
||||
this.delegate.accept(description)
|
||||
}
|
||||
|
||||
protected def IReferenceDescription createReferenceDescription(
|
||||
URI sourceURI,
|
||||
URI targetURI,
|
||||
EReference eReference,
|
||||
int index,
|
||||
URI containerURI
|
||||
) {
|
||||
return new DefaultReferenceDescription(sourceURI, targetURI, eReference, index, containerURI)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.generator;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.emf.common.notify.impl.AdapterImpl;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
|
||||
/**
|
||||
* @author Anton Kosyakov
|
||||
* @since 2.7
|
||||
*/
|
||||
public class FileSystemAccessQueue extends AdapterImpl {
|
||||
private final BlockingQueue<FileSystemAccessRequest> requestQueue;
|
||||
|
||||
private final IProgressMonitor monitor;
|
||||
|
||||
/**
|
||||
* @since 2.8
|
||||
*/
|
||||
public FileSystemAccessQueue(BlockingQueue<FileSystemAccessRequest> requestQueue, IProgressMonitor monitor) {
|
||||
this.requestQueue = requestQueue;
|
||||
this.monitor = monitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.9
|
||||
*/
|
||||
public void sendAsync(URI uri, Runnable runMe) {
|
||||
send(new FileSystemAccessRequest(uri, runMe));
|
||||
}
|
||||
|
||||
protected FileSystemAccessRequest send(FileSystemAccessRequest request) {
|
||||
if (monitor.isCanceled())
|
||||
throw new OperationCanceledException();
|
||||
try {
|
||||
requestQueue.put(request);
|
||||
return request;
|
||||
} catch (InterruptedException t) {
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.14
|
||||
*/
|
||||
@Beta
|
||||
public void waitForEmptyQueue() {
|
||||
while (!this.requestQueue.isEmpty()) {
|
||||
Thread.yield();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
package org.eclipse.xtext.generator
|
||||
|
||||
import com.google.common.annotations.Beta
|
||||
import java.util.concurrent.BlockingQueue
|
||||
import org.eclipse.core.runtime.IProgressMonitor
|
||||
import org.eclipse.core.runtime.OperationCanceledException
|
||||
import org.eclipse.emf.common.notify.impl.AdapterImpl
|
||||
import org.eclipse.emf.common.util.URI
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
|
||||
|
||||
/**
|
||||
* @author Anton Kosyakov
|
||||
* @since 2.7
|
||||
*/
|
||||
class FileSystemAccessQueue extends AdapterImpl {
|
||||
|
||||
val BlockingQueue<FileSystemAccessRequest> requestQueue
|
||||
val IProgressMonitor monitor
|
||||
|
||||
/**
|
||||
* @since 2.8
|
||||
*/
|
||||
@FinalFieldsConstructor
|
||||
new() {}
|
||||
|
||||
/**
|
||||
* @since 2.9
|
||||
*/
|
||||
def void sendAsync(URI uri, Runnable runMe) {
|
||||
send(new FileSystemAccessRequest(uri, runMe))
|
||||
}
|
||||
|
||||
protected def send(FileSystemAccessRequest request) {
|
||||
try {
|
||||
if (monitor.isCanceled) {
|
||||
throw new OperationCanceledException
|
||||
}
|
||||
requestQueue.put(request)
|
||||
return request
|
||||
} catch (InterruptedException e) {
|
||||
throw new OperationCanceledException
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.14
|
||||
*/
|
||||
@Beta
|
||||
def void waitForEmptyQueue() {
|
||||
while (!requestQueue.isEmpty) {
|
||||
Thread.yield
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Anton Kosyakov
|
||||
* @since 2.7
|
||||
*/
|
||||
class FileSystemAccessRequest implements Runnable {
|
||||
val URI uri
|
||||
val Runnable runMe
|
||||
|
||||
/**
|
||||
* @since 2.9
|
||||
*/
|
||||
@FinalFieldsConstructor
|
||||
new() {}
|
||||
|
||||
/**
|
||||
* @since 2.8
|
||||
*/
|
||||
@Pure
|
||||
def getUri() {
|
||||
return uri
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.9
|
||||
*/
|
||||
override run() {
|
||||
runMe.run
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.generator;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
|
||||
/**
|
||||
* @author Anton Kosyakov
|
||||
* @since 2.7
|
||||
*/
|
||||
public class FileSystemAccessRequest implements Runnable {
|
||||
private final URI uri;
|
||||
private final Runnable runMe;
|
||||
|
||||
/**
|
||||
* @since 2.9
|
||||
*/
|
||||
public FileSystemAccessRequest(URI uri, Runnable runMe) {
|
||||
this.uri = uri;
|
||||
this.runMe = runMe;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.8
|
||||
*/
|
||||
public URI getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.9
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
runMe.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FileSystemAccessRequest [uri=" + uri + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Copyright (c) 2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator;
|
||||
|
||||
import org.eclipse.xtext.util.CancelIndicator;
|
||||
|
||||
/**
|
||||
* @since 2.9
|
||||
*/
|
||||
public class GeneratorContext implements IGeneratorContext {
|
||||
private CancelIndicator cancelIndicator;
|
||||
|
||||
public CancelIndicator getCancelIndicator() {
|
||||
return cancelIndicator;
|
||||
}
|
||||
|
||||
public void setCancelIndicator(CancelIndicator cancelIndicator) {
|
||||
this.cancelIndicator = cancelIndicator;
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.generator
|
||||
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtext.util.CancelIndicator
|
||||
|
||||
/**
|
||||
* @since 2.9
|
||||
*/
|
||||
@Accessors
|
||||
class GeneratorContext implements IGeneratorContext {
|
||||
CancelIndicator cancelIndicator
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* Copyright (c) 2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator;
|
||||
|
||||
import static org.eclipse.xtext.xbase.lib.IterableExtensions.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.xtext.diagnostics.Severity;
|
||||
import org.eclipse.xtext.util.CancelIndicator;
|
||||
import org.eclipse.xtext.validation.CheckMode;
|
||||
import org.eclipse.xtext.validation.IResourceValidator;
|
||||
import org.eclipse.xtext.validation.Issue;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.inject.ImplementedBy;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
*
|
||||
* @since 2.9
|
||||
*/
|
||||
@Beta
|
||||
@ImplementedBy(IShouldGenerate.OnlyWithoutErrors.class)
|
||||
public interface IShouldGenerate {
|
||||
@Beta
|
||||
@Singleton
|
||||
class OnlyWithoutErrors implements IShouldGenerate {
|
||||
@Inject
|
||||
private IResourceValidator resourceValidator;
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerate(Resource resource, CancelIndicator cancelIndicator) {
|
||||
if (!resource.getErrors().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
List<Issue> issues = resourceValidator.validate(resource, CheckMode.NORMAL_AND_FAST, cancelIndicator);
|
||||
return !exists(issues, (Issue issue) -> Objects.equal(issue.getSeverity(), Severity.ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
@Beta
|
||||
@Singleton
|
||||
class Always implements IShouldGenerate {
|
||||
@Override
|
||||
public boolean shouldGenerate(Resource resource, CancelIndicator cancelIndicator) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether code should be generated for this resource.
|
||||
*/
|
||||
boolean shouldGenerate(Resource resource, CancelIndicator cancelIndicator);
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.generator
|
||||
|
||||
import com.google.common.annotations.Beta
|
||||
import com.google.inject.ImplementedBy
|
||||
import com.google.inject.Inject
|
||||
import org.eclipse.emf.ecore.resource.Resource
|
||||
import org.eclipse.xtext.diagnostics.Severity
|
||||
import org.eclipse.xtext.util.CancelIndicator
|
||||
import org.eclipse.xtext.validation.CheckMode
|
||||
import org.eclipse.xtext.validation.IResourceValidator
|
||||
import com.google.inject.Singleton
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
*
|
||||
* @since 2.9
|
||||
*/
|
||||
@Beta
|
||||
@ImplementedBy(OnlyWithoutErrors)
|
||||
interface IShouldGenerate {
|
||||
|
||||
/**
|
||||
* whether code should be generated for this resource.
|
||||
*/
|
||||
def boolean shouldGenerate(Resource resource, CancelIndicator cancelIndicator);
|
||||
|
||||
@Beta
|
||||
@Singleton
|
||||
static class OnlyWithoutErrors implements IShouldGenerate {
|
||||
|
||||
@Inject IResourceValidator resourceValidator
|
||||
|
||||
override shouldGenerate(Resource resource, CancelIndicator cancelIndicator) {
|
||||
if (!resource.errors.isEmpty)
|
||||
return false
|
||||
val issues = resourceValidator.validate(resource, CheckMode.NORMAL_AND_FAST, cancelIndicator)
|
||||
return !issues.exists[severity == Severity.ERROR]
|
||||
}
|
||||
|
||||
}
|
||||
@Beta
|
||||
@Singleton
|
||||
static class Always implements IShouldGenerate {
|
||||
|
||||
override shouldGenerate(Resource resource, CancelIndicator cancelIndicator) {
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* Copyright (c) 2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.emf.common.notify.impl.AdapterImpl;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/**
|
||||
* @noreference
|
||||
*/
|
||||
public class OutputConfigurationAdapter extends AdapterImpl {
|
||||
private final Map<String, Set<OutputConfiguration>> outputConfigurationsPerLanguage;
|
||||
|
||||
public OutputConfigurationAdapter(Map<String, Set<OutputConfiguration>> outputConfigurationsPerLanguage) {
|
||||
Preconditions.checkNotNull(outputConfigurationsPerLanguage);
|
||||
this.outputConfigurationsPerLanguage = outputConfigurationsPerLanguage;
|
||||
}
|
||||
|
||||
public Map<String, Set<OutputConfiguration>> getOutputConfigurationsPerLanguage() {
|
||||
return outputConfigurationsPerLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdapterForType(Object type) {
|
||||
return OutputConfigurationAdapter.class.equals(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * 1 + outputConfigurationsPerLanguage.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
OutputConfigurationAdapter other = (OutputConfigurationAdapter) obj;
|
||||
if (!outputConfigurationsPerLanguage.equals(other.outputConfigurationsPerLanguage))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OutputConfigurationAdapter [outputConfigurationsPerLanguage=" + outputConfigurationsPerLanguage + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.generator
|
||||
|
||||
import java.util.Set
|
||||
import org.eclipse.emf.common.notify.impl.AdapterImpl
|
||||
import org.eclipse.xtend.lib.annotations.Data
|
||||
import java.util.Map
|
||||
|
||||
/**
|
||||
* @noreference
|
||||
*/
|
||||
@Data
|
||||
class OutputConfigurationAdapter extends AdapterImpl {
|
||||
Map<String, Set<OutputConfiguration>> outputConfigurationsPerLanguage
|
||||
|
||||
override isAdapterForType(Object type) {
|
||||
type == OutputConfigurationAdapter
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,222 @@
|
|||
/**
|
||||
* Copyright (c) 2015, 2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.resource.URIConverter;
|
||||
import org.eclipse.xtext.generator.trace.ITraceRegionProvider;
|
||||
import org.eclipse.xtext.generator.trace.TraceFileNameProvider;
|
||||
import org.eclipse.xtext.generator.trace.TraceNotFoundException;
|
||||
import org.eclipse.xtext.generator.trace.TraceRegionSerializer;
|
||||
import org.eclipse.xtext.parser.IEncodingProvider;
|
||||
import org.eclipse.xtext.util.RuntimeIOException;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.io.CharStreams;
|
||||
|
||||
/**
|
||||
* A file system access implementation that is based on EMF URIs and URIConverter
|
||||
*
|
||||
* @since 2.9
|
||||
*/
|
||||
public class URIBasedFileSystemAccess extends AbstractFileSystemAccess2 {
|
||||
public interface BeforeDelete {
|
||||
/**
|
||||
* @return <code>true</code> if the file can be deleted, false otherwise
|
||||
*/
|
||||
boolean beforeDelete(URI changed);
|
||||
}
|
||||
|
||||
public interface BeforeWrite {
|
||||
InputStream beforeWrite(URI changed, String outputCfgName, InputStream in);
|
||||
}
|
||||
|
||||
public interface BeforeRead {
|
||||
InputStream beforeRead(URI changed, InputStream in);
|
||||
}
|
||||
|
||||
private URIConverter converter;
|
||||
private URI baseDir;
|
||||
private boolean generateTraces = false;
|
||||
private IEncodingProvider encodingProvider = new IEncodingProvider.Runtime();
|
||||
private TraceRegionSerializer traceRegionSerializer;
|
||||
private TraceFileNameProvider traceFileNameProvider;
|
||||
private URIBasedFileSystemAccess.BeforeDelete beforeDelete = (uri) -> true;
|
||||
private URIBasedFileSystemAccess.BeforeWrite beforeWrite = (uri, string, stream) -> stream;
|
||||
private URIBasedFileSystemAccess.BeforeRead beforeRead = (uri, stream) -> stream;
|
||||
|
||||
@Override
|
||||
public void setPostProcessor(IFilePostProcessor filePostProcessor) {
|
||||
super.setPostProcessor(filePostProcessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getURI(String path, String outputConfiguration) {
|
||||
String outlet = getPathes().get(outputConfiguration);
|
||||
if (outlet == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"A slot with name \'" + outputConfiguration + "\' has not been configured.");
|
||||
}
|
||||
URI uri = URI.createFileURI(outlet + File.separator + path);
|
||||
return baseDir != null ? uri.resolve(baseDir) : uri;
|
||||
}
|
||||
|
||||
public String getEncoding(URI uri) {
|
||||
return encodingProvider.getEncoding(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateFile(String fileName, String outputCfgName, CharSequence contents) {
|
||||
try {
|
||||
URI uri = getURI(fileName, outputCfgName);
|
||||
if (!getOutputConfig(outputCfgName).isOverrideExistingResources()
|
||||
&& converter.exists(uri, Collections.emptyMap())) {
|
||||
return;
|
||||
}
|
||||
String encoding = getEncoding(uri);
|
||||
CharSequence postProcessed = postProcess(fileName, outputCfgName, contents, encoding);
|
||||
generateTrace(fileName, outputCfgName, postProcessed);
|
||||
generateFile(fileName, outputCfgName,
|
||||
new ByteArrayInputStream(postProcessed.toString().getBytes(encoding)));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateTrace(String generatedFile, String outputConfigName, CharSequence contents) {
|
||||
if (isGenerateTraces() && contents instanceof ITraceRegionProvider) {
|
||||
try {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
traceRegionSerializer.writeTraceRegionTo(((ITraceRegionProvider) contents).getTraceRegion(), out);
|
||||
generateFile(traceFileNameProvider.getTraceFromJava(generatedFile), outputConfigName,
|
||||
new ByteArrayInputStream(out.toByteArray()));
|
||||
} catch (TraceNotFoundException e) {
|
||||
// do not re-throw
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeIOException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateFile(String fileName, String outputCfgName, InputStream content) throws RuntimeIOException {
|
||||
try {
|
||||
URI uri = getURI(fileName, outputCfgName);
|
||||
try (OutputStream out = converter.createOutputStream(uri)) {
|
||||
ByteStreams.copy(beforeWrite.beforeWrite(uri, outputCfgName, content), out);
|
||||
}
|
||||
} catch (IOException t) {
|
||||
throw new RuntimeIOException(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream readBinaryFile(String fileName, String outputCfgName) throws RuntimeIOException {
|
||||
try {
|
||||
URI uri = getURI(fileName, outputCfgName);
|
||||
return beforeRead.beforeRead(uri, converter.createInputStream(uri));
|
||||
} catch (IOException t) {
|
||||
throw new RuntimeIOException(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence readTextFile(String fileName, String outputCfgName) throws RuntimeIOException {
|
||||
try {
|
||||
return CharStreams.toString(new InputStreamReader(readBinaryFile(fileName, outputCfgName),
|
||||
getEncoding(getURI(fileName, outputCfgName))));
|
||||
} catch (RuntimeIOException t) {
|
||||
throw t;
|
||||
} catch (IOException t) {
|
||||
throw new RuntimeIOException(t);
|
||||
}
|
||||
}
|
||||
|
||||
public URIConverter getConverter() {
|
||||
return converter;
|
||||
}
|
||||
|
||||
public void setConverter(URIConverter converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
public URI getBaseDir() {
|
||||
return baseDir;
|
||||
}
|
||||
|
||||
public void setBaseDir(URI baseDir) {
|
||||
this.baseDir = baseDir;
|
||||
}
|
||||
|
||||
public boolean isGenerateTraces() {
|
||||
return generateTraces;
|
||||
}
|
||||
|
||||
public void setGenerateTraces(boolean generateTraces) {
|
||||
this.generateTraces = generateTraces;
|
||||
}
|
||||
|
||||
public IEncodingProvider getEncodingProvider() {
|
||||
return encodingProvider;
|
||||
}
|
||||
|
||||
public void setEncodingProvider(IEncodingProvider encodingProvider) {
|
||||
this.encodingProvider = encodingProvider;
|
||||
}
|
||||
|
||||
public TraceRegionSerializer getTraceRegionSerializer() {
|
||||
return traceRegionSerializer;
|
||||
}
|
||||
|
||||
public void setTraceRegionSerializer(TraceRegionSerializer traceRegionSerializer) {
|
||||
this.traceRegionSerializer = traceRegionSerializer;
|
||||
}
|
||||
|
||||
public TraceFileNameProvider getTraceFileNameProvider() {
|
||||
return traceFileNameProvider;
|
||||
}
|
||||
|
||||
public void setTraceFileNameProvider(TraceFileNameProvider traceFileNameProvider) {
|
||||
this.traceFileNameProvider = traceFileNameProvider;
|
||||
}
|
||||
|
||||
public URIBasedFileSystemAccess.BeforeDelete getBeforeDelete() {
|
||||
return beforeDelete;
|
||||
}
|
||||
|
||||
public void setBeforeDelete(URIBasedFileSystemAccess.BeforeDelete beforeDelete) {
|
||||
this.beforeDelete = beforeDelete;
|
||||
}
|
||||
|
||||
public URIBasedFileSystemAccess.BeforeWrite getBeforeWrite() {
|
||||
return beforeWrite;
|
||||
}
|
||||
|
||||
public void setBeforeWrite(URIBasedFileSystemAccess.BeforeWrite beforeWrite) {
|
||||
this.beforeWrite = beforeWrite;
|
||||
}
|
||||
|
||||
public URIBasedFileSystemAccess.BeforeRead getBeforeRead() {
|
||||
return beforeRead;
|
||||
}
|
||||
|
||||
public void setBeforeRead(URIBasedFileSystemAccess.BeforeRead beforeRead) {
|
||||
this.beforeRead = beforeRead;
|
||||
}
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2017 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.generator
|
||||
|
||||
import com.google.common.io.ByteStreams
|
||||
import com.google.common.io.CharStreams
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.InputStream
|
||||
import java.io.InputStreamReader
|
||||
import org.eclipse.emf.common.util.URI
|
||||
import org.eclipse.emf.ecore.resource.URIConverter
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtext.generator.trace.AbstractTraceRegion
|
||||
import org.eclipse.xtext.generator.trace.ITraceRegionProvider
|
||||
import org.eclipse.xtext.generator.trace.TraceFileNameProvider
|
||||
import org.eclipse.xtext.generator.trace.TraceRegionSerializer
|
||||
import org.eclipse.xtext.parser.IEncodingProvider
|
||||
import org.eclipse.xtext.util.RuntimeIOException
|
||||
import org.eclipse.xtext.generator.trace.TraceNotFoundException
|
||||
|
||||
/**
|
||||
* A file system access implementation that is based on EMF URIs and URIConverter
|
||||
* @since 2.9
|
||||
*/
|
||||
class URIBasedFileSystemAccess extends AbstractFileSystemAccess2 {
|
||||
|
||||
static interface BeforeDelete {
|
||||
/**
|
||||
* @return <code>true</code> if the file can be deleted, false otherwise
|
||||
*/
|
||||
def boolean beforeDelete(URI changed)
|
||||
}
|
||||
|
||||
static interface BeforeWrite {
|
||||
def InputStream beforeWrite(URI changed, String outputCfgName, InputStream in)
|
||||
}
|
||||
|
||||
static interface BeforeRead {
|
||||
def InputStream beforeRead(URI changed, InputStream in)
|
||||
}
|
||||
|
||||
@Accessors URIConverter converter
|
||||
@Accessors URI baseDir
|
||||
@Accessors boolean generateTraces = false
|
||||
@Accessors IEncodingProvider encodingProvider = new IEncodingProvider.Runtime()
|
||||
@Accessors TraceRegionSerializer traceRegionSerializer
|
||||
@Accessors TraceFileNameProvider traceFileNameProvider
|
||||
@Accessors BeforeDelete beforeDelete = [true]
|
||||
@Accessors BeforeWrite beforeWrite = [$2]
|
||||
@Accessors BeforeRead beforeRead = [$1]
|
||||
|
||||
override void setPostProcessor(IFilePostProcessor filePostProcessor) {
|
||||
super.postProcessor = filePostProcessor
|
||||
}
|
||||
|
||||
override getURI(String path, String outputConfiguration) {
|
||||
val outlet = pathes.get(outputConfiguration)
|
||||
if (outlet === null)
|
||||
throw new IllegalArgumentException("A slot with name '" + outputConfiguration + "' has not been configured.");
|
||||
val uri = URI.createFileURI(outlet + File.separator + path)
|
||||
if (baseDir !== null) {
|
||||
val resolved = uri.resolve(baseDir);
|
||||
return resolved
|
||||
} else {
|
||||
return uri;
|
||||
}
|
||||
}
|
||||
|
||||
def String getEncoding(URI uri) {
|
||||
return encodingProvider.getEncoding(uri)
|
||||
}
|
||||
|
||||
override generateFile(String fileName, String outputCfgName, CharSequence contents) {
|
||||
val uri = getURI(fileName, outputCfgName)
|
||||
if (!getOutputConfig(outputCfgName).isOverrideExistingResources && converter.exists(uri, emptyMap)) {
|
||||
return;
|
||||
}
|
||||
val encoding = getEncoding(uri)
|
||||
val postProcessed = postProcess(fileName, outputCfgName, contents, encoding)
|
||||
generateTrace(fileName, outputCfgName, postProcessed)
|
||||
val inStream = new ByteArrayInputStream(postProcessed.toString.getBytes(encoding))
|
||||
generateFile(fileName, outputCfgName, inStream)
|
||||
}
|
||||
|
||||
protected def void generateTrace(String generatedFile, String outputConfigName, CharSequence contents) {
|
||||
if (isGenerateTraces && contents instanceof ITraceRegionProvider) {
|
||||
try {
|
||||
var AbstractTraceRegion traceRegion = (contents as ITraceRegionProvider).getTraceRegion()
|
||||
var String traceFileName = traceFileNameProvider.getTraceFromJava(generatedFile)
|
||||
val out = new ByteArrayOutputStream()
|
||||
traceRegionSerializer.writeTraceRegionTo(traceRegion, out)
|
||||
generateFile(traceFileName, outputConfigName, new ByteArrayInputStream(out.toByteArray))
|
||||
} catch (TraceNotFoundException e) {
|
||||
// ok
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override generateFile(String fileName, String outputCfgName, InputStream content) throws RuntimeIOException {
|
||||
val uri = getURI(fileName, outputCfgName)
|
||||
val out = converter.createOutputStream(uri)
|
||||
try {
|
||||
val processedContent = beforeWrite.beforeWrite(uri, outputCfgName, content)
|
||||
ByteStreams.copy(processedContent, out);
|
||||
} finally {
|
||||
out.close
|
||||
}
|
||||
}
|
||||
|
||||
override readBinaryFile(String fileName, String outputCfgName) throws RuntimeIOException {
|
||||
try {
|
||||
val uri = getURI(fileName, outputCfgName)
|
||||
val input = converter.createInputStream(uri)
|
||||
return beforeRead.beforeRead(uri, input)
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
override readTextFile(String fileName, String outputCfgName) throws RuntimeIOException {
|
||||
val uri = getURI(fileName, outputCfgName)
|
||||
val inputstream = readBinaryFile(fileName, outputCfgName)
|
||||
return CharStreams.toString(new InputStreamReader(inputstream, getEncoding(uri)))
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* Copyright (c) 2015-2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator.trace;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtext.workspace.IProjectConfig;
|
||||
import org.eclipse.xtext.workspace.ISourceFolder;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
* An absolute URI that allows to obtain a resource in a {@link IProjectConfig project}.
|
||||
*
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
public class AbsoluteURI extends AbstractURIWrapper {
|
||||
public AbsoluteURI(URI absoluteURI) {
|
||||
super(absoluteURI);
|
||||
if (absoluteURI.isRelative() || !absoluteURI.isHierarchical()) {
|
||||
throw new IllegalArgumentException(absoluteURI.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public AbsoluteURI(String absoluteURI) {
|
||||
this(URI.createURI(absoluteURI));
|
||||
}
|
||||
|
||||
public SourceRelativeURI deresolve(URI sourceFolderURI) {
|
||||
try {
|
||||
return new SourceRelativeURI(getURI().deresolve(sourceFolderURI));
|
||||
} catch (IllegalArgumentException t) {
|
||||
throw new IllegalArgumentException("Base URI was " + getURI(), t);
|
||||
}
|
||||
}
|
||||
|
||||
public SourceRelativeURI deresolve(ISourceFolder sourceFolder) {
|
||||
return deresolve(sourceFolder.getPath());
|
||||
}
|
||||
|
||||
public SourceRelativeURI deresolve(IProjectConfig projectConfig) {
|
||||
ISourceFolder sourceFolder = projectConfig.findSourceFolderContaining(getURI());
|
||||
return sourceFolder != null ? deresolve(sourceFolder) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj != null && !Objects.equal(obj.getClass(), AbsoluteURI.class)) {
|
||||
throw new IllegalArgumentException(obj.toString() + " instanceof " + obj.getClass().getName());
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,411 @@
|
|||
/**
|
||||
* Copyright (c) 2015, 2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator.trace;
|
||||
|
||||
import static com.google.common.collect.Iterables.*;
|
||||
import static com.google.common.collect.Iterables.concat;
|
||||
import static com.google.common.collect.Multimaps.*;
|
||||
import static org.eclipse.xtext.util.Strings.*;
|
||||
import static org.eclipse.xtext.xbase.lib.IterableExtensions.*;
|
||||
import static org.eclipse.xtext.xbase.lib.IterableExtensions.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.xtext.util.ITextRegion;
|
||||
import org.eclipse.xtext.util.RuntimeIOException;
|
||||
import org.eclipse.xtext.util.TextRegion;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.io.CharStreams;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
public abstract class AbstractTraceRegionToString {
|
||||
protected static class Insert {
|
||||
private final int offset;
|
||||
|
||||
private final boolean open;
|
||||
|
||||
private final RegionHandle region;
|
||||
|
||||
private final LocationHandle location;
|
||||
|
||||
public Insert(int offset, boolean open, RegionHandle region, LocationHandle location) {
|
||||
this.offset = offset;
|
||||
this.open = open;
|
||||
this.region = region;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return open;
|
||||
}
|
||||
|
||||
public RegionHandle getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public LocationHandle getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class File {
|
||||
private final SourceRelativeURI uri;
|
||||
|
||||
private final List<Insert> inserts = new ArrayList<>();
|
||||
|
||||
private final List<String> lines = new ArrayList<>();
|
||||
|
||||
public File(SourceRelativeURI uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public SourceRelativeURI getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public List<Insert> getInserts() {
|
||||
return inserts;
|
||||
}
|
||||
|
||||
public List<String> getLines() {
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class RegionHandle {
|
||||
private final int id;
|
||||
|
||||
private final AbstractTraceRegion region;
|
||||
|
||||
private final List<LocationHandle> locations = new ArrayList<>();
|
||||
|
||||
private final List<RegionHandle> children = new ArrayList<>();
|
||||
|
||||
public RegionHandle(int id, AbstractTraceRegion region) {
|
||||
this.id = id;
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public AbstractTraceRegion getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public List<LocationHandle> getLocations() {
|
||||
return locations;
|
||||
}
|
||||
|
||||
public List<RegionHandle> getChildren() {
|
||||
return children;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class LocationHandle {
|
||||
private final RegionHandle region;
|
||||
|
||||
private final int id;
|
||||
|
||||
private final ILocationData location;
|
||||
|
||||
public LocationHandle(RegionHandle region, int id, ILocationData location) {
|
||||
this.region = region;
|
||||
this.id = id;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public RegionHandle getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ILocationData getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
||||
private int radix = 10;
|
||||
private boolean showTree = true;
|
||||
private boolean showLegend = true;
|
||||
|
||||
protected abstract String getRemoteText(SourceRelativeURI uri);
|
||||
|
||||
protected abstract String getLocalText();
|
||||
|
||||
protected abstract AbstractTraceRegion getTrace();
|
||||
|
||||
protected ITextRegion getLocalFrame() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected ITextRegion getRemoteFrame(SourceRelativeURI uri) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getLocalTitle() {
|
||||
return "generated.java";
|
||||
}
|
||||
|
||||
protected String getRemoteTitle(SourceRelativeURI uri) {
|
||||
return uri.getURI().toString();
|
||||
}
|
||||
|
||||
protected boolean shouldInclude(AbstractTraceRegion region) {
|
||||
ITextRegion frame = getLocalFrame();
|
||||
return frame == null ? true : frame.contains(region.getMyRegion());
|
||||
}
|
||||
|
||||
protected boolean shouldInclude(AbstractTraceRegion region, ILocationData location) {
|
||||
SourceRelativeURI srcRelativePath = location.getSrcRelativePath();
|
||||
ITextRegion frame = getRemoteFrame(
|
||||
srcRelativePath == null ? region.getAssociatedSrcRelativePath() : srcRelativePath);
|
||||
return frame == null ? true : frame.contains(location);
|
||||
}
|
||||
|
||||
protected void add(Map<SourceRelativeURI, File> files, SourceRelativeURI uri, ITextRegion it, RegionHandle region,
|
||||
LocationHandle location) {
|
||||
File file = files.get(uri);
|
||||
if (file == null) {
|
||||
file = new File(uri);
|
||||
files.put(uri, file);
|
||||
}
|
||||
add(file, it, region, location);
|
||||
}
|
||||
|
||||
protected void add(File file, ITextRegion it, RegionHandle region, LocationHandle location) {
|
||||
file.inserts.add(new Insert(it.getOffset(), true, region, location));
|
||||
file.inserts.add(new Insert(it.getOffset() + it.getLength(), false, region, location));
|
||||
}
|
||||
|
||||
protected int collect(AbstractTraceRegion reg, int nextID, File lFile, Map<SourceRelativeURI, File> rFiles,
|
||||
List<RegionHandle> result) {
|
||||
int i = nextID;
|
||||
List<RegionHandle> childResult = result;
|
||||
if (shouldInclude(reg)) {
|
||||
RegionHandle regHandle = new RegionHandle(i++, reg);
|
||||
result.add(regHandle);
|
||||
childResult = regHandle.children;
|
||||
add(lFile, reg.getMyRegion(), regHandle, null);
|
||||
List<ILocationData> locs = toList(filter(reg.getAssociatedLocations(), loc -> shouldInclude(reg, loc)));
|
||||
for (int j = 0; j < locs.size(); j++) {
|
||||
ILocationData loc = locs.get(j);
|
||||
LocationHandle locHandle = new LocationHandle(regHandle, locs.size() > 1 ? (j + 1) : -1, loc);
|
||||
regHandle.locations.add(locHandle);
|
||||
SourceRelativeURI srcRelativePath = loc.getSrcRelativePath();
|
||||
SourceRelativeURI path = srcRelativePath == null ? reg.getAssociatedSrcRelativePath() : srcRelativePath;
|
||||
add(rFiles, path, loc, regHandle, locHandle);
|
||||
}
|
||||
}
|
||||
for (AbstractTraceRegion child : reg.getNestedRegions()) {
|
||||
i = collect(child, i, lFile, rFiles, childResult);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
protected String render(AbstractTraceRegionToString.Insert it, int width) {
|
||||
String first = Strings.padStart(Integer.toString(it.region.id, this.radix), width, '0');
|
||||
return it.location != null && it.location.id >= 0 ? first + "_" + Integer.toString(it.location.id, this.radix)
|
||||
: first;
|
||||
}
|
||||
|
||||
protected int sortKey(AbstractTraceRegionToString.Insert it) {
|
||||
int base = it.region.id * Short.MAX_VALUE;
|
||||
return it.location != null && it.location.id >= 0 ? base + it.location.id : base;
|
||||
}
|
||||
|
||||
protected String render(Collection<AbstractTraceRegionToString.Insert> inserts, int width) {
|
||||
String opens = join(map(sortBy(filter(inserts, i -> i.open), i -> sortKey(i)), i -> render(i, width)), ",");
|
||||
String closes = join(map(sortBy(filter(inserts, i -> !i.open), i -> -sortKey(i)), i -> render(i, width)), ",");
|
||||
String s1 = opens.isEmpty() ? "" : ("[" + opens + "[");
|
||||
String s2 = closes.isEmpty() ? "" : ("]" + closes + "]");
|
||||
return (s2 + s1);
|
||||
}
|
||||
|
||||
protected List<String> render(AbstractTraceRegionToString.File file, int width) {
|
||||
try {
|
||||
String text = file.uri == null ? getLocalText() : getRemoteText(file.uri);
|
||||
ITextRegion localOrRemoteFrame = file.uri == null ? getLocalFrame() : getRemoteFrame(file.uri);
|
||||
ITextRegion frame = localOrRemoteFrame == null ? new TextRegion(0, text.length()) : localOrRemoteFrame;
|
||||
int last = frame.getOffset();
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Map.Entry<Integer, Collection<Insert>> e : sortBy(toList(index(
|
||||
filter(file.inserts,
|
||||
i -> i.offset >= frame.getOffset() && i.offset <= (frame.getOffset() + frame.getLength())),
|
||||
i -> i.offset).asMap().entrySet()), i -> i.getKey())) {
|
||||
int offset = e.getKey().intValue();
|
||||
result.append(text.substring(last, offset));
|
||||
result.append(render(e.getValue(), width));
|
||||
last = offset;
|
||||
}
|
||||
int end = frame.getOffset() + frame.getLength();
|
||||
if (last < end) {
|
||||
result.append(text.substring(last, end));
|
||||
}
|
||||
return CharStreams.readLines(new StringReader(result.toString()));
|
||||
} catch (IOException t) {
|
||||
throw new RuntimeIOException(t);
|
||||
}
|
||||
}
|
||||
|
||||
protected String title(SourceRelativeURI uri, int width) {
|
||||
String s = " " + (uri == null ? getLocalTitle() : getRemoteTitle(uri)) + " ";
|
||||
String left = Strings.repeat("-", (width - s.length()) / 2);
|
||||
String right = Strings.repeat("-", (width - (s.length() + left.length())));
|
||||
return left + s + right;
|
||||
}
|
||||
|
||||
protected <T extends Object> Set<T> collect(T start, Function1<? super T, ? extends Iterable<T>> reachable) {
|
||||
return collect(start, reachable, new LinkedHashSet<>());
|
||||
}
|
||||
|
||||
protected <R extends Collection<? super T>, T extends Object> R collect(T start,
|
||||
Function1<? super T, ? extends Iterable<T>> reachable, R collector) {
|
||||
if (collector.add(start)) {
|
||||
for (T r : reachable.apply(start)) {
|
||||
collect(r, reachable, collector);
|
||||
}
|
||||
}
|
||||
return collector;
|
||||
}
|
||||
|
||||
protected String render(AbstractTraceRegionToString.LocationHandle loc) {
|
||||
String prefix = loc.id >= 0 ? Integer.toString(loc.id, this.radix) + ": " : "";
|
||||
String name = loc.location.getClass().getSimpleName();
|
||||
String path = loc.location.getSrcRelativePath() == null ? "" : ("," + loc.location.getSrcRelativePath());
|
||||
return prefix + name + "[" + loc.location.getOffset() + "," + loc.location.getLength() + path + "]";
|
||||
}
|
||||
|
||||
protected void render(AbstractTraceRegionToString.RegionHandle region, int idW, int offsetW, int lengthW,
|
||||
int indent, List<String> result) {
|
||||
String id = Strings.padStart(Integer.toString(region.id, radix), idW, '0');
|
||||
String debug = region.region.isUseForDebugging() ? "D" : " ";
|
||||
String offset = Strings.padStart(Integer.toString(region.region.getMyOffset()), offsetW, '0');
|
||||
String length = Strings.padStart(Integer.toString(region.region.getMyLength()), lengthW, '0');
|
||||
String space = Strings.repeat(" ", indent);
|
||||
String name = region.region.getClass().getSimpleName();
|
||||
String locations = join(map(region.locations, it -> render(it)), ", ");
|
||||
String loc = debug + " " + offset + "-" + length + space;
|
||||
String header = id + ": " + loc + name + " -> " + locations;
|
||||
if (region.children.isEmpty()) {
|
||||
result.add(header);
|
||||
} else {
|
||||
result.add((header + " {"));
|
||||
for (RegionHandle child : region.children) {
|
||||
render(child, idW, offsetW, lengthW, (indent + 2), result);
|
||||
}
|
||||
result.add((id + ": " + Strings.repeat(" ", loc.length())) + "}");
|
||||
}
|
||||
}
|
||||
|
||||
protected String render() {
|
||||
File localFile = new File(null);
|
||||
LinkedHashMap<SourceRelativeURI, File> remoteFiles = new LinkedHashMap<>();
|
||||
List<RegionHandle> roothandles = new ArrayList<>();
|
||||
int maxid = collect(getTrace(), 1, localFile, remoteFiles, roothandles);
|
||||
int idwidth = Integer.toString(maxid, radix).length();
|
||||
addAll(localFile.lines, render(localFile, idwidth));
|
||||
for (File file : remoteFiles.values()) {
|
||||
addAll(file.lines, render(file, idwidth));
|
||||
}
|
||||
int localWidth = Math.max(max(map(localFile.lines, (String it) -> Integer.valueOf(it.length()))),
|
||||
getLocalTitle().length() + 2);
|
||||
int remoteWidth = max(map(remoteFiles.values(),
|
||||
(File it) -> Math.max(max(map(it.lines, (String it_1) -> Integer.valueOf(it_1.length()))),
|
||||
getRemoteTitle(it.uri).length() + 2)));
|
||||
localFile.lines.add(0, title(null, localWidth));
|
||||
for (File file : remoteFiles.values()) {
|
||||
file.lines.add(0, title(file.uri, remoteWidth));
|
||||
}
|
||||
List<String> left = localFile.lines;
|
||||
List<String> right = toList(concat(map(remoteFiles.values(), it -> it.lines)));
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if (showLegend) {
|
||||
result.add(
|
||||
"Regions are surrounded by [N[ ... ]N]. Regions on the left and right with the same N are associated.");
|
||||
}
|
||||
for (int i = 0; i < left.size() || i < right.size(); i++) {
|
||||
String l = Strings.padEnd(i < left.size() ? left.get(i) : "", localWidth, ' ');
|
||||
String r = i < right.size() ? right.get(i) : "";
|
||||
result.add(l + " | " + r);
|
||||
}
|
||||
if (showTree) {
|
||||
result.add(Strings.repeat("-", localWidth + remoteWidth + 3));
|
||||
if (showLegend) {
|
||||
result.add(
|
||||
"<N>: <isDebug> <offset>-<length> <RegionJavaClass> -> <LocationJavaClass>[<offset>,<length>,<uri>]");
|
||||
}
|
||||
Iterable<RegionHandle> allhandles = concat(map(roothandles, it -> collect(it, it_1 -> it_1.children)));
|
||||
int offsetWidth = String
|
||||
.valueOf(max(map(allhandles, (RegionHandle it) -> Integer.valueOf(it.region.getMyOffset()))))
|
||||
.length();
|
||||
int lengthWidth = String
|
||||
.valueOf(max(map(allhandles, (RegionHandle it) -> Integer.valueOf(it.region.getMyLength()))))
|
||||
.length();
|
||||
for (RegionHandle handle : roothandles) {
|
||||
render(handle, idwidth, offsetWidth, lengthWidth, 1, result);
|
||||
}
|
||||
}
|
||||
return join(result, newLine());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
return render();
|
||||
} catch (Exception t) {
|
||||
return Throwables.getStackTraceAsString(t);
|
||||
}
|
||||
}
|
||||
|
||||
public int getRadix() {
|
||||
return radix;
|
||||
}
|
||||
|
||||
public void setRadix(int radix) {
|
||||
this.radix = radix;
|
||||
}
|
||||
|
||||
public boolean isShowTree() {
|
||||
return showTree;
|
||||
}
|
||||
|
||||
public void setShowTree(boolean showTree) {
|
||||
this.showTree = showTree;
|
||||
}
|
||||
|
||||
public boolean isShowLegend() {
|
||||
return showLegend;
|
||||
}
|
||||
|
||||
public void setShowLegend(boolean showLegend) {
|
||||
this.showLegend = showLegend;
|
||||
}
|
||||
}
|
|
@ -1,269 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.generator.trace
|
||||
|
||||
import com.google.common.base.Throwables
|
||||
import com.google.common.io.CharStreams
|
||||
import java.io.StringReader
|
||||
import java.util.Collection
|
||||
import java.util.List
|
||||
import java.util.Map
|
||||
import java.util.Set
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtext.util.ITextRegion
|
||||
import org.eclipse.xtext.util.TextRegion
|
||||
|
||||
import static org.eclipse.xtext.util.Strings.*
|
||||
|
||||
import static extension com.google.common.base.Strings.*
|
||||
import static extension com.google.common.collect.Multimaps.*
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@Accessors abstract class AbstractTraceRegionToString {
|
||||
@Accessors protected static class Insert {
|
||||
val int offset
|
||||
val boolean open
|
||||
val RegionHandle region
|
||||
val LocationHandle location
|
||||
}
|
||||
|
||||
@Accessors protected static class File {
|
||||
val SourceRelativeURI uri
|
||||
val List<Insert> inserts = newArrayList()
|
||||
val List<String> lines = newArrayList()
|
||||
}
|
||||
|
||||
@Accessors protected static class RegionHandle {
|
||||
val int id
|
||||
val AbstractTraceRegion region
|
||||
val List<LocationHandle> locations = newArrayList()
|
||||
val List<RegionHandle> children = newArrayList()
|
||||
}
|
||||
|
||||
@Accessors protected static class LocationHandle {
|
||||
val RegionHandle region
|
||||
val int id
|
||||
val ILocationData location
|
||||
}
|
||||
|
||||
int radix = 10 // Character.MAX_RADIX
|
||||
boolean showTree = true
|
||||
boolean showLegend = true
|
||||
|
||||
def protected abstract String getRemoteText(SourceRelativeURI uri) ;
|
||||
|
||||
def protected abstract String getLocalText() ;
|
||||
|
||||
def protected abstract AbstractTraceRegion getTrace();
|
||||
|
||||
def protected ITextRegion getLocalFrame() {
|
||||
null
|
||||
}
|
||||
|
||||
def protected ITextRegion getRemoteFrame(SourceRelativeURI uri) {
|
||||
null
|
||||
}
|
||||
|
||||
def protected String getLocalTitle() {
|
||||
"generated.java"
|
||||
}
|
||||
|
||||
def protected String getRemoteTitle(SourceRelativeURI uri) {
|
||||
uri.URI.toString
|
||||
}
|
||||
|
||||
def protected boolean shouldInclude(AbstractTraceRegion region) {
|
||||
val frame = getLocalFrame()
|
||||
if (frame === null)
|
||||
return true
|
||||
else
|
||||
return frame.contains(region.myRegion)
|
||||
}
|
||||
|
||||
def protected boolean shouldInclude(AbstractTraceRegion region, ILocationData location) {
|
||||
val frame = getRemoteFrame(location.srcRelativePath ?: region.associatedSrcRelativePath)
|
||||
if (frame === null)
|
||||
return true
|
||||
else
|
||||
return frame.contains(location)
|
||||
}
|
||||
|
||||
def protected void add(Map<SourceRelativeURI, File> files, SourceRelativeURI uri, ITextRegion it,
|
||||
RegionHandle region, LocationHandle location) {
|
||||
var file = files.get(uri)
|
||||
if (file === null)
|
||||
files.put(uri, file = new File(uri))
|
||||
file.add(it, region, location)
|
||||
}
|
||||
|
||||
def protected void add(File file, ITextRegion it, RegionHandle region, LocationHandle location) {
|
||||
file.inserts += new Insert(offset, true, region, location)
|
||||
file.inserts += new Insert(offset + length, false, region, location)
|
||||
}
|
||||
|
||||
def protected int collect(AbstractTraceRegion reg, int nextID, File lFile, Map<SourceRelativeURI, File> rFiles,
|
||||
List<RegionHandle> result) {
|
||||
var i = nextID
|
||||
var childResult = result
|
||||
if (shouldInclude(reg)) {
|
||||
val regHandle = new RegionHandle(i++, reg)
|
||||
result += regHandle
|
||||
childResult = regHandle.children
|
||||
lFile.add(reg.myRegion, regHandle, null)
|
||||
val locs = reg.associatedLocations.filter[shouldInclude(reg, it)].toList
|
||||
for (var j = 0; j < locs.size; j++) {
|
||||
val loc = locs.get(j)
|
||||
val locHandle = new LocationHandle(regHandle, if(locs.size > 1) j + 1 else -1, loc)
|
||||
regHandle.locations += locHandle
|
||||
val path = loc.srcRelativePath ?: reg.associatedSrcRelativePath
|
||||
rFiles.add(path, loc, regHandle, locHandle)
|
||||
}
|
||||
}
|
||||
for (child : reg.nestedRegions) {
|
||||
i = child.collect(i, lFile, rFiles, childResult)
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
def protected String render(Insert it, int width) {
|
||||
val first = padStart(Integer.toString(region.id, radix), width, "0")
|
||||
return if(location !== null && location.id >= 0) first + "_" + Integer.toString(location.id, radix) else first
|
||||
}
|
||||
|
||||
def protected int sortKey(Insert it) {
|
||||
val base = (region.id * Short.MAX_VALUE)
|
||||
return if(location !== null && location.id >= 0) base + location.id else base
|
||||
}
|
||||
|
||||
def protected String render(Collection<Insert> inserts, int width) {
|
||||
val opens = inserts.filter[open].sortBy[sortKey].map[render(width)].join(",")
|
||||
val closes = inserts.filter[!open].sortBy[-sortKey].map[render(width)].join(",")
|
||||
val s1 = if(opens.isEmpty) "" else "[" + opens + "["
|
||||
val s2 = if(closes.isEmpty) "" else "]" + closes + "]"
|
||||
return s2 + s1
|
||||
}
|
||||
|
||||
def protected List<String> render(File file, int width) {
|
||||
val text = if(file.uri === null) localText else file.uri.remoteText
|
||||
val frame = (if(file.uri === null) localFrame else file.uri.remoteFrame) ?: new TextRegion(0, text.length)
|
||||
val inframe = file.inserts.filter[offset >= frame.offset && offset <= frame.offset + frame.length]
|
||||
val offsets = inframe.index[offset].asMap.entrySet.toList.sortBy[key]
|
||||
var last = frame.offset
|
||||
val result = new StringBuilder
|
||||
for (e : offsets) {
|
||||
val offset = e.key
|
||||
val insert = e.value.render(width)
|
||||
val prefix = text.substring(last, offset)
|
||||
result.append(prefix)
|
||||
result.append(insert)
|
||||
last = offset
|
||||
}
|
||||
val end = frame.offset + frame.length
|
||||
if (last < end)
|
||||
result.append(text.substring(last, end))
|
||||
return CharStreams.readLines(new StringReader(result.toString))
|
||||
}
|
||||
|
||||
def protected String title(SourceRelativeURI uri, int width) {
|
||||
val s = " " + (if(uri === null) localTitle else uri.remoteTitle) + " "
|
||||
val left = "-".repeat((width - s.length) / 2)
|
||||
val right = "-".repeat(width - (s.length + left.length))
|
||||
return left + s + right
|
||||
}
|
||||
|
||||
// workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=383426
|
||||
def protected <T> Set<T> collect(T start, (T)=>Iterable<T> reachable) {
|
||||
return collect(start, reachable, newLinkedHashSet)
|
||||
}
|
||||
|
||||
def protected <R extends Collection<? super T>, T> R collect(T start, (T)=>Iterable<T> reachable, R collector) {
|
||||
if (collector.add(start))
|
||||
for (r : reachable.apply(start))
|
||||
collect(r, reachable, collector)
|
||||
return collector
|
||||
}
|
||||
|
||||
def protected String render(LocationHandle loc) {
|
||||
val prefix = if(loc.id >= 0) Integer.toString(loc.id, radix) + ": " else ""
|
||||
val name = loc.location.class.simpleName
|
||||
val path = if(loc.location.srcRelativePath !== null) "," + loc.location.srcRelativePath else ""
|
||||
return prefix + name + "[" + loc.location.offset + "," + loc.location.length + path + "]"
|
||||
}
|
||||
|
||||
def protected void render(RegionHandle region, int idW, int offsetW, int lengthW, int indent, List<String> result) {
|
||||
val id = Integer.toString(region.id, radix).padStart(idW, "0")
|
||||
val debug = if(region.region.isUseForDebugging) "D" else " "
|
||||
val offset = Integer.toString(region.region.myOffset).padStart(offsetW, "0")
|
||||
val length = Integer.toString(region.region.myLength).padStart(lengthW, "0")
|
||||
val space = repeat(" ", indent)
|
||||
val name = region.region.class.simpleName
|
||||
val locations = region.locations.map[it.render].join(", ")
|
||||
val loc = debug + " " + offset + "-" + length + space
|
||||
val header = id + ": " + loc + name + " -> " + locations
|
||||
if (region.children.isEmpty) {
|
||||
result += header
|
||||
} else {
|
||||
result += header + " {"
|
||||
for (child : region.children)
|
||||
render(child, idW, offsetW, lengthW, indent + 2, result)
|
||||
result += id + ": " + repeat(" ", loc.length) + "}"
|
||||
}
|
||||
}
|
||||
|
||||
def protected String render() {
|
||||
val localFile = new File(null)
|
||||
val remoteFiles = <SourceRelativeURI, File>newLinkedHashMap()
|
||||
val List<RegionHandle> roothandles = newArrayList()
|
||||
val maxid = trace.collect(1, localFile, remoteFiles, roothandles)
|
||||
val idwidth = Integer.toString(maxid, radix).length
|
||||
localFile.lines += localFile.render(idwidth)
|
||||
for (file : remoteFiles.values)
|
||||
file.lines += file.render(idwidth)
|
||||
val localWidth = Math.max(localFile.lines.map[length].max, localTitle.length + 2)
|
||||
val remoteWidth = remoteFiles.values.map[Math.max(lines.map[length].max, uri.remoteTitle.length + 2)].max
|
||||
localFile.lines.add(0, title(null, localWidth))
|
||||
for (file : remoteFiles.values)
|
||||
file.lines.add(0, title(file.uri, remoteWidth))
|
||||
val left = localFile.lines
|
||||
val right = remoteFiles.values.map[lines].flatten.toList
|
||||
val result = newArrayList()
|
||||
if (showLegend)
|
||||
result +=
|
||||
"Regions are surrounded by [N[ ... ]N]. Regions on the left and right with the same N are associated."
|
||||
for (var i = 0; i < left.length || i < right.length; i++) {
|
||||
val l = (if(i < left.size) left.get(i) else "").padEnd(localWidth, " ")
|
||||
val r = if(i < right.size) right.get(i) else ""
|
||||
result += l + " | " + r
|
||||
}
|
||||
if (showTree) {
|
||||
result += repeat("-", localWidth + remoteWidth + 3)
|
||||
if (showLegend)
|
||||
result +=
|
||||
"<N>: <isDebug> <offset>-<length> <RegionJavaClass> -> <LocationJavaClass>[<offset>,<length>,<uri>]"
|
||||
val allhandles = roothandles.map[collect[children]].flatten
|
||||
val offsetWidth = String.valueOf(allhandles.map[region.myOffset].max).length
|
||||
val lengthWidth = String.valueOf(allhandles.map[region.myLength].max).length
|
||||
for (handle : roothandles)
|
||||
render(handle, idwidth, offsetWidth, lengthWidth, 1, result)
|
||||
}
|
||||
return result.join(newLine)
|
||||
}
|
||||
|
||||
override toString() {
|
||||
try {
|
||||
return render();
|
||||
} catch (Exception e) {
|
||||
Throwables.getStackTraceAsString(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Copyright (c) 2015-2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator.trace;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
public abstract class AbstractURIWrapper {
|
||||
private final URI uri;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
public AbstractURIWrapper(URI uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * 1 + (this.uri == null ? 0 : this.uri.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
AbstractURIWrapper other = (AbstractURIWrapper) obj;
|
||||
if (uri == null) {
|
||||
if (other.uri != null)
|
||||
return false;
|
||||
} else if (!uri.equals(other.uri))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public URI getURI() {
|
||||
return uri;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Copyright (c) 2015-2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator.trace;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
* A source relative URI.
|
||||
*
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
public class SourceRelativeURI extends AbstractURIWrapper {
|
||||
public static SourceRelativeURI fromAbsolute(URI uri) {
|
||||
if (uri.isRelative()) {
|
||||
throw new IllegalArgumentException(uri.toString());
|
||||
}
|
||||
return new SourceRelativeURI(uri.path().substring(1));
|
||||
}
|
||||
|
||||
public SourceRelativeURI(URI sourceRelativeURI) {
|
||||
super(sourceRelativeURI);
|
||||
if (!sourceRelativeURI.isRelative() || sourceRelativeURI.path().startsWith("/")) {
|
||||
throw new IllegalArgumentException(String.valueOf(sourceRelativeURI));
|
||||
}
|
||||
}
|
||||
|
||||
public SourceRelativeURI(String relativeURI) {
|
||||
this(URI.createURI(relativeURI));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj != null && !Objects.equal(obj.getClass(), SourceRelativeURI.class)) {
|
||||
throw new IllegalArgumentException(obj.toString() + " instanceof " + obj.getClass().getName());
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.generator.trace
|
||||
|
||||
import org.eclipse.emf.common.util.URI
|
||||
import org.eclipse.xtend.lib.annotations.Data
|
||||
import org.eclipse.xtext.workspace.IProjectConfig
|
||||
import org.eclipse.xtext.workspace.ISourceFolder
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
@Data
|
||||
abstract class AbstractURIWrapper {
|
||||
URI URI
|
||||
|
||||
override toString() {
|
||||
return URI.toString
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A source relative URI.
|
||||
*
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
class SourceRelativeURI extends AbstractURIWrapper {
|
||||
def static fromAbsolute(URI uri) {
|
||||
if (uri.isRelative) {
|
||||
throw new IllegalArgumentException(uri.toString)
|
||||
}
|
||||
return new SourceRelativeURI(uri.path.substring(1))
|
||||
}
|
||||
new(URI sourceRelativeURI) {
|
||||
super(sourceRelativeURI)
|
||||
if (!sourceRelativeURI.isRelative || sourceRelativeURI.path.startsWith('/')) {
|
||||
throw new IllegalArgumentException(String.valueOf(sourceRelativeURI))
|
||||
}
|
||||
}
|
||||
new(String relativeURI) {
|
||||
this(URI::createURI(relativeURI));
|
||||
}
|
||||
|
||||
override equals(Object obj) {
|
||||
if (obj !== null && obj.getClass != SourceRelativeURI) {
|
||||
throw new IllegalArgumentException(String.valueOf(obj) + " instanceof " + obj?.class?.name)
|
||||
}
|
||||
return super.equals(obj)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An absolute URI that allows to obtain a resource in a {@link IProjectConfig project}.
|
||||
*
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
class AbsoluteURI extends AbstractURIWrapper {
|
||||
|
||||
new(URI absoluteURI) {
|
||||
super(absoluteURI)
|
||||
if (absoluteURI.isRelative || !absoluteURI.isHierarchical) {
|
||||
throw new IllegalArgumentException(String.valueOf(absoluteURI))
|
||||
}
|
||||
}
|
||||
|
||||
new(String absoluteURI) {
|
||||
this(URI::createURI(absoluteURI));
|
||||
}
|
||||
|
||||
def deresolve(URI sourceFolderURI) {
|
||||
try {
|
||||
return new SourceRelativeURI(URI.deresolve(sourceFolderURI))
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IllegalArgumentException("Base URI was "+URI, e)
|
||||
}
|
||||
}
|
||||
|
||||
def deresolve(ISourceFolder sourceFolder) {
|
||||
return deresolve(sourceFolder.getPath());
|
||||
}
|
||||
|
||||
def deresolve(IProjectConfig projectConfig) {
|
||||
val sourceFolder = projectConfig.findSourceFolderContaining(URI);
|
||||
return sourceFolder?.deresolve
|
||||
}
|
||||
|
||||
override equals(Object obj) {
|
||||
if (obj !== null && obj.getClass != AbsoluteURI) {
|
||||
throw new IllegalArgumentException(String.valueOf(obj) + " instanceof " + obj?.class?.name)
|
||||
}
|
||||
return super.equals(obj)
|
||||
}
|
||||
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.findReferences;
|
||||
|
||||
import java.util.Map;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.EReference;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
|
||||
import org.eclipse.xtext.EcoreUtil2;
|
||||
import org.eclipse.xtext.findReferences.IReferenceFinder;
|
||||
import org.eclipse.xtext.resource.IEObjectDescription;
|
||||
import org.eclipse.xtext.resource.IReferenceDescription;
|
||||
import org.eclipse.xtext.resource.IResourceDescription;
|
||||
import org.eclipse.xtext.resource.IResourceServiceProvider;
|
||||
import org.eclipse.xtext.resource.impl.DefaultReferenceDescription;
|
||||
import org.eclipse.xtext.util.IAcceptor;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
|
||||
/**
|
||||
* For local references, populates an {@link IReferenceDescription} that knows its exported container URI.
|
||||
*
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
* @author kosyakov - Pulled up to the runtime project
|
||||
*/
|
||||
@FinalFieldsConstructor
|
||||
@SuppressWarnings("all")
|
||||
public class ReferenceAcceptor implements IReferenceFinder.Acceptor {
|
||||
private final IResourceServiceProvider.Registry resourceServiceProviderRegistry;
|
||||
|
||||
private final IAcceptor<IReferenceDescription> delegate;
|
||||
|
||||
private Resource currentResource;
|
||||
|
||||
private Map<EObject, URI> exportedContainersInCurrentResource;
|
||||
|
||||
@Override
|
||||
public void accept(final EObject source, final URI sourceURI, final EReference eReference, final int index, final EObject targetOrProxy, final URI targetURI) {
|
||||
if (((this.currentResource == null) || (source.eResource() != this.currentResource))) {
|
||||
this.computeExportedObjectsMap(source);
|
||||
this.currentResource = source.eResource();
|
||||
}
|
||||
this.accept(this.createReferenceDescription(EcoreUtil2.getFragmentPathURI(source), targetURI, eReference, index, this.findExportedContainer(source)));
|
||||
}
|
||||
|
||||
protected void computeExportedObjectsMap(final EObject source) {
|
||||
final Resource resource = source.eResource();
|
||||
final IResourceServiceProvider resourceServiceProvider = this.resourceServiceProviderRegistry.getResourceServiceProvider(resource.getURI());
|
||||
if ((resourceServiceProvider != null)) {
|
||||
final IResourceDescription resourceDescription = resourceServiceProvider.getResourceDescriptionManager().getResourceDescription(resource);
|
||||
this.exportedContainersInCurrentResource = CollectionLiterals.<EObject, URI>newHashMap();
|
||||
Iterable<IEObjectDescription> _exportedObjects = resourceDescription.getExportedObjects();
|
||||
for (final IEObjectDescription description : _exportedObjects) {
|
||||
{
|
||||
EObject instance = description.getEObjectOrProxy();
|
||||
boolean _eIsProxy = instance.eIsProxy();
|
||||
if (_eIsProxy) {
|
||||
instance = resource.getEObject(description.getEObjectURI().fragment());
|
||||
}
|
||||
this.exportedContainersInCurrentResource.put(instance, description.getEObjectURI());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.exportedContainersInCurrentResource = CollectionLiterals.<EObject, URI>emptyMap();
|
||||
}
|
||||
}
|
||||
|
||||
protected URI findExportedContainer(final EObject obj) {
|
||||
EObject source = obj;
|
||||
boolean _isEmpty = this.exportedContainersInCurrentResource.isEmpty();
|
||||
if (_isEmpty) {
|
||||
return null;
|
||||
}
|
||||
URI result = this.exportedContainersInCurrentResource.get(source);
|
||||
while ((result == null)) {
|
||||
{
|
||||
boolean _containsKey = this.exportedContainersInCurrentResource.containsKey(source);
|
||||
if (_containsKey) {
|
||||
return result;
|
||||
}
|
||||
source = source.eContainer();
|
||||
if ((source == null)) {
|
||||
return null;
|
||||
}
|
||||
result = this.exportedContainersInCurrentResource.get(source);
|
||||
}
|
||||
}
|
||||
this.exportedContainersInCurrentResource.put(source, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(final IReferenceDescription description) {
|
||||
this.delegate.accept(description);
|
||||
}
|
||||
|
||||
protected IReferenceDescription createReferenceDescription(final URI sourceURI, final URI targetURI, final EReference eReference, final int index, final URI containerURI) {
|
||||
return new DefaultReferenceDescription(sourceURI, targetURI, eReference, index, containerURI);
|
||||
}
|
||||
|
||||
public ReferenceAcceptor(final IResourceServiceProvider.Registry resourceServiceProviderRegistry, final IAcceptor<IReferenceDescription> delegate) {
|
||||
super();
|
||||
this.resourceServiceProviderRegistry = resourceServiceProviderRegistry;
|
||||
this.delegate = delegate;
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
package org.eclipse.xtext.generator;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.emf.common.notify.impl.AdapterImpl;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
|
||||
import org.eclipse.xtext.generator.FileSystemAccessRequest;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
|
||||
/**
|
||||
* @author Anton Kosyakov
|
||||
* @since 2.7
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class FileSystemAccessQueue extends AdapterImpl {
|
||||
private final BlockingQueue<FileSystemAccessRequest> requestQueue;
|
||||
|
||||
private final IProgressMonitor monitor;
|
||||
|
||||
/**
|
||||
* @since 2.8
|
||||
*/
|
||||
@FinalFieldsConstructor
|
||||
public FileSystemAccessQueue(final BlockingQueue<FileSystemAccessRequest> requestQueue, final IProgressMonitor monitor) {
|
||||
super();
|
||||
this.requestQueue = requestQueue;
|
||||
this.monitor = monitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.9
|
||||
*/
|
||||
public void sendAsync(final URI uri, final Runnable runMe) {
|
||||
FileSystemAccessRequest _fileSystemAccessRequest = new FileSystemAccessRequest(uri, runMe);
|
||||
this.send(_fileSystemAccessRequest);
|
||||
}
|
||||
|
||||
protected FileSystemAccessRequest send(final FileSystemAccessRequest request) {
|
||||
try {
|
||||
boolean _isCanceled = this.monitor.isCanceled();
|
||||
if (_isCanceled) {
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
this.requestQueue.put(request);
|
||||
return request;
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof InterruptedException) {
|
||||
throw new OperationCanceledException();
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.14
|
||||
*/
|
||||
@Beta
|
||||
public void waitForEmptyQueue() {
|
||||
while ((!this.requestQueue.isEmpty())) {
|
||||
Thread.yield();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package org.eclipse.xtext.generator;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
/**
|
||||
* @author Anton Kosyakov
|
||||
* @since 2.7
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class FileSystemAccessRequest implements Runnable {
|
||||
private final URI uri;
|
||||
|
||||
private final Runnable runMe;
|
||||
|
||||
/**
|
||||
* @since 2.9
|
||||
*/
|
||||
@FinalFieldsConstructor
|
||||
public FileSystemAccessRequest(final URI uri, final Runnable runMe) {
|
||||
super();
|
||||
this.uri = uri;
|
||||
this.runMe = runMe;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.8
|
||||
*/
|
||||
@Pure
|
||||
public URI getUri() {
|
||||
return this.uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.9
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
this.runMe.run();
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator;
|
||||
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtext.generator.IGeneratorContext;
|
||||
import org.eclipse.xtext.util.CancelIndicator;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
/**
|
||||
* @since 2.9
|
||||
*/
|
||||
@Accessors
|
||||
@SuppressWarnings("all")
|
||||
public class GeneratorContext implements IGeneratorContext {
|
||||
private CancelIndicator cancelIndicator;
|
||||
|
||||
@Pure
|
||||
public CancelIndicator getCancelIndicator() {
|
||||
return this.cancelIndicator;
|
||||
}
|
||||
|
||||
public void setCancelIndicator(final CancelIndicator cancelIndicator) {
|
||||
this.cancelIndicator = cancelIndicator;
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.inject.ImplementedBy;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.List;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.xtext.diagnostics.Severity;
|
||||
import org.eclipse.xtext.util.CancelIndicator;
|
||||
import org.eclipse.xtext.validation.CheckMode;
|
||||
import org.eclipse.xtext.validation.IResourceValidator;
|
||||
import org.eclipse.xtext.validation.Issue;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
*
|
||||
* @since 2.9
|
||||
*/
|
||||
@Beta
|
||||
@ImplementedBy(IShouldGenerate.OnlyWithoutErrors.class)
|
||||
@SuppressWarnings("all")
|
||||
public interface IShouldGenerate {
|
||||
@Beta
|
||||
@Singleton
|
||||
class OnlyWithoutErrors implements IShouldGenerate {
|
||||
@Inject
|
||||
private IResourceValidator resourceValidator;
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerate(final Resource resource, final CancelIndicator cancelIndicator) {
|
||||
boolean _isEmpty = resource.getErrors().isEmpty();
|
||||
boolean _not = (!_isEmpty);
|
||||
if (_not) {
|
||||
return false;
|
||||
}
|
||||
final List<Issue> issues = this.resourceValidator.validate(resource, CheckMode.NORMAL_AND_FAST, cancelIndicator);
|
||||
final Function1<Issue, Boolean> _function = (Issue it) -> {
|
||||
Severity _severity = it.getSeverity();
|
||||
return Boolean.valueOf(Objects.equal(_severity, Severity.ERROR));
|
||||
};
|
||||
boolean _exists = IterableExtensions.<Issue>exists(issues, _function);
|
||||
return (!_exists);
|
||||
}
|
||||
}
|
||||
|
||||
@Beta
|
||||
@Singleton
|
||||
class Always implements IShouldGenerate {
|
||||
@Override
|
||||
public boolean shouldGenerate(final Resource resource, final CancelIndicator cancelIndicator) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* whether code should be generated for this resource.
|
||||
*/
|
||||
boolean shouldGenerate(final Resource resource, final CancelIndicator cancelIndicator);
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.eclipse.emf.common.notify.impl.AdapterImpl;
|
||||
import org.eclipse.xtend.lib.annotations.Data;
|
||||
import org.eclipse.xtext.generator.OutputConfiguration;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* @noreference
|
||||
*/
|
||||
@Data
|
||||
@SuppressWarnings("all")
|
||||
public class OutputConfigurationAdapter extends AdapterImpl {
|
||||
private final Map<String, Set<OutputConfiguration>> outputConfigurationsPerLanguage;
|
||||
|
||||
@Override
|
||||
public boolean isAdapterForType(final Object type) {
|
||||
return Objects.equal(type, OutputConfigurationAdapter.class);
|
||||
}
|
||||
|
||||
public OutputConfigurationAdapter(final Map<String, Set<OutputConfiguration>> outputConfigurationsPerLanguage) {
|
||||
super();
|
||||
this.outputConfigurationsPerLanguage = outputConfigurationsPerLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public int hashCode() {
|
||||
return 31 * 1 + ((this.outputConfigurationsPerLanguage== null) ? 0 : this.outputConfigurationsPerLanguage.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
OutputConfigurationAdapter other = (OutputConfigurationAdapter) obj;
|
||||
if (this.outputConfigurationsPerLanguage == null) {
|
||||
if (other.outputConfigurationsPerLanguage != null)
|
||||
return false;
|
||||
} else if (!this.outputConfigurationsPerLanguage.equals(other.outputConfigurationsPerLanguage))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.addAllFields()
|
||||
.toString();
|
||||
}
|
||||
|
||||
@Pure
|
||||
public Map<String, Set<OutputConfiguration>> getOutputConfigurationsPerLanguage() {
|
||||
return this.outputConfigurationsPerLanguage;
|
||||
}
|
||||
}
|
|
@ -1,284 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015, 2017 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.io.CharStreams;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.resource.URIConverter;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtext.generator.AbstractFileSystemAccess2;
|
||||
import org.eclipse.xtext.generator.IFilePostProcessor;
|
||||
import org.eclipse.xtext.generator.trace.AbstractTraceRegion;
|
||||
import org.eclipse.xtext.generator.trace.ITraceRegionProvider;
|
||||
import org.eclipse.xtext.generator.trace.TraceFileNameProvider;
|
||||
import org.eclipse.xtext.generator.trace.TraceNotFoundException;
|
||||
import org.eclipse.xtext.generator.trace.TraceRegionSerializer;
|
||||
import org.eclipse.xtext.parser.IEncodingProvider;
|
||||
import org.eclipse.xtext.util.RuntimeIOException;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
/**
|
||||
* A file system access implementation that is based on EMF URIs and URIConverter
|
||||
* @since 2.9
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class URIBasedFileSystemAccess extends AbstractFileSystemAccess2 {
|
||||
public interface BeforeDelete {
|
||||
/**
|
||||
* @return <code>true</code> if the file can be deleted, false otherwise
|
||||
*/
|
||||
boolean beforeDelete(final URI changed);
|
||||
}
|
||||
|
||||
public interface BeforeWrite {
|
||||
InputStream beforeWrite(final URI changed, final String outputCfgName, final InputStream in);
|
||||
}
|
||||
|
||||
public interface BeforeRead {
|
||||
InputStream beforeRead(final URI changed, final InputStream in);
|
||||
}
|
||||
|
||||
@Accessors
|
||||
private URIConverter converter;
|
||||
|
||||
@Accessors
|
||||
private URI baseDir;
|
||||
|
||||
@Accessors
|
||||
private boolean generateTraces = false;
|
||||
|
||||
@Accessors
|
||||
private IEncodingProvider encodingProvider = new IEncodingProvider.Runtime();
|
||||
|
||||
@Accessors
|
||||
private TraceRegionSerializer traceRegionSerializer;
|
||||
|
||||
@Accessors
|
||||
private TraceFileNameProvider traceFileNameProvider;
|
||||
|
||||
@Accessors
|
||||
private URIBasedFileSystemAccess.BeforeDelete beforeDelete = ((URIBasedFileSystemAccess.BeforeDelete) (URI it) -> {
|
||||
return true;
|
||||
});
|
||||
|
||||
@Accessors
|
||||
private URIBasedFileSystemAccess.BeforeWrite beforeWrite = ((URIBasedFileSystemAccess.BeforeWrite) (URI $0, String $1, InputStream $2) -> {
|
||||
return $2;
|
||||
});
|
||||
|
||||
@Accessors
|
||||
private URIBasedFileSystemAccess.BeforeRead beforeRead = ((URIBasedFileSystemAccess.BeforeRead) (URI $0, InputStream $1) -> {
|
||||
return $1;
|
||||
});
|
||||
|
||||
@Override
|
||||
public void setPostProcessor(final IFilePostProcessor filePostProcessor) {
|
||||
super.setPostProcessor(filePostProcessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getURI(final String path, final String outputConfiguration) {
|
||||
final String outlet = this.getPathes().get(outputConfiguration);
|
||||
if ((outlet == null)) {
|
||||
throw new IllegalArgumentException((("A slot with name \'" + outputConfiguration) + "\' has not been configured."));
|
||||
}
|
||||
final URI uri = URI.createFileURI(((outlet + File.separator) + path));
|
||||
if ((this.baseDir != null)) {
|
||||
final URI resolved = uri.resolve(this.baseDir);
|
||||
return resolved;
|
||||
} else {
|
||||
return uri;
|
||||
}
|
||||
}
|
||||
|
||||
public String getEncoding(final URI uri) {
|
||||
return this.encodingProvider.getEncoding(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateFile(final String fileName, final String outputCfgName, final CharSequence contents) {
|
||||
try {
|
||||
final URI uri = this.getURI(fileName, outputCfgName);
|
||||
if (((!this.getOutputConfig(outputCfgName).isOverrideExistingResources()) && this.converter.exists(uri, CollectionLiterals.<Object, Object>emptyMap()))) {
|
||||
return;
|
||||
}
|
||||
final String encoding = this.getEncoding(uri);
|
||||
final CharSequence postProcessed = this.postProcess(fileName, outputCfgName, contents, encoding);
|
||||
this.generateTrace(fileName, outputCfgName, postProcessed);
|
||||
byte[] _bytes = postProcessed.toString().getBytes(encoding);
|
||||
final ByteArrayInputStream inStream = new ByteArrayInputStream(_bytes);
|
||||
this.generateFile(fileName, outputCfgName, inStream);
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateTrace(final String generatedFile, final String outputConfigName, final CharSequence contents) {
|
||||
try {
|
||||
if ((this.isGenerateTraces() && (contents instanceof ITraceRegionProvider))) {
|
||||
try {
|
||||
AbstractTraceRegion traceRegion = ((ITraceRegionProvider) contents).getTraceRegion();
|
||||
String traceFileName = this.traceFileNameProvider.getTraceFromJava(generatedFile);
|
||||
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
this.traceRegionSerializer.writeTraceRegionTo(traceRegion, out);
|
||||
byte[] _byteArray = out.toByteArray();
|
||||
ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
|
||||
this.generateFile(traceFileName, outputConfigName, _byteArrayInputStream);
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof TraceNotFoundException) {
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateFile(final String fileName, final String outputCfgName, final InputStream content) throws RuntimeIOException {
|
||||
try {
|
||||
final URI uri = this.getURI(fileName, outputCfgName);
|
||||
final OutputStream out = this.converter.createOutputStream(uri);
|
||||
try {
|
||||
final InputStream processedContent = this.beforeWrite.beforeWrite(uri, outputCfgName, content);
|
||||
ByteStreams.copy(processedContent, out);
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream readBinaryFile(final String fileName, final String outputCfgName) throws RuntimeIOException {
|
||||
try {
|
||||
try {
|
||||
final URI uri = this.getURI(fileName, outputCfgName);
|
||||
final InputStream input = this.converter.createInputStream(uri);
|
||||
return this.beforeRead.beforeRead(uri, input);
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof FileNotFoundException) {
|
||||
final FileNotFoundException e = (FileNotFoundException)_t;
|
||||
throw new RuntimeIOException(e);
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence readTextFile(final String fileName, final String outputCfgName) throws RuntimeIOException {
|
||||
try {
|
||||
final URI uri = this.getURI(fileName, outputCfgName);
|
||||
final InputStream inputstream = this.readBinaryFile(fileName, outputCfgName);
|
||||
String _encoding = this.getEncoding(uri);
|
||||
InputStreamReader _inputStreamReader = new InputStreamReader(inputstream, _encoding);
|
||||
return CharStreams.toString(_inputStreamReader);
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Pure
|
||||
public URIConverter getConverter() {
|
||||
return this.converter;
|
||||
}
|
||||
|
||||
public void setConverter(final URIConverter converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public URI getBaseDir() {
|
||||
return this.baseDir;
|
||||
}
|
||||
|
||||
public void setBaseDir(final URI baseDir) {
|
||||
this.baseDir = baseDir;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public boolean isGenerateTraces() {
|
||||
return this.generateTraces;
|
||||
}
|
||||
|
||||
public void setGenerateTraces(final boolean generateTraces) {
|
||||
this.generateTraces = generateTraces;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public IEncodingProvider getEncodingProvider() {
|
||||
return this.encodingProvider;
|
||||
}
|
||||
|
||||
public void setEncodingProvider(final IEncodingProvider encodingProvider) {
|
||||
this.encodingProvider = encodingProvider;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public TraceRegionSerializer getTraceRegionSerializer() {
|
||||
return this.traceRegionSerializer;
|
||||
}
|
||||
|
||||
public void setTraceRegionSerializer(final TraceRegionSerializer traceRegionSerializer) {
|
||||
this.traceRegionSerializer = traceRegionSerializer;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public TraceFileNameProvider getTraceFileNameProvider() {
|
||||
return this.traceFileNameProvider;
|
||||
}
|
||||
|
||||
public void setTraceFileNameProvider(final TraceFileNameProvider traceFileNameProvider) {
|
||||
this.traceFileNameProvider = traceFileNameProvider;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public URIBasedFileSystemAccess.BeforeDelete getBeforeDelete() {
|
||||
return this.beforeDelete;
|
||||
}
|
||||
|
||||
public void setBeforeDelete(final URIBasedFileSystemAccess.BeforeDelete beforeDelete) {
|
||||
this.beforeDelete = beforeDelete;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public URIBasedFileSystemAccess.BeforeWrite getBeforeWrite() {
|
||||
return this.beforeWrite;
|
||||
}
|
||||
|
||||
public void setBeforeWrite(final URIBasedFileSystemAccess.BeforeWrite beforeWrite) {
|
||||
this.beforeWrite = beforeWrite;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public URIBasedFileSystemAccess.BeforeRead getBeforeRead() {
|
||||
return this.beforeRead;
|
||||
}
|
||||
|
||||
public void setBeforeRead(final URIBasedFileSystemAccess.BeforeRead beforeRead) {
|
||||
this.beforeRead = beforeRead;
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator.trace;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtext.generator.trace.AbstractURIWrapper;
|
||||
import org.eclipse.xtext.generator.trace.SourceRelativeURI;
|
||||
import org.eclipse.xtext.workspace.IProjectConfig;
|
||||
import org.eclipse.xtext.workspace.ISourceFolder;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
|
||||
/**
|
||||
* An absolute URI that allows to obtain a resource in a {@link IProjectConfig project}.
|
||||
*
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class AbsoluteURI extends AbstractURIWrapper {
|
||||
public AbsoluteURI(final URI absoluteURI) {
|
||||
super(absoluteURI);
|
||||
if ((absoluteURI.isRelative() || (!absoluteURI.isHierarchical()))) {
|
||||
String _valueOf = String.valueOf(absoluteURI);
|
||||
throw new IllegalArgumentException(_valueOf);
|
||||
}
|
||||
}
|
||||
|
||||
public AbsoluteURI(final String absoluteURI) {
|
||||
this(URI.createURI(absoluteURI));
|
||||
}
|
||||
|
||||
public SourceRelativeURI deresolve(final URI sourceFolderURI) {
|
||||
try {
|
||||
URI _deresolve = this.getURI().deresolve(sourceFolderURI);
|
||||
return new SourceRelativeURI(_deresolve);
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof IllegalArgumentException) {
|
||||
final IllegalArgumentException e = (IllegalArgumentException)_t;
|
||||
URI _uRI = this.getURI();
|
||||
String _plus = ("Base URI was " + _uRI);
|
||||
throw new IllegalArgumentException(_plus, e);
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SourceRelativeURI deresolve(final ISourceFolder sourceFolder) {
|
||||
return this.deresolve(sourceFolder.getPath());
|
||||
}
|
||||
|
||||
public SourceRelativeURI deresolve(final IProjectConfig projectConfig) {
|
||||
final ISourceFolder sourceFolder = projectConfig.findSourceFolderContaining(this.getURI());
|
||||
SourceRelativeURI _deresolve = null;
|
||||
if (sourceFolder!=null) {
|
||||
_deresolve=this.deresolve(sourceFolder);
|
||||
}
|
||||
return _deresolve;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (((obj != null) && (!Objects.equal(obj.getClass(), AbsoluteURI.class)))) {
|
||||
String _valueOf = String.valueOf(obj);
|
||||
String _plus = (_valueOf + " instanceof ");
|
||||
Class<?> _class = null;
|
||||
if (obj!=null) {
|
||||
_class=obj.getClass();
|
||||
}
|
||||
String _name = null;
|
||||
if (_class!=null) {
|
||||
_name=_class.getName();
|
||||
}
|
||||
String _plus_1 = (_plus + _name);
|
||||
throw new IllegalArgumentException(_plus_1);
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
|
@ -1,667 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator.trace;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Multimaps;
|
||||
import com.google.common.io.CharStreams;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtext.generator.trace.AbstractTraceRegion;
|
||||
import org.eclipse.xtext.generator.trace.ILocationData;
|
||||
import org.eclipse.xtext.generator.trace.SourceRelativeURI;
|
||||
import org.eclipse.xtext.util.ITextRegion;
|
||||
import org.eclipse.xtext.util.TextRegion;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Conversions;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.ListExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@Accessors
|
||||
@SuppressWarnings("all")
|
||||
public abstract class AbstractTraceRegionToString {
|
||||
@Accessors
|
||||
protected static class Insert {
|
||||
private final int offset;
|
||||
|
||||
private final boolean open;
|
||||
|
||||
private final AbstractTraceRegionToString.RegionHandle region;
|
||||
|
||||
private final AbstractTraceRegionToString.LocationHandle location;
|
||||
|
||||
public Insert(final int offset, final boolean open, final AbstractTraceRegionToString.RegionHandle region, final AbstractTraceRegionToString.LocationHandle location) {
|
||||
super();
|
||||
this.offset = offset;
|
||||
this.open = open;
|
||||
this.region = region;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public int getOffset() {
|
||||
return this.offset;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public boolean isOpen() {
|
||||
return this.open;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public AbstractTraceRegionToString.RegionHandle getRegion() {
|
||||
return this.region;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public AbstractTraceRegionToString.LocationHandle getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
}
|
||||
|
||||
@Accessors
|
||||
protected static class File {
|
||||
private final SourceRelativeURI uri;
|
||||
|
||||
private final List<AbstractTraceRegionToString.Insert> inserts = CollectionLiterals.<AbstractTraceRegionToString.Insert>newArrayList();
|
||||
|
||||
private final List<String> lines = CollectionLiterals.<String>newArrayList();
|
||||
|
||||
public File(final SourceRelativeURI uri) {
|
||||
super();
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public SourceRelativeURI getUri() {
|
||||
return this.uri;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public List<AbstractTraceRegionToString.Insert> getInserts() {
|
||||
return this.inserts;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public List<String> getLines() {
|
||||
return this.lines;
|
||||
}
|
||||
}
|
||||
|
||||
@Accessors
|
||||
protected static class RegionHandle {
|
||||
private final int id;
|
||||
|
||||
private final AbstractTraceRegion region;
|
||||
|
||||
private final List<AbstractTraceRegionToString.LocationHandle> locations = CollectionLiterals.<AbstractTraceRegionToString.LocationHandle>newArrayList();
|
||||
|
||||
private final List<AbstractTraceRegionToString.RegionHandle> children = CollectionLiterals.<AbstractTraceRegionToString.RegionHandle>newArrayList();
|
||||
|
||||
public RegionHandle(final int id, final AbstractTraceRegion region) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public AbstractTraceRegion getRegion() {
|
||||
return this.region;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public List<AbstractTraceRegionToString.LocationHandle> getLocations() {
|
||||
return this.locations;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public List<AbstractTraceRegionToString.RegionHandle> getChildren() {
|
||||
return this.children;
|
||||
}
|
||||
}
|
||||
|
||||
@Accessors
|
||||
protected static class LocationHandle {
|
||||
private final AbstractTraceRegionToString.RegionHandle region;
|
||||
|
||||
private final int id;
|
||||
|
||||
private final ILocationData location;
|
||||
|
||||
public LocationHandle(final AbstractTraceRegionToString.RegionHandle region, final int id, final ILocationData location) {
|
||||
super();
|
||||
this.region = region;
|
||||
this.id = id;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public AbstractTraceRegionToString.RegionHandle getRegion() {
|
||||
return this.region;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public ILocationData getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
}
|
||||
|
||||
private int radix = 10;
|
||||
|
||||
private boolean showTree = true;
|
||||
|
||||
private boolean showLegend = true;
|
||||
|
||||
protected abstract String getRemoteText(final SourceRelativeURI uri);
|
||||
|
||||
protected abstract String getLocalText();
|
||||
|
||||
protected abstract AbstractTraceRegion getTrace();
|
||||
|
||||
protected ITextRegion getLocalFrame() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected ITextRegion getRemoteFrame(final SourceRelativeURI uri) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getLocalTitle() {
|
||||
return "generated.java";
|
||||
}
|
||||
|
||||
protected String getRemoteTitle(final SourceRelativeURI uri) {
|
||||
return uri.getURI().toString();
|
||||
}
|
||||
|
||||
protected boolean shouldInclude(final AbstractTraceRegion region) {
|
||||
final ITextRegion frame = this.getLocalFrame();
|
||||
if ((frame == null)) {
|
||||
return true;
|
||||
} else {
|
||||
return frame.contains(region.getMyRegion());
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean shouldInclude(final AbstractTraceRegion region, final ILocationData location) {
|
||||
SourceRelativeURI _elvis = null;
|
||||
SourceRelativeURI _srcRelativePath = location.getSrcRelativePath();
|
||||
if (_srcRelativePath != null) {
|
||||
_elvis = _srcRelativePath;
|
||||
} else {
|
||||
SourceRelativeURI _associatedSrcRelativePath = region.getAssociatedSrcRelativePath();
|
||||
_elvis = _associatedSrcRelativePath;
|
||||
}
|
||||
final ITextRegion frame = this.getRemoteFrame(_elvis);
|
||||
if ((frame == null)) {
|
||||
return true;
|
||||
} else {
|
||||
return frame.contains(location);
|
||||
}
|
||||
}
|
||||
|
||||
protected void add(final Map<SourceRelativeURI, AbstractTraceRegionToString.File> files, final SourceRelativeURI uri, final ITextRegion it, final AbstractTraceRegionToString.RegionHandle region, final AbstractTraceRegionToString.LocationHandle location) {
|
||||
AbstractTraceRegionToString.File file = files.get(uri);
|
||||
if ((file == null)) {
|
||||
AbstractTraceRegionToString.File _file = new AbstractTraceRegionToString.File(uri);
|
||||
AbstractTraceRegionToString.File _file_1 = file = _file;
|
||||
files.put(uri, _file_1);
|
||||
}
|
||||
this.add(file, it, region, location);
|
||||
}
|
||||
|
||||
protected void add(final AbstractTraceRegionToString.File file, final ITextRegion it, final AbstractTraceRegionToString.RegionHandle region, final AbstractTraceRegionToString.LocationHandle location) {
|
||||
int _offset = it.getOffset();
|
||||
AbstractTraceRegionToString.Insert _insert = new AbstractTraceRegionToString.Insert(_offset, true, region, location);
|
||||
file.inserts.add(_insert);
|
||||
int _offset_1 = it.getOffset();
|
||||
int _length = it.getLength();
|
||||
int _plus = (_offset_1 + _length);
|
||||
AbstractTraceRegionToString.Insert _insert_1 = new AbstractTraceRegionToString.Insert(_plus, false, region, location);
|
||||
file.inserts.add(_insert_1);
|
||||
}
|
||||
|
||||
protected int collect(final AbstractTraceRegion reg, final int nextID, final AbstractTraceRegionToString.File lFile, final Map<SourceRelativeURI, AbstractTraceRegionToString.File> rFiles, final List<AbstractTraceRegionToString.RegionHandle> result) {
|
||||
int i = nextID;
|
||||
List<AbstractTraceRegionToString.RegionHandle> childResult = result;
|
||||
boolean _shouldInclude = this.shouldInclude(reg);
|
||||
if (_shouldInclude) {
|
||||
int _plusPlus = i++;
|
||||
final AbstractTraceRegionToString.RegionHandle regHandle = new AbstractTraceRegionToString.RegionHandle(_plusPlus, reg);
|
||||
result.add(regHandle);
|
||||
childResult = regHandle.children;
|
||||
this.add(lFile, reg.getMyRegion(), regHandle, null);
|
||||
final Function1<ILocationData, Boolean> _function = (ILocationData it) -> {
|
||||
return Boolean.valueOf(this.shouldInclude(reg, it));
|
||||
};
|
||||
final List<ILocationData> locs = IterableExtensions.<ILocationData>toList(IterableExtensions.<ILocationData>filter(reg.getAssociatedLocations(), _function));
|
||||
for (int j = 0; (j < locs.size()); j++) {
|
||||
{
|
||||
final ILocationData loc = locs.get(j);
|
||||
int _xifexpression = (int) 0;
|
||||
int _size = locs.size();
|
||||
boolean _greaterThan = (_size > 1);
|
||||
if (_greaterThan) {
|
||||
_xifexpression = (j + 1);
|
||||
} else {
|
||||
_xifexpression = (-1);
|
||||
}
|
||||
final AbstractTraceRegionToString.LocationHandle locHandle = new AbstractTraceRegionToString.LocationHandle(regHandle, _xifexpression, loc);
|
||||
regHandle.locations.add(locHandle);
|
||||
SourceRelativeURI _elvis = null;
|
||||
SourceRelativeURI _srcRelativePath = loc.getSrcRelativePath();
|
||||
if (_srcRelativePath != null) {
|
||||
_elvis = _srcRelativePath;
|
||||
} else {
|
||||
SourceRelativeURI _associatedSrcRelativePath = reg.getAssociatedSrcRelativePath();
|
||||
_elvis = _associatedSrcRelativePath;
|
||||
}
|
||||
final SourceRelativeURI path = _elvis;
|
||||
this.add(rFiles, path, loc, regHandle, locHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<AbstractTraceRegion> _nestedRegions = reg.getNestedRegions();
|
||||
for (final AbstractTraceRegion child : _nestedRegions) {
|
||||
i = this.collect(child, i, lFile, rFiles, childResult);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
protected String render(final AbstractTraceRegionToString.Insert it, final int width) {
|
||||
final String first = Strings.padStart(Integer.toString(it.region.id, this.radix), width, '0');
|
||||
String _xifexpression = null;
|
||||
if (((it.location != null) && (it.location.id >= 0))) {
|
||||
String _string = Integer.toString(it.location.id, this.radix);
|
||||
_xifexpression = ((first + "_") + _string);
|
||||
} else {
|
||||
_xifexpression = first;
|
||||
}
|
||||
return _xifexpression;
|
||||
}
|
||||
|
||||
protected int sortKey(final AbstractTraceRegionToString.Insert it) {
|
||||
final int base = (it.region.id * Short.MAX_VALUE);
|
||||
int _xifexpression = (int) 0;
|
||||
if (((it.location != null) && (it.location.id >= 0))) {
|
||||
_xifexpression = (base + it.location.id);
|
||||
} else {
|
||||
_xifexpression = base;
|
||||
}
|
||||
return _xifexpression;
|
||||
}
|
||||
|
||||
protected String render(final Collection<AbstractTraceRegionToString.Insert> inserts, final int width) {
|
||||
final Function1<AbstractTraceRegionToString.Insert, Boolean> _function = (AbstractTraceRegionToString.Insert it) -> {
|
||||
return Boolean.valueOf(it.open);
|
||||
};
|
||||
final Function1<AbstractTraceRegionToString.Insert, Integer> _function_1 = (AbstractTraceRegionToString.Insert it) -> {
|
||||
return Integer.valueOf(this.sortKey(it));
|
||||
};
|
||||
final Function1<AbstractTraceRegionToString.Insert, String> _function_2 = (AbstractTraceRegionToString.Insert it) -> {
|
||||
return this.render(it, width);
|
||||
};
|
||||
final String opens = IterableExtensions.join(ListExtensions.<AbstractTraceRegionToString.Insert, String>map(IterableExtensions.<AbstractTraceRegionToString.Insert, Integer>sortBy(IterableExtensions.<AbstractTraceRegionToString.Insert>filter(inserts, _function), _function_1), _function_2), ",");
|
||||
final Function1<AbstractTraceRegionToString.Insert, Boolean> _function_3 = (AbstractTraceRegionToString.Insert it) -> {
|
||||
return Boolean.valueOf((!it.open));
|
||||
};
|
||||
final Function1<AbstractTraceRegionToString.Insert, Integer> _function_4 = (AbstractTraceRegionToString.Insert it) -> {
|
||||
int _sortKey = this.sortKey(it);
|
||||
return Integer.valueOf((-_sortKey));
|
||||
};
|
||||
final Function1<AbstractTraceRegionToString.Insert, String> _function_5 = (AbstractTraceRegionToString.Insert it) -> {
|
||||
return this.render(it, width);
|
||||
};
|
||||
final String closes = IterableExtensions.join(ListExtensions.<AbstractTraceRegionToString.Insert, String>map(IterableExtensions.<AbstractTraceRegionToString.Insert, Integer>sortBy(IterableExtensions.<AbstractTraceRegionToString.Insert>filter(inserts, _function_3), _function_4), _function_5), ",");
|
||||
String _xifexpression = null;
|
||||
boolean _isEmpty = opens.isEmpty();
|
||||
if (_isEmpty) {
|
||||
_xifexpression = "";
|
||||
} else {
|
||||
_xifexpression = (("[" + opens) + "[");
|
||||
}
|
||||
final String s1 = _xifexpression;
|
||||
String _xifexpression_1 = null;
|
||||
boolean _isEmpty_1 = closes.isEmpty();
|
||||
if (_isEmpty_1) {
|
||||
_xifexpression_1 = "";
|
||||
} else {
|
||||
_xifexpression_1 = (("]" + closes) + "]");
|
||||
}
|
||||
final String s2 = _xifexpression_1;
|
||||
return (s2 + s1);
|
||||
}
|
||||
|
||||
protected List<String> render(final AbstractTraceRegionToString.File file, final int width) {
|
||||
try {
|
||||
String _xifexpression = null;
|
||||
if ((file.uri == null)) {
|
||||
_xifexpression = this.getLocalText();
|
||||
} else {
|
||||
_xifexpression = this.getRemoteText(file.uri);
|
||||
}
|
||||
final String text = _xifexpression;
|
||||
ITextRegion _elvis = null;
|
||||
ITextRegion _xifexpression_1 = null;
|
||||
if ((file.uri == null)) {
|
||||
_xifexpression_1 = this.getLocalFrame();
|
||||
} else {
|
||||
_xifexpression_1 = this.getRemoteFrame(file.uri);
|
||||
}
|
||||
if (_xifexpression_1 != null) {
|
||||
_elvis = _xifexpression_1;
|
||||
} else {
|
||||
int _length = text.length();
|
||||
TextRegion _textRegion = new TextRegion(0, _length);
|
||||
_elvis = _textRegion;
|
||||
}
|
||||
final ITextRegion frame = _elvis;
|
||||
final Function1<AbstractTraceRegionToString.Insert, Boolean> _function = (AbstractTraceRegionToString.Insert it) -> {
|
||||
return Boolean.valueOf(((it.offset >= frame.getOffset()) && (it.offset <= (frame.getOffset() + frame.getLength()))));
|
||||
};
|
||||
final Iterable<AbstractTraceRegionToString.Insert> inframe = IterableExtensions.<AbstractTraceRegionToString.Insert>filter(file.inserts, _function);
|
||||
final Function<AbstractTraceRegionToString.Insert, Integer> _function_1 = (AbstractTraceRegionToString.Insert it) -> {
|
||||
return Integer.valueOf(it.offset);
|
||||
};
|
||||
final Function1<Map.Entry<Integer, Collection<AbstractTraceRegionToString.Insert>>, Integer> _function_2 = (Map.Entry<Integer, Collection<AbstractTraceRegionToString.Insert>> it) -> {
|
||||
return it.getKey();
|
||||
};
|
||||
final List<Map.Entry<Integer, Collection<AbstractTraceRegionToString.Insert>>> offsets = IterableExtensions.<Map.Entry<Integer, Collection<AbstractTraceRegionToString.Insert>>, Integer>sortBy(IterableExtensions.<Map.Entry<Integer, Collection<AbstractTraceRegionToString.Insert>>>toList(Multimaps.<Integer, AbstractTraceRegionToString.Insert>index(inframe, _function_1).asMap().entrySet()), _function_2);
|
||||
int last = frame.getOffset();
|
||||
final StringBuilder result = new StringBuilder();
|
||||
for (final Map.Entry<Integer, Collection<AbstractTraceRegionToString.Insert>> e : offsets) {
|
||||
{
|
||||
final Integer offset = e.getKey();
|
||||
final String insert = this.render(e.getValue(), width);
|
||||
final String prefix = text.substring(last, (offset).intValue());
|
||||
result.append(prefix);
|
||||
result.append(insert);
|
||||
last = (offset).intValue();
|
||||
}
|
||||
}
|
||||
int _offset = frame.getOffset();
|
||||
int _length_1 = frame.getLength();
|
||||
final int end = (_offset + _length_1);
|
||||
if ((last < end)) {
|
||||
result.append(text.substring(last, end));
|
||||
}
|
||||
String _string = result.toString();
|
||||
StringReader _stringReader = new StringReader(_string);
|
||||
return CharStreams.readLines(_stringReader);
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
protected String title(final SourceRelativeURI uri, final int width) {
|
||||
String _xifexpression = null;
|
||||
if ((uri == null)) {
|
||||
_xifexpression = this.getLocalTitle();
|
||||
} else {
|
||||
_xifexpression = this.getRemoteTitle(uri);
|
||||
}
|
||||
String _plus = (" " + _xifexpression);
|
||||
final String s = (_plus + " ");
|
||||
int _length = s.length();
|
||||
int _minus = (width - _length);
|
||||
int _divide = (_minus / 2);
|
||||
final String left = Strings.repeat("-", _divide);
|
||||
int _length_1 = s.length();
|
||||
int _length_2 = left.length();
|
||||
int _plus_1 = (_length_1 + _length_2);
|
||||
int _minus_1 = (width - _plus_1);
|
||||
final String right = Strings.repeat("-", _minus_1);
|
||||
return ((left + s) + right);
|
||||
}
|
||||
|
||||
protected <T extends Object> Set<T> collect(final T start, final Function1<? super T, ? extends Iterable<T>> reachable) {
|
||||
return this.<LinkedHashSet<T>, T>collect(start, reachable, CollectionLiterals.<T>newLinkedHashSet());
|
||||
}
|
||||
|
||||
protected <R extends Collection<? super T>, T extends Object> R collect(final T start, final Function1<? super T, ? extends Iterable<T>> reachable, final R collector) {
|
||||
boolean _add = collector.add(start);
|
||||
if (_add) {
|
||||
Iterable<T> _apply = reachable.apply(start);
|
||||
for (final T r : _apply) {
|
||||
this.<R, T>collect(r, reachable, collector);
|
||||
}
|
||||
}
|
||||
return collector;
|
||||
}
|
||||
|
||||
protected String render(final AbstractTraceRegionToString.LocationHandle loc) {
|
||||
String _xifexpression = null;
|
||||
if ((loc.id >= 0)) {
|
||||
String _string = Integer.toString(loc.id, this.radix);
|
||||
_xifexpression = (_string + ": ");
|
||||
} else {
|
||||
_xifexpression = "";
|
||||
}
|
||||
final String prefix = _xifexpression;
|
||||
final String name = loc.location.getClass().getSimpleName();
|
||||
String _xifexpression_1 = null;
|
||||
SourceRelativeURI _srcRelativePath = loc.location.getSrcRelativePath();
|
||||
boolean _tripleNotEquals = (_srcRelativePath != null);
|
||||
if (_tripleNotEquals) {
|
||||
SourceRelativeURI _srcRelativePath_1 = loc.location.getSrcRelativePath();
|
||||
_xifexpression_1 = ("," + _srcRelativePath_1);
|
||||
} else {
|
||||
_xifexpression_1 = "";
|
||||
}
|
||||
final String path = _xifexpression_1;
|
||||
int _offset = loc.location.getOffset();
|
||||
String _plus = (((prefix + name) + "[") + Integer.valueOf(_offset));
|
||||
String _plus_1 = (_plus + ",");
|
||||
int _length = loc.location.getLength();
|
||||
String _plus_2 = (_plus_1 + Integer.valueOf(_length));
|
||||
String _plus_3 = (_plus_2 + path);
|
||||
return (_plus_3 + "]");
|
||||
}
|
||||
|
||||
protected void render(final AbstractTraceRegionToString.RegionHandle region, final int idW, final int offsetW, final int lengthW, final int indent, final List<String> result) {
|
||||
final String id = Strings.padStart(Integer.toString(region.id, this.radix), idW, '0');
|
||||
String _xifexpression = null;
|
||||
boolean _isUseForDebugging = region.region.isUseForDebugging();
|
||||
if (_isUseForDebugging) {
|
||||
_xifexpression = "D";
|
||||
} else {
|
||||
_xifexpression = " ";
|
||||
}
|
||||
final String debug = _xifexpression;
|
||||
final String offset = Strings.padStart(Integer.toString(region.region.getMyOffset()), offsetW, '0');
|
||||
final String length = Strings.padStart(Integer.toString(region.region.getMyLength()), lengthW, '0');
|
||||
final String space = Strings.repeat(" ", indent);
|
||||
final String name = region.region.getClass().getSimpleName();
|
||||
final Function1<AbstractTraceRegionToString.LocationHandle, String> _function = (AbstractTraceRegionToString.LocationHandle it) -> {
|
||||
return this.render(it);
|
||||
};
|
||||
final String locations = IterableExtensions.join(ListExtensions.<AbstractTraceRegionToString.LocationHandle, String>map(region.locations, _function), ", ");
|
||||
final String loc = (((((debug + " ") + offset) + "-") + length) + space);
|
||||
final String header = (((((id + ": ") + loc) + name) + " -> ") + locations);
|
||||
boolean _isEmpty = region.children.isEmpty();
|
||||
if (_isEmpty) {
|
||||
result.add(header);
|
||||
} else {
|
||||
result.add((header + " {"));
|
||||
for (final AbstractTraceRegionToString.RegionHandle child : region.children) {
|
||||
this.render(child, idW, offsetW, lengthW, (indent + 2), result);
|
||||
}
|
||||
String _repeat = Strings.repeat(" ", loc.length());
|
||||
String _plus = ((id + ": ") + _repeat);
|
||||
String _plus_1 = (_plus + "}");
|
||||
result.add(_plus_1);
|
||||
}
|
||||
}
|
||||
|
||||
protected String render() {
|
||||
final AbstractTraceRegionToString.File localFile = new AbstractTraceRegionToString.File(null);
|
||||
final LinkedHashMap<SourceRelativeURI, AbstractTraceRegionToString.File> remoteFiles = CollectionLiterals.<SourceRelativeURI, AbstractTraceRegionToString.File>newLinkedHashMap();
|
||||
final List<AbstractTraceRegionToString.RegionHandle> roothandles = CollectionLiterals.<AbstractTraceRegionToString.RegionHandle>newArrayList();
|
||||
final int maxid = this.collect(this.getTrace(), 1, localFile, remoteFiles, roothandles);
|
||||
final int idwidth = Integer.toString(maxid, this.radix).length();
|
||||
List<String> _render = this.render(localFile, idwidth);
|
||||
Iterables.<String>addAll(localFile.lines, _render);
|
||||
Collection<AbstractTraceRegionToString.File> _values = remoteFiles.values();
|
||||
for (final AbstractTraceRegionToString.File file : _values) {
|
||||
List<String> _render_1 = this.render(file, idwidth);
|
||||
Iterables.<String>addAll(file.lines, _render_1);
|
||||
}
|
||||
final Function1<String, Integer> _function = (String it) -> {
|
||||
return Integer.valueOf(it.length());
|
||||
};
|
||||
Integer _max = IterableExtensions.<Integer>max(ListExtensions.<String, Integer>map(localFile.lines, _function));
|
||||
int _length = this.getLocalTitle().length();
|
||||
int _plus = (_length + 2);
|
||||
final int localWidth = Math.max((_max).intValue(), _plus);
|
||||
final Function1<AbstractTraceRegionToString.File, Integer> _function_1 = (AbstractTraceRegionToString.File it) -> {
|
||||
final Function1<String, Integer> _function_2 = (String it_1) -> {
|
||||
return Integer.valueOf(it_1.length());
|
||||
};
|
||||
Integer _max_1 = IterableExtensions.<Integer>max(ListExtensions.<String, Integer>map(it.lines, _function_2));
|
||||
int _length_1 = this.getRemoteTitle(it.uri).length();
|
||||
int _plus_1 = (_length_1 + 2);
|
||||
return Integer.valueOf(Math.max((_max_1).intValue(), _plus_1));
|
||||
};
|
||||
final Integer remoteWidth = IterableExtensions.<Integer>max(IterableExtensions.<AbstractTraceRegionToString.File, Integer>map(remoteFiles.values(), _function_1));
|
||||
localFile.lines.add(0, this.title(null, localWidth));
|
||||
Collection<AbstractTraceRegionToString.File> _values_1 = remoteFiles.values();
|
||||
for (final AbstractTraceRegionToString.File file_1 : _values_1) {
|
||||
file_1.lines.add(0, this.title(file_1.uri, (remoteWidth).intValue()));
|
||||
}
|
||||
final List<String> left = localFile.lines;
|
||||
final Function1<AbstractTraceRegionToString.File, List<String>> _function_2 = (AbstractTraceRegionToString.File it) -> {
|
||||
return it.lines;
|
||||
};
|
||||
final List<String> right = IterableExtensions.<String>toList(Iterables.<String>concat(IterableExtensions.<AbstractTraceRegionToString.File, List<String>>map(remoteFiles.values(), _function_2)));
|
||||
final ArrayList<String> result = CollectionLiterals.<String>newArrayList();
|
||||
if (this.showLegend) {
|
||||
result.add(
|
||||
"Regions are surrounded by [N[ ... ]N]. Regions on the left and right with the same N are associated.");
|
||||
}
|
||||
for (int i = 0; ((i < ((Object[])Conversions.unwrapArray(left, Object.class)).length) || (i < ((Object[])Conversions.unwrapArray(right, Object.class)).length)); i++) {
|
||||
{
|
||||
String _xifexpression = null;
|
||||
int _size = left.size();
|
||||
boolean _lessThan = (i < _size);
|
||||
if (_lessThan) {
|
||||
_xifexpression = left.get(i);
|
||||
} else {
|
||||
_xifexpression = "";
|
||||
}
|
||||
final String l = Strings.padEnd(_xifexpression, localWidth, ' ');
|
||||
String _xifexpression_1 = null;
|
||||
int _size_1 = right.size();
|
||||
boolean _lessThan_1 = (i < _size_1);
|
||||
if (_lessThan_1) {
|
||||
_xifexpression_1 = right.get(i);
|
||||
} else {
|
||||
_xifexpression_1 = "";
|
||||
}
|
||||
final String r = _xifexpression_1;
|
||||
result.add(((l + " | ") + r));
|
||||
}
|
||||
}
|
||||
if (this.showTree) {
|
||||
String _repeat = Strings.repeat("-", ((localWidth + (remoteWidth).intValue()) + 3));
|
||||
result.add(_repeat);
|
||||
if (this.showLegend) {
|
||||
result.add(
|
||||
"<N>: <isDebug> <offset>-<length> <RegionJavaClass> -> <LocationJavaClass>[<offset>,<length>,<uri>]");
|
||||
}
|
||||
final Function1<AbstractTraceRegionToString.RegionHandle, Set<AbstractTraceRegionToString.RegionHandle>> _function_3 = (AbstractTraceRegionToString.RegionHandle it) -> {
|
||||
final Function1<AbstractTraceRegionToString.RegionHandle, Iterable<AbstractTraceRegionToString.RegionHandle>> _function_4 = (AbstractTraceRegionToString.RegionHandle it_1) -> {
|
||||
return it_1.children;
|
||||
};
|
||||
return this.<AbstractTraceRegionToString.RegionHandle>collect(it, _function_4);
|
||||
};
|
||||
final Iterable<AbstractTraceRegionToString.RegionHandle> allhandles = Iterables.<AbstractTraceRegionToString.RegionHandle>concat(ListExtensions.<AbstractTraceRegionToString.RegionHandle, Set<AbstractTraceRegionToString.RegionHandle>>map(roothandles, _function_3));
|
||||
final Function1<AbstractTraceRegionToString.RegionHandle, Integer> _function_4 = (AbstractTraceRegionToString.RegionHandle it) -> {
|
||||
return Integer.valueOf(it.region.getMyOffset());
|
||||
};
|
||||
final int offsetWidth = String.valueOf(IterableExtensions.<Integer>max(IterableExtensions.<AbstractTraceRegionToString.RegionHandle, Integer>map(allhandles, _function_4))).length();
|
||||
final Function1<AbstractTraceRegionToString.RegionHandle, Integer> _function_5 = (AbstractTraceRegionToString.RegionHandle it) -> {
|
||||
return Integer.valueOf(it.region.getMyLength());
|
||||
};
|
||||
final int lengthWidth = String.valueOf(IterableExtensions.<Integer>max(IterableExtensions.<AbstractTraceRegionToString.RegionHandle, Integer>map(allhandles, _function_5))).length();
|
||||
for (final AbstractTraceRegionToString.RegionHandle handle : roothandles) {
|
||||
this.render(handle, idwidth, offsetWidth, lengthWidth, 1, result);
|
||||
}
|
||||
}
|
||||
return IterableExtensions.join(result, org.eclipse.xtext.util.Strings.newLine());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String _xtrycatchfinallyexpression = null;
|
||||
try {
|
||||
return this.render();
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof Exception) {
|
||||
final Exception e = (Exception)_t;
|
||||
_xtrycatchfinallyexpression = Throwables.getStackTraceAsString(e);
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
return _xtrycatchfinallyexpression;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public int getRadix() {
|
||||
return this.radix;
|
||||
}
|
||||
|
||||
public void setRadix(final int radix) {
|
||||
this.radix = radix;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public boolean isShowTree() {
|
||||
return this.showTree;
|
||||
}
|
||||
|
||||
public void setShowTree(final boolean showTree) {
|
||||
this.showTree = showTree;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public boolean isShowLegend() {
|
||||
return this.showLegend;
|
||||
}
|
||||
|
||||
public void setShowLegend(final boolean showLegend) {
|
||||
this.showLegend = showLegend;
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator.trace;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtend.lib.annotations.Data;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
@Data
|
||||
@SuppressWarnings("all")
|
||||
public abstract class AbstractURIWrapper {
|
||||
private final URI URI;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.URI.toString();
|
||||
}
|
||||
|
||||
public AbstractURIWrapper(final URI URI) {
|
||||
super();
|
||||
this.URI = URI;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public int hashCode() {
|
||||
return 31 * 1 + ((this.URI== null) ? 0 : this.URI.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
AbstractURIWrapper other = (AbstractURIWrapper) obj;
|
||||
if (this.URI == null) {
|
||||
if (other.URI != null)
|
||||
return false;
|
||||
} else if (!this.URI.equals(other.URI))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public URI getURI() {
|
||||
return this.URI;
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.generator.trace;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtext.generator.trace.AbstractURIWrapper;
|
||||
|
||||
/**
|
||||
* A source relative URI.
|
||||
*
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class SourceRelativeURI extends AbstractURIWrapper {
|
||||
public static SourceRelativeURI fromAbsolute(final URI uri) {
|
||||
boolean _isRelative = uri.isRelative();
|
||||
if (_isRelative) {
|
||||
String _string = uri.toString();
|
||||
throw new IllegalArgumentException(_string);
|
||||
}
|
||||
String _substring = uri.path().substring(1);
|
||||
return new SourceRelativeURI(_substring);
|
||||
}
|
||||
|
||||
public SourceRelativeURI(final URI sourceRelativeURI) {
|
||||
super(sourceRelativeURI);
|
||||
if (((!sourceRelativeURI.isRelative()) || sourceRelativeURI.path().startsWith("/"))) {
|
||||
String _valueOf = String.valueOf(sourceRelativeURI);
|
||||
throw new IllegalArgumentException(_valueOf);
|
||||
}
|
||||
}
|
||||
|
||||
public SourceRelativeURI(final String relativeURI) {
|
||||
this(URI.createURI(relativeURI));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (((obj != null) && (!Objects.equal(obj.getClass(), SourceRelativeURI.class)))) {
|
||||
String _valueOf = String.valueOf(obj);
|
||||
String _plus = (_valueOf + " instanceof ");
|
||||
Class<?> _class = null;
|
||||
if (obj!=null) {
|
||||
_class=obj.getClass();
|
||||
}
|
||||
String _name = null;
|
||||
if (_class!=null) {
|
||||
_name=_class.getName();
|
||||
}
|
||||
String _plus_1 = (_plus + _name);
|
||||
throw new IllegalArgumentException(_plus_1);
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue