当前位置: 首页>>代码示例>>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;未经允许,请勿转载。