當前位置: 首頁>>代碼示例>>Java>>正文


Java PsiElement.getTextOffset方法代碼示例

本文整理匯總了Java中com.intellij.psi.PsiElement.getTextOffset方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiElement.getTextOffset方法的具體用法?Java PsiElement.getTextOffset怎麽用?Java PsiElement.getTextOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.psi.PsiElement的用法示例。


在下文中一共展示了PsiElement.getTextOffset方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: postProcessEnter

import com.intellij.psi.PsiElement; //導入方法依賴的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;
}
 
開發者ID:google,項目名稱:bamboo-soy,代碼行數:24,代碼來源:EnterHandler.java

示例2: letExpressionToLogicalPosition

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@NotNull
private static Function<PsiLet, LogicalPosition> letExpressionToLogicalPosition(Editor selectedTextEditor) {
    return letStatement -> {
        PsiElement letName = letStatement.getNameIdentifier();
        if (letName == null) {
            return null;
        }

        int nameOffset = letName.getTextOffset();
        return selectedTextEditor.offsetToLogicalPosition(nameOffset);
    };
}
 
開發者ID:reasonml-editor,項目名稱:reasonml-idea-plugin,代碼行數:13,代碼來源:InferredTypes.java

示例3: isJavaElementFor

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
private static boolean isJavaElementFor( PsiModifierListOwner modifierListOwner, PsiElement element )
{
  PsiAnnotation annotation = modifierListOwner.getModifierList().findAnnotation( SourcePosition.class.getName() );
  if( annotation != null )
  {
    int textOffset = element.getTextOffset();
    int textLength = element instanceof PsiNamedElement ? ((PsiNamedElement)element).getName().length() : element.getTextLength();
    PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
    int offset = -1;
    for( PsiNameValuePair pair : attributes )
    {
      if( pair.getNameIdentifier().getText().equals( SourcePosition.OFFSET ) )
      {
        String literalValue = pair.getLiteralValue();
        if( literalValue == null )
        {
          return false;
        }
        offset = Integer.parseInt( literalValue );
        break;
      }
    }
    if( offset >= textOffset && offset <= textOffset + textLength )
    {
      return true;
    }
  }
  return false;
}
 
開發者ID:manifold-systems,項目名稱:manifold-ij,代碼行數:30,代碼來源:ResourceToManifoldUtil.java

示例4: findExistingSettings

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
static private Map<String, JSProperty> findExistingSettings(CompletionParameters parameters, String prefix)
{
    PsiFile file = parameters.getOriginalFile();
    StringBuffer buffer;

    // User was typing and probably screwed up the syntax in the process :-/
    if (parameters.isAutoPopup())
    {
        PsiElement position = parameters.getPosition();

        Integer startOffset = position.getTextOffset();
        Integer endOffset = startOffset + prefix.length();

        buffer = new StringBuffer(file.getText());
        buffer = buffer.replace(startOffset, endOffset, "");

        file = PsiFileFactory
            .getInstance(position.getProject())
            .createFileFromText(position.getLanguage(), buffer.toString());
    }

    try
    {
        RecursivePropertyWalker walker = new RecursivePropertyWalker();
        walker.visitFile(file);

        return walker.getExistingProperties();
    }
    catch (Exception e)
    {
        return Collections.emptyMap();
    }
}
 
開發者ID:whitefire,項目名稱:roc-completion,代碼行數:34,代碼來源:SettingCompletionBuilder.java

示例5: getOpeningQuotePosition

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
public static int getOpeningQuotePosition(PsiElement firstFieldElement, PsiElement lastFieldElement) {
    if (getElementType(firstFieldElement) != CsvTypes.QUOTE) {
        return firstFieldElement.getTextOffset();
    }
    if (getElementType(lastFieldElement) == CsvTypes.QUOTE) {
        return lastFieldElement.getTextOffset();
    }
    return -1;
}
 
開發者ID:SeeSharpSoft,項目名稱:intellij-csv-validator,代碼行數:10,代碼來源:CsvIntentionHelper.java

示例6: isBefore

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
public static boolean isBefore(@NotNull final PsiElement e1, @NotNull final PsiElement e2, boolean strict) {
  return strict ? e1.getTextOffset() < e2.getTextOffset() : e1.getTextOffset() <= e2.getTextOffset();
}
 
開發者ID:ant-druha,項目名稱:AppleScript-IDEA,代碼行數:4,代碼來源:AppleScriptPsiImplUtil.java

示例7: annotate

import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@Override
public void annotate( PsiElement element, AnnotationHolder holder )
{
  PsiClass psiClass =  ResourceToManifoldUtil.findPsiClass( element.getContainingFile() );
  if( psiClass == null )
  {
    return;
  }

  if( PsiErrorClassUtil.isErrorClass( psiClass ) && element instanceof PsiFileSystemItem )
  {
    holder.createErrorAnnotation( new TextRange( 0, element.getContainingFile().getTextLength() ), PsiErrorClassUtil.getErrorFrom( psiClass ).getMessage() );
    return;
  }

  if( !(psiClass instanceof ManifoldPsiClass) )
  {
    return;
  }

  DiagnosticCollector issues = ((ManifoldPsiClass)psiClass).getIssues();
  if( issues == null )
  {
    return;
  }

  for( Object obj : issues.getDiagnostics() )
  {
    Diagnostic issue = (Diagnostic)obj;

    if( element.getTextOffset() > issue.getStartPosition() ||
        element.getTextOffset() + element.getTextLength() <= issue.getStartPosition() )
    {
      continue;
    }

    PsiElement deepestElement = element.getContainingFile().findElementAt( (int)issue.getStartPosition() );
    if( deepestElement != element )
    {
      continue;
    }

    switch( issue.getKind() )
    {
      case ERROR:
        holder.createErrorAnnotation( deepestElement, issue.getMessage( Locale.getDefault() ) );
        break;
      case WARNING:
      case MANDATORY_WARNING:
        holder.createWarningAnnotation( deepestElement, issue.getMessage( Locale.getDefault() ) );
        break;
      case NOTE:
      case OTHER:
        holder.createInfoAnnotation( deepestElement, issue.getMessage( Locale.getDefault() ) );
        break;
    }
  }
}
 
開發者ID:manifold-systems,項目名稱:manifold-ij,代碼行數:59,代碼來源:ManifoldPsiClassAnnotator.java


注:本文中的com.intellij.psi.PsiElement.getTextOffset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。