• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java PsiForStatement类的典型用法和代码示例

java 1次浏览

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

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

示例1: verifyVariable

点赞 3

import com.intellij.psi.PsiForStatement; //导入依赖的package包/类
public void verifyVariable(@NotNull final PsiLocalVariable psiLocalVariable, @NotNull final ProblemsHolder holder) {
  boolean isVal = isSameName(psiLocalVariable.getTypeElement().getText());
  boolean isVar = isVar(psiLocalVariable.getTypeElement().getText());
  final String ann = isVal ? "val" : "var";
  if (isVal || isVar) {
    final PsiExpression initializer = psiLocalVariable.getInitializer();
    if (initializer == null) {
      holder.registerProblem(psiLocalVariable, "'" + ann + "' on a local variable requires an initializer expression", ProblemHighlightType.ERROR);
    } else if (initializer instanceof PsiArrayInitializerExpression) {
      holder.registerProblem(psiLocalVariable, "'" + ann + "' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })", ProblemHighlightType.ERROR);
    } else if (initializer instanceof PsiLambdaExpression) {
      holder.registerProblem(psiLocalVariable, "'" + ann + "' is not allowed with lambda expressions.", ProblemHighlightType.ERROR);
    } else if (isVal) {
      final PsiElement typeParentParent = psiLocalVariable.getParent();
      if (typeParentParent instanceof PsiDeclarationStatement && typeParentParent.getParent() instanceof PsiForStatement) {
        holder.registerProblem(psiLocalVariable, "'" + ann + "' is not allowed in old-style for loops", ProblemHighlightType.ERROR);
      }
    }
  }
}
 

开发者ID:mplushnikov,
项目名称:lombok-intellij-plugin,
代码行数:21,
代码来源:ValProcessor.java

示例2: registerErrorOffset

点赞 3

import com.intellij.psi.PsiForStatement; //导入依赖的package包/类
/**
 * {@link JavaSmartEnterProcessor#registerUnresolvedError(int) registers target offset} taking care of the situation when
 * current code style implies white space after 'for' part's semicolon.
 *
 * @param editor           target editor
 * @param processor        target smart enter processor
 * @param lastValidForPart last valid element of the target 'for' loop
 * @param forStatement     PSI element for the target 'for' loop
 */
private static void registerErrorOffset(@NotNull Editor editor, @NotNull JavaSmartEnterProcessor processor, @NotNull PsiElement lastValidForPart, @NotNull PsiForStatement forStatement)
{
	final Project project = editor.getProject();
	int offset = lastValidForPart.getTextRange().getEndOffset();
	if(project != null && CodeStyleSettingsManager.getSettings(project).SPACE_AFTER_COMMA)
	{
		if(editor.getDocument().getCharsSequence().charAt(lastValidForPart.getTextRange().getEndOffset() - 1) != ';')
		{
			offset++;
		}
		for(PsiElement element = lastValidForPart.getNextSibling(); element != null && element != forStatement.getRParenth() && element.getParent() == forStatement; element = element
				.getNextSibling())
		{
			final ASTNode node = element.getNode();
			if(node != null && JavaJspElementType.WHITE_SPACE_BIT_SET.contains(node.getElementType()) && element.getTextLength() > 0)
			{
				offset++;
				break;
			}
		}
	}

	processor.registerUnresolvedError(offset);
}
 

开发者ID:consulo,
项目名称:consulo-java
代码行数:34,
代码来源:ForStatementFixer.java

示例3: satisfiedBy

点赞 2

import com.intellij.psi.PsiForStatement; //导入依赖的package包/类
public boolean satisfiedBy(PsiElement element) {
  if (!(element instanceof PsiJavaToken)) {
    return false;
  }
  final PsiJavaToken token = (PsiJavaToken)element;
  final IElementType tokenType = token.getTokenType();
  if (!JavaTokenType.FOR_KEYWORD.equals(tokenType)) {
    return false;
  }
  final PsiElement parent = element.getParent();
  return parent instanceof PsiForStatement &&
         !ErrorUtil.containsError(parent);
}
 

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

示例4: verifyParameter

点赞 2

