com.github.javaparser.Range Java Examples
The following examples show how to use
com.github.javaparser.Range.
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: ASTHelper.java From stategen with GNU Affero General Public License v3.0 | 6 votes |
protected static void addBlankImports(List<ImportDeclaration> imports, CompilationUnit nowCompilationUnit) { String lastStartWith = null; int size = imports.size(); for (int i = size - 1; i >= 0; i--) { ImportDeclaration importDeclaration = imports.get(i); String importName = importDeclaration.getName().toString(); int idx = importName.indexOf('.'); if (idx > 0) { String nowStrartWith = importName.substring(0, idx + 1); if (lastStartWith != null && !lastStartWith.equals(nowStrartWith)) { Range range = new Range(Position.pos(0, 0), Position.pos(0, 0)); ImportDeclaration emptyDeclaration = new ImportDeclaration(range, new Name(), false, false); imports.add(i + 1, emptyDeclaration); lastStartWith = null; } else { lastStartWith = nowStrartWith; } } } }
Example #2
Source File: JavaEditorPane.java From Recaf with MIT License | 6 votes |
@Override public void selectMember(String name, String desc) { // Delay until analysis has run while(code == null || (code.getUnit() == null && hasNoErrors())) try { Thread.sleep(50); } catch(InterruptedException ex) { /* ignored */ } // Select member if unit analysis was a success if (code != null && code.getUnit() != null) { // Jump to range if found Optional<Range> range = JavaParserUtil.getMemberRange(code.getUnit(), name, desc); if(range.isPresent()) { int line = range.get().begin.line - 1; int column = range.get().begin.column - 1; Platform.runLater(() -> { codeArea.moveTo(line, column); codeArea.requestFollowCaret(); codeArea.requestFocus(); }); } } }
Example #3
Source File: RefactoringResult.java From gauge-java with Apache License 2.0 | 6 votes |
private Messages.FileChanges getFileChanges(JavaRefactoringElement element) { ArrayList<Diff> diffs = element.getDiffs(); Messages.FileChanges.Builder changes = Messages.FileChanges.newBuilder().setFileName(element.getFile().getAbsolutePath()); for (Diff diff : diffs) { Range range = diff.getRange(); String text = diff.getText(); Spec.Span span = Spec.Span.newBuilder() .setStart(range.begin.line) .setStartChar(range.begin.column) .setEnd(range.end.line) .setEndChar(range.end.column).build(); Messages.TextDiff textDiff = Messages.TextDiff.newBuilder().setContent(text).setSpan(span).build(); changes.addDiffs(textDiff); } return changes.build(); }
Example #4
Source File: MethodBoundaryExtractor.java From scott with MIT License | 5 votes |
@Override public void visit(MethodDeclaration methodDeclaration, Bounderies boundaries) { if (methodDeclaration.getName().getIdentifier().equals(methodName) && isInTheCorrectClass(methodDeclaration)) { Optional<Range> range = methodDeclaration.getRange(); if (range.isPresent()) { boundaries.beginLine = range.get().begin.line; boundaries.endLine = range.get().end.line; } } }
Example #5
Source File: JavaRefactoring.java From gauge-java with Apache License 2.0 | 5 votes |
private Range getParamsRange() { List<Parameter> parameters = registry.get(oldStepValue.getStepText()).getParameters(); if (parameters.isEmpty()) { int line = registry.get(oldStepValue.getStepText()).getSpan().begin.line + 1; int column = registry.get(oldStepValue.getStepText()).getName().length(); return new Range(new Position(line, column), new Position(line, column)); } Range firstParam = parameters.get(0).getRange().get(); Range lastParam = parameters.get(parameters.size() - 1).getRange().get(); return new Range(new Position(firstParam.begin.line, firstParam.begin.column - 1), new Position(lastParam.end.line, lastParam.end.column)); }
Example #6
Source File: JavaRefactoring.java From gauge-java with Apache License 2.0 | 5 votes |
private JavaRefactoringElement addJavaDiffElements(RefactoringMethodVisitor methodVisitor, JavaRefactoringElement javaElement) { List<Parameter> newParameters = methodVisitor.getNewParameters(); Range stepLineSpan = methodVisitor.getStepLineSpan(); javaElement.addDiffs(new Diff("\"" + parameterizedStepValue + "\"", getStepRange(stepLineSpan))); javaElement.addDiffs(new Diff(updatedParameters(newParameters), getParamsRange())); return javaElement; }
Example #7
Source File: StepRegistryEntry.java From gauge-java with Apache License 2.0 | 4 votes |
public void setSpan(Range span) { this.span = span; }
Example #8
Source File: StepRegistryEntry.java From gauge-java with Apache License 2.0 | 4 votes |
public Range getSpan() { return span; }
Example #9
Source File: StepNameRequestProcessor.java From gauge-java with Apache License 2.0 | 4 votes |
public Messages.Message process(Messages.Message message) { boolean isStepPresent = registry.contains(message.getStepNameRequest().getStepValue()); if (!isStepPresent) { return Messages.Message.newBuilder() .setMessageId(message.getMessageId()) .setMessageType(Messages.Message.MessageType.StepNameResponse) .setStepNameResponse(Messages.StepNameResponse.newBuilder().setIsStepPresent(false).build()) .build(); } StepRegistryEntry entry = registry.get(message.getStepNameRequest().getStepValue()); if (entry.getIsExternal()) { return Messages.Message.newBuilder() .setMessageId(message.getMessageId()) .setMessageType(Messages.Message.MessageType.StepNameResponse) .setStepNameResponse(Messages.StepNameResponse.newBuilder() .setIsStepPresent(true) .setIsExternal(true)) .build(); } List<String> stepTexts = entry.getAliases(); Range range = entry.getSpan(); String stepText = entry.getStepText(); String fileName = entry.getFileName(); boolean hasAlias = entry.getHasAlias(); if (!hasAlias) { stepTexts.add(stepText); } Spec.Span.Builder spanBuilder = Spec.Span.newBuilder() .setStart(range.begin.line) .setStartChar(range.begin.column) .setEnd(range.end.line) .setEndChar(range.end.column); return Messages.Message.newBuilder() .setMessageId(message.getMessageId()) .setMessageType(Messages.Message.MessageType.StepNameResponse) .setStepNameResponse(Messages.StepNameResponse.newBuilder() .addAllStepName(stepTexts) .setIsStepPresent(true) .setHasAlias(hasAlias) .setFileName(fileName) .setSpan(spanBuilder).build()) .build(); }
Example #10
Source File: Diff.java From gauge-java with Apache License 2.0 | 4 votes |
public Diff(String text, Range range) { this.text = text; this.range = range; }
Example #11
Source File: Diff.java From gauge-java with Apache License 2.0 | 4 votes |
public Range getRange() { return range; }
Example #12
Source File: JavaRefactoring.java From gauge-java with Apache License 2.0 | 4 votes |
private Range getStepRange(Range range) { return new Range(new Position(range.begin.line, range.begin.column - 1), new Position(range.end.line, range.end.column)); }
Example #13
Source File: RefactoringMethodVisitor.java From gauge-java with Apache License 2.0 | 4 votes |
public Range getStepLineSpan() { return stepSpan; }