本文整理汇总了Java中org.eclipse.jface.text.BadLocationException类的典型用法代码示例。如果您正苦于以下问题:Java BadLocationException类的具体用法?Java BadLocationException怎么用?Java BadLocationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BadLocationException类属于org.eclipse.jface.text包,在下文中一共展示了BadLocationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUnitFqn
import org.eclipse.jface.text.BadLocationException; //导入依赖的package包/类
private String getUnitFqn(int lineNumber, int offset, int length) throws BadLocationException {
IDocument document = getDocument();
IFile file = getFile();
String content = document.get(offset, length).trim();
if (content.trim().length() > 0) {
String className = file.getName().substring(0, file.getName().lastIndexOf('.'));
VFUnit resultantUnit = getSelectedUnit(className, document, content.trim().substring(0, content.length() - 1), lineNumber);
if (resultantUnit != null) {
return resultantUnit.getFullyQualifiedName();
}
}
throw new UnitNotFoundException("Couldn't determine fully qualified name for unit");
}
示例2: computeInitialPattern
import org.eclipse.jface.text.BadLocationException; //导入依赖的package包/类
/**
* Computes and returns the initial pattern for the type search dialog.
*
* If no initial pattern can be computed, an empty string is returned.
*/
private String computeInitialPattern() {
IEditorPart activeEditor = HandlerServiceUtils.getActiveEditor().orNull();
if (activeEditor instanceof N4JSEditor) {
Point range = ((N4JSEditor) activeEditor).getSourceViewer2().getSelectedRange();
try {
String text = ((N4JSEditor) activeEditor).getDocument().get(range.x, range.y);
if (N4JSLanguageUtils.isValidIdentifier(text)
&& !startWithLowercaseLetter(text)
&& !languageHelper.isReservedIdentifier(text)) {
return text;
}
} catch (BadLocationException e) {
LOGGER.error("Failed to infer type search pattern from editor selection.", e);
}
}
return "";
}
示例3: getSelectedUnit
import org.eclipse.jface.text.BadLocationException; //导入依赖的package包/类
private VFUnit getSelectedUnit(String className, IDocument document, String content, int lineNumber) throws BadLocationException {
DataModel dataModel = ServiceUtil.getService(DataModel.class);
// VFClass
// vfClass=dataModel.listClasses().stream().filter(x->x.getSootClass().getName()==className).collect(Collectors.toList()).get(0);
for (VFClass vfClass : dataModel.listClasses()) {
if (vfClass.getSootClass().getName().equals(className)) {
List<VFMethod> vfMethods = vfClass.getMethods();
Map<String, Integer> methodLines = getMethodLineNumbers(document, vfMethods);
Collection<Integer> allMethodLines = methodLines.values();
List<Integer> lesserThanCuurent = allMethodLines.stream().filter(x -> x.intValue() < lineNumber)
.collect(Collectors.toList());
int toBeCompared = lesserThanCuurent.get(lesserThanCuurent.size() - 1);
for (VFMethod method : vfMethods) {
int methodLine = methodLines.get(method.getSootMethod().getDeclaration());
if (toBeCompared == methodLine) {
for (VFUnit unit : method.getUnits()) {
if (unit.getUnit().toString().trim().equals(content)) {
return unit;
}
}
}
}
}
}
return null;
}
示例4: getLineByOffset
import org.eclipse.jface.text.BadLocationException; //导入依赖的package包/类
public static String getLineByOffset(IDocument document, int offset) {
final Scanner scanner = new Scanner(document.get());
int lineNumber = 0;
try {
while (scanner.hasNextLine()) {
final String line = scanner.nextLine();
if (lineNumber == document.getLineOfOffset(offset)) {
return line;
}
lineNumber++;
}
} catch (BadLocationException e) {
e.printStackTrace();
} finally {
if (scanner != null)
scanner.close();
}
return "";
}
示例5: applyAllInSameDocument
import org.eclipse.jface.text.BadLocationException; //导入依赖的package包/类
/**
* Applies all given changes to the given document. This method assumes that 'changes' contains only changes
* intended for the given document; the actual URI stored in the changes is ignored.
*/
public void applyAllInSameDocument(Collection<? extends IAtomicChange> changes, IDocument document)
throws BadLocationException {
DocumentRewriteSession rewriteSession = null;
try {
// prepare
if (document instanceof IDocumentExtension4) {
rewriteSession = ((IDocumentExtension4) document).startRewriteSession(
DocumentRewriteSessionType.UNRESTRICTED);
}
// perform replacements
for (IAtomicChange currRepl : changes) {
currRepl.apply(document);
}
} finally {
// cleanup
if (rewriteSession != null)
((IDocumentExtension4) document).stopRewriteSession(rewriteSession);
}
}
示例6: insertLineAbove
import org.eclipse.jface.text.BadLocationException; //导入依赖的package包/类
/**
* Insert the given string as a new line above the line at the given offset. The given string need not contain any
* line delimiters and the offset need not point to the beginning of a line. If 'sameIndentation' is set to
* <code>true</code>, the new line will be indented as the line at the given offset (i.e. same leading white space).
*/
public static IChange insertLineAbove(IXtextDocument doc, int offset, String txt, boolean sameIndentation)
throws BadLocationException {
final String NL = lineDelimiter(doc, offset);
final IRegion currLineReg = doc.getLineInformationOfOffset(offset);
String indent = "";
if (sameIndentation) {
final String currLine = doc.get(currLineReg.getOffset(), currLineReg.getLength());
int idx = 0;
while (idx < currLine.length() && Character.isWhitespace(currLine.charAt(idx))) {
idx++;
}
indent = currLine.substring(0, idx);
}
return new Replacement(getURI(doc), currLineReg.getOffset(), 0, indent + txt + NL);
}
示例7: removeText
import org.eclipse.jface.text.BadLocationException; //导入依赖的package包/类
/**
* Removes text of the given length at the given offset. If 'removeEntireLineIfEmpty' is set to <code>true</code>,
* the line containing the given text region will be deleted entirely iff the change would leave the line empty
* (i.e. contains only white space) <em>after</em> the removal of the text region.
*/
public static IChange removeText(IXtextDocument doc, int offset, int length, boolean removeEntireLineIfEmpty)
throws BadLocationException {
if (!removeEntireLineIfEmpty) {
// simple
return new Replacement(getURI(doc), offset, length, "");
} else {
// get entire line containing the region to be removed
// OR in case the region spans multiple lines: get *all* lines affected by the removal
final IRegion linesRegion = DocumentUtilN4.getLineInformationOfRegion(doc, offset, length, true);
final String lines = doc.get(linesRegion.getOffset(), linesRegion.getLength());
// simulate the removal
final int offsetRelative = offset - linesRegion.getOffset();
final String lineAfterRemoval = removeSubstring(lines, offsetRelative, length);
final boolean isEmptyAfterRemoval = lineAfterRemoval.trim().isEmpty();
if (isEmptyAfterRemoval) {
// remove entire line (or in case the removal spans multiple lines: remove all affected lines entirely)
return new Replacement(getURI(doc),
linesRegion.getOffset(), linesRegion.getLength(), "");
} else {
// just remove the given text region
return new Replacement(getURI(doc), offset, length, "");
}
}
}
示例8: getPartitionsInfoByType
import org.eclipse.jface.text.BadLocationException; //导入依赖的package包/类
public static HashMap<String, IRegion> getPartitionsInfoByType(IDocument document,
String partitionType) {
HashMap<String, IRegion> lines = new HashMap<String, IRegion>();
final Scanner scanner = new Scanner(document.get());
int lineNumber = 0;
try {
while (scanner.hasNextLine()) {
final String line = scanner.nextLine();
final int offset = document.getLineOffset(lineNumber);
if (document.getPartition(offset).getType().equals(partitionType)) {
lines.put(line, document.getLineInformation(lineNumber));
}
lineNumber++;
}
} catch (BadLocationException e) {
e.printStackTrace();
} finally {
if (scanner != null)
scanner.close();
}
return lines;
}
示例9: endOfLineOf
import org.eclipse.jface.text.BadLocationException; //导入依赖的package包/类
/**
* Returns the end offset of the line that contains the specified offset or
* if the offset is inside a line delimiter, the end offset of the next
* line.
*
* @param offset
* the offset whose line end offset must be computed
* @return the line end offset for the given offset
* @exception BadLocationException
* if offset is invalid in the current document
*/
protected int endOfLineOf(int offset) throws BadLocationException {
IRegion info = fDocument.getLineInformationOfOffset(offset);
if (offset <= info.getOffset() + info.getLength()){
return info.getOffset() + info.getLength();
}
int line = fDocument.getLineOfOffset(offset);
try {
info = fDocument.getLineInformation(line + 1);
return info.getOffset() + info.getLength();
} catch (BadLocationException x) {
return fDocument.getLength();
}
}
示例10: getDamageRegion
import org.eclipse.jface.text.BadLocationException; //导入依赖的package包/类
@Override
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged) {
if (!documentPartitioningChanged) {
try {
IRegion info = fDocument.getLineInformationOfOffset(event.getOffset());
int start = Math.max(partition.getOffset(), info.getOffset());
int end = event.getOffset() + (event.getText() == null ? event.getLength() : event.getText().length());
if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
// optimize the case of the same line
end = info.getOffset() + info.getLength();
} else{
end = endOfLineOf(end);
}
end = Math.min(partition.getOffset() + partition.getLength(), end);
return new Region(start, end - start);
} catch (BadLocationException x) {
}
}
return partition;
}
示例11: getLoadsFromDoc
import org.eclipse.jface.text.BadLocationException; //导入依赖的package包/类
public static List<LoadItem> getLoadsFromDoc(IDocument document)
throws IOException, BadLocationException, IndexOutOfBoundsException, TraceException {
List<LoadItem> loads = new ArrayList<>();
HashMap<String, Integer> aliasLines =
getPartitionsLinesByType(document, MetaModelPartitionScanner.META_MODEL_LOADALIAS);
for (String alias : aliasLines.keySet()) {
String modelPath = "/", instancePath = "/";
int aliasOffset = aliasLines.get(alias);
alias = alias.substring(alias.indexOf("@") + 1);
for (int i = 1; i <= 2; i++) {
IRegion lineInfo = document.getLineInformation(aliasOffset + i);
String line = document.get(lineInfo.getOffset(), lineInfo.getLength());
if (line.toLowerCase().contains("[email protected]")) {
modelPath = line.substring(line.indexOf("@") + 1);
} else if (line.toLowerCase().contains("[email protected]")) {
instancePath = line.substring(line.indexOf("@") + 1);
}
}
LoadItem load = new LoadItem(alias, modelPath, instancePath);
loads.add(load);
}
return loads;
}
示例12: getOffsetAdjustment
import org.eclipse.jface.text.BadLocationException; //导入依赖的package包/类
protected int getOffsetAdjustment(IDocument document, int offset, int length) {
if (length == 0 || Math.abs(length) > 1)
return 0;
try {
if (length < 0) {
if (isOpeningBracket(document.getChar(offset))) {
return 1;
}
} else {
if (isClosingBracket(document.getChar(offset - 1))) {
return -1;
}
}
} catch (BadLocationException e) {
// do nothing
}
return 0;
}
示例13: apply
import org.eclipse.jface.text.BadLocationException; //导入依赖的package包/类
@Override
public void apply(IDocument document) {
// the proposal shall enter always a space after applyment...
String proposal = word;
if (isAddingSpaceAtEnd()) {
proposal += " ";
}
int zeroOffset = offset - textBefore.length();
try {
document.replace(zeroOffset, textBefore.length(), proposal);
nextSelection = zeroOffset + proposal.length();
} catch (BadLocationException e) {
BashEditorUtil.logError("Not able to replace by proposal:" + word +", zero offset:"+zeroOffset+", textBefore:"+textBefore, e);
}
}
示例14: addErrorMarkers
import org.eclipse.jface.text.BadLocationException; //导入依赖的package包/类
private void addErrorMarkers(BashScriptModel model, int severity) {
if (model == null) {
return;
}
IDocument document = getDocument();
if (document == null) {
return;
}
Collection<BashError> errors = model.getErrors();
for (BashError error : errors) {
int startPos = error.getStart();
int line;
try {
line = document.getLineOfOffset(startPos);
} catch (BadLocationException e) {
EclipseUtil.logError("Cannot get line offset for " + startPos, e);
line = 0;
}
BashEditorUtil.addScriptError(this, line, error, severity);
}
}
示例15: postprocessGlobal
import org.eclipse.jface.text.BadLocationException; //导入依赖的package包/类
/**
* Performs global post-processing of synthesized code:
* - Adds import declarations
*
* @param ast the owner of the document
* @param env environment that was used for synthesis
* @param document draft program document
* @throws BadLocationException if an error occurred when rewriting document
*/
private void postprocessGlobal(AST ast, Environment env, Document document)
throws BadLocationException {
/* add imports */
ASTRewrite rewriter = ASTRewrite.create(ast);
ListRewrite lrw = rewriter.getListRewrite(cu, CompilationUnit.IMPORTS_PROPERTY);
Set<Class> toImport = new HashSet<>(env.imports);
toImport.addAll(sketch.exceptionsThrown()); // add all catch(...) types to imports
for (Class cls : toImport) {
while (cls.isArray())
cls = cls.getComponentType();
if (cls.isPrimitive() || cls.getPackage().getName().equals("java.lang"))
continue;
ImportDeclaration impDecl = cu.getAST().newImportDeclaration();
String className = cls.getName().replaceAll("\\$", "\\.");
impDecl.setName(cu.getAST().newName(className.split("\\.")));
lrw.insertLast(impDecl, null);
}
rewriter.rewriteAST(document, null).apply(document);
}