import com.intellij.psi.PsiForStatement; //导入依赖的package包/类
public void verifyParameter(@NotNull final PsiParameter psiParameter, @NotNull final ProblemsHolder holder) {
  final PsiTypeElement typeElement = psiParameter.getTypeElement();
  boolean isVal = null != typeElement && isSameName(typeElement.getText());
  boolean isVar = null != typeElement && isVar(typeElement.getText());
  if (isVar || isVal) {
    PsiElement scope = psiParameter.getDeclarationScope();
    boolean isForeachStatement = scope instanceof PsiForeachStatement;
    boolean isForStatement = scope instanceof PsiForStatement;
    if (isVal && !isForeachStatement) {
      holder.registerProblem(psiParameter, "'val' works only on local variables and on foreach loops", ProblemHighlightType.ERROR);
    } else if (isVar && !(isForeachStatement || isForStatement)) {
      holder.registerProblem(psiParameter, "'var' works only on local variables and on for/foreach loops", ProblemHighlightType.ERROR);
    }
  }
}
 

开发者ID:mplushnikov,
项目名称:lombok-intellij-plugin,
代码行数:16,
代码来源:ValProcessor.java

示例5: apply

点赞 2

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

	final Document doc = editor.getDocument();

	PsiElement body = forStatement.getBody();
	if(body instanceof PsiBlockStatement)
	{
		return;
	}
	if(body != null && startLine(doc, body) == startLine(doc, forStatement))
	{
		return;
	}

	PsiElement eltToInsertAfter = forStatement.getRParenth();
	String text = "{}";
	if(eltToInsertAfter == null)
	{
		eltToInsertAfter = forStatement;
		text = "){}";
	}
	doc.insertString(eltToInsertAfter.getTextRange().getEndOffset(), text);
}
 

开发者ID:consulo,
项目名称:consulo-java
代码行数:31,
代码来源:MissingForBodyFixer.java

示例6: getForStatementParent

点赞 2

import com.intellij.psi.PsiForStatement; //导入依赖的package包/类
@Nullable
private static PsiForStatement getForStatementParent(PsiElement psiElement)
{
	PsiForStatement statement = PsiTreeUtil.getParentOfType(psiElement, PsiForStatement.class);
	if(statement == null)
	{
		return null;
	}

	PsiStatement init = statement.getInitialization();
	PsiStatement update = statement.getUpdate();
	PsiExpression check = statement.getCondition();

	return isValidChild(init, psiElement) || isValidChild(update, psiElement) || isValidChild(check, psiElement) ? statement : null;
}
 

开发者ID:consulo,
项目名称:consulo-java
代码行数:16,
代码来源:MissingForBodyFixer.java

示例7: apply

点赞 2

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

	PsiForStatement forStatement = (PsiForStatement) psiElement;
	final PsiJavaToken lParenth = forStatement.getLParenth();
	final PsiJavaToken rParenth = forStatement.getRParenth();
	if(lParenth == null || rParenth == null)
	{
		final TextRange textRange = forStatement.getTextRange();
		editor.getDocument().replaceString(textRange.getStartOffset(), textRange.getEndOffset(), "for () {\n}");
		processor.registerUnresolvedError(textRange.getStartOffset() + "for (".length());
		return;
	}

	final PsiStatement initialization = forStatement.getInitialization();
	if(initialization == null)
	{
		processor.registerUnresolvedError(lParenth.getTextRange().getEndOffset());
		return;
	}

	final PsiExpression condition = forStatement.getCondition();
	if(condition == null)
	{
		registerErrorOffset(editor, processor, initialization, forStatement);
		return;
	}

	if(forStatement.getUpdate() == null)
	{
		registerErrorOffset(editor, processor, condition, forStatement);
	}
}
 

开发者ID:consulo,
项目名称:consulo-java
代码行数:39,
代码来源:ForStatementFixer.java

示例8: visitForStatement

点赞 2

import com.intellij.psi.PsiForStatement; //导入依赖的package包/类
@Override
public void visitForStatement(PsiForStatement statement) {
    mVisitor.report("PsiForStatement", statement.getText(), statement);
    super.visitStatement(statement);
}
 

开发者ID:cch-robo,
项目名称:Android_Lint_SRP_Practice_Example,
代码行数:6,
代码来源:PsiClassStructureDetector.java

示例9: visitForStatement

点赞 2

import com.intellij.psi.PsiForStatement; //导入依赖的package包/类
@Override
public void visitForStatement(
  @NotNull PsiForStatement statement) {
  super.visitForStatement(statement);
  checkStatement(statement);
}
 

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

示例10: from

点赞 2

