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

Java PsiStatement类代码示例

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

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



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

示例1: LambdaMethodFilter

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
public LambdaMethodFilter(PsiLambdaExpression lambda, int expressionOrdinal, Range<Integer> callingExpressionLines) {
  myLambdaOrdinal = expressionOrdinal;
  myCallingExpressionLines = callingExpressionLines;

  SourcePosition firstStatementPosition = null;
  SourcePosition lastStatementPosition = null;
  final PsiElement body = lambda.getBody();
  if (body instanceof PsiCodeBlock) {
    final PsiStatement[] statements = ((PsiCodeBlock)body).getStatements();
    if (statements.length > 0) {
      firstStatementPosition = SourcePosition.createFromElement(statements[0]);
      if (firstStatementPosition != null) {
        final PsiStatement lastStatement = statements[statements.length - 1];
        lastStatementPosition =
          SourcePosition.createFromOffset(firstStatementPosition.getFile(), lastStatement.getTextRange().getEndOffset());
      }
    }
  }
  else if (body != null) {
    firstStatementPosition = SourcePosition.createFromElement(body);
  }
  myFirstStatementPosition = firstStatementPosition;
  myLastStatementLine = lastStatementPosition != null ? lastStatementPosition.getLine() : -1;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:LambdaMethodFilter.java


示例2: AnonymousClassMethodFilter

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
public AnonymousClassMethodFilter(PsiMethod psiMethod, Range<Integer> lines) {
  super(psiMethod, lines);
  SourcePosition firstStatementPosition = null;
  SourcePosition lastStatementPosition = null;
  final PsiCodeBlock body = psiMethod.getBody();
  if (body != null) {
    final PsiStatement[] statements = body.getStatements();
    if (statements.length > 0) {
      firstStatementPosition = SourcePosition.createFromElement(statements[0]);
      if (firstStatementPosition != null) {
        final PsiStatement lastStatement = statements[statements.length - 1];
        lastStatementPosition = SourcePosition.createFromOffset(firstStatementPosition.getFile(), lastStatement.getTextRange().getEndOffset());
      }
    }
  }
  myBreakpointPosition = firstStatementPosition;
  myLastStatementLine = lastStatementPosition != null? lastStatementPosition.getLine() : -1;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:AnonymousClassMethodFilter.java


示例3: getFinallyStatements

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
private static List<PsiStatement> getFinallyStatements(@Nullable SourcePosition position) {
  if (position == null) {
    return Collections.emptyList();
  }
  List<PsiStatement> res = new ArrayList<PsiStatement>();
  PsiElement element = position.getFile().findElementAt(position.getOffset());
  PsiTryStatement tryStatement = PsiTreeUtil.getParentOfType(element, PsiTryStatement.class);
  while (tryStatement != null) {
    PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock();
    if (finallyBlock != null) {
      ContainerUtil.addAll(res, finallyBlock.getStatements());
    }
    tryStatement = PsiTreeUtil.getParentOfType(tryStatement, PsiTryStatement.class);
  }
  return res;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:PopFrameAction.java


示例4: visitContinueStatement

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
@Override
public void visitContinueStatement(
  @NotNull PsiContinueStatement statement) {
  super.visitContinueStatement(statement);
  if (!ControlFlowUtils.isInFinallyBlock(statement)) {
    return;
  }
  final PsiStatement continuedStatement =
    statement.findContinuedStatement();
  if (continuedStatement == null) {
    return;
  }
  if (ControlFlowUtils.isInFinallyBlock(continuedStatement)) {
    return;
  }
  registerStatementError(statement);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:ContinueOrBreakFromFinallyBlockInspection.java


示例5: calculateReturnPointCount

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
private int calculateReturnPointCount(PsiMethod method) {
  final ReturnPointCountVisitor visitor =
    new ReturnPointCountVisitor(ignoreGuardClauses);
  method.accept(visitor);
  final int count = visitor.getCount();
  if (!mayFallThroughBottom(method)) {
    return count;
  }
  final PsiCodeBlock body = method.getBody();
  if (body == null) {
    return count;
  }
  final PsiStatement[] statements = body.getStatements();
  if (statements.length == 0) {
    return count + 1;
  }
  final PsiStatement lastStatement =
    statements[statements.length - 1];
  if (ControlFlowUtils.statementMayCompleteNormally(lastStatement)) {
    return count + 1;
  }
  return count;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:MultipleReturnPointsPerMethodInspection.java


示例6: visitIfStatement

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
@Override
public void visitIfStatement(@NotNull PsiIfStatement statement) {
  super.visitIfStatement(statement);
  final PsiElement parent = statement.getParent();
  if (parent instanceof PsiIfStatement) {
    final PsiIfStatement parentStatement = (PsiIfStatement)parent;
    final PsiStatement elseBranch = parentStatement.getElseBranch();
    if (statement.equals(elseBranch)) {
      return;
    }
  }
  final int branchCount = calculateBranchCount(statement);
  if (branchCount <= m_limit) {
    return;
  }
  registerStatementError(statement, Integer.valueOf(branchCount));
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:18,代码来源:IfStatementWithTooManyBranchesInspection.java


示例7: visitSynchronizedStatement

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
@Override
public void visitSynchronizedStatement(
  @NotNull PsiSynchronizedStatement statement) {
  super.visitSynchronizedStatement(statement);
  if (FileTypeUtils.isInJsp(statement.getContainingFile())) {
    return;
  }
  final PsiCodeBlock body = statement.getBody();
  if (body == null) {
    return;
  }
  final PsiStatement[] statements = body.getStatements();
  if (statements.length > 0) {
    return;
  }
  registerStatementError(statement);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:18,代码来源:EmptySynchronizedStatementInspection.java


示例8: isChainingConstructor

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
private boolean isChainingConstructor(PsiMethod constructor) {
  PsiCodeBlock body = constructor.getBody();
  if (body != null) {
    PsiStatement[] statements = body.getStatements();
    if (statements.length == 1 && statements[0] instanceof PsiExpressionStatement) {
      PsiExpression expression = ((PsiExpressionStatement) statements[0]).getExpression();
      if (expression instanceof PsiMethodCallExpression) {
        PsiReferenceExpression methodExpr = ((PsiMethodCallExpression) expression).getMethodExpression();
        if ("this".equals(methodExpr.getReferenceName())) {
          PsiElement resolved = methodExpr.resolve();
          return resolved instanceof PsiMethod && ((PsiMethod) resolved).isConstructor(); //delegated via "this" call
        }
      }
    }
  }
  return false;
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:18,代码来源:LombokInlineMethodHandler.java


示例9: addAfter

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
/**
 * Add new statement after given anchor statement creating code block, if necessary
 *
 * @param anchor       existing statement
 * @param newStatement a new statement which should be added after an existing one
 * @return added physical statement
 */
public static PsiStatement addAfter(PsiStatement anchor, PsiStatement newStatement)
{
	PsiElement oldStatement = anchor;
	PsiElement parent = oldStatement.getParent();
	while(parent instanceof PsiLabeledStatement)
	{
		oldStatement = parent;
		parent = oldStatement.getParent();
	}
	final PsiElement result;
	if(parent instanceof PsiCodeBlock)
	{
		result = parent.addAfter(newStatement, oldStatement);
	}
	else
	{
		PsiElementFactory factory = JavaPsiFacade.getElementFactory(anchor.getProject());
		final PsiBlockStatement newBlockStatement = (PsiBlockStatement) factory.createStatementFromText("{}", oldStatement);
		final PsiElement codeBlock = newBlockStatement.getCodeBlock();
		codeBlock.add(oldStatement);
		codeBlock.add(newStatement);
		result = ((PsiBlockStatement) oldStatement.replace(newBlockStatement)).getCodeBlock().getStatements()[1];
	}
	return (PsiStatement) result;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:33,代码来源:BlockUtils.java


示例10: collectSlowLineMarkers

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
@RequiredReadAction
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result)
{
	final Set<PsiStatement> statements = new HashSet<>();

	for(PsiElement element : elements)
	{
		ProgressManager.checkCanceled();
		if(element instanceof PsiMethodCallExpression)
		{
			final PsiMethodCallExpression methodCall = (PsiMethodCallExpression) element;
			final PsiStatement statement = PsiTreeUtil.getParentOfType(methodCall, PsiStatement.class, true, PsiMethod.class);
			if(!statements.contains(statement) && isRecursiveMethodCall(methodCall))
			{
				statements.add(statement);
				result.add(new RecursiveMethodCallMarkerInfo(methodCall));
			}
		}
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:22,代码来源:RecursiveCallLineMarkerProvider.java


示例11: invoke

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException
{
	PsiExpressionStatement statement = myPointer.getElement();
	if(statement == null)
	{
		return;
	}
	PsiExpression expression = statement.getExpression();
	List<PsiExpression> sideEffects = SideEffectChecker.extractSideEffectExpressions(expression);
	PsiStatement[] statements = StatementExtractor.generateStatements(sideEffects, expression);
	if(statements.length > 0)
	{
		BlockUtils.addBefore(statement, statements);
	}
	statement.delete();
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:18,代码来源:DeleteSideEffectsAwareFix.java


示例12: replaceSimplifiableAssignment

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


示例13: replaceSimplifiableAssignmentNegated

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


示例14: isSimplifiableImplicitReturn

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
public static boolean isSimplifiableImplicitReturn(
  PsiIfStatement ifStatement) {
  if (ifStatement.getElseBranch() != null) {
    return false;
  }
  PsiStatement thenBranch = ifStatement.getThenBranch();
  thenBranch = ControlFlowUtils.stripBraces(thenBranch);
  final PsiElement nextStatement =
    PsiTreeUtil.skipSiblingsForward(ifStatement,
                                    PsiWhiteSpace.class);
  if (!(nextStatement instanceof PsiStatement)) {
    return false;
  }

  final PsiStatement elseBranch = (PsiStatement)nextStatement;
  return ConditionalUtils.isReturn(thenBranch, PsiKeyword.TRUE)
         && ConditionalUtils.isReturn(elseBranch, PsiKeyword.FALSE);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:TrivialIfInspection.java


示例15: isSimplifiableImplicitReturnNegated

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
public static boolean isSimplifiableImplicitReturnNegated(
  PsiIfStatement ifStatement) {
  if (ifStatement.getElseBranch() != null) {
    return false;
  }
  PsiStatement thenBranch = ifStatement.getThenBranch();
  thenBranch = ControlFlowUtils.stripBraces(thenBranch);

  final PsiElement nextStatement =
    PsiTreeUtil.skipSiblingsForward(ifStatement,
                                    PsiWhiteSpace.class);
  if (!(nextStatement instanceof PsiStatement)) {
    return false;
  }
  final PsiStatement elseBranch = (PsiStatement)nextStatement;
  return ConditionalUtils.isReturn(thenBranch, PsiKeyword.FALSE)
         && ConditionalUtils.isReturn(elseBranch, PsiKeyword.TRUE);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:TrivialIfInspection.java


示例16: checkStatement

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
private void checkStatement(PsiStatement statement)
{
	if(ControlFlowUtils.statementMayCompleteNormally(statement))
	{
		return;
	}
	if(ControlFlowUtils.containsReturn(statement))
	{
		return;
	}
	if(ControlFlowUtils.containsSystemExit(statement))
	{
		return;
	}
	registerStatementError(statement);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:17,代码来源:InfiniteLoopStatementInspection.java


示例17: visitSynchronizedStatement

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
@Override
public void visitSynchronizedStatement(
  @NotNull PsiSynchronizedStatement statement) {
  super.visitSynchronizedStatement(statement);
 /* if (JspPsiUtil.isInJspFile(statement.getContainingFile())) {
    return;
  }*/
  final PsiCodeBlock body = statement.getBody();
  if (body == null) {
    return;
  }
  final PsiStatement[] statements = body.getStatements();
  if (statements.length > 0) {
    return;
  }
  registerStatementError(statement);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:18,代码来源:EmptySynchronizedStatementInspection.java


示例18: AnonymousClassMethodFilter

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
public AnonymousClassMethodFilter(PsiMethod psiMethod, Range<Integer> lines)
{
	super(psiMethod, lines);
	SourcePosition firstStatementPosition = null;
	SourcePosition lastStatementPosition = null;
	final PsiCodeBlock body = psiMethod.getBody();
	if(body != null)
	{
		final PsiStatement[] statements = body.getStatements();
		if(statements.length > 0)
		{
			firstStatementPosition = SourcePosition.createFromElement(statements[0]);
			if(firstStatementPosition != null)
			{
				final PsiStatement lastStatement = statements[statements.length - 1];
				lastStatementPosition = SourcePosition.createFromOffset(firstStatementPosition.getFile(), lastStatement.getTextRange().getEndOffset());
			}
		}
	}
	myBreakpointPosition = firstStatementPosition;
	myLastStatementLine = lastStatementPosition != null ? lastStatementPosition.getLine() : -1;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:23,代码来源:AnonymousClassMethodFilter.java


示例19: extractStatements

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
private static void extractStatements(@NonNull PsiElement element, List<PsiStatement> statements) {
    for (PsiElement child : element.getChildren()) {
        if (child instanceof PsiStatement) {
            statements.add((PsiStatement) child);
            continue;
        }
        extractStatements(child, statements);
    }
}
 
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:10,代码来源:ElementUtil.java


示例20: startElement

import com.intellij.psi.PsiStatement; //导入依赖的package包/类
public void startElement(PsiElement element) {
  myElementStack.push(element);
  myElementToStartOffsetMap.put(element, myInstructions.size());

  if (LOG.isDebugEnabled()){
    if (element instanceof PsiStatement){
      String text = element.getText();
      int index = Math.min(text.indexOf('\n'), text.indexOf('\r'));
      if (index >= 0){
        text = text.substring(0, index);
      }
      addInstruction(new CommentInstruction(text));
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:ControlFlowImpl.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java SnmpOidTable类代码示例发布时间:2022-05-22
下一篇:
Java Color类代码示例发布时间: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