use of org.eclipse.jface.text.Document in project che by eclipse.
the class DelegateCreator method createEdit.
/**
* Performs the actual rewriting and adds an edit to the ASTRewrite set with
* {@link #setSourceRewrite(CompilationUnitRewrite)}.
*
* @throws JavaModelException
*/
public void createEdit() throws JavaModelException {
try {
IDocument document = new Document(fDelegateRewrite.getCu().getBuffer().getContents());
TextEdit edit = fDelegateRewrite.getASTRewrite().rewriteAST(document, fDelegateRewrite.getCu().getJavaProject().getOptions(true));
edit.apply(document, TextEdit.UPDATE_REGIONS);
String newSource = Strings.trimIndentation(document.get(fTrackedPosition.getStartPosition(), fTrackedPosition.getLength()), fPreferences.tabWidth, fPreferences.indentWidth, false);
ASTNode placeholder = fOriginalRewrite.getASTRewrite().createStringPlaceholder(newSource, fDeclaration.getNodeType());
CategorizedTextEditGroup groupDescription = fOriginalRewrite.createCategorizedGroupDescription(getTextEditGroupLabel(), CATEGORY_DELEGATE);
ListRewrite bodyDeclarationsListRewrite = fOriginalRewrite.getASTRewrite().getListRewrite(fDeclaration.getParent(), getTypeBodyDeclarationsProperty());
if (fCopy)
if (fInsertBefore)
bodyDeclarationsListRewrite.insertBefore(placeholder, fDeclaration, groupDescription);
else
bodyDeclarationsListRewrite.insertAfter(placeholder, fDeclaration, groupDescription);
else
bodyDeclarationsListRewrite.replace(fDeclaration, placeholder, groupDescription);
} catch (BadLocationException e) {
JavaPlugin.log(e);
}
}
use of org.eclipse.jface.text.Document in project che by eclipse.
the class SourceProvider method initialize.
public void initialize() throws JavaModelException {
fDocument = fSource == null ? new Document(fTypeRoot.getBuffer().getContents()) : fSource;
fAnalyzer.initialize();
if (hasReturnValue()) {
ASTNode last = getLastStatement();
if (last != null) {
ReturnAnalyzer analyzer = new ReturnAnalyzer();
last.accept(analyzer);
}
}
}
use of org.eclipse.jface.text.Document in project che by eclipse.
the class CodeAssist method createOrganizeImportOperation.
private OrganizeImportResult createOrganizeImportOperation(ICompilationUnit compilationUnit, List<String> chosen) throws CoreException {
CodeGenerationSettings settings = JavaPreferencesSettings.getCodeGenerationSettings(compilationUnit.getJavaProject());
OrganizeImportsOperation operation = new OrganizeImportsOperation(compilationUnit, null, settings.importIgnoreLowercase, !compilationUnit.isWorkingCopy(), true, chosen, null);
NullProgressMonitor monitor = new NullProgressMonitor();
TextEdit edit = operation.createTextEdit(monitor);
OrganizeImportResult result = DtoFactory.newDto(OrganizeImportResult.class);
TypeNameMatch[][] choices = operation.getChoices();
//or all conflicts were resolved (!chosen.isEmpty())
if ((chosen != null && !chosen.isEmpty()) || choices == null || choices.length == 0) {
IBuffer buffer = compilationUnit.getBuffer();
IDocument document = new Document(buffer.getContents());
DocumentChangeListener documentChangeListener = new DocumentChangeListener(document);
try {
edit.apply(document);
} catch (BadLocationException e) {
LOG.debug("Applying Organize import text edits goes wrong:", e);
}
result.setChanges(documentChangeListener.getChanges());
return result;
}
result.setConflicts(createListOfDTOMatches(choices));
return result;
}
use of org.eclipse.jface.text.Document in project che by eclipse.
the class MavenServerService method createProblem.
private Problem createProblem(VirtualFileEntry entry, SAXParseException spe) {
Problem problem = DtoFactory.newDto(Problem.class);
problem.setError(true);
problem.setMessage(spe.getMessage());
if (entry != null) {
int lineNumber = spe.getLineNumber();
int columnNumber = spe.getColumnNumber();
try {
String content = entry.getVirtualFile().getContentAsString();
Document document = new Document(content);
int lineOffset = document.getLineOffset(lineNumber - 1);
problem.setSourceStart(lineOffset + columnNumber - 1);
problem.setSourceEnd(lineOffset + columnNumber);
} catch (ForbiddenException | ServerException | BadLocationException e) {
LOG.error(e.getMessage(), e);
}
}
return problem;
}
use of org.eclipse.jface.text.Document in project che by eclipse.
the class JavaDebuggerUtils method findFqnByPosition.
/**
* Return nested class fqn if line with number {@code lineNumber} contains such element, otherwise return outer class fqn.
*
* @param projectPath
* project path which contains class with {@code outerClassFqn}
* @param outerClassFqn
* fqn outer class
* @param lineNumber
* line position to search
* @throws DebuggerException
*/
public String findFqnByPosition(String projectPath, String outerClassFqn, int lineNumber) throws DebuggerException {
if (projectPath == null) {
return outerClassFqn;
}
IJavaProject project = MODEL.getJavaProject(projectPath);
IType outerClass;
IMember iMember;
try {
outerClass = project.findType(outerClassFqn);
if (outerClass == null) {
return outerClassFqn;
}
String source;
if (outerClass.isBinary()) {
IClassFile classFile = outerClass.getClassFile();
source = classFile.getSource();
} else {
ICompilationUnit unit = outerClass.getCompilationUnit();
source = unit.getSource();
}
Document document = new Document(source);
IRegion region = document.getLineInformation(lineNumber);
int start = region.getOffset();
int end = start + region.getLength();
iMember = binSearch(outerClass, start, end);
} catch (JavaModelException e) {
throw new DebuggerException(format("Unable to find source for class with fqn '%s' in the project '%s'", outerClassFqn, project), e);
} catch (BadLocationException e) {
throw new DebuggerException("Unable to calculate breakpoint location", e);
}
if (iMember instanceof IType) {
return ((IType) iMember).getFullyQualifiedName();
}
if (iMember != null) {
return iMember.getDeclaringType().getFullyQualifiedName();
}
return outerClassFqn;
}
Aggregations