import com.intellij.psi.PsiForStatement; //导入依赖的package包/类
@Nullable
public static CountingLoop from(PsiForStatement forStatement)
{
	// check that initialization is for(int/long i = <initial_value>;...;...)
	PsiDeclarationStatement initialization = tryCast(forStatement.getInitialization(), PsiDeclarationStatement.class);
	if(initialization == null || initialization.getDeclaredElements().length != 1)
	{
		return null;
	}
	PsiLocalVariable counter = tryCast(initialization.getDeclaredElements()[0], PsiLocalVariable.class);
	if(counter == null)
	{
		return null;
	}
	if(!counter.getType().equals(PsiType.INT) && !counter.getType().equals(PsiType.LONG))
	{
		return null;
	}

	PsiExpression initializer = PsiUtil.skipParenthesizedExprDown(counter.getInitializer());
	if(initializer == null)
	{
		return null;
	}

	// check that increment is like for(...;...;i++)
	if(!VariableAccessUtils.variableIsIncremented(counter, forStatement.getUpdate()))
	{
		return null;
	}

	// check that condition is like for(...;i<bound;...) or for(...;i<=bound;...)
	PsiBinaryExpression condition = tryCast(forStatement.getCondition(), PsiBinaryExpression.class);
	if(condition == null)
	{
		return null;
	}
	IElementType type = condition.getOperationTokenType();
	boolean closed = false;
	PsiExpression bound;
	PsiExpression ref;
	if(type.equals(JavaTokenType.LE))
	{
		bound = condition.getROperand();
		ref = condition.getLOperand();
		closed = true;
	}
	else if(type.equals(JavaTokenType.LT))
	{
		bound = condition.getROperand();
		ref = condition.getLOperand();
	}
	else if(type.equals(JavaTokenType.GE))
	{
		bound = condition.getLOperand();
		ref = condition.getROperand();
		closed = true;
	}
	else if(type.equals(JavaTokenType.GT))
	{
		bound = condition.getLOperand();
		ref = condition.getROperand();
	}
	else
	{
		return null;
	}
	if(bound == null || !ExpressionUtils.isReferenceTo(ref, counter))
	{
		return null;
	}
	if(!TypeConversionUtil.areTypesAssignmentCompatible(counter.getType(), bound))
	{
		return null;
	}
	return new CountingLoop(forStatement, counter, initializer, bound, closed);
}
 

开发者ID:consulo,
项目名称:consulo-java
代码行数:78,
代码来源:CountingLoop.java

示例11: visitForStatement

点赞 2

import com.intellij.psi.PsiForStatement; //导入依赖的package包/类
@Override
public void visitForStatement(@NotNull PsiForStatement statement)
{
	super.visitForStatement(statement);
	checkStatement(statement);
}
 

开发者ID:consulo,
项目名称:consulo-java
代码行数:7,
代码来源:InfiniteLoopStatementInspection.java

示例12: calcPsiElement

点赞 2

import com.intellij.psi.PsiForStatement; //导入依赖的package包/类
@Nullable
protected PsiElement calcPsiElement() {
  PsiFile psiFile = getFile();
  int lineNumber = getLine();
  if(lineNumber < 0) {
    return psiFile;
  }

  final Document document = PsiDocumentManager.getInstance(psiFile.getProject()).getDocument(psiFile);
  if (document == null) {
    return null;
  }
  if (lineNumber >= document.getLineCount()) {
    return psiFile;
  }
  int startOffset = document.getLineStartOffset(lineNumber);
  if(startOffset == -1) {
    return null;
  }

  PsiElement rootElement = psiFile;

  List<PsiFile> allFiles = psiFile.getViewProvider().getAllFiles();
  if (allFiles.size() > 1) { // jsp & gsp
    PsiClassOwner owner = ContainerUtil.findInstance(allFiles, PsiClassOwner.class);
    if (owner != null) {
      PsiClass[] classes = owner.getClasses();
      if (classes.length == 1 && classes[0]  instanceof SyntheticElement) {
        rootElement = classes[0];
      }
    }
  }

  PsiElement element;
  while(true) {
    final CharSequence charsSequence = document.getCharsSequence();
    for (; startOffset < charsSequence.length(); startOffset++) {
      char c = charsSequence.charAt(startOffset);
      if (c != ' ' && c != '\t') {
        break;
      }
    }
    element = rootElement.findElementAt(startOffset);

    if(element instanceof PsiComment) {
      startOffset = element.getTextRange().getEndOffset() + 1;
    }
    else{
      break;
    }
  }

  if (element != null && element.getParent() instanceof PsiForStatement) {
    return ((PsiForStatement)element.getParent()).getInitialization();
  }
  return element;
}
 

开发者ID:consulo,
项目名称:consulo-java,
代码行数:58,
代码来源:SourcePosition.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)