/******************************************************************************* * Copyright (c) 2000, 2009 IBM Corporation 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 * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.che.ide.ext.java.jdt.internal.core.dom.rewrite; import org.eclipse.che.ide.ext.java.jdt.core.dom.ASTNode; import org.eclipse.che.ide.ext.java.jdt.core.dom.rewrite.ITrackedNodePosition; import org.eclipse.che.ide.ext.java.jdt.text.edits.TextEdit; import org.eclipse.che.ide.ext.java.jdt.text.edits.TextEditGroup; import org.eclipse.che.ide.api.text.Region; public class TrackedNodePosition implements ITrackedNodePosition { private final TextEditGroup group; private final ASTNode node; public TrackedNodePosition(TextEditGroup group, ASTNode node) { this.group = group; this.node = node; } /* * (non-Javadoc) * @see org.eclipse.jdt.internal.corext.dom.ITrackedNodePosition#getStartPosition () */ public int getStartPosition() { if (this.group.isEmpty()) { return this.node.getStartPosition(); } Region coverage = TextEdit.getCoverage(this.group.getTextEdits()); if (coverage == null) { return this.node.getStartPosition(); } return coverage.getOffset(); } /* * (non-Javadoc) * @see org.eclipse.jdt.internal.corext.dom.ITrackedNodePosition#getLength() */ public int getLength() { if (this.group.isEmpty()) { return this.node.getLength(); } Region coverage = TextEdit.getCoverage(this.group.getTextEdits()); if (coverage == null) { return this.node.getLength(); } return coverage.getLength(); } }