本文整理汇总了Java中org.eclipse.text.edits.MalformedTreeException类的典型用法代码示例。如果您正苦于以下问题:Java MalformedTreeException类的具体用法?Java MalformedTreeException怎么用?Java MalformedTreeException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MalformedTreeException类属于org.eclipse.text.edits包,在下文中一共展示了MalformedTreeException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyEdits
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
/**
* Method will apply all edits to document as single modification. Needs to
* be executed in UI thread.
*
* @param document
* document to modify
* @param edits
* list of LSP TextEdits
*/
public static void applyEdits(IDocument document, TextEdit edit) {
if (document == null) {
return;
}
IDocumentUndoManager manager = DocumentUndoManagerRegistry.getDocumentUndoManager(document);
if (manager != null) {
manager.beginCompoundChange();
}
try {
RewriteSessionEditProcessor editProcessor = new RewriteSessionEditProcessor(document, edit,
org.eclipse.text.edits.TextEdit.NONE);
editProcessor.performEdits();
} catch (MalformedTreeException | BadLocationException e) {
EditorConfigPlugin.logError(e);
}
if (manager != null) {
manager.endCompoundChange();
}
}
示例2: visit
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
@Override
public boolean visit(CopyTargetEdit edit) {
try {
org.eclipse.lsp4j.TextEdit te = new org.eclipse.lsp4j.TextEdit();
te.setRange(JDTUtils.toRange(compilationUnit, edit.getOffset(), edit.getLength()));
Document doc = new Document(compilationUnit.getSource());
edit.apply(doc, TextEdit.UPDATE_REGIONS);
String content = doc.get(edit.getSourceEdit().getOffset(), edit.getSourceEdit().getLength());
te.setNewText(content);
converted.add(te);
} catch (MalformedTreeException | BadLocationException | CoreException e) {
JavaLanguageServerPlugin.logException("Error converting TextEdits", e);
}
return false; // do not visit children
}
示例3: removeComment
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
private void removeComment(IDocument doc, int offset) {
try {
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
undoMgr.beginCompoundChange();
ITypedRegion par = TextUtilities.getPartition(doc, Partitions.MK_PARTITIONING, offset, false);
int beg = par.getOffset();
int len = par.getLength();
String comment = doc.get(beg, len);
int eLen = markerLen(comment);
int bLen = eLen + 1;
MultiTextEdit edit = new MultiTextEdit();
edit.addChild(new DeleteEdit(beg, bLen));
edit.addChild(new DeleteEdit(beg + len - eLen, eLen));
edit.apply(doc);
undoMgr.endCompoundChange();
} catch (MalformedTreeException | BadLocationException e) {
Log.error("Failure removing comment " + e.getMessage());
}
}
示例4: applyEdits
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
/**
* Method will apply all edits to document as single modification. Needs to
* be executed in UI thread.
*
* @param document
* document to modify
* @param edits
* list of TypeScript {@link CodeEdit}.
* @throws TypeScriptException
* @throws BadLocationException
* @throws MalformedTreeException
*/
public static void applyEdits(IDocument document, List<CodeEdit> codeEdits)
throws TypeScriptException, MalformedTreeException, BadLocationException {
if (document == null || codeEdits.isEmpty()) {
return;
}
IDocumentUndoManager manager = DocumentUndoManagerRegistry.getDocumentUndoManager(document);
if (manager != null) {
manager.beginCompoundChange();
}
try {
TextEdit edit = toTextEdit(codeEdits, document);
// RewriteSessionEditProcessor editProcessor = new
// RewriteSessionEditProcessor(document, edit,
// org.eclipse.text.edits.TextEdit.NONE);
// editProcessor.performEdits();
edit.apply(document);
} finally {
if (manager != null) {
manager.endCompoundChange();
}
}
}
示例5: format
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
/**
* Formats the template buffer.
*
* @param buffer
* @param context
* @throws BadLocationException
*/
public void format(TemplateBuffer buffer, TemplateContext context) throws BadLocationException {
try {
VariableTracker tracker = new VariableTracker(buffer);
IDocument document = tracker.getDocument();
internalFormat(document, context);
convertLineDelimiters(document);
if (!(context instanceof JavaDocContext) && !isReplacedAreaEmpty(context))
trimStart(document);
tracker.updateBuffer();
} catch (MalformedTreeException e) {
throw new BadLocationException();
}
}
示例6: performEdits
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
/**
* Executes the text edits on the given document. Subclasses that override this method should call
* <code>super.performEdits(document)</code>.
*
* @param document the document
* @return an object representing the undo of the executed edits
* @exception MalformedTreeException is thrown if the edit tree isn't in a valid state. This
* exception is thrown before any edit is executed. So the document is still in its original
* state.
* @exception BadLocationException is thrown if one of the edits in the tree can't be executed.
* The state of the document is undefined if this exception is thrown.
* @since 3.5
*/
protected UndoEdit performEdits(IDocument document)
throws BadLocationException, MalformedTreeException {
DocumentRewriteSession session = null;
try {
if (document instanceof IDocumentExtension4) {
session =
((IDocumentExtension4) document)
.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
}
LinkedModeModel.closeAllModels(document);
TextEditProcessor processor = createTextEditProcessor(document, TextEdit.CREATE_UNDO, false);
return processor.performEdits();
} finally {
if (session != null) {
((IDocumentExtension4) document).stopRewriteSession(session);
}
}
}
示例7: _processUnit
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
private void _processUnit(ICompilationUnit cu)
throws JavaModelException, MalformedTreeException, BadLocationException {
// Parse the javacode to be able to modify it
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setSource(cu);
// Create a copy of the CompilationUnit to work on
CompilationUnit copyOfUnit = (CompilationUnit)parser.createAST(null);
MemberComparator comparator = new MemberComparator();
// This helper method will sort our java code with the given comparator
TextEdit edits = CompilationUnitSorter.sort(copyOfUnit, comparator, 0, null, null);
// The sort method gives us null if there weren't any changes
if (edits != null) {
ICompilationUnit workingCopy = cu.getWorkingCopy(new WorkingCopyOwner() {}, null);
workingCopy.applyTextEdit(edits, null);
// Commit changes
workingCopy.commitWorkingCopy(true, null);
}
}
示例8: _sortSelection
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
private void _sortSelection(IStructuredSelection selection)
throws JavaModelException, MalformedTreeException, BadLocationException {
// Iterate through the selected elements
for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
Object fragment = iterator.next();
// If the current element is a java package the retrieve
// its compilation units and process them
if (fragment instanceof IPackageFragment) {
IPackageFragment pkg = (IPackageFragment)fragment;
ICompilationUnit[] compilationUnits = pkg.getCompilationUnits();
for (ICompilationUnit iCompilationUnit : compilationUnits) {
_processUnit(iCompilationUnit);
}
}
else if (fragment instanceof ICompilationUnit) {
_processUnit((ICompilationUnit)fragment);
}
}
}
示例9: format
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
/**
* Formats the template buffer.
* @param buffer
* @param context
* @throws BadLocationException
*/
public void format(TemplateBuffer buffer, TemplateContext context) throws BadLocationException {
try {
VariableTracker tracker= new VariableTracker(buffer);
IDocument document= tracker.getDocument();
internalFormat(document, context);
convertLineDelimiters(document);
if (!(context instanceof JavaDocContext) && !isReplacedAreaEmpty(context))
trimStart(document);
tracker.updateBuffer();
} catch (MalformedTreeException e) {
throw new BadLocationException();
}
}
示例10: fixEmptyVariables
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
private static String fixEmptyVariables(TemplateBuffer buffer, String[] variables) throws MalformedTreeException, BadLocationException {
IDocument doc= new Document(buffer.getString());
int nLines= doc.getNumberOfLines();
MultiTextEdit edit= new MultiTextEdit();
HashSet<Integer> removedLines= new HashSet<Integer>();
for (int i= 0; i < variables.length; i++) {
TemplateVariable position= findVariable(buffer, variables[i]); // look if Javadoc tags have to be added
if (position == null || position.getLength() > 0) {
continue;
}
int[] offsets= position.getOffsets();
for (int k= 0; k < offsets.length; k++) {
int line= doc.getLineOfOffset(offsets[k]);
IRegion lineInfo= doc.getLineInformation(line);
int offset= lineInfo.getOffset();
String str= doc.get(offset, lineInfo.getLength());
if (Strings.containsOnlyWhitespaces(str) && nLines > line + 1 && removedLines.add(new Integer(line))) {
int nextStart= doc.getLineOffset(line + 1);
edit.addChild(new DeleteEdit(offset, nextStart - offset));
}
}
}
edit.apply(doc, 0);
return doc.get();
}
示例11: performEdit
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
private void performEdit(IDocument document, long oldFileValue, LinkedList<UndoEdit> editCollector, long[] oldDocValue, boolean[] setContentStampSuccess) throws MalformedTreeException, BadLocationException, CoreException {
if (document instanceof IDocumentExtension4) {
oldDocValue[0]= ((IDocumentExtension4)document).getModificationStamp();
} else {
oldDocValue[0]= oldFileValue;
}
// perform the changes
for (int index= 0; index < fUndos.length; index++) {
UndoEdit edit= fUndos[index];
UndoEdit redo= edit.apply(document, TextEdit.CREATE_UNDO);
editCollector.addFirst(redo);
}
if (document instanceof IDocumentExtension4 && fDocumentStamp != IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP) {
try {
((IDocumentExtension4)document).replace(0, 0, "", fDocumentStamp); //$NON-NLS-1$
setContentStampSuccess[0]= true;
} catch (BadLocationException e) {
throw wrapBadLocationException(e);
}
}
}
示例12: modify
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
@Override
public void modify(ICompilationUnit cu, IProgressMonitor monitor)
throws MalformedTreeException, BadLocationException, CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, modifiers.size() + 1);
// parse compilation unit
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setSource(cu);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
CompilationUnit astRoot = (CompilationUnit) parser.createAST(subMonitor.split(1));
for (ICompilationUnitModifier compilationUnitModifier : modifiers) {
compilationUnitModifier.modifyCompilationUnit(astRoot, subMonitor.split(1));
}
}
示例13: run
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
@Override
protected IStatus run(IProgressMonitor monitor) {
SubMonitor subMonitor = SubMonitor.convert(monitor, selectedElements.size());
try {
for (Object object : selectedElements) {
if (object instanceof IJavaProject) {
getConverter().modify((IJavaProject) object, subMonitor.split(1));
} else if (object instanceof IPackageFragment) {
getConverter().modify((IPackageFragment) object, subMonitor.split(1));
} else if (object instanceof ICompilationUnit) {
getConverter().modify((ICompilationUnit) object, subMonitor.split(1));
}
}
} catch (MalformedTreeException | BadLocationException | CoreException e) {
return new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass())
.getSymbolicName(), e.getLocalizedMessage(), e);
}
return Status.OK_STATUS;
}
示例14: applyGenerateProperties
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
private IDocument applyGenerateProperties(MockupGeneratePropertiesRequestProcessor requestProcessor)
throws BadLocationException, MalformedTreeException, MisconfigurationException {
IDocument refactoringDoc = new Document(data.source);
MultiTextEdit multi = new MultiTextEdit();
for (GeneratePropertiesRequest req : requestProcessor.getRefactoringRequests()) {
SelectionState state = req.getSelectionState();
if (state.isGetter()) {
multi.addChild(new GetterMethodEdit(req).getEdit());
}
if (state.isSetter()) {
multi.addChild(new SetterMethodEdit(req).getEdit());
}
if (state.isDelete()) {
multi.addChild(new DeleteMethodEdit(req).getEdit());
}
multi.addChild(new PropertyEdit(req).getEdit());
}
multi.apply(refactoringDoc);
return refactoringDoc;
}
示例15: format
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
/**
* Formats the template buffer.
* @param buffer
* @param context
* @throws BadLocationException
*/
public void format(TemplateBuffer buffer, CompilationUnitContext context) throws BadLocationException {
try {
VariableTracker tracker= new VariableTracker(buffer);
IDocument document= tracker.getDocument();
internalFormat(document, context);
convertLineDelimiters(document);
if (!(context instanceof JavaDocContext) && !isReplacedAreaEmpty(context))
trimStart(document);
tracker.updateBuffer();
} catch (MalformedTreeException e) {
throw new BadLocationException();
}
}