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

Java PsiDeclarationStatement类代码示例

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

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



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

示例1: getContainer

import com.intellij.psi.PsiDeclarationStatement; //导入依赖的package包/类
@Override
@Nullable
public PsiDocCommentOwner getContainer(final PsiElement element) {
  PsiDocCommentOwner container = super.getContainer(element);
  if (container == null || container instanceof PsiClass){
    return null;
  }
  while (container != null ) {
    final PsiClass parentClass = PsiTreeUtil.getParentOfType(container, PsiClass.class);
    if ((parentClass == null || container.getParent() instanceof PsiDeclarationStatement || container.getParent() instanceof PsiClass) && container instanceof PsiClass){
      return container;
    }
    container = parentClass;
  }
  return container;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:SuppressForClassFix.java


示例2: findMethodCall

import com.intellij.psi.PsiDeclarationStatement; //导入依赖的package包/类
private PsiMethodCallExpression findMethodCall(PsiElement element) {
    // This covers the case if there is a method being used to initialize a variable..
    // i.e int a = random();
    if (element instanceof PsiDeclarationStatement) {
        PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement) element;
        for (PsiElement declarationElement : declarationStatement.getDeclaredElements()) {
            if (declarationElement instanceof PsiVariable) {
                PsiVariable variable = (PsiVariable) declarationElement;
                PsiExpression initializer = variable.getInitializer();
                if (initializer instanceof PsiMethodCallExpression) {
                    return (PsiMethodCallExpression) initializer;
                }
            }
        }
    }
    if (element instanceof PsiExpressionStatement) {
        PsiExpression expression = ((PsiExpressionStatement) element).getExpression();
        if (expression instanceof PsiMethodCallExpression) {
            return (PsiMethodCallExpression) expression;
        }
    }
    return null;
}
 
开发者ID:mParticle,项目名称:mparticle-android-sdk,代码行数:24,代码来源:MpApiDetector.java


示例3: verifyVariable

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


示例4: visitDeclarationStatement

