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


Java PsiComment类代码示例

本文整理汇总了Java中com.intellij.psi.PsiComment的典型用法代码示例。如果您正苦于以下问题:Java PsiComment类的具体用法?Java PsiComment怎么用?Java PsiComment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: KeywordCompletionContributor

import com.intellij.psi.PsiComment; //导入依赖的package包/类
public KeywordCompletionContributor() {

    extend(CompletionType.BASIC, psiElement().inFile(StandardPatterns.instanceOf(AppleScriptFile.class)),
        new CompletionProvider<CompletionParameters>() {
          @Override
          protected void addCompletions(@NotNull CompletionParameters completionParameters,
                                        ProcessingContext processingContext,
                                        @NotNull CompletionResultSet completionResultSet) {
            PsiFile file = completionParameters.getOriginalFile();
            if (!(file instanceof AppleScriptFile)) return;
            PsiElement position = completionParameters.getPosition();
            if (position instanceof PsiComment) return;

            ASTNode node = position.getNode();
            if (node.getElementType() == AppleScriptTypes.STRING_LITERAL) return;

            for (IElementType kwElem : AppleScriptTokenTypesSets.KEYWORDS.getTypes()) {
              completionResultSet.addElement(LookupElementBuilder
                  .create(kwElem.toString().toLowerCase().replaceAll("_", " ")).bold()
                  .withTypeText("keyword", true));
            }
          }
        });
  }
 
开发者ID:ant-druha,项目名称:AppleScript-IDEA,代码行数:25,代码来源:KeywordCompletionContributor.java

示例2: postProcessEnter

import com.intellij.psi.PsiComment; //导入依赖的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

示例3: prevElementIsUserRightsMacros

