Java Code Examples for spoon.reflect.code.CtStatement#getPosition()

The following examples show how to use spoon.reflect.code.CtStatement#getPosition() . 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: DelegatingProcessor.java    From nopol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @see spoon.processing.AbstractProcessor#isToBeProcessed(spoon.reflect.declaration.CtElement)
 */
@Override
public boolean isToBeProcessed(final CtStatement candidate) {
    boolean isPracticable = this.predicate.apply(candidate);
    if (isPracticable) {
        SourcePosition position = candidate.getPosition();
        if (position == null || position == SourcePosition.NOPOSITION) {
            return false;
        }
        boolean isSameFile = false;
        boolean isSameLine = position.getLine() == this.line;
        try {
            File f1 = position.getFile().getCanonicalFile().getAbsoluteFile();
            File f2 = file.getCanonicalFile();
            isSameFile = f1.getAbsolutePath().equals(f2.getAbsolutePath());
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
        isPracticable = this.process && isSameLine && isSameFile;
    }
    return isPracticable;
}
 
Example 2
Source File: AbstractCodeAnalyzer.java    From coming with MIT License 6 votes vote down vote up
public boolean isElementBeforeVariable(CtVariableAccess variableAffected, CtElement element) {

		try {
			CtStatement stst = (element instanceof CtStatement) ? (CtStatement) element
					: element.getParent(CtStatement.class);

			CtStatement target = (variableAffected instanceof CtStatement) ? (CtStatement) variableAffected
					: variableAffected.getParent(CtStatement.class);

			return target.getPosition() != null && getParentNotBlock(stst) != null
					&& target.getPosition().getSourceStart() > stst.getPosition().getSourceStart();
		} catch (Exception e) {
			// e.printStackTrace();
		}
		return false;

	}
 
Example 3
Source File: InitialisationProcessor.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isToBeProcessed(CtStatement statement) {
    if (statement.getPosition() == null || statement.getPosition() instanceof NoSourcePosition) {
        return false;
    }
    return (statement.getPosition().getLine() == target().getPosition().getLine()) &&
            (statement.getPosition().getColumn() == target().getPosition().getColumn()) &&
            (FileLibrary.isSameFile(target().getPosition().getFile(), statement.getPosition().getFile()));
}
 
Example 4
Source File: NopolProcessorBuilder.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isToBeProcessed(CtStatement candidate) {
    SourcePosition position = candidate.getPosition();
    if (position == null || position instanceof NoSourcePosition) {
        return false;
    }
    if (!new LineFilter().matches(candidate)) {
        return false;
    }
    boolean isSameFile = FileLibrary.isSameFile(file, position.getFile());
    boolean isSameLine = position.getLine() == this.line;
    return isSameLine && isSameFile && super.isToBeProcessed(candidate);
}
 
Example 5
Source File: NopolProcessor.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isToBeProcessed(CtStatement statement) {
    if (statement.getPosition() instanceof NoSourcePosition || target.getPosition() instanceof NoSourcePosition) {
        return false;
    }
    return target.getPosition().getSourceStart() == statement.getPosition().getSourceStart() && target.getPosition().getSourceEnd() == statement.getPosition().getSourceEnd() && statement.equals(target);
}