本文整理汇总了Java中org.eclipse.jface.text.TextUtilities.getContentType方法的典型用法代码示例。如果您正苦于以下问题:Java TextUtilities.getContentType方法的具体用法?Java TextUtilities.getContentType怎么用?Java TextUtilities.getContentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.TextUtilities
的用法示例。
在下文中一共展示了TextUtilities.getContentType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeCompletionEngine
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
protected TemplateEngine computeCompletionEngine(TypeScriptContentAssistInvocationContext context) {
try {
IResource resource = context.getResource();
if (resource == null || !AngularProject.isAngularProject(resource.getProject())) {
return null;
}
String partition = TextUtilities.getContentType(context.getDocument(),
IJavaScriptPartitions.JAVA_PARTITIONING, context.getInvocationOffset(), true);
if (partition.equals(IJavaScriptPartitions.JAVA_DOC)) {
return null;
} else {
return ng2TemplateEngine;
}
} catch (BadLocationException x) {
return null;
}
}
开发者ID:angelozerr,项目名称:angular-eclipse,代码行数:19,代码来源:TypeScriptAngularTemplateCompletionProposalComputer.java
示例2: computeCompletionEngine
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
protected TemplateEngine computeCompletionEngine(TypeScriptContentAssistInvocationContext context) {
try {
if (!TypeScriptResourceUtil.isTsxOrJsxFile(context.getResource())) {
return null;
}
String partition = TextUtilities.getContentType(context.getDocument(),
IJavaScriptPartitions.JAVA_PARTITIONING, context.getInvocationOffset(), true);
if (partition.equals(IJavaScriptPartitions.JAVA_DOC)) {
return null;
} else if (partition.equals(IJSXPartitions.JSX)) {
return null;
} else {
return reactTemplateEngine;
}
} catch (BadLocationException x) {
return null;
}
}
示例3: getCurrentIndent
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
* Returns the indentation of the line <code>line</code> in <code>document</code>. The returned
* string may contain pairs of leading slashes that are considered part of the indentation. The
* space before the asterix in a javadoc-like comment is not considered part of the indentation.
*
* @param document the document
* @param line the line
* @return the indentation of <code>line</code> in <code>document</code>
* @throws BadLocationException if the document is changed concurrently
*/
private static String getCurrentIndent(IDocument document, int line) throws BadLocationException {
IRegion region = document.getLineInformation(line);
int from = region.getOffset();
int endOffset = region.getOffset() + region.getLength();
// go behind line comments
int to = from;
while (to < endOffset - 2 && document.get(to, 2).equals(SLASHES)) to += 2;
while (to < endOffset) {
char ch = document.getChar(to);
if (!Character.isWhitespace(ch)) break;
to++;
}
// don't count the space before javadoc like, asterix-style comment lines
if (to > from && to < endOffset - 1 && document.get(to - 1, 2).equals(" *")) { // $NON-NLS-1$
String type =
TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, to, true);
if (type.equals(IJavaPartitions.JAVA_DOC)
|| type.equals(IJavaPartitions.JAVA_MULTI_LINE_COMMENT)) to--;
}
return document.get(from, to - from);
}
示例4: getProcessor
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
* Returns the code assist processor for the content type of the specified document position.
*
* @param viewer
* the text viewer
* @param offset
* a offset within the document
* @return a content-assist processor or <code>null</code> if none exists
* @since 3.0
*/
public IContentAssistProcessor getProcessor(ITextViewer viewer, int offset)
{
try
{
IDocument document = viewer.getDocument();
String type = TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true);
return getContentAssistProcessor(type);
}
catch (BadLocationException x)
{
}
return null;
}
示例5: isValidSelection
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
* Computes the partition type at the selection start and checks whether the proposal category
* has any computers for this partition.
*
* @param selection the selection
* @return <code>true</code> if there are any computers for the selection
*/
private boolean isValidSelection(ISelection selection) {
if (!(selection instanceof ITextSelection))
return false;
int offset= ((ITextSelection) selection).getOffset();
IDocument document= getDocument();
if (document == null)
return false;
String contentType;
try {
contentType= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, offset, true);
} catch (BadLocationException x) {
return false;
}
return fCategory.hasComputers(contentType);
}
示例6: computeCompletionEngine
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
protected TemplateEngine computeCompletionEngine(JavaContentAssistInvocationContext context) {
try {
String partition= TextUtilities.getContentType(context.getDocument(), IJavaPartitions.JAVA_PARTITIONING, context.getInvocationOffset(), true);
if (partition.equals(IJavaPartitions.JAVA_DOC))
return fJavadocTemplateEngine;
else {
CompletionContext coreContext= context.getCoreContext();
if (coreContext != null) {
int tokenLocation= coreContext.getTokenLocation();
if ((tokenLocation & CompletionContext.TL_MEMBER_START) != 0) {
return fJavaMembersTemplateEngine;
}
if ((tokenLocation & CompletionContext.TL_STATEMENT_START) != 0) {
return fJavaStatementsTemplateEngine;
}
}
return fJavaTemplateEngine;
}
} catch (BadLocationException x) {
return null;
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:24,代码来源:TemplateCompletionProposalComputer.java
示例7: performMatch
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
protected IRegion performMatch(IDocument doc, int caretOffset) throws BadLocationException {
final int charOffset= caretOffset - 1;
final char prevChar= doc.getChar(Math.max(charOffset, 0));
if (!fPairs.contains(prevChar)) return null;
final boolean isForward= fPairs.isStartCharacter(prevChar);
fAnchor= isForward ? ICharacterPairMatcher.LEFT : ICharacterPairMatcher.RIGHT;
final int searchStartPosition= isForward ? caretOffset : caretOffset - 2;
final int adjustedOffset= isForward ? charOffset : caretOffset;
final String partition= TextUtilities.getContentType(doc, fPartitioning, charOffset, false);
final DocumentPartitionAccessor partDoc= new DocumentPartitionAccessor(doc, fPartitioning, partition);
int endOffset= findMatchingPeer(partDoc, prevChar, fPairs.getMatching(prevChar),
isForward, isForward ? doc.getLength() : -1,
searchStartPosition);
if (endOffset == -1) return null;
final int adjustedEndOffset= isForward ? endOffset + 1: endOffset;
if (adjustedEndOffset == adjustedOffset) return null;
return new Region(Math.min(adjustedOffset, adjustedEndOffset),
Math.abs(adjustedEndOffset - adjustedOffset));
}
示例8: computeCompletionEngine
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
protected TemplateEngine computeCompletionEngine(TypeScriptContentAssistInvocationContext context) {
try {
String partition = TextUtilities.getContentType(context.getDocument(),
IJavaScriptPartitions.JAVA_PARTITIONING, context.getInvocationOffset(), true);
if (partition.equals(IJavaScriptPartitions.JAVA_DOC)) {
return jsDocTemplateEngine;
} else {
return typeScriptTemplateEngine;
}
} catch (BadLocationException x) {
return null;
}
}
开发者ID:angelozerr,项目名称:typescript.java,代码行数:15,代码来源:TypeScriptTemplateCompletionProposalComputer.java
示例9: getCurrentIndent
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
* Returns the indentation of the line <code>line</code> in <code>document</code>.
* The returned string may contain pairs of leading slashes that are considered
* part of the indentation. The space before the asterisk in a javadoc-like
* comment is not considered part of the indentation.
*
* @param document the document
* @param line the line
* @return the indentation of <code>line</code> in <code>document</code>
* @throws BadLocationException if the document is changed concurrently
*/
private static String getCurrentIndent(Document document, int line) throws BadLocationException {
IRegion region= document.getLineInformation(line);
int from= region.getOffset();
int endOffset= region.getOffset() + region.getLength();
// go behind line comments
int to= from;
while (to < endOffset - 2 && document.get(to, 2).equals(LINE_COMMENT))
to += 2;
while (to < endOffset) {
char ch= document.getChar(to);
if (!Character.isWhitespace(ch))
break;
to++;
}
// don't count the space before javadoc like, asterisk-style comment lines
if (to > from && to < endOffset - 1 && document.get(to - 1, 2).equals(" *")) { //$NON-NLS-1$
String type= TextUtilities.getContentType(document, IJavaScriptPartitions.JAVA_PARTITIONING, to, true);
if (type.equals(IJavaScriptPartitions.JAVA_DOC) || type.equals(IJavaScriptPartitions.JAVA_MULTI_LINE_COMMENT))
to--;
}
return document.get(from, to - from);
}
示例10: getLineStartPosition
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
protected int getLineStartPosition(final IDocument document, final String line, final int length,
final int offset) {
String type = IDocument.DEFAULT_CONTENT_TYPE;
try {
type = TextUtilities.getContentType(document, IDocumentExtension3.DEFAULT_PARTITIONING, offset, false);
} catch (BadLocationException exception) {
// Should not happen
}
int lineStartPosition = super.getLineStartPosition(document, line, length, offset);
if (tokenTypeToPartitionTypeMapperExtension.isMultiLineComment(type)
|| tokenTypeToPartitionTypeMapperExtension.isSingleLineComment(type)) {
try {
IRegion lineInformation = document.getLineInformationOfOffset(offset);
int offsetInLine = offset - lineInformation.getOffset();
return getCommentLineStartPosition(line, length, offsetInLine, lineStartPosition);
} catch(BadLocationException e) {
// Should not happen
}
}
if (type.equals(IDocument.DEFAULT_CONTENT_TYPE)) {
if (isStartOfSingleLineComment(line, length, lineStartPosition) && !isStartOfMultiLineComment(line, length, lineStartPosition)) {
return getTextStartPosition(line, length, lineStartPosition + 1);
}
}
return lineStartPosition;
}
示例11: computeCompletionEngine
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
protected TemplateEngine computeCompletionEngine(JavaContentAssistInvocationContext context) {
try {
String partition =
TextUtilities.getContentType(
context.getDocument(),
IJavaPartitions.JAVA_PARTITIONING,
context.getInvocationOffset(),
true);
if (partition.equals(IJavaPartitions.JAVA_DOC)) return fJavadocTemplateEngine;
else {
CompletionContext coreContext = context.getCoreContext();
if (coreContext != null) {
int tokenLocation = coreContext.getTokenLocation();
if ((tokenLocation & CompletionContext.TL_MEMBER_START) != 0) {
return fJavaMembersTemplateEngine;
}
if ((tokenLocation & CompletionContext.TL_STATEMENT_START) != 0) {
return fJavaStatementsTemplateEngine;
}
}
return fJavaTemplateEngine;
}
} catch (BadLocationException x) {
return null;
}
}
示例12: getContextTypeIds
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
* Get the active contexts for the given position in the document.
* <p>
* FIXME: should trigger code assist to get the context.
* </p>
*
* @param document the document
* @param offset the offset
* @return an array of valid context id
*/
@Override
protected String[] getContextTypeIds(IDocument document, int offset) {
try {
String partition= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, offset, true);
String[] ids= new String[] { JavaContextType.ID_ALL, JavaContextType.ID_MEMBERS, JavaContextType.ID_STATEMENTS, SWTContextType.ID_ALL, SWTContextType.ID_STATEMENTS, SWTContextType.ID_MEMBERS};
if (partition.equals(IJavaPartitions.JAVA_DOC))
ids= new String[] { JavaDocContextType.ID };
return ids;
} catch (BadLocationException e) {
return new String[0];
}
}
示例13: getLineStartPosition
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
protected int getLineStartPosition(final IDocument document, final String line, final int length, final int offset) {
String type= IDocument.DEFAULT_CONTENT_TYPE;
try {
type= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, offset, true);
} catch (BadLocationException exception) {
// Should not happen
}
int index= super.getLineStartPosition(document, line, length, offset);
if (type.equals(IJavaPartitions.JAVA_DOC) || type.equals(IJavaPartitions.JAVA_MULTI_LINE_COMMENT)) {
if (index < length - 1 && line.charAt(index) == '*' && line.charAt(index + 1) != '/') {
do {
++index;
} while (index < length && Character.isWhitespace(line.charAt(index)));
}
} else {
if (index < length - 1 && line.charAt(index) == '/' && line.charAt(index + 1) == '/') {
index++;
do {
++index;
} while (index < length && Character.isWhitespace(line.charAt(index)));
}
}
return index;
}
示例14: getCurrentIndent
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
* Returns the indentation of the line <code>line</code> in <code>document</code>.
* The returned string may contain pairs of leading slashes that are considered
* part of the indentation. The space before the asterix in a javadoc-like
* comment is not considered part of the indentation.
*
* @param document the document
* @param line the line
* @return the indentation of <code>line</code> in <code>document</code>
* @throws BadLocationException if the document is changed concurrently
*/
private static String getCurrentIndent(IDocument document, int line) throws BadLocationException {
IRegion region= document.getLineInformation(line);
int from= region.getOffset();
int endOffset= region.getOffset() + region.getLength();
// go behind line comments
int to= from;
while (to < endOffset - 2 && document.get(to, 2).equals(SLASHES))
to += 2;
while (to < endOffset) {
char ch= document.getChar(to);
if (!Character.isWhitespace(ch))
break;
to++;
}
// don't count the space before javadoc like, asterix-style comment lines
if (to > from && to < endOffset - 1 && document.get(to - 1, 2).equals(" *")) { //$NON-NLS-1$
String type= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, to, true);
if (type.equals(IJavaPartitions.JAVA_DOC) || type.equals(IJavaPartitions.JAVA_MULTI_LINE_COMMENT))
to--;
}
return document.get(from, to - from);
}
示例15: isInJavadoc
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
private static boolean isInJavadoc(JavaEditor editor) {
ITextSelection selection= getTextSelection(editor);
if (selection == null)
return false;
IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput());
try {
String contentType= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, selection.getOffset(), true);
return contentType.equals(IJavaPartitions.JAVA_DOC);
} catch (BadLocationException e) {
return false;
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:14,代码来源:SurroundWithTemplateMenuAction.java