import com.intellij.psi.PsiDeclarationStatement; //导入依赖的package包/类
@Override
public void visitDeclarationStatement(
  @NotNull PsiDeclarationStatement statement) {
  if (assignedFrom) {
    return;
  }
  super.visitDeclarationStatement(statement);
  final PsiElement[] declaredElements = statement.getDeclaredElements();
  for (PsiElement declaredElement : declaredElements) {
    if (declaredElement instanceof PsiVariable) {
      final PsiVariable declaredVariable =
        (PsiVariable)declaredElement;
      final PsiExpression initializer =
        declaredVariable.getInitializer();
      if (initializer != null &&
          VariableAccessUtils.mayEvaluateToVariable(initializer,
                                                    variable)) {
        assignedFrom = true;
        return;
      }
    }
  }
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:24,代码来源:VariableAssignedFromVisitor.java


示例5: extractDeclarations

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


示例6: getVariable

import com.intellij.psi.PsiDeclarationStatement; //导入依赖的package包/类
/**
 * ローカル変数取得 (宣言文で定義された変数)
 * @param declaration ルートノード
 * @return ローカル変数 (空要素の場合もあります)
 */
public static @Nullable PsiLocalVariable getVariable(PsiDeclarationStatement declaration) {
    PsiElement[] elements = declaration.getDeclaredElements();
    for (PsiElement element : elements) {
        if (element instanceof PsiLocalVariable) {
            PsiLocalVariable valiable = (PsiLocalVariable) element;
            return valiable;
        }
    }
    return null;
}
 
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:16,代码来源:ElementUtil.java


示例7: debugDeclarations

import com.intellij.psi.PsiDeclarationStatement; //导入依赖的package包/类
public static void debugDeclarations(String tag, PsiElement root, List<PsiDeclarationStatement> declarations) {
    System.out.println(tag + " :root=>>>>\n" + root.getText() + "\n<<<");
    for (PsiDeclarationStatement declaration : declarations) {
        System.out.println("declaration -> " + declaration.getText());
        debugVariable(declaration);
    }
    System.out.println();
}
 
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:9,代码来源:ElementUtil.java


示例8: debugVariable

import com.intellij.psi.PsiDeclarationStatement; //导入依赖的package包/类
public static void debugVariable(PsiDeclarationStatement declaration) {
    PsiLocalVariable variable = getVariable(declaration);
    debugVariable(variable);
    System.out.println();
}
 
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:6,代码来源:ElementUtil.java


示例9: visitDeclarationStatement

import com.intellij.psi.PsiDeclarationStatement; //导入依赖的package包/类
@Override
public void visitDeclarationStatement(PsiDeclarationStatement statement) {
    mVisitor.report("PsiDeclarationStatement", statement.getText(), statement);
    super.visitStatement(statement);
}
 
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:6,代码来源:PsiClassStructureDetector.java


示例10: visitClass

import com.intellij.psi.PsiDeclarationStatement; //导入依赖的package包/类
@Override
public void visitClass(@NotNull PsiClass aClass) {
  if (aClass.getParent() instanceof PsiDeclarationStatement) {
    registerClassError(aClass);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:LimitedScopeInnerClassInspectionBase.java


示例11: from

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


示例12: apply

import com.intellij.psi.PsiDeclarationStatement; //导入依赖的package包/类
@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException
{
	if(!(psiElement instanceof PsiMethod))
	{
		return;
	}
	PsiMethod method = (PsiMethod) psiElement;
	final PsiClass containingClass = method.getContainingClass();
	if(!shouldHaveBody(method))
	{
		return;
	}

	final PsiCodeBlock body = method.getBody();
	final Document doc = editor.getDocument();
	if(body != null)
	{
		// See IDEADEV-1093. This is quite hacky heuristic but it seem to be best we can do.
		String bodyText = body.getText();
		if(bodyText.startsWith("{"))
		{
			final PsiStatement[] statements = body.getStatements();
			if(statements.length > 0)
			{
				if(statements[0] instanceof PsiDeclarationStatement)
				{
					if(PsiTreeUtil.getDeepestLast(statements[0]) instanceof PsiErrorElement)
					{
						if(containingClass.getRBrace() == null)
						{
							doc.insertString(body.getTextRange().getStartOffset() + 1, "\n}");
						}
					}
				}
			}
		}
		return;
	}
	int endOffset = method.getThrowsList().getTextRange().getEndOffset();
	if(endOffset < doc.getTextLength() && doc.getCharsSequence().charAt(endOffset) == ';')
	{
		doc.deleteString(endOffset, endOffset + 1);
	}
	doc.insertString(endOffset, "{\n}");
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:47,代码来源:MissingMethodBodyFixer.java


示例13: getContextElement

import com.intellij.psi.PsiDeclarationStatement; //导入依赖的package包/类
@Nullable
public static PsiElement getContextElement(final StackFrameContext context, final SourcePosition position)
{
	if(LOG.isDebugEnabled())
	{
		final SourcePosition sourcePosition = getSourcePosition(context);
		LOG.assertTrue(Comparing.equal(sourcePosition, position));
	}

	return ReadAction.compute(() ->
	{
		final PsiElement element = getContextElement(position);

		if(element == null)
		{
			return null;
		}

		// further code is java specific, actually
		if(element.getLanguage().getAssociatedFileType() != DefaultCodeFragmentFactory.getInstance().getFileType())
		{
			return element;
		}

		final StackFrameProxyImpl frameProxy = (StackFrameProxyImpl) context.getFrameProxy();

		if(frameProxy == null)
		{
			return element;
		}

		try
		{
			List<LocalVariableProxyImpl> list = frameProxy.visibleVariables();

			PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(element.getProject()).getResolveHelper();
			StringBuilder buf = null;
			for(LocalVariableProxyImpl localVariable : list)
			{
				final String varName = localVariable.name();
				if(resolveHelper.resolveReferencedVariable(varName, element) == null)
				{
					if(buf == null)
					{
						buf = new StringBuilder("{");
					}
					buf.append(localVariable.getVariable().typeName()).append(" ").append(varName).append(";");
				}
			}
			if(buf == null)
			{
				return element;
			}

			buf.append('}');

			final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(element.getProject()).getElementFactory();
			final PsiCodeBlock codeBlockFromText = elementFactory.createCodeBlockFromText(buf.toString(), element);

			final PsiStatement[] statements = codeBlockFromText.getStatements();
			for(PsiStatement statement : statements)
			{
				if(statement instanceof PsiDeclarationStatement)
				{
					PsiDeclarationStatement declStatement = (PsiDeclarationStatement) statement;
					PsiElement[] declaredElements = declStatement.getDeclaredElements();
					for(PsiElement declaredElement : declaredElements)
					{
						declaredElement.putUserData(IS_JSP_IMPLICIT, Boolean.TRUE);
					}
				}
			}
			return codeBlockFromText;
		}
		catch(IncorrectOperationException | EvaluateException ignored)
		{
			return element;
		}
	});
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:81,代码来源:ContextUtil.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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