if (thenStatement != null) { if (!(thenStatement instanceof CtBlock)) { if (comment.getPosition().getSourceEnd() <= thenStatement.getPosition().getSourceStart()) { thenStatement.addComment(comment); return; SourcePosition thenPosition = thenStatement.getPosition(); if (!thenPosition.isValidPosition() && thenStatement instanceof CtBlock) { CtStatement thenExpression = ((CtBlock) thenStatement).getStatement(0); thenPosition = thenExpression.getPosition(); SourcePosition elsePosition = elseStatement.getPosition(); if (!elsePosition.isValidPosition() && elseStatement instanceof CtBlock) { CtStatement elseExpression = ((CtBlock) elseStatement).getStatement(0); elsePosition = elseExpression.getPosition();
SourcePosition buildPosition(CtCase<?> child) { List<CtStatement> statements = child.getStatements(); SourcePosition oldPosition = child.getPosition(); if (statements.isEmpty()) { //There are no statements. Keep origin position return oldPosition; } int[] lineSeparatorPositions = this.jdtTreeBuilder.getContextBuilder().getCompilationUnitLineSeparatorPositions(); int bodyStart = child.getPosition().getSourceEnd() + 1; int bodyEnd = statements.get(statements.size() - 1).getPosition().getSourceEnd(); return child.getFactory().Core().createBodyHolderSourcePosition( oldPosition.getCompilationUnit(), oldPosition.getSourceStart(), oldPosition.getSourceEnd(), oldPosition.getSourceStart(), oldPosition.getSourceStart() - 1, oldPosition.getSourceStart(), bodyEnd, bodyStart, bodyEnd, lineSeparatorPositions); }
List<CtComment> comments = elementPrinterHelper.getComments(ifElement, CommentOffset.INSIDE); if (thenStmt != null) { SourcePosition thenPosition = thenStmt.getPosition(); if (!thenPosition.isValidPosition() && thenStmt instanceof CtBlock) { CtStatement thenExpression = ((CtBlock) thenStmt).getStatement(0); thenPosition = thenExpression.getPosition();
SourcePosition oldPos = childStmt.getPosition(); int newSourceStart = Math.min(oldPos.getSourceStart(), block.getPosition().getSourceStart()); if (newSourceStart != oldPos.getSourceStart()) {
@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); }
@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())); }
private String getLine() { CtStatement parent = getParentLine(target); String[] split = getClassContent().split("\n"); StringBuilder output = new StringBuilder(); for (int i = parent.getPosition().getLine() - 1; i < parent.getPosition().getEndLine(); i++) { String s = split[i]; output.append(s); output.append("\n"); } return output.toString(); }
/** * @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; }
private Filter<CtAssignment<?, ?>> initializationAssignmentsFilterFor(CtVariable<?> variable, CtStatement statement) { VariableAssignmentFilter variableAssignment = new VariableAssignmentFilter(variable); BeforeLocationFilter<CtAssignment<?, ?>> beforeLocation = new BeforeLocationFilter(CtAssignment.class, statement.getPosition()); InBlockFilter<CtAssignment<?, ?>> inVariableDeclarationBlock = new InBlockFilter(CtAssignment.class, asList(variable.getParent(CtBlock.class))); InBlockFilter<CtAssignment<?, ?>> inStatementBlock = new InBlockFilter(CtAssignment.class, asList(statement.getParent(CtBlock.class))); Filter<CtAssignment<?, ?>> inBlockFilter = new CompositeFilter(FilteringOperator.UNION, inStatementBlock, inVariableDeclarationBlock); return new CompositeFilter(FilteringOperator.INTERSECTION, variableAssignment, beforeLocation, inBlockFilter); }
for (int i = 0; i < split.length; i++) { String s = split[i]; if (i >= parentLine.getPosition().getLine() - 1 && i <= parentLine.getPosition().getEndLine() - 1) { if (i == parentLine.getPosition().getLine() - 1) { output.write(strPatch).line();
@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); }
private void runOnStatement(SourceLocation sourceLocation, List<TestResult> tests) { logger.debug("Analysing {} which is executed by {} tests", sourceLocation, tests.size()); SpoonedClass spoonCl = spooner.forked(sourceLocation.getRootClassName()); if (spoonCl == null || spoonCl.getSimpleType() == null) { logger.debug("cannot spoon "+sourceLocation.toString()); return; } System.out.println(spoonCl.getSimpleType().hashCode()); NopolProcessorBuilder builder = new NopolProcessorBuilder(spoonCl.getSimpleType().getPosition().getFile(), sourceLocation.getLineNumber(), nopolContext); // here, we only collect the processors to be applied later // this does not change the class itself spoonCl.process(builder); final List<NopolProcessor> nopolProcessors = builder.getNopolProcessors(); for (NopolProcessor nopolProcessor : nopolProcessors) { logger.debug("looking with "+nopolProcessor.getClass().toString()); SourcePosition position = nopolProcessor.getTarget().getPosition(); sourceLocation.setSourceStart(position.getSourceStart()); sourceLocation.setSourceEnd(position.getSourceEnd()); List<Patch> patches = executeNopolProcessor(tests, sourceLocation, spoonCl, nopolProcessor); this.nopolResult.addPatches(patches); if (nopolContext.isOnlyOneSynthesisResult() && !patches.isEmpty()) { return; } } }
SourcePosition position = nopolProcessor.getTarget().getPosition(); this.sourceLocation.setSourceStart(position.getSourceStart()); this.sourceLocation.setSourceEnd(position.getSourceEnd());
writer.write("} else "); writer.write(classContent.substring(parentLine.getPosition().getSourceStart(), target.getPosition().getSourceStart())); writer.write(patch.asString()); writer.write(writer.addIndentationToString(classContent.substring(target.getPosition().getSourceEnd() + 1, parentLine.getPosition().getSourceEnd() + 1)));