Search in sources :

Example 56 with RefactoringStatus

use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.

the class ConvertAnonymousToNestedRefactoring method checkInitialConditions.

@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
    RefactoringStatus result = Checks.validateModifiesFiles(ResourceUtil.getFiles(new ICompilationUnit[] { fCu }), getValidationContext());
    if (result.hasFatalError())
        return result;
    initAST(pm);
    if (fAnonymousInnerClassNode == null)
        return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_place_caret);
    if (!fSelfInitializing)
        initializeDefaults();
    if (getSuperConstructorBinding() == null)
        return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_compile_errors);
    if (getSuperTypeBinding().isLocal())
        return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_extends_local_class);
    return new RefactoringStatus();
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Example 57 with RefactoringStatus

use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.

the class ExtractConstantRefactoring method checkExpression.

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;
}
Also used : IExpressionFragment(org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment) Expression(org.eclipse.jdt.core.dom.Expression) SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) FieldAccess(org.eclipse.jdt.core.dom.FieldAccess) NullLiteral(org.eclipse.jdt.core.dom.NullLiteral)

Example 58 with RefactoringStatus

use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.

the class ExtractConstantRefactoring method checkSelection.

private RefactoringStatus checkSelection(IProgressMonitor pm) throws JavaModelException {
    try {
        //$NON-NLS-1$
        pm.beginTask("", 2);
        IExpressionFragment selectedExpression = getSelectedExpression();
        if (selectedExpression == null) {
            String message = RefactoringCoreMessages.ExtractConstantRefactoring_select_expression;
            return CodeRefactoringUtil.checkMethodSyntaxErrors(fSelectionStart, fSelectionLength, fCuRewrite.getRoot(), message);
        }
        pm.worked(1);
        RefactoringStatus result = new RefactoringStatus();
        result.merge(checkExpression());
        if (result.hasFatalError())
            return result;
        pm.worked(1);
        return result;
    } finally {
        pm.done();
    }
}
Also used : IExpressionFragment(org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Example 59 with RefactoringStatus

use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.

the class ExtractConstantRefactoring method checkFinalConditions.

@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
    pm.beginTask(RefactoringCoreMessages.ExtractConstantRefactoring_checking_preconditions, 2);
    try {
        RefactoringStatus result = new RefactoringStatus();
        createConstantDeclaration();
        replaceExpressionsWithConstant();
        fChange = fCuRewrite.createChange(RefactoringCoreMessages.ExtractConstantRefactoring_change_name, true, new SubProgressMonitor(pm, 1));
        if (fCheckResultForCompileProblems) {
            checkSource(new SubProgressMonitor(pm, 1), result);
        }
        return result;
    } finally {
        fConstantTypeCache = null;
        fCuRewrite.clearASTAndImportRewrites();
        pm.done();
    }
}
Also used : RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 60 with RefactoringStatus

use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.

the class TypeContextChecker method checkParameterTypeSyntax.

public static RefactoringStatus checkParameterTypeSyntax(String type, IJavaProject project) {
    String newTypeName = ParameterInfo.stripEllipsis(type.trim()).trim();
    String typeLabel = BasicElementLabels.getJavaElementName(type);
    if ("".equals(newTypeName.trim())) {
        //$NON-NLS-1$
        String msg = Messages.format(RefactoringCoreMessages.TypeContextChecker_parameter_type, typeLabel);
        return RefactoringStatus.createFatalErrorStatus(msg);
    }
    if (ParameterInfo.isVarargs(type) && !JavaModelUtil.is50OrHigher(project)) {
        String msg = Messages.format(RefactoringCoreMessages.TypeContextChecker_no_vararg_below_50, typeLabel);
        return RefactoringStatus.createFatalErrorStatus(msg);
    }
    List<String> problemsCollector = new ArrayList<String>(0);
    Type parsedType = parseType(newTypeName, project, problemsCollector);
    boolean valid = parsedType != null;
    if (valid && parsedType instanceof PrimitiveType)
        valid = !PrimitiveType.VOID.equals(((PrimitiveType) parsedType).getPrimitiveTypeCode());
    if (!valid) {
        String msg = Messages.format(RefactoringCoreMessages.TypeContextChecker_invalid_type_name, BasicElementLabels.getJavaElementName(newTypeName));
        return RefactoringStatus.createFatalErrorStatus(msg);
    }
    if (problemsCollector.size() == 0)
        return null;
    RefactoringStatus result = new RefactoringStatus();
    for (Iterator<String> iter = problemsCollector.iterator(); iter.hasNext(); ) {
        String msg = Messages.format(RefactoringCoreMessages.TypeContextChecker_invalid_type_syntax, new String[] { BasicElementLabels.getJavaElementName(newTypeName), BasicElementLabels.getJavaElementName(iter.next()) });
        result.addError(msg);
    }
    return result;
}
Also used : NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType) IType(org.eclipse.jdt.core.IType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) Type(org.eclipse.jdt.core.dom.Type) QualifiedType(org.eclipse.jdt.core.dom.QualifiedType) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType)

Aggregations

RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)251 IType (org.eclipse.jdt.core.IType)62 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)53 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)30 IMethod (org.eclipse.jdt.core.IMethod)29 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)28 IJavaElement (org.eclipse.jdt.core.IJavaElement)28 Test (org.junit.Test)26 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)24 ArrayList (java.util.ArrayList)23 BaseTest (org.eclipse.che.plugin.java.server.che.BaseTest)21 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)19 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)18 IFile (org.eclipse.core.resources.IFile)16 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)16 ASTNode (org.eclipse.jdt.core.dom.ASTNode)16 CoreException (org.eclipse.core.runtime.CoreException)15 IField (org.eclipse.jdt.core.IField)15 IStatus (org.eclipse.core.runtime.IStatus)14 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)13