本文整理汇总了Java中com.intellij.psi.PsiCodeBlock类的典型用法代码示例。如果您正苦于以下问题:Java PsiCodeBlock类的具体用法?Java PsiCodeBlock怎么用?Java PsiCodeBlock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PsiCodeBlock类属于com.intellij.psi包,在下文中一共展示了PsiCodeBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkNestedStringFormat
import com.intellij.psi.PsiCodeBlock; //导入依赖的package包/类
/**
* Reports issue if this call is inside PLog.x().
* Calling this method assumes actual calling method is 'String#format'.
*
* @see #ISSUE_NESTED_FORMAT
*/
private static void checkNestedStringFormat(JavaContext context, PsiMethodCallExpression call) {
PsiElement current = call;
while (true) {
current = LintUtils.skipParentheses(current.getParent());
if (current == null || current instanceof PsiCodeBlock) {
// Reached AST root or code block node; String.format not inside PLog.X(..).
return;
}
if (current instanceof PsiMethodCallExpression) {
PsiMethodCallExpression expression = (PsiMethodCallExpression) current;
if (Pattern.matches("org\\.mym\\.plog\\.PLog\\.(v|d|i|w|e)",
expression.getMethodExpression().getQualifiedName())) {
sHelper.reportIssue(context, ISSUE_NESTED_FORMAT, call);
return;
}
}
}
}
示例2: LambdaMethodFilter
import com.intellij.psi.PsiCodeBlock; //导入依赖的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;
}
示例3: AnonymousClassMethodFilter
import com.intellij.psi.PsiCodeBlock; //导入依赖的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;
}
示例4: getFinallyStatements
import com.intellij.psi.PsiCodeBlock; //导入依赖的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;
}
示例5: visitTryStatement
import com.intellij.psi.PsiCodeBlock; //导入依赖的package包/类
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
super.visitTryStatement(statement);
final PsiTryStatement parentTry = PsiTreeUtil.getParentOfType(statement, PsiTryStatement.class);
if (parentTry == null) {
return;
}
final PsiCodeBlock tryBlock = parentTry.getTryBlock();
if (tryBlock == null) {
return;
}
if (!PsiTreeUtil.isAncestor(tryBlock, statement, true)) {
return;
}
if (NestedSynchronizedStatementInspection.isNestedStatement(statement, PsiTryStatement.class)) {
registerStatementError(statement);
}
}
示例6: visitTryStatement
import com.intellij.psi.PsiCodeBlock; //导入依赖的package包/类
@Override
public void visitTryStatement(@NotNull PsiTryStatement statement) {
super.visitTryStatement(statement);
final PsiCodeBlock finallyBlock = statement.getFinallyBlock();
if (finallyBlock == null) {
return;
}
if (ControlFlowUtils.codeBlockMayCompleteNormally(finallyBlock)) {
return;
}
final PsiElement[] children = statement.getChildren();
for (final PsiElement child : children) {
final String childText = child.getText();
if (PsiKeyword.FINALLY.equals(childText)) {
registerError(child);
return;
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:FinallyBlockCannotCompleteNormallyInspection.java
示例7: calculateReturnPointCount
import com.intellij.psi.PsiCodeBlock; //导入依赖的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
示例8: readMethod
import com.intellij.psi.PsiCodeBlock; //导入依赖的package包/类
@Override
public void readMethod(PsiCodeBlock methodBody, PsiElementFactory factory, PsiField field) {
if (null == methodBody) {
return;
}
String fieldName = field.getName();
String parameterType = ((PsiClassReferenceType) field.getType()).getParameters()[0].getPresentableText();
// // phones = new ArrayList<>();
// // in.readTypedList(phones, Phone.CREATOR);
// methodBody.add(factory.createStatementFromText(fieldName + " = new ArrayList<" + parameterType + ">();", null));
// methodBody.add(factory.createStatementFromText("in.readTypedList(" + fieldName + ", " + parameterType + ".CREATOR);", null));
// phones = in.createTypedArrayList(Phone.CREATOR);
methodBody.add(factory.createStatementFromText(fieldName + " = in.createTypedArrayList(" + parameterType + ".CREATOR);", null));
}
示例9: visitSynchronizedStatement
import com.intellij.psi.PsiCodeBlock; //导入依赖的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);
}
示例10: createCodeBlock
import com.intellij.psi.PsiCodeBlock; //导入依赖的package包/类
@NotNull
private PsiCodeBlock createCodeBlock(@NotNull PsiField psiField, @NotNull PsiClass psiClass, PsiType returnType, boolean isStatic, PsiParameter methodParameter) {
final String blockText;
if (isShouldGenerateFullBodyBlock()) {
final String thisOrClass = isStatic ? psiClass.getName() : "this";
blockText = String.format("%s.%s = %s; ", thisOrClass, psiField.getName(), methodParameter.getName());
} else {
blockText = "";
}
String codeBlockText = blockText;
if (!isStatic && !PsiType.VOID.equals(returnType)) {
codeBlockText += "return this;";
}
return PsiMethodUtil.createCodeBlockFromText(codeBlockText, psiClass);
}
示例11: createBuildMethodCodeBlock
import com.intellij.psi.PsiCodeBlock; //导入依赖的package包/类
@NotNull
private PsiCodeBlock createBuildMethodCodeBlock(@Nullable PsiMethod psiMethod, @NotNull PsiClass psiClass, @NotNull PsiType buildMethodReturnType,
@NotNull String buildMethodPrepare, @NotNull String buildMethodParameters) {
final String blockText;
if (isShouldGenerateFullBodyBlock()) {
final String codeBlockFormat, callExpressionText;
if (null == psiMethod || psiMethod.isConstructor()) {
codeBlockFormat = "%s\n return new %s(%s);";
callExpressionText = buildMethodReturnType.getPresentableText();
} else {
if (PsiType.VOID.equals(buildMethodReturnType)) {
codeBlockFormat = "%s\n %s(%s);";
} else {
codeBlockFormat = "%s\n return %s(%s);";
}
callExpressionText = calculateCallExpressionForMethod(psiMethod, psiClass);
}
blockText = String.format(codeBlockFormat, buildMethodPrepare, callExpressionText, buildMethodParameters);
} else {
blockText = "return " + PsiTypeUtil.getReturnValueOfType(buildMethodReturnType) + ";";
}
return PsiMethodUtil.createCodeBlockFromText(blockText, psiClass);
}
示例12: isChainingConstructor
import com.intellij.psi.PsiCodeBlock; //导入依赖的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;
}
示例13: generateGetters
import com.intellij.psi.PsiCodeBlock; //导入依赖的package包/类
@Override
public PsiMethod[] generateGetters(PsiField field) {
final Project project = field.getProject();
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
final PsiMethod getter = PropertyUtil.generateGetterPrototype(field);
final PsiType wrappedType = JavaFxPsiUtil.getWrappedPropertyType(field, project, JavaFxCommonClassNames.ourReadOnlyMap);
final PsiTypeElement returnTypeElement = getter.getReturnTypeElement();
LOG.assertTrue(returnTypeElement != null);
returnTypeElement.replace(factory.createTypeElement(wrappedType));
final PsiCodeBlock getterBody = getter.getBody();
LOG.assertTrue(getterBody != null);
getterBody.getStatements()[0].replace(factory.createStatementFromText("return " + field.getName() + ".get();", field));
final PsiMethod propertyGetter = PropertyUtil.generateGetterPrototype(field);
propertyGetter.setName(JavaCodeStyleManager.getInstance(project).variableNameToPropertyName(field.getName(), VariableKind.FIELD) + "Property");
return new PsiMethod[] {getter, propertyGetter};
}
示例14: generateSetters
import com.intellij.psi.PsiCodeBlock; //导入依赖的package包/类
@Override
public PsiMethod[] generateSetters(PsiField field) {
final PsiMethod setter = PropertyUtil.generateSetterPrototype(field);
final Project project = field.getProject();
final PsiType wrappedType = JavaFxPsiUtil.getWrappedPropertyType(field, project, JavaFxCommonClassNames.ourWritableMap);
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
final PsiTypeElement newTypeElement = elementFactory.createTypeElement(wrappedType);
final PsiParameter[] parameters = setter.getParameterList().getParameters();
LOG.assertTrue(parameters.length == 1);
final PsiParameter parameter = parameters[0];
final PsiTypeElement typeElement = parameter.getTypeElement();
LOG.assertTrue(typeElement != null);
typeElement.replace(newTypeElement);
final PsiCodeBlock body = setter.getBody();
LOG.assertTrue(body != null);
body.getStatements()[0].replace(elementFactory.createStatementFromText("this." + field.getName() + ".set(" + parameter.getName() + ");", field));
return new PsiMethod[] {setter};
}
示例15: toContracts
import com.intellij.psi.PsiCodeBlock; //导入依赖的package包/类
@NotNull
@Override
public List<StandardMethodContract> toContracts(PsiMethod method, Supplier<PsiCodeBlock> body)
{
PsiExpression expression = call.restoreExpression(body.get());
if(!(expression instanceof PsiMethodCallExpression))
{
return Collections.emptyList();
}
PsiMethod target = ((PsiMethodCallExpression) expression).resolveMethod();
if(target != null && NullableNotNullManager.isNotNull(target))
{
return ContractInferenceInterpreter.toContracts(ContainerUtil.map(states, it -> it.toArray(new MethodContract.ValueConstraint[it.size()])), MethodContract.ValueConstraint.NOT_NULL_VALUE);
}
return Collections.emptyList();
}