Search in sources :

Example 1 with NotImplementedException

use of org.autorefactor.util.NotImplementedException in project AutoRefactor by JnRouvignac.

the class RemoveUnneededThisExpressionRefactoring method thisExpressionRefersToEnclosingType.

private static boolean thisExpressionRefersToEnclosingType(Name thisQualifierName, ASTNode node) {
    if (thisQualifierName == null) {
        return true;
    }
    final ASTNode enclosingType = getEnclosingType(node);
    if (enclosingType instanceof AnonymousClassDeclaration) {
        return false;
    }
    final AbstractTypeDeclaration ancestor = (AbstractTypeDeclaration) enclosingType;
    if (thisQualifierName instanceof SimpleName) {
        return isEqual((SimpleName) thisQualifierName, ancestor.getName());
    } else if (thisQualifierName instanceof QualifiedName) {
        final QualifiedName qn = (QualifiedName) thisQualifierName;
        return isEqual(qn.getName(), ancestor.getName()) && thisExpressionRefersToEnclosingType(qn.getQualifier(), ancestor);
    }
    throw new NotImplementedException(thisQualifierName);
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) NotImplementedException(org.autorefactor.util.NotImplementedException) ASTNode(org.eclipse.jdt.core.dom.ASTNode) AnonymousClassDeclaration(org.eclipse.jdt.core.dom.AnonymousClassDeclaration) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

Example 2 with NotImplementedException

use of org.autorefactor.util.NotImplementedException in project AutoRefactor by JnRouvignac.

the class RemoveUnneededThisExpressionRefactoring method isCallingMethodDeclaredInEnclosingType.

private boolean isCallingMethodDeclaredInEnclosingType(MethodInvocation node) {
    final ASTNode currentType = getEnclosingType(node);
    final IMethodBinding mb = node.resolveMethodBinding();
    if (currentType instanceof AnonymousClassDeclaration) {
        final AnonymousClassDeclaration c = (AnonymousClassDeclaration) currentType;
        final ITypeBinding enclosingTypeBinding = c.resolveBinding();
        return enclosingTypeBinding.isSubTypeCompatible(mb.getDeclaringClass());
    } else if (currentType instanceof AbstractTypeDeclaration) {
        final AbstractTypeDeclaration ed = (AbstractTypeDeclaration) currentType;
        final ITypeBinding enclosingTypeBinding = ed.resolveBinding();
        return enclosingTypeBinding.isSubTypeCompatible(mb.getDeclaringClass());
    }
    throw new NotImplementedException(node, node);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) NotImplementedException(org.autorefactor.util.NotImplementedException) ASTNode(org.eclipse.jdt.core.dom.ASTNode) AnonymousClassDeclaration(org.eclipse.jdt.core.dom.AnonymousClassDeclaration) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

Example 3 with NotImplementedException

use of org.autorefactor.util.NotImplementedException in project AutoRefactor by JnRouvignac.

the class PreferenceInitializer method initializeDefaultPreferences.

@Override
public void initializeDefaultPreferences() {
    // TODO initialize preferences from the JDT preferences like:
    // code style/cleanup/formatting
    final IPreferenceStore store = AutoRefactorPlugin.getDefault().getPreferenceStore();
    for (PreferenceConstants preference : PreferenceConstants.values()) {
        final String name = preference.getName();
        final Object defaultValue = preference.getDefaultValue();
        if (defaultValue instanceof Boolean) {
            store.setDefault(name, (Boolean) defaultValue);
        } else if (defaultValue instanceof Integer) {
            store.setDefault(name, (Integer) defaultValue);
        } else if (defaultValue instanceof Long) {
            store.setDefault(name, (Long) defaultValue);
        } else if (defaultValue instanceof Double) {
            store.setDefault(name, (Double) defaultValue);
        } else if (defaultValue instanceof Float) {
            store.setDefault(name, (Float) defaultValue);
        } else if (defaultValue instanceof String) {
            store.setDefault(name, (String) defaultValue);
        } else {
            throw new NotImplementedException(null, defaultValue);
        }
    }
    for (RefactoringRule refactoringRule : AllRefactoringRules.getAllRefactoringRules()) {
        store.setDefault(refactoringRule.getClass().getCanonicalName(), refactoringRule.isByDefault());
    }
}
Also used : PreferenceConstants(org.autorefactor.preferences.PreferenceConstants) RefactoringRule(org.autorefactor.refactoring.RefactoringRule) NotImplementedException(org.autorefactor.util.NotImplementedException) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 4 with NotImplementedException

