use of org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment in project che by eclipse.
the class ExtractConstantRefactoring method getExcludedVariableNames.
private String[] getExcludedVariableNames() {
if (fExcludedVariableNames == null) {
try {
IExpressionFragment expr = getSelectedExpression();
Collection<String> takenNames = new ScopeAnalyzer(fCuRewrite.getRoot()).getUsedVariableNames(expr.getStartPosition(), expr.getLength());
fExcludedVariableNames = takenNames.toArray(new String[takenNames.size()]);
} catch (JavaModelException e) {
fExcludedVariableNames = new String[0];
}
}
return fExcludedVariableNames;
}
use of org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment in project che by eclipse.
the class ExtractTempRefactoring method isLiteralNodeSelected.
private boolean isLiteralNodeSelected() throws JavaModelException {
IExpressionFragment fragment = getSelectedExpression();
if (fragment == null)
return false;
Expression expression = fragment.getAssociatedExpression();
if (expression == null)
return false;
switch(expression.getNodeType()) {
case ASTNode.BOOLEAN_LITERAL:
case ASTNode.CHARACTER_LITERAL:
case ASTNode.NULL_LITERAL:
case ASTNode.NUMBER_LITERAL:
return true;
default:
return false;
}
}
use of org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment in project che by eclipse.
the class InlineConstantRefactoring method checkInitializer.
private RefactoringStatus checkInitializer() {
Expression initializer = getInitializer();
if (initializer == null)
return RefactoringStatus.createStatus(RefactoringStatus.FATAL, RefactoringCoreMessages.InlineConstantRefactoring_blank_finals, null, Corext.getPluginId(), RefactoringStatusCodes.CANNOT_INLINE_BLANK_FINAL, null);
fInitializerAllStaticFinal = ConstantChecks.isStaticFinalConstant((IExpressionFragment) ASTFragmentFactory.createFragmentForFullSubtree(initializer));
fInitializerChecked = true;
return new RefactoringStatus();
}
use of org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment in project che by eclipse.
the class ExtractTempRefactoring method checkSelection.
private RefactoringStatus checkSelection(IProgressMonitor pm) throws JavaModelException {
try {
//$NON-NLS-1$
pm.beginTask("", 8);
IExpressionFragment selectedExpression = getSelectedExpression();
if (selectedExpression == null) {
String message = RefactoringCoreMessages.ExtractTempRefactoring_select_expression;
return CodeRefactoringUtil.checkMethodSyntaxErrors(fSelectionStart, fSelectionLength, fCompilationUnitNode, message);
}
pm.worked(1);
if (isUsedInExplicitConstructorCall())
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_explicit_constructor);
pm.worked(1);
ASTNode associatedNode = selectedExpression.getAssociatedNode();
if (getEnclosingBodyNode() == null || ASTNodes.getParent(associatedNode, Annotation.class) != null)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_expr_in_method_or_initializer);
pm.worked(1);
if (associatedNode instanceof Name && associatedNode.getParent() instanceof ClassInstanceCreation && associatedNode.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_name_in_new);
pm.worked(1);
RefactoringStatus result = new RefactoringStatus();
result.merge(checkExpression());
if (result.hasFatalError())
return result;
pm.worked(1);
result.merge(checkExpressionFragmentIsRValue());
if (result.hasFatalError())
return result;
pm.worked(1);
if (isUsedInForInitializerOrUpdater(getSelectedExpression().getAssociatedExpression()))
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_for_initializer_updater);
pm.worked(1);
if (isReferringToLocalVariableFromFor(getSelectedExpression().getAssociatedExpression()))
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_refers_to_for_variable);
pm.worked(1);
return result;
} finally {
pm.done();
}
}
use of org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment in project che by eclipse.
the class ExtractConstantRefactoring method getConstantType.
private Type getConstantType() throws JavaModelException {
if (fConstantTypeCache == null) {
IExpressionFragment fragment = getSelectedExpression();
ITypeBinding typeBinding = guessBindingForReference(fragment.getAssociatedExpression());
AST ast = fCuRewrite.getAST();
typeBinding = Bindings.normalizeForDeclarationUse(typeBinding, ast);
ImportRewrite importRewrite = fCuRewrite.getImportRewrite();
ImportRewriteContext context = new ContextSensitiveImportRewriteContext(fCuRewrite.getRoot(), fSelectionStart, importRewrite);
fConstantTypeCache = importRewrite.addImport(typeBinding, ast, context);
}
return fConstantTypeCache;
}
Aggregations