import com.intellij.psi.PsiComment; //导入依赖的package包/类
@Nullable
@Contract(pure = true)
public static boolean prevElementIsUserRightsMacros(@NotNull final PsiElement element) {
    Validate.notNull(element);

    final Class[] skipClasses = {ImpexValueLine.class, PsiComment.class, PsiWhiteSpace.class};
    PsiElement prevElement = PsiTreeUtil.skipSiblingsBackward(element, skipClasses);

    while (null != prevElement) {
        if (isHeaderLine(prevElement)) {
            return false;
        }
        if (isUserRightsMacros(prevElement)) {
            return true;
        }
        prevElement = PsiTreeUtil.skipSiblingsBackward(prevElement, skipClasses);
    }

    return false;
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:21,代码来源:ImpexPsiUtils.java

示例4: scanFile

import com.intellij.psi.PsiComment; //导入依赖的package包/类
protected void scanFile() {
  PsiElement first = getFile().getFirstChild(); // PropertiesList
  PsiElement last = first;
  PsiElement next = first;
  while (next != null) {
    if (next instanceof PsiComment || next instanceof PsiWhiteSpace) {
      next = getNextSibling(next);
    }
    else {
      break;
    }
    last = next;
  }

  if (first != null) {
    checkComments(first, last, true);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:UpdatePropertiesFileCopyright.java

示例5: satisfiedBy

import com.intellij.psi.PsiComment; //导入依赖的package包/类
@Override
public boolean satisfiedBy(PsiElement element) {
  if (!(element instanceof PsiComment)) {
    return false;
  }
  if (element instanceof PsiDocComment) {
    return false;
  }
  final PsiComment comment = (PsiComment) element;
  final IElementType type = comment.getTokenType();
  if (!GroovyTokenTypes.mML_COMMENT.equals(type)) {
    return false;
  }
  final PsiElement sibling = PsiTreeUtil.nextLeaf(comment);
  if(sibling == null)
  {
    return true;
  }
  if (!(isWhitespace(sibling))) {
    return false;
  }
  final String whitespaceText = sibling.getText();
  return whitespaceText.indexOf((int) '\n') >= 0 ||
      whitespaceText.indexOf((int) '\r') >= 0;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:CStyleCommentPredicate.java

示例6: shouldSkip

import com.intellij.psi.PsiComment; //导入依赖的package包/类
private boolean shouldSkip(boolean classLevel, PsiElement psi) {
  if (psi instanceof PsiComment) {
    PsiElement prev = psi.getPrevSibling();
    if (prev != null) {
      if (!classLevel || !PsiUtil.isNewLine(prev) || !fieldGroupEnded(psi)) {
        return true;
      }
    }
  }
  if (psi.getParent() instanceof GrLabeledStatement) {
    if (psi instanceof GrLiteral && GrStringUtil.isStringLiteral((GrLiteral)psi) //skip string comments at the beginning of spock table
        || !(psi instanceof GrStatement)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GroovyBlockGenerator.java

示例7: getStatementForElement

import com.intellij.psi.PsiComment; //导入依赖的package包/类
/**
 * @return the nearest ancestor {@link SQFStatement} that contains the given element, or null if not in a {@link SQFStatement}
 * @throws IllegalArgumentException when element is a PsiComment or when it is not in an SQFFile
 */
@Nullable
public static SQFStatement getStatementForElement(@NotNull PsiElement element) {
	if (element instanceof PsiComment) {
		throw new IllegalArgumentException("element is a comment");
	}
	if (element.getContainingFile() == null || !(element.getContainingFile() instanceof SQFFile)) {
		throw new IllegalArgumentException("element isn't in an SQFFile");
	}
	while (!(element instanceof SQFStatement)) {
		element = element.getParent();
		if (element == null) {
			return null;
		}
	}
	return (SQFStatement) element;
}
 
开发者ID:kayler-renslow,项目名称:arma-intellij-plugin,代码行数:21,代码来源:SQFStatement.java

示例8: debug_getStatementTextForElement

import com.intellij.psi.PsiComment; //导入依赖的package包/类
/**
 * Used for debugging. Will return the statement the given element is contained in.
 * If the element is a PsiComment, &lt;PsiComment&gt; will be returned. Otherwise, the element's ancestor statement
 * text will be returned with all newlines replaced with spaces.
 * <p>
 * If the element has no parent or no {@link SQFStatement} parent, &lt;No Statement Parent&gt; will be returned
 *
 * @return the text, or &lt;PsiComment&gt; if element is a PsiComment
 */
@NotNull
public static String debug_getStatementTextForElement(@NotNull PsiElement element) {
	if (element instanceof PsiComment) {
		return "<PsiComment>";
	}
	if (element.getContainingFile() == null || !(element.getContainingFile() instanceof SQFFile)) {
		throw new IllegalArgumentException("element isn't in an SQFFile");
	}
	while (!(element instanceof SQFStatement)) {
		element = element.getParent();
		if (element == null) {
			return "<No Statement Parent>";
		}
	}
	return element.getText().replaceAll("\n", " ");
}
 
开发者ID:kayler-renslow,项目名称:arma-intellij-plugin,代码行数:26,代码来源:SQFStatement.java

示例9: isEmpty

import com.intellij.psi.PsiComment; //导入依赖的package包/类
private boolean isEmpty(@NotNull GrOpenBlock body) {
  final GrStatement[] statements = body.getStatements();
  if (statements.length != 0) return false;

  if (myCountCommentsAsContent) {
    final PsiElement brace = body.getLBrace();
    if (brace != null) {
      final PsiElement next = PsiUtil.skipWhitespaces(brace.getNextSibling(), true);
      if (next instanceof PsiComment) {
        return false;
      }
    }
  }

  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:GroovyEmptyCatchBlockInspection.java

示例10: checkFileHeader

import com.intellij.psi.PsiComment; //导入依赖的package包/类
static ProblemDescriptor checkFileHeader(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean onTheFly) {
  TIntObjectHashMap<String> offsetToProperty = new TIntObjectHashMap<String>();
  FileTemplate defaultTemplate = FileTemplateManager.getInstance(file.getProject()).getDefaultTemplate(FileTemplateManager.FILE_HEADER_TEMPLATE_NAME);
  Pattern pattern = getTemplatePattern(defaultTemplate, file.getProject(), offsetToProperty);
  Matcher matcher = pattern.matcher(file.getViewProvider().getContents());
  if (!matcher.matches()) {
    return null;
  }

  PsiComment element = PsiTreeUtil.findElementOfClassAtRange(file, matcher.start(1), matcher.end(1), PsiComment.class);
  if (element == null) {
    return null;
  }

  LocalQuickFix[] fixes = createQuickFix(matcher, offsetToProperty, file.getProject());
  String description = InspectionsBundle.message("default.file.template.description");
  return manager.createProblemDescriptor(element, description, onTheFly, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:FileHeaderChecker.java

示例11: nlsAfter

import com.intellij.psi.PsiComment; //导入依赖的package包/类
private static boolean nlsAfter(@Nullable PsiElement element) {
  if (element == null) return false;

  PsiElement sibling = element;
  while (true) {
    sibling = PsiTreeUtil.nextLeaf(sibling);
    if (sibling == null) {
      return true; //eof
    }

    final String text = sibling.getText();
    if (text.contains("\n")) {
      return text.charAt(CharArrayUtil.shiftForward(text, 0, " \t")) == '\n';
    }

    if (!(sibling instanceof PsiComment) && !StringUtil.isEmptyOrSpaces(text) && !text.equals(";")) {
      return false;
    }

  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:GroovyStatementMover.java

示例12: getUsageType

import com.intellij.psi.PsiComment; //导入依赖的package包/类
@Nullable
private static UsageType getUsageType(PsiElement element, @NotNull UsageTarget[] targets) {
  if (element == null) return null;

  if (PsiTreeUtil.getParentOfType(element, PsiComment.class, false) != null) { return UsageType.COMMENT_USAGE; }

  UsageTypeProvider[] providers = Extensions.getExtensions(UsageTypeProvider.EP_NAME);
  for(UsageTypeProvider provider: providers) {
    UsageType usageType;
    if (provider instanceof UsageTypeProviderEx) {
      usageType = ((UsageTypeProviderEx) provider).getUsageType(element, targets);
    }
    else {
      usageType = provider.getUsageType(element);
    }
    if (usageType != null) {
      return usageType;
    }
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:UsageTypeGroupingRule.java

示例13: getStatementToolSuppressedIn

import com.intellij.psi.PsiComment; //导入依赖的package包/类
@Nullable
public static PsiElement getStatementToolSuppressedIn(@NotNull PsiElement place,
                                                      @NotNull String toolId,
                                                      @NotNull Class<? extends PsiElement> statementClass,
                                                      @NotNull Pattern suppressInLineCommentPattern) {
  PsiElement statement = PsiTreeUtil.getNonStrictParentOfType(place, statementClass);
  if (statement != null) {
    PsiElement prev = PsiTreeUtil.skipSiblingsBackward(statement, PsiWhiteSpace.class);
    if (prev instanceof PsiComment) {
      String text = prev.getText();
      Matcher matcher = suppressInLineCommentPattern.matcher(text);
      if (matcher.matches() && isInspectionToolIdMentioned(matcher.group(1), toolId)) {
        return prev;
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:SuppressionUtil.java

示例14: processComment

import com.intellij.psi.PsiComment; //导入依赖的package包/类
/**
 * Check if comment can be recognized as section start/end
 * @return true for section comment, false otherwise
 */
public boolean processComment(@NotNull PsiComment comment) {
  final TextRange range = comment.getTextRange();
  final TextRange expandedRange = myDocument == null ? range : ArrangementUtil.expandToLineIfPossible(range, myDocument);
  final TextRange sectionTextRange = new TextRange(expandedRange.getStartOffset(), expandedRange.getEndOffset());

  final String commentText = comment.getText().trim();
  final ArrangementSectionRule openSectionRule = isSectionStartComment(mySettings, commentText);
  if (openSectionRule != null) {
    mySectionEntryProducer.consume(new ArrangementSectionEntryTemplate(comment, START_SECTION, sectionTextRange, commentText));
    myOpenedSections.push(openSectionRule);
    return true;
  }

  if (!myOpenedSections.isEmpty()) {
    final ArrangementSectionRule lastSection = myOpenedSections.peek();
    if (lastSection.getEndComment() != null && StringUtil.equals(commentText, lastSection.getEndComment())) {
      mySectionEntryProducer.consume(new ArrangementSectionEntryTemplate(comment, END_SECTION, sectionTextRange, commentText));
      myOpenedSections.pop();
      return true;
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:ArrangementSectionDetector.java

示例15: copySpacesAndCommentsBefore

import com.intellij.psi.PsiComment; //导入依赖的package包/类
public static PsiElement copySpacesAndCommentsBefore(PsiElement elementToReplace,
                                                        PsiElement[] patternElements,
                                                        String replacementToMake,
                                                        PsiElement elementParent) {
  int i = 0;
  while (true) {    // if it goes out of bounds then deep error happens
    if (!(patternElements[i] instanceof PsiComment || patternElements[i] instanceof PsiWhiteSpace)) {
      break;
    }
    ++i;
    if (patternElements.length == i) {
      break;
    }
  }

  if (patternElements.length == i) {
    Logger logger = Logger.getInstance(StructuralSearchProfile.class.getName());
    logger.error("Unexpected replacement structure:" + replacementToMake);
  }

  if (i != 0) {
    elementParent.addRangeBefore(patternElements[0], patternElements[i - 1], elementToReplace);
  }
  return patternElements[i];
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:ReplacerUtil.java


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