Java Code Examples for org.eclipse.xtext.util.LineAndColumn#getLine()

The following examples show how to use org.eclipse.xtext.util.LineAndColumn#getLine() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: N4JSDiagnosticConverter.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected IssueLocation getLocationForNode(INode node) {
	ITextRegionWithLineInformation nodeRegion = node.getTextRegionWithLineInformation();
	N4JSIssueLocation result = new N4JSIssueLocation();
	result.offset = nodeRegion.getOffset();
	result.length = nodeRegion.getLength();

	LineAndColumn lineAndColumnStart = NodeModelUtils.getLineAndColumn(node, result.offset);
	result.lineNumber = lineAndColumnStart.getLine();
	result.column = lineAndColumnStart.getColumn();

	LineAndColumn lineAndColumnEnd = NodeModelUtils.getLineAndColumn(node, result.offset + result.length);
	result.lineNumberEnd = lineAndColumnEnd.getLine();
	result.columnEnd = lineAndColumnEnd.getColumn();
	return result;
}
 
Example 2
Source File: PreparationStep.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Here we use the target of the original cross reference "id", "property", or "declaredType" to set the rewired
 * target (i.e. symbol table entry) of the corresponding IM-model reference "id_IM", "property_IM", or
 * "declaredType_IM".
 */
private void rewire(EObject eObject, ReferencingElement_IM copyEObject) {
	final IdentifiableElement originalTarget = getOriginalTargetOfNodeToRewire(eObject);
	final SymbolTableEntry rewiredTarget;
	if (!originalTarget.eIsProxy()) {
		// standard case: original target is a valid IdentifiableElement
		rewiredTarget = getSymbolTableEntry(originalTarget, true);
		copyEObject.setRewiredTarget(rewiredTarget);
	} else {
		// special case: unresolved proxy
		// -> this is usually an error, except in the following special cases:
		if (eObject instanceof ParameterizedPropertyAccessExpression) {
			// property access to an any+ type
			// -> because we know the transpiler is never invoked for resources that contain errors, we can
			// simply assume that we have the any+ case without actually checking the type of the receiver
			final String propName = getPropertyAsString((ParameterizedPropertyAccessExpression) eObject);
			((ParameterizedPropertyAccessExpression_IM) copyEObject).setAnyPlusAccess(true);
			((ParameterizedPropertyAccessExpression_IM) copyEObject).setNameOfAnyPlusProperty(propName);
		} else if (isDynamicNamespaceReference(eObject)) {
			// type references via dynamic namespace imports can still be transpiled
			// (no additional properties to set in ParameterizedTypeRef_IM)
		} else if (eObject instanceof IdentifierRef && eObject.eContainer() instanceof JSXElementName) {
			// name of a JSX element, e.g. the "div" in something like: <div prop='value'></div>
			String tagName = ((IdentifierRef) eObject).getIdAsText();
			((IdentifierRef_IM) copyEObject).setIdAsText(tagName);
		} else if (MigrationUtils.isMigrateCall(eObject.eContainer())) {
			// unresolved migrate-calls can still be transpiled
		} else {
			final ICompositeNode node = NodeModelUtils.findActualNodeFor(eObject);
			final LineAndColumn pos = NodeModelUtils.getLineAndColumn(node, node.getOffset());
			throw new UnresolvedProxyInSubGeneratorException(
					eObject.eResource(), pos.getLine(), pos.getColumn());
		}
	}
}
 
Example 3
Source File: DiagnosticConverterImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Computes {@link IssueLocation} for the given offset and length in the given node.
 * 
 * @since 2.21
 */
protected IssueLocation getLocationForNode(INode node, int offset, int length) {
	IssueLocation result = new IssueLocation();
	result.offset = offset;
	result.length = length;
	
	LineAndColumn lineAndColumnStart = NodeModelUtils.getLineAndColumn(node, offset);
	result.lineNumber = lineAndColumnStart.getLine();
	result.column = lineAndColumnStart.getColumn();
	
	LineAndColumn lineAndColumnEnd = NodeModelUtils.getLineAndColumn(node, offset + length);
	result.lineNumberEnd = lineAndColumnEnd.getLine();
	result.columnEnd = lineAndColumnEnd.getColumn();
	return result;
}
 
Example 4
Source File: DocumentExtensions.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public Position newPosition(Resource resource, int offset) {
	if (resource instanceof XtextResource) {
		ICompositeNode rootNode = ((XtextResource) resource).getParseResult().getRootNode();
		LineAndColumn lineAndColumn = getLineAndColumn(rootNode, offset);
		return new Position(lineAndColumn.getLine() - 1, lineAndColumn.getColumn() - 1);
	}
	return null;
}
 
Example 5
Source File: ScriptError.java    From openhab-core with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Creates new ScriptError.
 *
 * This constructor uses the given EObject instance to calculate the exact position.
 *
 * @param message Error Message
 * @param atEObject the EObject instance to use for calculating the position
 *
 */
public ScriptError(final String message, final EObject atEObject) {
    this.message = message;
    INode node = NodeModelUtils.getNode(atEObject);
    LineAndColumn lac = NodeModelUtils.getLineAndColumn(node, node.getOffset());
    this.line = lac.getLine();
    this.column = lac.getColumn();
    this.length = node.getEndOffset() - node.getOffset();
}
 
Example 6
Source File: ScriptError.java    From smarthome with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Creates new ScriptError.
 *
 * This constructor uses the given EObject instance to calculate the exact position.
 *
 * @param message Error Message
 * @param atEObject the EObject instance to use for calculating the position
 *
 */
public ScriptError(final String message, final EObject atEObject) {
    this.message = message;
    INode node = NodeModelUtils.getNode(atEObject);
    LineAndColumn lac = NodeModelUtils.getLineAndColumn(node, node.getOffset());
    this.line = lac.getLine();
    this.column = lac.getColumn();
    this.length = node.getEndOffset() - node.getOffset();
}