當前位置: 首頁>>代碼示例>>Java>>正文


Java MalformedTreeException類代碼示例

本文整理匯總了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();
	}
}
 
開發者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


注:本文中的org.eclipse.text.edits.MalformedTreeException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。