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


Java IDocument.getLineInformation方法代碼示例

本文整理匯總了Java中org.eclipse.jface.text.IDocument.getLineInformation方法的典型用法代碼示例。如果您正苦於以下問題:Java IDocument.getLineInformation方法的具體用法?Java IDocument.getLineInformation怎麽用?Java IDocument.getLineInformation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jface.text.IDocument的用法示例。


在下文中一共展示了IDocument.getLineInformation方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getLoadsFromDoc

import org.eclipse.jface.text.IDocument; //導入方法依賴的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

示例2: validateInsertFinalNewline

import org.eclipse.jface.text.IDocument; //導入方法依賴的package包/類
/**
 * Validate 'insert_final_newline' if needed and update the given set of marker.
 *
 * @param document
 *            the document to validate
 * @param remainingMarkers
 *            set of markers to update.
 * @throws BadLocationException
 */
private void validateInsertFinalNewline(IDocument document, Set<IMarker> remainingMarkers)
		throws BadLocationException {
	boolean insertFinalNewline = preferenceStore.getBoolean(EDITOR_INSERT_FINAL_NEWLINE);
	if (!insertFinalNewline) {
		return;
	}
	// Check if there are an empty line at the end of the document.
	if (document.getLength() == 0) {
		return;
	}
	int line = document.getNumberOfLines() - 1;
	IRegion region = document.getLineInformation(line);
	if (region.getLength() > 0) {
		int end = region.getOffset() + region.getLength();
		int start = end - 1;
		addOrUpdateMarker(start, end, insertFinalNewlineType, document, remainingMarkers);
	}
}
 
開發者ID:angelozerr,項目名稱:ec4e,代碼行數:28,代碼來源:ValidateAppliedOptionsStrategy.java

示例3: extractChecker

import org.eclipse.jface.text.IDocument; //導入方法依賴的package包/類
/**
 * Tente de créer un inspecteur de déclaration KSP si la ligne en contient une.
 * 
 * @param file Fichier KSP.
 * @param document Document du fichier.
 * @param lineIdx Index en base zéro de la ligne du document.
 * @return Inspecteur si présence de déclaration KSP, <code>null</code> sinon.
 */
public static KspDeclarationChecker extractChecker(IFile file, IDocument document, int lineIdx) {
	try {
		/* Extrait la ligne du document. */
		IRegion lineInformation = document.getLineInformation(lineIdx);
		String lineContent = document.get(lineInformation.getOffset(), lineInformation.getLength());

		/* Extrait une déclaration KSP. */
		KspDeclarationMainParts declarationParts = KspStringUtils.getVertigoKspDeclarationParts(lineContent);
		if (declarationParts != null) {
			/* Calcule la région du nom de la déclaration KSP */
			String name = declarationParts.getConstantCaseName();
			int fullNameLineOffSet = lineContent.indexOf(name);
			int taskNameOffSet = lineInformation.getOffset() + fullNameLineOffSet;

			/* Vérifie qu'on est dans une région standard */
			/* Permet d'ignorer le contenu des string et des commentaires KSP. */
			if (!DocumentUtils.isContentType(document, taskNameOffSet, KspRegionType.DEFAULT)) {
				return null;
			}

			/* Retourne un inspecteur */
			return new KspDeclarationChecker(document, file);
		}
	} catch (BadLocationException e) {
		ErrorUtils.handle(e);
	}

	/* Pas de déclaration KSP : on retourne null */
	return null;
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:39,代碼來源:KspDeclarationChecker.java

示例4: getStartEndOffsetFromXML

import org.eclipse.jface.text.IDocument; //導入方法依賴的package包/類
/**
 * Returns character offsets from line numbers from JFace Text Document object.
 */
private static int[] getStartEndOffsetFromXML(final XMLStreamReader streamReader,
    final IFile file, final EventMemento memento, final EventMemento current) {
  final int[] offsetStartEnd = new int[2];
  try {
    String charsetName = streamReader.getCharacterEncodingScheme();
    if (charsetName == null) {
      charsetName = "UTF-8";
    }
    final Scanner scanner = new Scanner(file.getContents(), charsetName);
    final IDocument document = new Document(scanner.useDelimiter("\\A").next());
    scanner.close();

    int start = 0;
    int end = 0;

    final IRegion startRegion = document.getLineInformation(memento.getLineNumber() - 1);
    start = startRegion.getOffset() + memento.getColumnNumber() - 2;
    final IRegion endRegion = document.getLineInformation(current.getLineNumber());
    end = endRegion.getOffset() - 1;

    offsetStartEnd[0] = start;
    offsetStartEnd[1] = end;

  } catch (final BadLocationException e1) {
    // e1.printStackTrace();
    System.out
        .println(e1.toString() + " --> in MarkerFactory's getStartEndOffsetFromXML function");
  } catch (final CoreException e) {
    e.printStackTrace();
  }
  return offsetStartEnd;
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:36,代碼來源:MarkerFactory.java

示例5: validateTrimTrailingWhiteSpace

import org.eclipse.jface.text.IDocument; //導入方法依賴的package包/類
/**
 * Validate 'trim_trailing_whitespace' of the lines where region changed if
 * needed and update the given set of marker.
 *
 * @param partition
 *            the region which changed
 * @param remainingMarkers
 *            set of markers to update.
 * @throws BadLocationException
 */
private void validateTrimTrailingWhiteSpace(IDocument document, IRegion partition, Set<IMarker> remainingMarkers)
		throws BadLocationException, CoreException {
	boolean trimTrailingWhiteSpace = preferenceStore.getBoolean(EDITOR_TRIM_TRAILING_WHITESPACE);
	if (!trimTrailingWhiteSpace) {
		return;
	}
	int startLine = document.getLineOfOffset(partition.getOffset());
	int endLine = document.getLineOfOffset(partition.getOffset() + partition.getLength());

	IRegion region = null;
	for (int i = startLine; i < endLine + 1; i++) {
		region = document.getLineInformation(i);
		if (region.getLength() == 0)
			continue;
		int lineStart = region.getOffset();
		int lineExclusiveEnd = lineStart + region.getLength();
		int j = lineExclusiveEnd - 1;
		while (j >= lineStart && Character.isWhitespace(document.getChar(j)))
			--j;
		++j;
		if (j < lineExclusiveEnd) {
			addOrUpdateMarker(j, lineExclusiveEnd, trimTrailingWhitespaceType, document, remainingMarkers);
		}
	}
	if (region != null) {
		for (IMarker marker : new HashSet<>(remainingMarkers)) {
			if (MarkerUtils.getOptionType(marker) == trimTrailingWhitespaceType) {
				int line = MarkerUtilities.getLineNumber(marker) + 1;
				if (line < startLine || line > endLine) {
					remainingMarkers.remove(marker);
				}
			}
		}
	}
}
 
開發者ID:angelozerr,項目名稱:ec4e,代碼行數:46,代碼來源:ValidateAppliedOptionsStrategy.java


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