本文整理匯總了Java中com.intellij.psi.PsiMethod.getBody方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiMethod.getBody方法的具體用法?Java PsiMethod.getBody怎麽用?Java PsiMethod.getBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.psi.PsiMethod
的用法示例。
在下文中一共展示了PsiMethod.getBody方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: AnonymousClassMethodFilter
import com.intellij.psi.PsiMethod; //導入方法依賴的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;
}
示例2: calculateReturnPointCount
import com.intellij.psi.PsiMethod; //導入方法依賴的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
示例3: findOrCreateSetUpMethod
import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
@Override
protected PsiMethod findOrCreateSetUpMethod(PsiClass clazz) throws IncorrectOperationException {
LOG.assertTrue(clazz.getLanguage() == GroovyLanguage.INSTANCE);
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(clazz.getProject());
final PsiMethod patternMethod = createSetUpPatternMethod(factory);
final PsiClass baseClass = clazz.getSuperClass();
if (baseClass != null) {
final PsiMethod baseMethod = baseClass.findMethodBySignature(patternMethod, false);
if (baseMethod != null && baseMethod.hasModifierProperty(PsiModifier.PUBLIC)) {
PsiUtil.setModifierProperty(patternMethod, PsiModifier.PROTECTED, false);
PsiUtil.setModifierProperty(patternMethod, PsiModifier.PUBLIC, true);
}
}
PsiMethod inClass = clazz.findMethodBySignature(patternMethod, false);
if (inClass == null) {
PsiMethod testMethod = JUnitUtil.findFirstTestMethod(clazz);
if (testMethod != null) {
return (PsiMethod)clazz.addBefore(patternMethod, testMethod);
}
return (PsiMethod)clazz.add(patternMethod);
}
else if (inClass.getBody() == null) {
return (PsiMethod)inClass.replace(patternMethod);
}
return inClass;
}