use of org.autorefactor.util.NotImplementedException in project AutoRefactor by JnRouvignac.

the class AbstractUnitTestRefactoring method invokeFail.

private MethodInvocation invokeFail(final ASTNode node, final MethodInvocation originalMethod, final Expression failureMessage) {
    final ASTBuilder b = this.ctx.getASTBuilder();
    final List<Expression> args = arguments(originalMethod);
    if ((args.size() == 1) || (args.size() == 2)) {
        return invokeMethod(b, originalMethod, "fail", null, null, failureMessage);
    } else {
        throw new NotImplementedException(node);
    }
}
Also used : InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) Expression(org.eclipse.jdt.core.dom.Expression) PrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression) NotImplementedException(org.autorefactor.util.NotImplementedException) ASTBuilder(org.autorefactor.refactoring.ASTBuilder)

Example 5 with NotImplementedException

use of org.autorefactor.util.NotImplementedException in project AutoRefactor by JnRouvignac.

the class RemoveSemiColonRefactoring method visit.

private boolean visit(BodyDeclaration node) {
    final BodyDeclaration nextSibling = getNextSibling(node);
    final ASTNode parent = node.getParent();
    if (nextSibling != null) {
        return removeSuperfluousSemiColons(node, getEndPosition(node), nextSibling.getStartPosition());
    } else if (parent instanceof AbstractTypeDeclaration) {
        final AbstractTypeDeclaration typeDecl = (AbstractTypeDeclaration) parent;
        return removeSuperfluousSemiColons(node, getEndPosition(node), getEndPosition(typeDecl) - 1);
    } else if (parent instanceof AnonymousClassDeclaration) {
        final AnonymousClassDeclaration classDecl = (AnonymousClassDeclaration) parent;
        return removeSuperfluousSemiColons(node, getEndPosition(node), getEndPosition(classDecl) - 1);
    } else if (parent instanceof CompilationUnit) {
        final CompilationUnit cu = (CompilationUnit) parent;
        return removeSuperfluousSemiColons(node, getEndPosition(node), getEndPosition(cu) - 1);
    } else if (parent instanceof TypeDeclarationStatement) {
        return VISIT_SUBTREE;
    }
    throw new NotImplementedException(node, "for a parent of type " + (parent != null ? parent.getClass().getSimpleName() : null));
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) TypeDeclarationStatement(org.eclipse.jdt.core.dom.TypeDeclarationStatement) NotImplementedException(org.autorefactor.util.NotImplementedException) ASTNode(org.eclipse.jdt.core.dom.ASTNode) AnonymousClassDeclaration(org.eclipse.jdt.core.dom.AnonymousClassDeclaration) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

Aggregations

NotImplementedException (org.autorefactor.util.NotImplementedException)5 ASTNode (org.eclipse.jdt.core.dom.ASTNode)3 AbstractTypeDeclaration (org.eclipse.jdt.core.dom.AbstractTypeDeclaration)3 AnonymousClassDeclaration (org.eclipse.jdt.core.dom.AnonymousClassDeclaration)3 PreferenceConstants (org.autorefactor.preferences.PreferenceConstants)1 ASTBuilder (org.autorefactor.refactoring.ASTBuilder)1 RefactoringRule (org.autorefactor.refactoring.RefactoringRule)1 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 Expression (org.eclipse.jdt.core.dom.Expression)1 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)1 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)1 InfixExpression (org.eclipse.jdt.core.dom.InfixExpression)1 PrefixExpression (org.eclipse.jdt.core.dom.PrefixExpression)1 QualifiedName (org.eclipse.jdt.core.dom.QualifiedName)1 SimpleName (org.eclipse.jdt.core.dom.SimpleName)1 TypeDeclarationStatement (org.eclipse.jdt.core.dom.TypeDeclarationStatement)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1