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


Java ITypedRegion.getLength方法代码示例

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


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

示例1: 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

示例2: 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

示例3: getCurrentTagname

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
public String getCurrentTagname(int documentOffset) {
	try {
		ITypedRegion region = getPartition(documentOffset);
		int partitionOffset = region.getOffset();
		int readLength = region.getLength();
		ColorManager colorManager = new ColorManager();
		scanner = new XMLTagScanner(colorManager);

		String text = get(partitionOffset, 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 "";
}
 
开发者ID:ncleclipse,项目名称:ncl30-eclipse,代码行数:27,代码来源:NCLSourceDocument.java

示例4: removeElement

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
public boolean removeElement(String id, int offset) {
	try {
		int elementOffset = getElementOffset(id);
		ITypedRegion region = getNextTagPartition(elementOffset);
		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; // or false?
	}
}
 
开发者ID:ncleclipse,项目名称:ncl30-eclipse,代码行数:22,代码来源:NCLSourceDocument.java

示例5: 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

示例6: findExtendedDoubleClickSelection

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
@Override
protected IRegion findExtendedDoubleClickSelection(IDocument document, int offset) {
	IRegion match= super.findExtendedDoubleClickSelection(document, offset);
	if (match != null)
		return match;

	try {
		ITypedRegion region= TextUtilities.getPartition(document, fPartitioning, offset, true);
		if (offset == region.getOffset() + 1 || offset == region.getOffset() + region.getLength() - 1) {
			return getSelectedRegion(document, region);
		}
	} catch (BadLocationException e) {
		return null;
	}
	return null;
}
 
开发者ID:cplutte,项目名称:bts,代码行数:17,代码来源:AbstractPartitionDoubleClickSelector.java

示例7: 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

示例8: 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

示例9: AbstractLexemeProvider

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
/**
 * Convert the partition that contains the given offset into a list of lexemes. If the includeOffset is not within
 * the partition found at offset, then the range is extended to include it
 * 
 * @param document
 * @param offset
 * @param includeOffset
 * @param scanner
 */
protected AbstractLexemeProvider(IDocument document, int offset, int includeOffset, U scanner)
{
	int start = offset;
	int end = offset;

	try
	{
		ITypedRegion partition = document.getPartition(offset);

		start = partition.getOffset();
		end = start + partition.getLength();

		start = Math.max(0, Math.min(start, includeOffset));
		end = Math.min(Math.max(end, includeOffset), document.getLength());
	}
	catch (BadLocationException e)
	{
	}

	this.createLexemeList(document, start, end - start, scanner);
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:31,代码来源:AbstractLexemeProvider.java

示例10: isInsertClosingBracket

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
@Override
public boolean isInsertClosingBracket(IDocument doc, int offset) throws BadLocationException {
	if (offset >= 2) {
		ITypedRegion prevPartition = doc.getPartition(offset - 1);
		String prevPartitionType = prevPartition.getType();
		if (TerminalsTokenTypeToPartitionMapper.SL_COMMENT_PARTITION.equals(prevPartitionType)) {
			return false;
		}
		if (TokenTypeToPartitionMapper.REG_EX_PARTITION.equals(prevPartitionType)) {
			return prevPartition.getLength() == 1;
		}
	}
	return SingleLineTerminalsStrategy.DEFAULT.isInsertClosingBracket(doc, offset);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:15,代码来源:SupressingMLCommentPredicate.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: printPartition

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
/**
 * Prints partition information
 * @param region
 * @param document
 */
public static void printPartition(ITypedRegion region, IDocument document)
{
    if (region == null)
    {
        return;
    }

    try
    {
        StringBuffer messageBuffer = new StringBuffer();
        String location = "[" + region.getOffset() + ":" + region.getLength() + "]";

        if (region instanceof TLCRegion)
        {
            TLCRegion tlcRegion = (TLCRegion) region;
            messageBuffer.append("TLC:" + tlcRegion.getMessageCode() + " " + tlcRegion.getSeverity() + " "
                    + location);
        } else
        {
            int offset = region.getOffset();
            int printLength = Math.min(region.getLength(), 255);

            String type = region.getType();
            Assert.isTrue(type.equals(TagBasedTLCOutputTokenScanner.DEFAULT_CONTENT_TYPE));

            String head = document.get(offset, printLength);
            messageBuffer.append("OUTPUT:" + location + ": >" + head + "< ...");
        }

        TLCUIActivator.getDefault().logDebug(messageBuffer.toString());

    } catch (BadLocationException e)
    {
        TLCUIActivator.getDefault().logError("Error printing partition", e);
    }

}
 
开发者ID:tlaplus,项目名称:tlaplus,代码行数:43,代码来源:PartitionToolkit.java

示例13: 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

示例14: setAttribute

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
public boolean setAttribute(String attr, String value, int offset) {
	try {
		ITypedRegion region = getPartition(offset);
		String startTag;

		startTag = get(region.getOffset(), region.getLength());

		String attrAtual = getAttributeValueFromCurrentTagName(offset, attr);
		int begin = 0;
		String newValue = attr + "=\"" + value + "\"";
		if (attrAtual == null) {
			begin = region.getOffset() + region.getLength() - 1;
			if (startTag.endsWith("/>"))
				begin--;
			if (!get(begin - 1, 1).equals(" "))
				newValue = " " + newValue;

			replace(begin, 0, newValue);
		} else {
			int attrOffset = getAttributePosition(attr, region.getOffset())
					- attr.length() - 1;
			int attrSizeAtual = attrAtual.length();
			begin = region.getOffset() + attrOffset;
			newValue = attr + "=\"" + value + "\"";
			if (!get(begin - 1, 1).equals(" "))
				newValue = " " + newValue;
			if (!get(begin + attrSizeAtual, 1).equals(" "))
				newValue = newValue + " ";
			replace(begin, attrSizeAtual + attr.length() + 3, newValue);
		}
		return true;
	} catch (BadLocationException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:ncleclipse,项目名称:ncl30-eclipse,代码行数:38,代码来源:NCLSourceDocument.java

示例15: isNewComment

import org.eclipse.jface.text.ITypedRegion; //导入方法依赖的package包/类
/**
 * Guesses if the command operates within a newly created javadoc comment or
 * not. If in doubt, it will assume that the javadoc is new.
 *
 * @param document
 *            the document
 * @param commandOffset
 *            the command offset
 * @return <code>true</code> if the comment should be closed,
 *         <code>false</code> if not
 */
private boolean isNewComment(IDocument document, int commandOffset) {

	try {
		int lineIndex = document.getLineOfOffset(commandOffset) + 1;
		if (lineIndex >= document.getNumberOfLines())
			return true;

		IRegion line = document.getLineInformation(lineIndex);
		ITypedRegion partition = TextUtilities.getPartition(document, fPartitioning, commandOffset, false);
		int partitionEnd = partition.getOffset() + partition.getLength();
		if (line.getOffset() >= partitionEnd)
			return false;

		if (document.getLength() == partitionEnd)
			return true; // partition goes to end of document - probably a
							// new comment

		String comment = document.get(partition.getOffset(), partition.getLength());
		if (comment.indexOf("/*", 2) != -1) //$NON-NLS-1$
			return true; // enclosed another comment -> probably a new
							// comment

		return false;

	} catch (BadLocationException e) {
		return false;
	}
}
 
开发者ID:angelozerr,项目名称:typescript.java,代码行数:40,代码来源:JSDocAutoIndentStrategy.java


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