本文整理汇总了Java中com.intellij.openapi.util.TextRange类的典型用法代码示例。如果您正苦于以下问题:Java TextRange类的具体用法?Java TextRange怎么用?Java TextRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextRange类属于com.intellij.openapi.util包,在下文中一共展示了TextRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: errrantThisOrExtension
import com.intellij.openapi.util.TextRange; //导入依赖的package包/类
private void errrantThisOrExtension( PsiElement element, AnnotationHolder holder )
{
if( element instanceof PsiModifierList )
{
PsiModifierList mods = (PsiModifierList)element;
PsiAnnotation annotation;
if( (annotation = mods.findAnnotation( Extension.class.getName() )) != null ||
(annotation = mods.findAnnotation( This.class.getName() )) != null)
{
TextRange range = new TextRange( annotation.getTextRange().getStartOffset(),
annotation.getTextRange().getEndOffset() );
//noinspection ConstantConditions
holder.createErrorAnnotation( range, ExtIssueMsg.MSG_NOT_IN_EXTENSION_CLASS.get( ClassUtil.extractClassName( annotation.getQualifiedName() ) ) );
}
}
}
示例2: getRanges
import com.intellij.openapi.util.TextRange; //导入依赖的package包/类
@NotNull
@Override
public List<TextRange> getRanges() {
List<TextRange> result = new ArrayList<>();
final int parentOffset = -getElement().getTextRange().getStartOffset();
List<AppleScriptHandlerArgument> arguments = getArguments();
for (AppleScriptHandlerArgument argument : arguments) {
PsiElement id = argument.getArgumentSelector().getSelectorIdentifier();
if (id != null) {
TextRange argumentRange = id.getTextRange();
if (!argumentRange.isEmpty()) {
result.add(argumentRange.shiftRight(parentOffset));
}
}
}
return result;
}
示例3: verifyExtensionInterfaces
import com.intellij.openapi.util.TextRange; //导入依赖的package包/类
private void verifyExtensionInterfaces( PsiElement element, AnnotationHolder holder )
{
if( element instanceof PsiJavaCodeReferenceElementImpl &&
((PsiJavaCodeReferenceElementImpl)element).getTreeParent() instanceof ReferenceListElement &&
((PsiJavaCodeReferenceElementImpl)element).getTreeParent().getText().startsWith( PsiKeyword.IMPLEMENTS ) )
{
final PsiElement resolve = element.getReference().resolve();
if( resolve instanceof PsiExtensibleClass )
{
PsiExtensibleClass iface = (PsiExtensibleClass)resolve;
if( !isStructuralInterface( iface ) )
{
TextRange range = new TextRange( element.getTextRange().getStartOffset(),
element.getTextRange().getEndOffset() );
holder.createErrorAnnotation( range, ExtIssueMsg.MSG_ONLY_STRUCTURAL_INTERFACE_ALLOWED_HERE.get( iface.getName() ) );
}
}
}
}
示例4: getSelectedText
import com.intellij.openapi.util.TextRange; //导入依赖的package包/类
@Nullable
String getSelectedText(Editor editor) {
SelectionModel selectionModel = editor.getSelectionModel();
if(selectionModel.hasSelection()){
return selectionModel.getSelectedText();
}else {
final ArrayList<TextRange> ranges = new ArrayList<>();
final int offset = editor.getCaretModel().getOffset();
SelectWordUtilCompat.addWordOrLexemeSelection(false, editor, offset, ranges, SelectWordUtilCompat.JAVASCRIPT_IDENTIFIER_PART_CONDITION);
if(ranges.size()>0){
return editor.getDocument().getText(ranges.get(0));
}else {
return null;
}
}
}
示例5: appendDescriptors
import com.intellij.openapi.util.TextRange; //导入依赖的package包/类
private void appendDescriptors(final ASTNode node, final Document document, final List<FoldingDescriptor> descriptors) {
if (node.getElementType() == GCMTypes.CLASS_DECLARATION || node.getElementType() == GCMTypes.CUSTOM_TYPE_DECLARATION) {
TextRange fullRange = node.getTextRange();
if (fullRange.getEndOffset() - fullRange.getStartOffset() > 0) {
try {
int startOffset = fullRange.getStartOffset() + document.getText(fullRange).indexOf("{") + 1;
int endOffset = fullRange.getEndOffset() - 1;
if (startOffset < endOffset) {
TextRange shortRange = new TextRange(startOffset, fullRange.getEndOffset() - 1);
if (shortRange.getEndOffset() - shortRange.getStartOffset() > 1) {
descriptors.add(new FoldingDescriptor(node, shortRange));
}
}
} catch (Throwable e) {
}
}
}
ASTNode child = node.getFirstChildNode();
while (child != null) {
appendDescriptors(child, document, descriptors);
child = child.getTreeNext();
}
}
示例6: generateGherkinRunIcons
import com.intellij.openapi.util.TextRange; //导入依赖的package包/类
public void generateGherkinRunIcons(Document rootDocument, Editor rootEditor) {
for (int i = 0; i < rootDocument.getLineCount(); i++) {
int startOffset = rootDocument.getLineStartOffset(i);
int endOffset = rootDocument.getLineEndOffset(i);
String lineText = rootDocument.getText(new TextRange(startOffset, endOffset)).trim();
Icon icon;
if (lineText.matches(SCENARIO_REGEX)) {
icon = GherkinIconRenderer.SCENARIO_ICON;
} else if (lineText.matches(FEATURE_REGEX)) {
icon = GherkinIconRenderer.FEATURE_ICON;
} else {
// System.out.println();
continue;
}
GherkinIconRenderer gherkinIconRenderer = new GherkinIconRenderer(rootEditor.getProject(), fileName);
gherkinIconRenderer.setLine(i);
gherkinIconRenderer.setIcon(icon);
RangeHighlighter rangeHighlighter = createRangeHighlighter(rootDocument, rootEditor, i, i, new TextAttributes());
rangeHighlighter.setGutterIconRenderer(gherkinIconRenderer);
}
}
示例7: getReferences
import com.intellij.openapi.util.TextRange; //导入依赖的package包/类
@Override
public PsiReference[] getReferences() {
PsiElement element = getNode().getPsi();
String maybeEmbeddedExpression = this.getText();
if (!maybeEmbeddedExpression.startsWith("\"")) {
PsiReference singleReference = getReference();
return singleReference == null ? new PsiReference[] {} : new PsiReference[] {singleReference};
}
Matcher identifierMatcher = identifierPattern.matcher(maybeEmbeddedExpression);
List<PsiReference> variableReferenceList = new ArrayList<>();
while (identifierMatcher.find()) {
variableReferenceList.add(
new VariableReference(
element,
maybeEmbeddedExpression.substring(
identifierMatcher.start() + 1, identifierMatcher.end()),
new TextRange(
element.getTextRange().getStartOffset() + identifierMatcher.start(),
element.getTextRange().getStartOffset() + identifierMatcher.end()),
new TextRange(identifierMatcher.start(), identifierMatcher.end())));
}
return variableReferenceList.toArray(new PsiReference[variableReferenceList.size()]);
}
示例8: handleEnterInComment
import com.intellij.openapi.util.TextRange; //导入依赖的package包/类
private static void handleEnterInComment(
PsiElement element, @NotNull PsiFile file, @NotNull Editor editor) {
if (element.getText().startsWith("/*")) {
Document document = editor.getDocument();
int caretOffset = editor.getCaretModel().getOffset();
int lineNumber = document.getLineNumber(caretOffset);
String lineTextBeforeCaret =
document.getText(new TextRange(document.getLineStartOffset(lineNumber), caretOffset));
String lineTextAfterCaret =
document.getText(new TextRange(caretOffset, document.getLineEndOffset(lineNumber)));
if (lineTextAfterCaret.equals("*/")) {
return;
}
String toInsert = lineTextBeforeCaret.equals("") ? " * " : "* ";
insertText(file, editor, toInsert, toInsert.length());
}
}
示例9: postProcessEnter
import com.intellij.openapi.util.TextRange; //导入依赖的package包/类
@Override
public Result postProcessEnter(
@NotNull PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext) {
if (file.getFileType() != SoyFileType.INSTANCE) {
return Result.Continue;
}
int caretOffset = editor.getCaretModel().getOffset();
PsiElement element = file.findElementAt(caretOffset);
Document document = editor.getDocument();
int lineNumber = document.getLineNumber(caretOffset) - 1;
int lineStartOffset = document.getLineStartOffset(lineNumber);
String lineTextBeforeCaret = document.getText(new TextRange(lineStartOffset, caretOffset));
if (element instanceof PsiComment && element.getTextOffset() < caretOffset) {
handleEnterInComment(element, file, editor);
} else if (lineTextBeforeCaret.startsWith("/*")) {
insertText(file, editor, " * \n ", 3);
}
return Result.Continue;
}
示例10: getLineNumber
import com.intellij.openapi.util.TextRange; //导入依赖的package包/类
private static int getLineNumber(VirtualFile virtualFile, TextRange textRange) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(virtualFile.getInputStream()));
String line;
int pos = 0;
int lineNumber = 0;
while ((line = br.readLine()) != null) {
pos += line.length() + 1; //+1 for new line
lineNumber++;
if (pos >= textRange.getStartOffset()) {
return lineNumber;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return -1;
}
示例11: EmojiResourceCompletionContributor
import com.intellij.openapi.util.TextRange; //导入依赖的package包/类
public EmojiResourceCompletionContributor() {
extend(CompletionType.BASIC, PlatformPatterns.psiElement(PsiElement.class), new CompletionProvider<CompletionParameters>() {
@Override
protected void addCompletions(@NotNull CompletionParameters completionParameters,
ProcessingContext processingContext,
@NotNull CompletionResultSet completionResultSet) {
Document document = completionParameters.getEditor().getDocument();
int lineStart = document.getLineStartOffset(document.getLineNumber(completionParameters.getOffset()));
String lineText = document.getText(new TextRange(lineStart, completionParameters.getOffset()));
if (includeCount(lineText) == 1) {
for (Map.Entry<String, Icon> iconEntry : EmojiUtil.getEmojiMap().entrySet()) {
completionResultSet.addElement(LookupElementBuilder.create(iconEntry.getKey(), ":" + iconEntry.getKey() + ":")
.withIcon(iconEntry.getValue())
.withInsertHandler((insertionContext, lookupElement) -> {
int startOffset = insertionContext.getStartOffset();
Document insertDocument = insertionContext.getDocument();
if (startOffset > 0 && insertDocument.getCharsSequence().charAt(startOffset - 1) == ':') {
insertDocument.deleteString(startOffset - 1, startOffset);
}
}));
}
}
}
});
}
示例12: registerReferenceProviders
import com.intellij.openapi.util.TextRange; //导入依赖的package包/类
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
// TODO
registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class),
new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
@NotNull ProcessingContext
context) {
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
String value = literalExpression.getValue() instanceof String ?
(String) literalExpression.getValue() : null;
if (value != null && value.startsWith("simple" + ":")) {
return new PsiReference[]{
new CptReference(element, new TextRange(8, value.length() + 1))};
}
return PsiReference.EMPTY_ARRAY;
}
});
}
示例13: saveIndent
import com.intellij.openapi.util.TextRange; //导入依赖的package包/类
private static void saveIndent(AnswerPlaceholder placeholder, CCState state, boolean visible) {
Document document = state.getEditor().getDocument();
int offset = placeholder.getOffset();
int lineNumber = document.getLineNumber(offset);
int nonSpaceCharOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, lineNumber);
int newOffset = offset;
int endOffset = offset + placeholder.getRealLength();
if (!visible && nonSpaceCharOffset == offset) {
newOffset = document.getLineStartOffset(lineNumber);
}
if (visible) {
newOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, offset, endOffset);
}
placeholder.setOffset(newOffset);
int delta = offset - newOffset;
placeholder.setPossibleAnswer(document.getText(TextRange.create(newOffset, newOffset + delta + placeholder.getRealLength())));
String oldTaskText = placeholder.getTaskText();
if (delta >= 0) {
placeholder.setTaskText(StringUtil.repeat(" ", delta) + oldTaskText);
}
else {
String newTaskText = oldTaskText.substring(Math.abs(delta));
placeholder.setTaskText(newTaskText);
}
}
示例14: resolvePsiReferences
import com.intellij.openapi.util.TextRange; //导入依赖的package包/类
@NotNull
protected List<PsiReference> resolvePsiReferences(@NotNull PsiElement element, String value, int rangeOffset) {
if (value != null) {
String[] split = value.split("\\.");
List<PsiReference> psiReferences = new ArrayList<>();
StringBuilder sb = new StringBuilder();
int startIndex = 0;
for (int i = 0; i < split.length; i++) {
if (i > 0) {
sb.append(".");
startIndex = sb.length();
}
sb.append(split[i]);
psiReferences.add(new CoffigReference(element, new TextRange(rangeOffset + startIndex, rangeOffset + sb.length()), sb.toString()));
}
return psiReferences;
} else {
return new ArrayList<>();
}
}
示例15: registerReferenceProviders
import com.intellij.openapi.util.TextRange; //导入依赖的package包/类
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class),
new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
@NotNull ProcessingContext
context) {
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
String value = literalExpression.getValue() instanceof String ?
(String) literalExpression.getValue() : null;
if (value != null && value.startsWith("simple" + ":")) {
return new PsiReference[]{
new CrystalReference(element, new TextRange(8, value.length() + 1))};
}
return PsiReference.EMPTY_ARRAY;
}
});
}