<commit_before>/*******************************************************************************
 * Copyright (c) 2012 itemis AG (http://www.itemis.eu) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.xtext.generator.trace;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.resource.ILocationInFileProvider;
import org.eclipse.xtext.util.ITextRegionWithLineInformation;
import org.eclipse.xtext.util.Strings;
import org.eclipse.xtext.workspace.IWorkspaceConfig;
import org.eclipse.xtext.workspace.IWorkspaceConfigProvider;

import com.google.inject.Inject;

/**
 * @author <NAME> - Initial contribution and API
 */
public class CharSequenceTraceWrapper {

	@Inject
	private ILocationInFileProvider locationInFileProvider;
	
	@Inject
	private IWorkspaceConfigProvider workspaceConfigProvider;
	
	public CharSequence wrapWithTraceData(CharSequence sequence, EObject origin) {
		ITextRegionWithLineInformation location = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(origin);
		AbsoluteURI absoluteURI = new AbsoluteURI(origin.eResource().getURI());
		IWorkspaceConfig workspaceConfig = workspaceConfigProvider.getWorkspaceConfig(EcoreUtil2.getResourceSet(origin));
		SourceRelativeURI sourceRelativeURI = absoluteURI.deresolve(workspaceConfig);
		return wrapWithTraceData(sequence, sourceRelativeURI, location.getOffset(), location.getLength(), location.getLineNumber(), location.getEndLineNumber());
	}
	
	public CharSequence wrapWithTraceData(CharSequence sequence, SourceRelativeURI originResourceURI, int originOffset, int originLength, int originLineNumber, int originEndLineNumber) {
		if (!originResourceURI.getURI().isPlatformResource()) {
			throw new IllegalArgumentException("URI has to be a platform resource uri but was: " + originResourceURI+ ". Use #wrapWithTraceData(CharSequence, URI, String, int, int) instead.");
		}
		return wrapWithTraceData(sequence, originResourceURI, originResourceURI.getURI().segment(1), originOffset, originLength, originLineNumber, originEndLineNumber);
	}
	
	public CharSequence wrapWithTraceData(CharSequence sequence, SourceRelativeURI originURI, String originProject, int originOffset, int originLength, int originLineNumber, int originEndLineNumber) {
		return new CharSequenceBasedTraceRegionProvider(sequence, originURI, originOffset, originLength, originLineNumber, originEndLineNumber);
	}
	
	protected static class CharSequenceBasedTraceRegionProvider implements ITraceRegionProvider, CharSequence {

		private final CharSequence delegate;
		private final SourceRelativeURI originURI;
		private final int originOffset;
		private final int originLength;
		private final int originLineNumber;
		private final int originEndLineNumber;

		public CharSequenceBasedTraceRegionProvider(CharSequence delegate, SourceRelativeURI originURI,
				int originOffset, int originLength, int originLineNumber, int originEndLineNumber) {<commit_msg>[473079] Removed wrong guard condition<commit_after>/*******************************************************************************
 * Copyright (c) 2012 itemis AG (http://www.itemis.eu) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.xtext.generator.trace;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.resource.ILocationInFileProvider;
import org.eclipse.xtext.util.ITextRegionWithLineInformation;
import org.eclipse.xtext.util.Strings;
import org.eclipse.xtext.workspace.IWorkspaceConfig;
import org.eclipse.xtext.workspace.IWorkspaceConfigProvider;

import com.google.inject.Inject;

/**
 * @author <NAME> - Initial contribution and API
 */
public class CharSequenceTraceWrapper {

	@Inject
	private ILocationInFileProvider locationInFileProvider;
	
	@Inject
	private IWorkspaceConfigProvider workspaceConfigProvider;
	
	public CharSequence wrapWithTraceData(CharSequence sequence, EObject origin) {
		ITextRegionWithLineInformation location = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(origin);
		AbsoluteURI absoluteURI = new AbsoluteURI(origin.eResource().getURI());
		IWorkspaceConfig workspaceConfig = workspaceConfigProvider.getWorkspaceConfig(EcoreUtil2.getResourceSet(origin));
		SourceRelativeURI sourceRelativeURI = absoluteURI.deresolve(workspaceConfig);
		return wrapWithTraceData(sequence, sourceRelativeURI, location.getOffset(), location.getLength(), location.getLineNumber(), location.getEndLineNumber());
	}
	
	public CharSequence wrapWithTraceData(CharSequence sequence, SourceRelativeURI originResourceURI, int originOffset, int originLength, int originLineNumber, int originEndLineNumber) {
		return wrapWithTraceData(sequence, originResourceURI, originResourceURI.getURI().segment(1), originOffset, originLength, originLineNumber, originEndLineNumber);
	}
	
	public CharSequence wrapWithTraceData(CharSequence sequence, SourceRelativeURI originURI, String originProject, int originOffset, int originLength, int originLineNumber, int originEndLineNumber) {
		return new CharSequenceBasedTraceRegionProvider(sequence, originURI, originOffset, originLength, originLineNumber, originEndLineNumber);
	}
	
	protected static class CharSequenceBasedTraceRegionProvider implements ITraceRegionProvider, CharSequence {

		private final CharSequence delegate;
		private final SourceRelativeURI originURI;
		private final int originOffset;
		private final int originLength;
		private final int originLineNumber;
		private final int originEndLineNumber;

		public CharSequenceBasedTraceRegionProvider(CharSequence delegate, SourceRelativeURI originURI,
				int originOffset, int originLength, int originLineNumber, int originEndLineNumber) {
{'fraction_non_alphanumeric': 0.11894620602618709, 'fraction_numerical': 0.004417100489036125, 'mean_word_length': 7.625850340136054, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2149003', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1530, 'n_words': 408}