• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PsiJavaToken类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: run

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
@Override
public void run() {
    // deleting old fields
    Stream.of(sourceJavaPsiClass.getAllFields())
            .peek(psiField -> System.out.println("going to delete field: " + psiField.getText()))
            .forEach(psiField -> psiField.delete());

    // deleting orphanage COMMAs
    Stream.of(sourceJavaPsiClass.getChildren())
            .filter(psiElement -> psiElement instanceof PsiJavaToken)
            .map(psiElement -> (PsiJavaToken) psiElement)
            .filter(psiJavaToken -> "COMMA".equals(psiJavaToken.getTokenType().toString()))
            .peek(psiJavaToken -> System.out.println("going to delete token:" + psiJavaToken))
            .forEach(psiElement -> psiElement.delete());

    // start of additions
    new ValueClass(extractedVariables, sourceClass).getGeneratedPsiElements(project).forEach(
            psiElement -> sourceJavaPsiClass.add(psiElement)
    );
    CodeStyleManager.getInstance(project).reformat(rootPsiFile);
    JavaCodeStyleManager.getInstance(project).shortenClassReferences(rootPsiFile);
}
 
开发者ID:Ingwersaft,项目名称:ValueClassGenerator,代码行数:23,代码来源:GeneratedValueWriter.java


示例2: select

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
  List<TextRange> result = new ArrayList<TextRange>();
  result.addAll(expandToWholeLine(editorText, e.getTextRange(), false));

  PsiTypeCastExpression expression = (PsiTypeCastExpression)e;
  PsiElement[] children = expression.getChildren();
  PsiElement lParen = null;
  PsiElement rParen = null;
  for (PsiElement child : children) {
    if (child instanceof PsiJavaToken) {
      PsiJavaToken token = (PsiJavaToken)child;
      if (token.getTokenType() == JavaTokenType.LPARENTH) lParen = token;
      if (token.getTokenType() == JavaTokenType.RPARENTH) rParen = token;
    }
  }

  if (lParen != null && rParen != null) {
    result.addAll(expandToWholeLine(editorText,
                                    new TextRange(lParen.getTextRange().getStartOffset(),
                                                  rParen.getTextRange().getEndOffset()),
                                    false));
  }

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


示例3: visitBinaryExpression

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  if (!ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  if (!ExpressionUtils.hasStringType(lhs)) {
    return;
  }
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null || !ExpressionUtils.hasStringType(rhs)) {
    return;
  }
  if (ExpressionUtils.isNullLiteral(lhs) || ExpressionUtils.isNullLiteral(rhs)) {
    return;
  }
  final PsiJavaToken sign = expression.getOperationSign();
  registerError(sign);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:StringEqualityInspection.java


