private RefactoringStatus checkExpression() throws JavaModelException { RefactoringStatus result = new RefactoringStatus(); result.merge(checkExpressionBinding()); if (result.hasFatalError()) return result; checkAllStaticFinal(); IExpressionFragment selectedExpression = getSelectedExpression(); Expression associatedExpression = selectedExpression.getAssociatedExpression(); if (associatedExpression instanceof NullLiteral) result.merge( RefactoringStatus.createFatalErrorStatus( RefactoringCoreMessages.ExtractConstantRefactoring_null_literals)); else if (!ConstantChecks.isLoadTimeConstant(selectedExpression)) result.merge( RefactoringStatus.createFatalErrorStatus( RefactoringCoreMessages.ExtractConstantRefactoring_not_load_time_constant)); else if (associatedExpression instanceof SimpleName) { if (associatedExpression.getParent() instanceof QualifiedName && associatedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || associatedExpression.getParent() instanceof FieldAccess && associatedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY) return RefactoringStatus.createFatalErrorStatus( RefactoringCoreMessages.ExtractConstantRefactoring_select_expression); } return result; }
/** * If the passed node is a method invocation or class creation then return the return type of the * method based on what is the returned value assigned to. * * @param node * @return return type */ private String getReturnType(Expression node) { ASTNode parent = node.getParent(); if (parent instanceof VariableDeclarationFragment) { ASTNode grandParent = parent.getParent(); if (grandParent instanceof VariableDeclarationStatement) { Type typ = ((VariableDeclarationStatement) grandParent).getType(); return removeSpecialSymbols(getFullyQualifiedNameFor(typ.toString())); } } return null; }