当前位置: 首页>>代码示例>>Java>>正文


Java ITypedRegion.getOffset方法代码示例

本文整理汇总了Java中org.eclipse.jface.text.ITypedRegion.getOffset方法的典型用法代码示例。如果您正苦于以下问题:Java ITypedRegion.getOffset方法的具体用法?Java ITypedRegion.getOffset怎么用?Java ITypedRegion.getOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jface.text.ITypedRegion的用法示例。


在下文中一共展示了ITypedRegion.getOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeElement

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
public boolean removeElement(int offset) {
	try {
		ITypedRegion region = getNextTagPartition(offset);
		String tag = get(region.getOffset(), region.getLength());
		if (tag.endsWith("/>"))
			replace(region.getOffset(), region.getLength(), "");
		else {
			String tagname = getCurrentTagname(offset);
			ITypedRegion endTagRegion = getNextEndTagPartition(tagname,
					offset);
			int begin = region.getOffset();
			int end = endTagRegion.getOffset() + endTagRegion.getLength()
					- begin;
			replace(begin, end, "");
		}
		return true;
	} catch (BadLocationException e) {
		return true;
	}
}
 
开发者ID:ncleclipse,项目名称:ncl30-eclipse,代码行数:21,代码来源:NCLSourceDocument.java

示例2: removeComment

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
private void removeComment(IDocument doc, int offset) {
	try {
		IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
		undoMgr.beginCompoundChange();

		ITypedRegion par = TextUtilities.getPartition(doc, Partitions.MK_PARTITIONING, offset, false);
		int beg = par.getOffset();
		int len = par.getLength();

		String comment = doc.get(beg, len);
		int eLen = markerLen(comment);
		int bLen = eLen + 1;

		MultiTextEdit edit = new MultiTextEdit();
		edit.addChild(new DeleteEdit(beg, bLen));
		edit.addChild(new DeleteEdit(beg + len - eLen, eLen));
		edit.apply(doc);
		undoMgr.endCompoundChange();
	} catch (MalformedTreeException | BadLocationException e) {
		Log.error("Failure removing comment " + e.getMessage());
	}
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:23,代码来源:ToggleHiddenCommentHandler.java

示例3: addTagStart

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
/**
 * Add start of coverage
 * @param start
 */
public void addTagStart(ITypedRegion start)
{
    // Assert.isTrue(inTag() && !inTag() == !hasUserPartitions(),
    // "Found user partitions which have not been removed. This is a bug.");

    ITypedRegion userRegion = getUserRegion();
    if (userRegion != null)
    {
        stack.push(userRegion);
    }
    TLCRegion startRegion = new TLCRegion(start.getOffset(), start.getLength(), start.getType());
    startRegion.setMessageCode(getMessageCode(start, START));
    startRegion.setSeverity(getSeverity(start));
    // add start to stack
    stack.push(startRegion);
}
 
开发者ID:tlaplus,项目名称:tlaplus,代码行数:21,代码来源:TagBasedTLCAnalyzer.java

示例4: uncommentSelection

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
public void uncommentSelection(ITypedRegion region, IDocument doc){
	int offset  = region.getOffset();
	int endOffset = region.getOffset() + (region.getLength() - commentBegin.length() - commentEnd.length());
	
	if(!region.getType().equals("__xml_comment"))
		return; // we should ignore if the region is not a comment
			
	try {
		doc.replace(offset, commentBegin.length(), ""); // remove start comment
		
		if(doc.get(endOffset, commentEnd.length()).equals(commentEnd))
			doc.replace(endOffset, commentEnd.length(), ""); // remove end comment
		
	} catch (BadLocationException e) {
		e.printStackTrace();
	}
}
 
开发者ID:ncleclipse,项目名称:ncl30-eclipse,代码行数:18,代码来源:CommentSelectionAction.java

示例5: getCharStart

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
private Integer getCharStart(int lineNumber, int columnNumber) {
	try {
		int lineStartChar = document.getLineOffset(lineNumber - 1);
		Integer charEnd = getCharEnd(lineNumber, columnNumber);
		if (charEnd != null) {
			ITypedRegion typedRegion = document.getPartition(charEnd
					.intValue() - 2);
			int partitionStartChar = typedRegion.getOffset();
			return new Integer(partitionStartChar);
		} else
			return new Integer(lineStartChar);
	} catch (BadLocationException e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:ncleclipse,项目名称:ncl30-eclipse,代码行数:17,代码来源:MarkingErrorHandler.java

示例6: checkPartition

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
private int checkPartition(IDocument doc, int beg, int len) {
	try {
		boolean begCmt = TextUtilities.getContentType(doc, Partitions.MK_PARTITIONING, beg, false)
				.equals(Partitions.COMMENT);
		boolean endCmt = TextUtilities.getContentType(doc, Partitions.MK_PARTITIONING, beg + len - 1, false)
				.equals(Partitions.COMMENT);

		if (begCmt && endCmt) {
			ITypedRegion begPar = TextUtilities.getPartition(doc, Partitions.MK_PARTITIONING, beg, false);
			ITypedRegion endPar = TextUtilities.getPartition(doc, Partitions.MK_PARTITIONING, beg + len - 1, false);
			if (begPar.getOffset() == endPar.getOffset()) return SAME;
			return DIFF;
		}
		if ((begCmt && !endCmt) || (!begCmt && endCmt)) return LAPD;
		return NONE;
	} catch (BadLocationException e) {
		Log.error("Bad comment partitioning " + e.getMessage());
		return UNKN;
	}
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:21,代码来源:ToggleHiddenCommentHandler.java

示例7: getOffsetByValue

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
public int getOffsetByValue(String attribute, String value) {
	try {
		if (attribute == null || value == null)
			return -1;
		ITypedRegion region = getPartition(0);
		String t;
		do {
			t = get(region.getOffset(), region.getLength());
			String tagId;
			if (region.getType().equals(XMLPartitionScanner.XML_START_TAG)) {
				tagId = getAttributeValueFromCurrentTagName(
						region.getOffset(), attribute);
				if (tagId != null && !tagId.equals(""))
					if (tagId.equals(value))
						return region.getOffset();
			}
			region = getNextPartition(region);
		} while (!t.equals("</ncl>"));
	} catch (BadLocationException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return -1;
}
 
开发者ID:ncleclipse,项目名称:ncl30-eclipse,代码行数:25,代码来源:NCLSourceDocument.java

示例8: computeCommentFolding

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
@Override
protected void computeCommentFolding(final IXtextDocument xtextDocument,
		final IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor, final ITypedRegion typedRegion,
		final boolean initiallyFolded) throws BadLocationException {
	final int offset = typedRegion.getOffset();
	final int length = typedRegion.getLength();
	final Matcher matcher = getTextPatternInComment().matcher(xtextDocument.get(offset, length));
	((GamaFoldingRegionAcceptor) foldingRegionAcceptor).type = typedRegion.getType();
	if (matcher.find()) {
		final TextRegion significant = new TextRegion(offset + matcher.start(), 0);
		((IFoldingRegionAcceptorExtension<ITextRegion>) foldingRegionAcceptor).accept(offset, length,
				initiallyFolded, significant);
	} else {
		((IFoldingRegionAcceptorExtension<ITextRegion>) foldingRegionAcceptor).accept(offset, length,
				initiallyFolded);
	}
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:18,代码来源:GamaFoldingRegionProvider.java

示例9: getPartition

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
/**
 * Finds the partition containing the given offset.
 * 
 * @param document the document to search
 * @param offset the offset used to find a matching partition
 * @return the partition, or null
 */
public static ITypedRegion getPartition(IStructuredDocument document, int offset) {
  ITypedRegion[] partitions;
  try {
    partitions = TextUtilities.computePartitioning(document,
        IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING, 0,
        document.getLength(), true);
  } catch (BadLocationException e) {
    CorePluginLog.logError(e, "Unexpected bad location exception.");
    return null;
  }

  for (ITypedRegion partition : partitions) {
    if (partition.getOffset() <= offset
        && offset < partition.getOffset() + partition.getLength()) {
      return partition;
    }
  }
  
  return null;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:28,代码来源:SseUtilities.java

示例10: getEnclosingJsniRegion

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
public static ITypedRegion getEnclosingJsniRegion(ITextSelection selection,
    IDocument document) {
  try {
    ITypedRegion region = TextUtilities.getPartition(document,
        GWTPartitions.GWT_PARTITIONING, selection.getOffset(), false);

    if (region.getType().equals(GWTPartitions.JSNI_METHOD)) {
      int regionEnd = region.getOffset() + region.getLength();
      int selectionEnd = selection.getOffset() + selection.getLength();

      // JSNI region should entirely contain the selection
      if (region.getOffset() <= selection.getOffset()
          && regionEnd >= selectionEnd) {
        return region;
      }
    }
  } catch (BadLocationException e) {
    GWTPluginLog.logError(e);
  }

  return null;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:23,代码来源:JsniParser.java

示例11: isExactKspString

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
/**
 * Indique si une sélection d'un document représente exactement une région de string (aux double quote près).
 * 
 * @param document Document.
 * @param selection Sélection de texte.
 * @return <code>true</code> si c'est exactement une région de string.
 */
public static boolean isExactKspString(IDocument document, ITextSelection selection) {
	IDocumentExtension3 extension = (IDocumentExtension3) document;
	try {
		/* Charge les régions du document couverte par la sélecion. */
		ITypedRegion[] regions = extension.computePartitioning(KspRegionType.PARTITIONING, selection.getOffset(), selection.getLength(), false);

		/* Vérifie qu'on a une seule région. */
		if (regions.length != 1) {
			return false;
		}

		/* Charge la région entière */
		ITypedRegion region = extension.getPartition(KspRegionType.PARTITIONING, selection.getOffset(), false);

		/* Vérifie que c'est une région de string KSP. */
		if (!region.getType().equals(KspRegionType.STRING.getContentType())) {
			return false;
		}

		/* Vérifie que la région couvre exactement la sélection */
		int selectionWithQuoteOffset = selection.getOffset() - 1; // Prend en compte la double quote ouvrante.
		int selectionWithQuoteLength = selection.getLength() + 2; // Prend en compte les deux double quote.
		if (region.getOffset() == selectionWithQuoteOffset && region.getLength() == selectionWithQuoteLength) {
			return true;
		}
	} catch (BadLocationException | BadPartitioningException e) {
		ErrorUtils.handle(e);
	}

	return false;
}
 
开发者ID:sebez,项目名称:vertigo-chroma-kspplugin,代码行数:39,代码来源:DocumentUtils.java

示例12: shouldCollapse

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
private boolean shouldCollapse(ITypedRegion beginRegion, int lines) {
	String autofoldOption = prefs.getPreferenceStore().getString(SolidityPreferences.FOLDING_COMMENT_AUTOFOLD);
	if (SolidityPreferences.FOLDING_COMMENT_AUTOFOLD_NONE.equals(autofoldOption))
		return false;
	if (SolidityPreferences.FOLDING_COMMENT_AUTOFOLD_ALL.equals(autofoldOption))
		return true;
	if (SolidityPreferences.FOLDING_COMMENT_AUTOFOLD_HEADER.equals(autofoldOption))
		return beginRegion.getOffset() == 0;
	return false;
}
 
开发者ID:Yakindu,项目名称:solidity-ide,代码行数:11,代码来源:SolidityFoldingRegionProvider.java

示例13: getBaseOffset

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
public int getBaseOffset(String base, String id) {
	if (base == null || base.equals(""))
		return -1;
	try {
		ITypedRegion region = getPartition(0);
		region = getNextTagPartition(region);
		String tagname = getCurrentTagname(region.getOffset());

		while (!tagname.equals("/head")) {
			if (tagname.equals(base))
				if (id == null || id.equals(""))
					return region.getOffset();
				else {
					String baseId = getAttributeValueFromCurrentTagName(
							region.getOffset(), "id");
					if (baseId != null && baseId.equals(id))
						return region.getOffset();
				}

			region = getNextTagPartition(region);
			if (region == null)
				break;
			tagname = getCurrentTagname(region.getOffset());
		}

		return -1;
	} catch (BadLocationException e) {
		e.printStackTrace();
		return -1;
	}
}
 
开发者ID:ncleclipse,项目名称:ncl30-eclipse,代码行数:32,代码来源:NCLSourceDocument.java

示例14: nextPartitionOrLineEnd

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
/**
 * Returns a position in the first java partition after the last non-empty and non-comment
 * partition. There is no non-whitespace from the returned position to the end of the partition
 * it is contained in.
 *
 * @param document the document being modified
 * @param line the line under investigation
 * @param offset the caret offset into <code>line</code>
 * @param partitioning the document partitioning
 * @return the position of the next Java partition, or the end of <code>line</code>
 */
private static int nextPartitionOrLineEnd(IDocument document, ITextSelection line, int offset,
		String partitioning) {
	// run relative to document
	final int docOffset = offset + line.getOffset();
	final int eol = line.getOffset() + line.getLength();
	int nextPartitionPos = eol; // init with line end
	int validPosition = docOffset;

	try {
		ITypedRegion partition = TextUtilities.getPartition(document, partitioning, nextPartitionPos, true);
		validPosition = getValidPositionForPartition(document, partition, eol);
		while (validPosition == -1) {
			nextPartitionPos = partition.getOffset() - 1;
			if (nextPartitionPos < docOffset) {
				validPosition = docOffset;
				break;
			}
			partition = TextUtilities.getPartition(document, partitioning, nextPartitionPos, false);
			validPosition = getValidPositionForPartition(document, partition, eol);
		}
	} catch (BadLocationException e) {}

	validPosition = Math.max(validPosition, docOffset);
	// make relative to line
	validPosition -= line.getOffset();
	return validPosition;
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:39,代码来源:SmartAutoEditStrategy.java

示例15: getCurrentEndTagName

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
public String getCurrentEndTagName(int documentOffset) {
	try {
		ITypedRegion region = getPartition(documentOffset);
		if (!region.getType().equals(XMLPartitionScanner.XML_END_TAG))
			return null;
		int partitionOffset = region.getOffset();
		int readLength = region.getLength();

		String text = get(partitionOffset + 1, readLength);
		int p = 0;
		char ch;
		String tagname = "";
		ch = text.charAt(0);
		while (true) {
			if (p + 1 >= text.length()
					|| !Character.isJavaIdentifierPart(text.charAt(p + 1)))
				break;
			ch = text.charAt(++p);
			tagname += ch;
		}
		return tagname;

	} catch (BadLocationException e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:ncleclipse,项目名称:ncl30-eclipse,代码行数:28,代码来源:NCLSourceDocument.java


注:本文中的org.eclipse.jface.text.ITypedRegion.getOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。