本文整理匯總了Java中org.eclipse.jface.text.IRegion類的典型用法代碼示例。如果您正苦於以下問題:Java IRegion類的具體用法?Java IRegion怎麽用?Java IRegion使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IRegion類屬於org.eclipse.jface.text包,在下文中一共展示了IRegion類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: format
import org.eclipse.jface.text.IRegion; //導入依賴的package包/類
/**
* This method makes sure that no changes are applied (no dirty state), if there are no changes. This fixes bug
* GHOLD-272
*/
@Override
public void format(IDocument document, IRegion region) {
IXtextDocument doc = (IXtextDocument) document;
TextEdit e = doc.priorityReadOnly(new FormattingUnitOfWork(doc, region));
if (e == null)
return;
if (e instanceof ReplaceEdit) {
ReplaceEdit r = (ReplaceEdit) e;
if ((r.getOffset() == 0) && (r.getLength() == 0) && (r.getText().isEmpty())) {
return;
}
}
try {
e.apply(document);
} catch (BadLocationException ex) {
throw new RuntimeException(ex);
}
}
示例2: insertLineAbove
import org.eclipse.jface.text.IRegion; //導入依賴的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);
}
示例3: removeText
import org.eclipse.jface.text.IRegion; //導入依賴的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, "");
}
}
}
示例4: endOfLineOf
import org.eclipse.jface.text.IRegion; //導入依賴的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();
}
}
示例5: getDamageRegion
import org.eclipse.jface.text.IRegion; //導入依賴的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;
}
示例6: detectHyperlinks
import org.eclipse.jface.text.IRegion; //導入依賴的package包/類
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region,
boolean canShowMultipleHyperlinks) {
SQLEditor editor = getAdapter(SQLEditor.class);
PgDbParser parser = editor.getParser();
int offset = region.getOffset();
List<PgObjLocation> refs = parser.getObjsForEditor(editor.getEditorInput());
for (PgObjLocation obj : refs) {
if (offset > obj.getOffset()
&& offset < (obj.getOffset() + obj.getObjLength())) {
IHyperlink[] links = parser.getDefinitionsForObj(obj)
.map(def -> new SQLEditorHyperLink(
new Region(def.getOffset(), def.getObjLength()),
new Region(obj.getOffset(), obj.getObjLength()),
obj.getObjName(), def.getFilePath(), def.getLineNumber()))
.toArray(IHyperlink[]::new);
if (links.length != 0) {
return links;
}
}
}
return null;
}
示例7: getHoverRegion
import org.eclipse.jface.text.IRegion; //導入依賴的package包/類
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
PgDbParser parser = editor.getParser();
List<PgObjLocation> refs = parser.getObjsForEditor(editor.getEditorInput());
for (PgObjLocation obj : refs) {
if (offset > obj.getOffset()
&& offset < (obj.getOffset() + obj.getObjLength())) {
Optional<PgObjLocation> loc = parser.getDefinitionsForObj(obj).findAny();
if (loc.isPresent()) {
SQLEditorMyRegion region = new SQLEditorMyRegion(obj.getOffset(), obj.getObjLength());
region.setComment(loc.get().getComment());
return region;
}
}
}
return new Region(offset, 0);
}
示例8: getHoverRegion
import org.eclipse.jface.text.IRegion; //導入依賴的package包/類
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
IDocument document = textViewer.getDocument();
/* Vérifie qu'on est dans une String de KSP */
boolean isSqlString = DocumentUtils.isContentType(document, offset, KspRegionType.STRING);
if (!isSqlString) {
return null;
}
/* Extrait le mot courant. */
ITextSelection selection = new TextSelection(document, offset, 0);
ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.SNAKE_CASE);
if (currentWordSelection == null) {
return null;
}
String currentWord = currentWordSelection.getText();
if (currentWord == null) {
return null;
}
/* Renvoie la région du mot. */
return new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
}
示例9: getHoverInfo
import org.eclipse.jface.text.IRegion; //導入依賴的package包/類
@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
/* Extrait le mot de la région. */
String currentWord = getSelectedWord(textViewer, hoverRegion);
/* Extrait un nom de DTO : Calcul le nom en PascalCase */
String javaName = StringUtils.toPascalCase(currentWord);
/* Cherche le fichier Java du DTO. */
DtoFile dtoFile = DtoManager.getInstance().findDtoFile(javaName);
if (dtoFile == null) {
return null;
}
/* Renvoie le nom Java. Le texte complet sera généré par KspInformationPresenter. */
return javaName;
}
示例10: detectKspName
import org.eclipse.jface.text.IRegion; //導入依賴的package包/類
private IHyperlink[] detectKspName(String currentWord, IRegion targetRegion, FileRegion fileRegion) {
/* Cherche la déclaration. */
KspDeclaration kspDeclaration = KspManager.getInstance().findKspDeclarationByConstantCaseName(currentWord);
if (kspDeclaration == null) {
return null; // NOSONAR
}
/* Vérifie que le focus n'est pas déjà sur la déclaration. */
if (fileRegion.equals(kspDeclaration.getFileRegion())) {
return null; // NOSONAR
}
/* Renvoie un lien vers la déclaration. */
return new IHyperlink[] { new KspDeclarationHyperLink(targetRegion, kspDeclaration) };
}
示例11: reconcile
import org.eclipse.jface.text.IRegion; //導入依賴的package包/類
@Override
public void reconcile(final IRegion partition) {
if (this.document == null) {
return;
}
try {
final ITypedRegion[] partitionRegions =
this.document.computePartitioning(partition.getOffset(), partition.getLength());
for (int i = 0; i < partitionRegions.length; i++) {
if (partitionRegions[i].getType().equals(MetaModelPartitionScanner.META_MODEL_REASON)) {
this.reconcile(null, partitionRegions[i]);
}
}
} catch (final BadLocationException e) {
e.printStackTrace();
}
}
示例12: getPartitionsInfoByType
import org.eclipse.jface.text.IRegion; //導入依賴的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;
}
示例13: getLoadsFromDoc
import org.eclipse.jface.text.IRegion; //導入依賴的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;
}
示例14: validateInsertFinalNewline
import org.eclipse.jface.text.IRegion; //導入依賴的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);
}
}
示例15: getMethodLineNumbers
import org.eclipse.jface.text.IRegion; //導入依賴的package包/類
/**
* This method returns the line numbers of all the methods passed to it.
* @param document The document with which the user is interacting.
* @param vfMethods The list of methods for which the line numbers are required.
* @return Map containing method names and their starting line numbers.
*/
private Map<String, Integer> getMethodLineNumbers(IDocument document, List<VFMethod> vfMethods) {
FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(document);
TreeMap<String, Integer> result = new TreeMap<String, Integer>();
for (VFMethod method : vfMethods) {
try {
method.getSootMethod().getBytecodeSignature();
IRegion region = findReplaceDocumentAdapter.find(0,
method.getSootMethod().getDeclaration().substring(0, method.getSootMethod().getDeclaration().indexOf('(')), true, true, false, false);
if (region != null) {
result.put(method.getSootMethod().getDeclaration(), document.getLineOfOffset(region.getOffset()));
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
return MapUtil.sortByValue(result);
}