示例4: getTextForElement

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
public String getTextForElement(PsiElement element) {
  String operatorText = "";
  String flippedOperatorText = "";
  final PsiBinaryExpression expression = (PsiBinaryExpression)element;
  if (expression != null) {
    final PsiJavaToken sign = expression.getOperationSign();
    operatorText = sign.getText();
    flippedOperatorText =
      ComparisonUtils.getFlippedComparison(sign.getTokenType());
  }
  if (operatorText.equals(flippedOperatorText)) {
    return IntentionPowerPackBundle.message("flip.smth.intention.name",
                                            operatorText);
  }
  else {
    return IntentionPowerPackBundle.message(
      "flip.comparison.intention.name",
      operatorText, flippedOperatorText);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:FlipComparisonIntention.java


示例5: getTextForElement

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
public String getTextForElement(PsiElement element) {
  String operatorText = "";
  String negatedOperatorText = "";
  final PsiBinaryExpression exp = (PsiBinaryExpression)element;
  if (exp != null) {
    final PsiJavaToken sign = exp.getOperationSign();
    operatorText = sign.getText();
    negatedOperatorText =
      ComparisonUtils.getNegatedComparison(sign.getTokenType());
  }
  if (operatorText.equals(negatedOperatorText)) {
    return IntentionPowerPackBundle.message(
      "negate.comparison.intention.name", operatorText);
  }
  else {
    return IntentionPowerPackBundle.message(
      "negate.comparison.intention.name1", operatorText,
      negatedOperatorText);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:NegateComparisonIntention.java


示例6: satisfiedBy

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
public boolean satisfiedBy(PsiElement element) {
  if (!(element instanceof PsiJavaToken)) {
    return false;
  }
  final PsiJavaToken token = (PsiJavaToken)element;
  if (token.getTokenType() != JavaTokenType.IF_KEYWORD) {
    return false;
  }
  final PsiElement parent = element.getParent();
  if (!(parent instanceof PsiIfStatement)) {
    return false;
  }
  final PsiIfStatement statement = (PsiIfStatement)parent;
  if (ErrorUtil.containsError(statement)) {
    return false;
  }
  return SwitchUtils.getSwitchExpression(statement, 0) != null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:IfToSwitchPredicate.java


示例7: satisfiedBy

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
public boolean satisfiedBy(PsiElement element) {
  if (!(element instanceof PsiJavaToken)) {
    return false;
  }
  final PsiJavaToken token = (PsiJavaToken)element;
  final IElementType tokenType = token.getTokenType();
  if (!JavaTokenType.DO_KEYWORD.equals(tokenType)) {
    return false;
  }
  final PsiElement parent = element.getParent();
  if (!(parent instanceof PsiDoWhileStatement)) {
    return false;
  }
  final PsiDoWhileStatement doWhileStatement =
    (PsiDoWhileStatement)parent;
  return !(doWhileStatement.getCondition() == null ||
           doWhileStatement.getBody() == null);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:DoWhileLoopPredicate.java


示例8: satisfiedBy

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
public boolean satisfiedBy(PsiElement element) {
  if (!(element instanceof PsiJavaToken)) {
    return false;
  }
  final PsiJavaToken token = (PsiJavaToken)element;
  final IElementType tokenType = token.getTokenType();
  if (!JavaTokenType.WHILE_KEYWORD.equals(tokenType)) {
    return false;
  }
  final PsiElement parent = element.getParent();
  if (!(parent instanceof PsiWhileStatement)) {
    return false;
  }
  final PsiWhileStatement whileStatement = (PsiWhileStatement)parent;
  return !(whileStatement.getCondition() == null ||
           whileStatement.getBody() == null);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:WhileLoopPredicate.java


示例9: processIntention

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
@Override
public void processIntention(@NotNull PsiElement element) {
  final PsiJavaToken token = (PsiJavaToken)element;
  final PsiElement parent = token.getParent();
  if (!(parent instanceof PsiPolyadicExpression)) {
    return;
  }
  final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)parent;
  final PsiExpression[] operands = polyadicExpression.getOperands();
  final StringBuilder newExpression = new StringBuilder();
  String prevOperand = null;
  final String tokenText = token.getText() + ' '; // 2- -1 without the space is not legal
  for (PsiExpression operand : operands) {
    final PsiJavaToken token1 = polyadicExpression.getTokenBeforeOperand(operand);
    if (token == token1) {
      newExpression.append(operand.getText()).append(tokenText);
      continue;
    }
    if (prevOperand != null) {
      newExpression.append(prevOperand).append(tokenText);
    }
    prevOperand = operand.getText();
  }
  newExpression.append(prevOperand);
  PsiReplacementUtil.replaceExpression(polyadicExpression, newExpression.toString());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:FlipExpressionIntention.java


示例10: satisfiedBy

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
public boolean satisfiedBy(PsiElement element) {
  if (!(element instanceof PsiJavaToken)) {
    return false;
  }
  final PsiElement parent = element.getParent();
  if (!(parent instanceof PsiPolyadicExpression)) {
    return false;
  }
  final PsiPolyadicExpression expression = (PsiPolyadicExpression)parent;
  final PsiExpression[] operands = expression.getOperands();
  if (operands.length < 2) {
    return false;
  }
  PsiExpression prevOperand = null;
  for (PsiExpression operand : operands) {
    final PsiJavaToken token = expression.getTokenBeforeOperand(operand);
    if (element == token) {
      if (prevOperand == null || operand.getText().equals(prevOperand.getText())) {
        return false;
      }
      break;
    }
    prevOperand = operand;
  }
  return !ComparisonUtils.isComparison(expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:ExpressionPredicate.java


示例11: getElementPredicate

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
@NotNull
public PsiElementPredicate getElementPredicate() {
  return new PsiElementPredicate() {
    public boolean satisfiedBy(PsiElement element) {
      if (!(element instanceof PsiJavaToken)) {
        return false;
      }
      final PsiJavaToken token = (PsiJavaToken)element;
      final PsiElement parent = token.getParent();
      if (!(parent instanceof PsiIfStatement)) {
        return false;
      }
      return TrivialIfInspection.isTrivial((PsiIfStatement)parent);
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:SimplifyIfElseIntention.java


示例12: visitBinaryExpression

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
@Override
public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) {
  super.visitBinaryExpression(expression);
  if (!ComparisonUtils.isEqualityComparison(expression)) {
    return;
  }
  final PsiExpression lhs = expression.getLOperand();
  if (!ExpressionUtils.hasStringType(lhs)) {
    return;
  }
  final PsiExpression rhs = expression.getROperand();
  if (rhs == null || !ExpressionUtils.hasStringType(rhs)) {
    return;
  }
  final String lhsText = lhs.getText();
  if (PsiKeyword.NULL.equals(lhsText)) {
    return;
  }
  final String rhsText = rhs.getText();
  if (PsiKeyword.NULL.equals(rhsText)) {
    return;
  }
  final PsiJavaToken sign = expression.getOperationSign();
  registerError(sign);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:26,代码来源:StringEqualityInspection.java


示例13: getTextForElement

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
public String getTextForElement(PsiElement element) {
  String operatorText = "";
  String flippedOperatorText = "";
  final PsiBinaryExpression expression = (PsiBinaryExpression)element;
  if (expression != null) {
    final PsiJavaToken sign = expression.getOperationSign();
    operatorText = sign.getText();
    flippedOperatorText =
      ComparisonUtils.getFlippedComparison(sign);
  }
  if (operatorText.equals(flippedOperatorText)) {
    return IntentionPowerPackBundle.message("flip.smth.intention.name",
                                            operatorText);
  }
  else {
    return IntentionPowerPackBundle.message(
      "flip.comparison.intention.name",
      operatorText, flippedOperatorText);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:21,代码来源:FlipComparisonIntention.java


示例14: processIntention

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
@Override
public void processIntention(@NotNull PsiElement element) {
  final PsiJavaToken token = (PsiJavaToken)element;
  final PsiElement parent = token.getParent();
  if (!(parent instanceof PsiPolyadicExpression)) {
    return;
  }
  final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)parent;
  final PsiExpression[] operands = polyadicExpression.getOperands();
  final StringBuilder newExpression = new StringBuilder();
  String prevOperand = null;
  final String tokenText = token.getText() + ' '; // 2- -1 without the space is not legal
  for (PsiExpression operand : operands) {
    final PsiJavaToken token1 = polyadicExpression.getTokenBeforeOperand(operand);
    if (token == token1) {
      newExpression.append(operand.getText()).append(tokenText);
      continue;
    }
    if (prevOperand != null) {
      newExpression.append(prevOperand).append(tokenText);
    }
    prevOperand = operand.getText();
  }
  newExpression.append(prevOperand);
  replaceExpression(newExpression.toString(), polyadicExpression);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:27,代码来源:FlipExpressionIntention.java


示例15: apply

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException
{
	if(!(psiElement instanceof PsiCatchSection))
	{
		return;
	}
	PsiCatchSection catchSection = (PsiCatchSection) psiElement;

	final Document doc = editor.getDocument();

	PsiCodeBlock body = catchSection.getCatchBlock();
	if(body != null && startLine(doc, body) == startLine(doc, catchSection))
	{
		return;
	}

	final PsiJavaToken rParenth = catchSection.getRParenth();
	if(rParenth == null)
	{
		return;
	}

	doc.insertString(rParenth.getTextRange().getEndOffset(), "{}");
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:26,代码来源:MissingCatchBodyFixer.java


示例16: getSubexpression

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
@Nullable
static PsiPolyadicExpression getSubexpression(PsiPolyadicExpression expression, PsiJavaToken token) {
  final PsiExpression[] operands = expression.getOperands();
  if (operands.length == 2) {
    return expression;
  }
  for (int i = 1; i < operands.length; i++) {
    final PsiExpression operand = operands[i];
    final PsiJavaToken currentToken = expression.getTokenBeforeOperand(operand);
    if (currentToken == token) {
      final String binaryExpressionText = operands[i - 1].getText() + ' ' + token.getText() + ' ' + operand.getText();
      final PsiElementFactory factory = JavaPsiFacade.getElementFactory(expression.getProject());
      return (PsiPolyadicExpression)factory.createExpressionFromText(binaryExpressionText, expression);
    }
  }
  return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:18,代码来源:ConstantSubexpressionPredicate.java


示例17: getTextForElement

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
public String getTextForElement(PsiElement element)
{
	String operatorText = "";
	String flippedOperatorText = "";
	final PsiBinaryExpression expression = (PsiBinaryExpression) element;
	if(expression != null)
	{
		final PsiJavaToken sign = expression.getOperationSign();
		operatorText = sign.getText();
		flippedOperatorText = ComparisonUtils.getFlippedComparison(sign.getTokenType());
	}
	if(operatorText.equals(flippedOperatorText))
	{
		return IntentionPowerPackBundle.message("flip.smth.intention.name", operatorText);
	}
	else
	{
		return IntentionPowerPackBundle.message("flip.comparison.intention.name", operatorText, flippedOperatorText);
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:21,代码来源:FlipComparisonIntention.java


示例18: satisfiedBy

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
public boolean satisfiedBy(PsiElement element) {
  if (!(element instanceof PsiJavaToken)) {
    return false;
  }
  final PsiJavaToken token = (PsiJavaToken)element;
  if (token.getTokenType() != JavaTokenType.IF_KEYWORD) {
    return false;
  }
  final PsiElement parent = element.getParent();
  if (!(parent instanceof PsiIfStatement)) {
    return false;
  }
  final PsiIfStatement statement = (PsiIfStatement)parent;
  if (ErrorUtil.containsError(statement)) {
    return false;
  }
  return SwitchUtils.getSwitchExpression(statement) != null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:IfToSwitchPredicate.java


示例19: replaceSimplifiableAssignment

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
private static void replaceSimplifiableAssignment(
  PsiIfStatement statement)
  throws IncorrectOperationException {
  final PsiExpression condition = statement.getCondition();
  if (condition == null) {
    return;
  }
  final String conditionText = condition.getText();
  final PsiStatement thenBranch = statement.getThenBranch();
  final PsiExpressionStatement assignmentStatement =
    (PsiExpressionStatement)
      ControlFlowUtils.stripBraces(thenBranch);
  final PsiAssignmentExpression assignmentExpression =
    (PsiAssignmentExpression)assignmentStatement.getExpression();
  final PsiJavaToken operator =
    assignmentExpression.getOperationSign();
  final String operand = operator.getText();
  final PsiExpression lhs = assignmentExpression.getLExpression();
  final String lhsText = lhs.getText();
  replaceStatement(statement,
                   lhsText + operand + conditionText + ';');
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:23,代码来源:TrivialIfInspection.java


示例20: replaceSimplifiableAssignmentNegated

import com.intellij.psi.PsiJavaToken; //导入依赖的package包/类
private static void replaceSimplifiableAssignmentNegated(
  PsiIfStatement statement)
  throws IncorrectOperationException {
  final PsiExpression condition = statement.getCondition();
  if (condition == null) {
    return;
  }
  final String conditionText =
    BoolUtils.getNegatedExpressionText(condition);
  final PsiStatement thenBranch = statement.getThenBranch();
  final PsiExpressionStatement assignmentStatement =
    (PsiExpressionStatement)
      ControlFlowUtils.stripBraces(thenBranch);
  final PsiAssignmentExpression assignmentExpression =
    (PsiAssignmentExpression)
      assignmentStatement.getExpression();
  final PsiJavaToken operator =
    assignmentExpression.getOperationSign();
  final String operand = operator.getText();
  final PsiExpression lhs = assignmentExpression.getLExpression();
  final String lhsText = lhs.getText();
  replaceStatement(statement,
                   lhsText + operand + conditionText + ';');
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:25,代码来源:TrivialIfInspection.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java VmSchedulerTimeSharedOverSubscription类代码示例发布时间:2022-05-22
下一篇:
Java NumberFormatAnnotationFormatterFactory类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap