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


Java BadLocationException類代碼示例

本文整理匯總了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");
}
 
開發者ID:VisuFlow,項目名稱:visuflow-plugin,代碼行數:14,代碼來源:ToggleJimpleBreakpointsTarget.java

示例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 "";
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:26,代碼來源:OpenTypeSelectionDialogHandler.java

示例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;
}
 
開發者ID:VisuFlow,項目名稱:visuflow-plugin,代碼行數:27,代碼來源:ToggleJimpleBreakpointsTarget.java

示例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 "";
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:20,代碼來源:EditorUtilities.java

示例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);
	}
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:24,代碼來源:ChangeManager.java

示例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);
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:21,代碼來源:ChangeProvider.java

示例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, "");
		}
	}
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:30,代碼來源:ChangeProvider.java

示例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;
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:24,代碼來源:EditorUtilities.java

示例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();
	}
}
 
開發者ID:de-jcup,項目名稱:eclipse-batch-editor,代碼行數:27,代碼來源:PresentationSupport.java

示例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;
}
 
開發者ID:de-jcup,項目名稱:eclipse-batch-editor,代碼行數:27,代碼來源:PresentationSupport.java

示例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;
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:24,代碼來源:EditorUtilities.java

示例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;
}
 
開發者ID:de-jcup,項目名稱:eclipse-bash-editor,代碼行數:19,代碼來源:BashBracketsSupport.java

示例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);
	}

}
 
開發者ID:de-jcup,項目名稱:eclipse-bash-editor,代碼行數:17,代碼來源:BashEditorSimpleWordContentAssistProcessor.java

示例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);
	}

}
 
開發者ID:de-jcup,項目名稱:eclipse-bash-editor,代碼行數:23,代碼來源:BashEditor.java

示例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);
}
 
開發者ID:capergroup,項目名稱:bayou,代碼行數:29,代碼來源:Visitor.java


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