All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.xtext.xbase.compiler.TreeAppendableUtil.xtend Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2013 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.xbase.compiler

import org.eclipse.xtext.xbase.compiler.output.ITreeAppendable
import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.util.ITextRegionWithLineInformation
import org.eclipse.xtext.generator.trace.LocationData
import org.eclipse.xtext.resource.ILocationInFileProviderExtension
import org.eclipse.xtext.resource.ILocationInFileProvider
import com.google.inject.Inject
import org.eclipse.xtext.xbase.compiler.output.TreeAppendable
import org.eclipse.xtext.util.ITextRegion

class TreeAppendableUtil {
	
	@Inject ILocationInFileProvider locationProvider
	
	def traceSignificant(ITreeAppendable appendable, EObject source) {
		traceSignificant(appendable, source, false)
	}
	
	def traceSignificant(ITreeAppendable appendable, EObject source, boolean useForDebugging) {
		if (appendable instanceof TreeAppendable) {
			appendable.trace(source, ILocationInFileProviderExtension.RegionDescription.SIGNIFICANT, useForDebugging)
		} else {
			val it = locationProvider.getSignificantTextRegion(source) as ITextRegionWithLineInformation
			if (it !== null && it !== ITextRegion.EMPTY_REGION)
				appendable.trace(new LocationData(offset, length, lineNumber, endLineNumber, null), useForDebugging)
			else
				appendable
		}
	}
	
	def traceWithComments(ITreeAppendable appendable, EObject source) {
		if (appendable instanceof TreeAppendable) {
			appendable.trace(source, ILocationInFileProviderExtension.RegionDescription.INCLUDING_COMMENTS, false)
		} else {
			val it = switch(locationProvider) {
				ILocationInFileProviderExtension: locationProvider.getTextRegion(source, ILocationInFileProviderExtension.RegionDescription.INCLUDING_COMMENTS)
				default: locationProvider.getFullTextRegion(source)
			} as ITextRegionWithLineInformation
			if (it != null && it !== ITextRegion.EMPTY_REGION)
				appendable.trace(new LocationData(offset, length, lineNumber, endLineNumber, null))
			else
				appendable
		}
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy