本文整理汇总了Java中org.eclipse.text.edits.MalformedTreeException类的典型用法代码示例。如果您正苦于以下问题:Java MalformedTreeException类的具体用法?Java MalformedTreeException怎么用?Java MalformedTreeException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MalformedTreeException类属于org.eclipse.text.edits包,在下文中一共展示了MalformedTreeException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
}
开发者ID:angelozerr,项目名称:ec4e,代码行数:30,代码来源:MarkerUtils.java
示例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
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:17,代码来源:TextEditConverter.java
示例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());
}
}
开发者ID:grosenberg,项目名称:fluentmark,代码行数:23,代码来源:ToggleHiddenCommentHandler.java
示例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();
}
}
}
开发者ID:angelozerr,项目名称:typescript.java,代码行数:37,代码来源:DocumentUtils.java
示例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();
}
}
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:JavaFormatter.java
示例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);
}
}
}
开发者ID:eclipse,项目名称:che,代码行数:34,代码来源:TextChange.java
示例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);
}
}
开发者ID:Ixenit,项目名称:eclipsemembersort,代码行数:26,代码来源:SortHandler.java
示例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);
}
}
}
开发者ID:Ixenit,项目名称:eclipsemembersort,代码行数:24,代码来源:SortHandler.java
示例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();
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:JavaFormatter.java
示例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();
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:StubUtility.java
示例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);
}
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:24,代码来源:CleanUpPostSaveListener.java
示例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));
}
}
开发者ID:vogellacompany,项目名称:codemodify,代码行数:19,代码来源:DefaultCodeModifier.java
示例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;
}
开发者ID:vogellacompany,项目名称:codemodify,代码行数:20,代码来源:CodeModifierJob.java
示例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;
}
开发者ID:fabioz,项目名称:Pydev,代码行数:22,代码来源:GeneratePropertiesTestCase.java
示例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();
}
}
开发者ID:GoClipse,项目名称:goclipse,代码行数:22,代码来源:JavaFormatter.java
示例16: renameClass
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
/**
* Rename a class name into another name
*
* @param file
* @param oldClassname
* @param newName
* @param monitor
* @return
* @throws MalformedTreeException
* @throws BadLocationException
* @throws CoreException
*/
public static IFile renameClass(IFile file, String oldClassname, String newName, IProgressMonitor monitor)
throws MalformedTreeException, BadLocationException, CoreException {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
try {
ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file);
CompilationUnit cu = parse(unit);
AST ast = cu.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
String classname = file.getName();
classname = classname.substring(0, classname.indexOf("."));
final String clazz = classname;
ASTVisitor visitor = new ASTVisitor() {
public boolean visit(SimpleName node) {
String s = node.getIdentifier();
if (oldClassname.equalsIgnoreCase(s)) {
rewrite.replace(node, ast.newSimpleName(newName), null);
}
return true;
}
};
cu.accept(visitor);
addPackageDeclarationIfNeeded(file, cu, rewrite, ast);
file.refreshLocal(IResource.DEPTH_ZERO, monitor);
cu = parse(JavaCore.createCompilationUnitFrom(file));
save(cu, rewrite);
} catch (Exception e) {
ResourceManager.logException(e);
}
}
});
return file;
}
开发者ID:gw4e,项目名称:gw4e.project,代码行数:51,代码来源:JDTManager.java
示例17: updateTests
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
private void updateTests(List<ICompilationUnit> findTests,IProgressMonitor monitor) throws MalformedTreeException, BadLocationException, CoreException {
for (ICompilationUnit iCompilationUnit : findTests) {
AnnotationParsing ap = JDTManager.findAnnotationParsingInGeneratedAnnotation(iCompilationUnit, "value");
if (ap.getAnnotations().size()==0) {
JDTManager.addGeneratedAnnotation((IFile)iCompilationUnit.getResource(), newGraphFile, monitor);
}
}
}
开发者ID:gw4e,项目名称:gw4e.project,代码行数:9,代码来源:TestConvertor.java
示例18: rewriteCompilationUnit
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
/**
* Rewrites compilation unit with new source
*
* @param unit
* compilation unit to be rewritten
* @param source
* new source of compilation unit
*/
private void rewriteCompilationUnit(final ICompilationUnit unit, final String source) {
try {
final TextEdit edits = rewriter.rewriteAST();
final Document document = new Document(source);
edits.apply(document);
unit.getBuffer().setContents(document.get());
change.setEdit(edits);
} catch (final JavaModelException | MalformedTreeException | BadLocationException e) {
ConsoleUtils.printError(e.getMessage());
}
}
开发者ID:SAP,项目名称:hybris-commerce-eclipse-plugin,代码行数:20,代码来源:CopyrightManager.java
示例19: remove
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
private void remove(int beg, int len, int markLen) {
try {
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
undoMgr.beginCompoundChange();
MultiTextEdit edit = new MultiTextEdit();
edit.addChild(new DeleteEdit(beg - markLen, markLen));
edit.addChild(new DeleteEdit(beg + len, markLen));
edit.apply(doc);
undoMgr.endCompoundChange();
} catch (MalformedTreeException | BadLocationException e) {
Log.error("Failure removing mark" + e.getMessage());
}
}
开发者ID:grosenberg,项目名称:fluentmark,代码行数:15,代码来源:AbstractMarksHandler.java
示例20: addComment
import org.eclipse.text.edits.MalformedTreeException; //导入依赖的package包/类
private void addComment(IDocument doc, int beg, int len) {
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
undoMgr.beginCompoundChange();
MultiTextEdit edit = new MultiTextEdit();
edit.addChild(new InsertEdit(beg, getCommentBeg()));
edit.addChild(new InsertEdit(beg + len, getCommentEnd()));
try {
edit.apply(doc);
undoMgr.endCompoundChange();
} catch (MalformedTreeException | BadLocationException e) {
Log.error("Failure creating comment " + e.getMessage());
}
}
开发者ID:grosenberg,项目名称:fluentmark,代码行数:15,代码来源:ToggleHiddenCommentHandler.java
注:本文中的org.eclipse.text.edits.MalformedTreeException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论