本文整理汇总了Java中com.intellij.psi.PsiExpressionStatement类的典型用法代码示例。如果您正苦于以下问题:Java PsiExpressionStatement类的具体用法?Java PsiExpressionStatement怎么用?Java PsiExpressionStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PsiExpressionStatement类属于com.intellij.psi包,在下文中一共展示了PsiExpressionStatement类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: visitMethod
import com.intellij.psi.PsiExpressionStatement; //导入依赖的package包/类
@Override
public void visitMethod(JavaContext context, JavaElementVisitor visitor, PsiMethodCallExpression call, PsiMethod method) {
super.visitMethod(context, visitor, call, method);
if (isRxSubscribeableClass(method.getContainingClass()) && !PsiType.VOID.equals(method.getReturnType())) {
PsiElement element = LintUtils.skipParentheses(call.getParent());
if (element instanceof PsiExpressionStatement) {
String message;
if (isRx2(method.getContainingClass())) {
message = "No reference to the disposable is kept";
} else {
message = "No reference to the subscription is kept";
}
context.report(ISSUE, call, context.getLocation(call), message);
}
}
}
开发者ID:IlyaGulya,项目名称:rxlint,代码行数:17,代码来源:DanglingSubscriptionDetector.java
示例2: visitExpressionStatement
import com.intellij.psi.PsiExpressionStatement; //导入依赖的package包/类
@Override
public void visitExpressionStatement(@NotNull PsiExpressionStatement statement) {
super.visitExpressionStatement(statement);
final PsiExpression expression = statement.getExpression();
if (!(expression instanceof PsiNewExpression)) {
return;
}
final PsiNewExpression newExpression = (PsiNewExpression)expression;
final PsiExpression[] arrayDimensions = newExpression.getArrayDimensions();
if (arrayDimensions.length != 0) {
return;
}
if (newExpression.getArrayInitializer() != null) {
return;
}
registerNewExpressionError(newExpression);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:ResultOfObjectAllocationIgnoredInspection.java
示例3: findMethodCall
import com.intellij.psi.PsiExpressionStatement; //导入依赖的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
示例4: isChainingConstructor
import com.intellij.psi.PsiExpressionStatement; //导入依赖的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
示例5: invoke
import com.intellij.psi.PsiExpressionStatement; //导入依赖的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
示例6: replaceSimplifiableAssignment
import com.intellij.psi.PsiExpressionStatement; //导入依赖的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
示例7: replaceSimplifiableAssignmentNegated
import com.intellij.psi.PsiExpressionStatement; //导入依赖的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
示例8: match
import com.intellij.psi.PsiExpressionStatement; //导入依赖的package包/类
public boolean match(PsiElement patternNode, PsiElement matchedNode, MatchContext context) {
if (!super.match(patternNode,matchedNode,context)) {
return false;
}
return context.getMatcher().match(
((PsiExpressionStatement)patternNode).getExpression(),
matchedNode
);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:ExpressionHandler.java
示例9: inline
import com.intellij.psi.PsiExpressionStatement; //导入依赖的package包/类
@Override
protected void inline(Project project, PsiReferenceExpression methodExpression, PsiMethod method) {
final PsiElement statement = methodExpression.getParent().getParent();
if (statement instanceof PsiExpressionStatement) {
statement.delete();
} else {
super.inline(project, methodExpression, method);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:CallToSimpleGetterInClassInspection.java
示例10: visitAssignmentExpression
import com.intellij.psi.PsiExpressionStatement; //导入依赖的package包/类
@Override
public void visitAssignmentExpression(
@NotNull PsiAssignmentExpression expression) {
super.visitAssignmentExpression(expression);
final PsiElement parent = expression.getParent();
if (parent == null) {
return;
}
final PsiElement grandparent = parent.getParent();
if (parent instanceof PsiExpressionStatement ||
grandparent instanceof PsiExpressionListStatement) {
return;
}
registerError(expression);
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:16,代码来源:NestedAssignmentInspection.java
示例11: DeleteSideEffectsAwareFix
import com.intellij.psi.PsiExpressionStatement; //导入依赖的package包/类
public DeleteSideEffectsAwareFix(PsiExpressionStatement statement)
{
myPointer = SmartPointerManager.getInstance(statement.getProject()).createSmartPsiElementPointer(statement);
PsiExpression expression = statement.getExpression();
List<PsiExpression> sideEffects = SideEffectChecker.extractSideEffectExpressions(expression);
if(sideEffects.isEmpty())
{
myMessage = JavaQuickFixBundle.message("delete.element.fix.text");
}
else if(sideEffects.size() == 1 && sideEffects.get(0) == PsiUtil.skipParenthesizedExprDown(expression))
{
// "Remove unnecessary parentheses" action is already present which will do the same
myMessage = "";
}
else
{
PsiStatement[] statements = StatementExtractor.generateStatements(sideEffects, expression);
if(statements.length == 1)
{
if(statements[0] instanceof PsiIfStatement)
{
myMessage = JavaQuickFixBundle.message("extract.side.effects.convert.to.if");
}
else
{
myMessage = JavaQuickFixBundle.message("extract.side.effects.single");
}
}
else
{
myMessage = JavaQuickFixBundle.message("extract.side.effects.multiple");
}
}
}
开发者ID:consulo,项目名称:consulo-java,代码行数:35,代码来源:DeleteSideEffectsAwareFix.java
示例12: replaceSimplifiableImplicitAssignment
import com.intellij.psi.PsiExpressionStatement; //导入依赖的package包/类
private static void replaceSimplifiableImplicitAssignment(
PsiIfStatement statement) throws IncorrectOperationException {
final PsiElement prevStatement =
PsiTreeUtil.skipSiblingsBackward(statement,
PsiWhiteSpace.class);
if (prevStatement == null) {
return;
}
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 + ';');
deleteElement(prevStatement);
}
开发者ID:consulo,项目名称:consulo-java,代码行数:29,代码来源:TrivialIfInspection.java
示例13: isSimplifiableAssignment
import com.intellij.psi.PsiExpressionStatement; //导入依赖的package包/类
public static boolean isSimplifiableAssignment(PsiIfStatement ifStatement) {
PsiStatement thenBranch = ifStatement.getThenBranch();
thenBranch = ControlFlowUtils.stripBraces(thenBranch);
PsiStatement elseBranch = ifStatement.getElseBranch();
elseBranch = ControlFlowUtils.stripBraces(elseBranch);
if (ConditionalUtils.isAssignment(thenBranch, PsiKeyword.TRUE) &&
ConditionalUtils.isAssignment(elseBranch, PsiKeyword.FALSE)) {
final PsiExpressionStatement thenExpressionStatement =
(PsiExpressionStatement)thenBranch;
final PsiAssignmentExpression thenExpression =
(PsiAssignmentExpression)
thenExpressionStatement.getExpression();
final PsiExpressionStatement elseExpressionStatement =
(PsiExpressionStatement)elseBranch;
final PsiAssignmentExpression elseExpression =
(PsiAssignmentExpression)
elseExpressionStatement.getExpression();
final IElementType thenTokenType = thenExpression.getOperationTokenType();
if (!thenTokenType.equals(elseExpression.getOperationTokenType())) {
return false;
}
final PsiExpression thenLhs = thenExpression.getLExpression();
final PsiExpression elseLhs = elseExpression.getLExpression();
return EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(thenLhs,
elseLhs);
}
else {
return false;
}
}
开发者ID:consulo,项目名称:consulo-java,代码行数:31,代码来源:TrivialIfInspection.java
示例14: isSimplifiableAssignmentNegated
import com.intellij.psi.PsiExpressionStatement; //导入依赖的package包/类
public static boolean isSimplifiableAssignmentNegated(
PsiIfStatement ifStatement) {
PsiStatement thenBranch = ifStatement.getThenBranch();
thenBranch = ControlFlowUtils.stripBraces(thenBranch);
PsiStatement elseBranch = ifStatement.getElseBranch();
elseBranch = ControlFlowUtils.stripBraces(elseBranch);
if (ConditionalUtils.isAssignment(thenBranch, PsiKeyword.FALSE) &&
ConditionalUtils.isAssignment(elseBranch, PsiKeyword.TRUE)) {
final PsiExpressionStatement thenExpressionStatement =
(PsiExpressionStatement)thenBranch;
final PsiAssignmentExpression thenExpression =
(PsiAssignmentExpression)
thenExpressionStatement.getExpression();
final PsiExpressionStatement elseExpressionStatement =
(PsiExpressionStatement)elseBranch;
final PsiAssignmentExpression elseExpression =
(PsiAssignmentExpression)
elseExpressionStatement.getExpression();
final IElementType thenTokenType = thenExpression.getOperationTokenType();
if (!thenTokenType.equals(elseExpression.getOperationTokenType())) {
return false;
}
final PsiExpression thenLhs = thenExpression.getLExpression();
final PsiExpression elseLhs = elseExpression.getLExpression();
return EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(thenLhs,
elseLhs);
}
else {
return false;
}
}
开发者ID:consulo,项目名称:consulo-java,代码行数:32,代码来源:TrivialIfInspection.java
示例15: isSimplifiableImplicitAssignment
import com.intellij.psi.PsiExpressionStatement; //导入依赖的package包/类
public static boolean isSimplifiableImplicitAssignment(
PsiIfStatement ifStatement) {
if (ifStatement.getElseBranch() != null) {
return false;
}
PsiStatement thenBranch = ifStatement.getThenBranch();
thenBranch = ControlFlowUtils.stripBraces(thenBranch);
final PsiElement nextStatement =
PsiTreeUtil.skipSiblingsBackward(ifStatement,
PsiWhiteSpace.class);
if (!(nextStatement instanceof PsiStatement)) {
return false;
}
PsiStatement elseBranch = (PsiStatement)nextStatement;
elseBranch = ControlFlowUtils.stripBraces(elseBranch);
if (ConditionalUtils.isAssignment(thenBranch, PsiKeyword.TRUE) &&
ConditionalUtils.isAssignment(elseBranch, PsiKeyword.FALSE)) {
final PsiExpressionStatement thenExpressionStatement =
(PsiExpressionStatement)thenBranch;
final PsiAssignmentExpression thenExpression =
(PsiAssignmentExpression)
thenExpressionStatement.getExpression();
final PsiExpressionStatement elseExpressionStatement =
(PsiExpressionStatement)elseBranch;
final PsiAssignmentExpression elseExpression =
(PsiAssignmentExpression)
elseExpressionStatement.getExpression();
final IElementType thenTokenType = thenExpression.getOperationTokenType();
if (!thenTokenType.equals(elseExpression.getOperationTokenType())) {
return false;
}
final PsiExpression thenLhs = thenExpression.getLExpression();
final PsiExpression elseLhs = elseExpression.getLExpression();
return EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(thenLhs,
elseLhs);
}
else {
return false;
}
}
开发者ID:consulo,项目名称:consulo-java,代码行数:41,代码来源:TrivialIfInspection.java
示例16: isSimplifiableImplicitAssignmentNegated
import com.intellij.psi.PsiExpressionStatement; //导入依赖的package包/类
public static boolean isSimplifiableImplicitAssignmentNegated(
PsiIfStatement ifStatement) {
if (ifStatement.getElseBranch() != null) {
return false;
}
PsiStatement thenBranch = ifStatement.getThenBranch();
thenBranch = ControlFlowUtils.stripBraces(thenBranch);
final PsiElement nextStatement =
PsiTreeUtil.skipSiblingsBackward(ifStatement,
PsiWhiteSpace.class);
if (!(nextStatement instanceof PsiStatement)) {
return false;
}
PsiStatement elseBranch = (PsiStatement)nextStatement;
elseBranch = ControlFlowUtils.stripBraces(elseBranch);
if (ConditionalUtils.isAssignment(thenBranch, PsiKeyword.FALSE) &&
ConditionalUtils.isAssignment(elseBranch, PsiKeyword.TRUE)) {
final PsiExpressionStatement thenExpressionStatement =
(PsiExpressionStatement)thenBranch;
final PsiAssignmentExpression thenExpression =
(PsiAssignmentExpression)
thenExpressionStatement.getExpression();
final PsiExpressionStatement elseExpressionStatement =
(PsiExpressionStatement)elseBranch;
final PsiAssignmentExpression elseExpression =
(PsiAssignmentExpression)
elseExpressionStatement.getExpression();
final IElementType thenTokenType = thenExpression.getOperationTokenType();
if (!thenTokenType.equals(elseExpression.getOperationTokenType())) {
return false;
}
final PsiExpression thenLhs = thenExpression.getLExpression();
final PsiExpression elseLhs = elseExpression.getLExpression();
return EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(thenLhs,
elseLhs);
}
else {
return false;
}
}
开发者ID:consulo,项目名称:consulo-java,代码行数:41,代码来源:TrivialIfInspection.java
示例17: visitExpressionStatement
import com.intellij.psi.PsiExpressionStatement; //导入依赖的package包/类
@Override
public void visitExpressionStatement(PsiExpressionStatement statement) {
mVisitor.report("PsiExpressionStatement", statement.getText(), statement);
super.visitStatement(statement);
}
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:6,代码来源:PsiClassStructureDetector.java
示例18: sideEffectAwareRemove
import com.intellij.psi.PsiExpressionStatement; //导入依赖的package包/类
protected void sideEffectAwareRemove(Project project, PsiElement psiInitializer, PsiElement elementToDelete, PsiVariable variable)
{
if(!FileModificationService.getInstance().prepareFileForWrite(elementToDelete.getContainingFile()))
{
return;
}
final PsiElement declaration = variable.getParent();
final List<PsiElement> sideEffects = new ArrayList<PsiElement>();
boolean hasSideEffects = RemoveUnusedVariableUtil.checkSideEffects(psiInitializer, variable, sideEffects);
int res = RemoveUnusedVariableUtil.DELETE_ALL;
if(hasSideEffects)
{
hasSideEffects = PsiUtil.isStatement(psiInitializer);
res = RemoveUnusedVariableFix.showSideEffectsWarning(sideEffects, variable, FileEditorManager.getInstance(project).getSelectedTextEditor
(), hasSideEffects, sideEffects.get(0).getText(), variable.getTypeElement().getText() +
" " +
variable.getName() +
";<br>" +
PsiExpressionTrimRenderer.render((PsiExpression) psiInitializer));
}
try
{
if(res == RemoveUnusedVariableUtil.DELETE_ALL)
{
elementToDelete.delete();
}
else if(res == RemoveUnusedVariableUtil.MAKE_STATEMENT)
{
final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
final PsiStatement statementFromText = factory.createStatementFromText(psiInitializer.getText() + ";", null);
final PsiElement parent = elementToDelete.getParent();
if(parent instanceof PsiExpressionStatement)
{
parent.replace(statementFromText);
}
else
{
declaration.getParent().addAfter(statementFromText, declaration);
elementToDelete.delete();
}
}
}
catch(IncorrectOperationException e)
{
LOG.error(e);
}
}
开发者ID:consulo,项目名称:consulo-java,代码行数:49,代码来源:RemoveInitializerFix.java
注:本文中的com.intellij.psi.PsiExpressionStatement类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论