Search in sources :

Example 86 with SingleVariableDeclaration

use of org.eclipse.jdt.core.dom.SingleVariableDeclaration in project che by eclipse.

the class InferTypeArgumentsConstraintCreator method visit.

@Override
public boolean visit(CatchClause node) {
    SingleVariableDeclaration exception = node.getException();
    IVariableBinding variableBinding = exception.resolveBinding();
    VariableVariable2 cv = fTCModel.makeDeclaredVariableVariable(variableBinding, fCU);
    setConstraintVariable(exception, cv);
    return true;
}
Also used : SingleVariableDeclaration(org.eclipse.jdt.core.dom.SingleVariableDeclaration) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) VariableVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.VariableVariable2)

Example 87 with SingleVariableDeclaration

use of org.eclipse.jdt.core.dom.SingleVariableDeclaration in project che by eclipse.

the class SourceAnalyzer method initialize.

public void initialize() {
    Block body = fDeclaration.getBody();
    // first collect the static imports. This is necessary to not mark
    // static imported fields and methods as implicit visible.
    fTypesToImport = new ArrayList<SimpleName>();
    fStaticsToImport = new ArrayList<SimpleName>();
    ImportReferencesCollector.collect(body, fTypeRoot.getJavaProject(), null, fTypesToImport, fStaticsToImport);
    // Now collect implicit references and name references
    body.accept(new UpdateCollector());
    int numberOfLocals = LocalVariableIndex.perform(fDeclaration);
    FlowContext context = new FlowContext(0, numberOfLocals + 1);
    context.setConsiderAccessMode(true);
    context.setComputeMode(FlowContext.MERGE);
    InOutFlowAnalyzer flowAnalyzer = new InOutFlowAnalyzer(context);
    FlowInfo info = flowAnalyzer.perform(getStatements());
    for (Iterator<SingleVariableDeclaration> iter = fDeclaration.parameters().iterator(); iter.hasNext(); ) {
        SingleVariableDeclaration element = iter.next();
        IVariableBinding binding = element.resolveBinding();
        ParameterData data = (ParameterData) element.getProperty(ParameterData.PROPERTY);
        data.setAccessMode(info.getAccessMode(context, binding));
    }
}
Also used : FlowInfo(org.eclipse.jdt.internal.corext.refactoring.code.flow.FlowInfo) SingleVariableDeclaration(org.eclipse.jdt.core.dom.SingleVariableDeclaration) SimpleName(org.eclipse.jdt.core.dom.SimpleName) Block(org.eclipse.jdt.core.dom.Block) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) FlowContext(org.eclipse.jdt.internal.corext.refactoring.code.flow.FlowContext) InOutFlowAnalyzer(org.eclipse.jdt.internal.corext.refactoring.code.flow.InOutFlowAnalyzer)

Example 88 with SingleVariableDeclaration

use of org.eclipse.jdt.core.dom.SingleVariableDeclaration in project che by eclipse.

the class FlowContext method isExceptionCaught.

boolean isExceptionCaught(ITypeBinding excpetionType) {
    for (Iterator<List<CatchClause>> exceptions = fExceptionStack.iterator(); exceptions.hasNext(); ) {
        for (Iterator<CatchClause> catchClauses = exceptions.next().iterator(); catchClauses.hasNext(); ) {
            SingleVariableDeclaration caughtException = catchClauses.next().getException();
            IVariableBinding binding = caughtException.resolveBinding();
            if (binding == null)
                continue;
            ITypeBinding caughtype = binding.getType();
            while (caughtype != null) {
                if (caughtype == excpetionType)
                    return true;
                caughtype = caughtype.getSuperclass();
            }
        }
    }
    return false;
}
Also used : SingleVariableDeclaration(org.eclipse.jdt.core.dom.SingleVariableDeclaration) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) List(java.util.List) ArrayList(java.util.ArrayList) CatchClause(org.eclipse.jdt.core.dom.CatchClause) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding)

Example 89 with SingleVariableDeclaration

use of org.eclipse.jdt.core.dom.SingleVariableDeclaration in project che by eclipse.

the class DelegateMethodCreator method createArguments.

@SuppressWarnings("unchecked")
private void createArguments(final MethodDeclaration declaration, final List<? extends ASTNode> arguments, boolean methodInvocation) {
    Assert.isNotNull(declaration);
    Assert.isNotNull(arguments);
    SingleVariableDeclaration variable = null;
    final int size = declaration.parameters().size();
    for (int index = 0; index < size; index++) {
        variable = (SingleVariableDeclaration) declaration.parameters().get(index);
        if (methodInvocation) {
            // we are creating method invocation parameters
            final SimpleName expression = getAst().newSimpleName(variable.getName().getIdentifier());
            ((List<Expression>) arguments).add(expression);
        } else {
            // we are creating type info for the javadoc
            final MethodRefParameter parameter = getAst().newMethodRefParameter();
            parameter.setType(ASTNodeFactory.newType(getAst(), variable));
            if ((index == size - 1) && declaration.isVarargs())
                parameter.setVarargs(true);
            ((List<MethodRefParameter>) arguments).add(parameter);
        }
    }
}
Also used : SingleVariableDeclaration(org.eclipse.jdt.core.dom.SingleVariableDeclaration) SimpleName(org.eclipse.jdt.core.dom.SimpleName) MethodRefParameter(org.eclipse.jdt.core.dom.MethodRefParameter) List(java.util.List)

Example 90 with SingleVariableDeclaration

use of org.eclipse.jdt.core.dom.SingleVariableDeclaration in project che by eclipse.

the class StubUtility2 method createDelegationStub.

public static MethodDeclaration createDelegationStub(ICompilationUnit unit, ASTRewrite rewrite, ImportRewrite imports, ImportRewriteContext context, IMethodBinding delegate, IVariableBinding delegatingField, CodeGenerationSettings settings) throws CoreException {
    Assert.isNotNull(delegate);
    Assert.isNotNull(delegatingField);
    Assert.isNotNull(settings);
    AST ast = rewrite.getAST();
    MethodDeclaration decl = ast.newMethodDeclaration();
    decl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, delegate.getModifiers() & ~Modifier.SYNCHRONIZED & ~Modifier.ABSTRACT & ~Modifier.NATIVE));
    decl.setName(ast.newSimpleName(delegate.getName()));
    decl.setConstructor(false);
    createTypeParameters(imports, context, ast, delegate, decl);
    decl.setReturnType2(imports.addImport(delegate.getReturnType(), ast, context));
    List<SingleVariableDeclaration> params = createParameters(unit.getJavaProject(), imports, context, ast, delegate, null, decl);
    createThrownExceptions(decl, delegate, imports, context, ast);
    Block body = ast.newBlock();
    decl.setBody(body);
    String delimiter = StubUtility.getLineDelimiterUsed(unit);
    Statement statement = null;
    MethodInvocation invocation = ast.newMethodInvocation();
    invocation.setName(ast.newSimpleName(delegate.getName()));
    List<Expression> arguments = invocation.arguments();
    for (int i = 0; i < params.size(); i++) arguments.add(ast.newSimpleName(params.get(i).getName().getIdentifier()));
    if (settings.useKeywordThis) {
        FieldAccess access = ast.newFieldAccess();
        access.setExpression(ast.newThisExpression());
        access.setName(ast.newSimpleName(delegatingField.getName()));
        invocation.setExpression(access);
    } else
        invocation.setExpression(ast.newSimpleName(delegatingField.getName()));
    if (delegate.getReturnType().isPrimitive() && delegate.getReturnType().getName().equals("void")) {
        //$NON-NLS-1$
        statement = ast.newExpressionStatement(invocation);
    } else {
        ReturnStatement returnStatement = ast.newReturnStatement();
        returnStatement.setExpression(invocation);
        statement = returnStatement;
    }
    body.statements().add(statement);
    ITypeBinding declaringType = delegatingField.getDeclaringClass();
    if (declaringType == null) {
        // can be null for
        return decl;
    }
    String qualifiedName = declaringType.getQualifiedName();
    IPackageBinding packageBinding = declaringType.getPackage();
    if (packageBinding != null) {
        if (packageBinding.getName().length() > 0 && qualifiedName.startsWith(packageBinding.getName()))
            qualifiedName = qualifiedName.substring(packageBinding.getName().length());
    }
    if (settings.createComments) {
        /*
			 * TODO: have API for delegate method comments This is an inlined
			 * version of
			 * {@link CodeGeneration#getMethodComment(ICompilationUnit, String, MethodDeclaration, IMethodBinding, String)}
			 */
        delegate = delegate.getMethodDeclaration();
        String declaringClassQualifiedName = delegate.getDeclaringClass().getQualifiedName();
        String linkToMethodName = delegate.getName();
        String[] parameterTypesQualifiedNames = StubUtility.getParameterTypeNamesForSeeTag(delegate);
        String string = StubUtility.getMethodComment(unit, qualifiedName, decl, delegate.isDeprecated(), linkToMethodName, declaringClassQualifiedName, parameterTypesQualifiedNames, true, delimiter);
        if (string != null) {
            Javadoc javadoc = (Javadoc) rewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
            decl.setJavadoc(javadoc);
        }
    }
    return decl;
}
Also used : AST(org.eclipse.jdt.core.dom.AST) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) SingleVariableDeclaration(org.eclipse.jdt.core.dom.SingleVariableDeclaration) Statement(org.eclipse.jdt.core.dom.Statement) ReturnStatement(org.eclipse.jdt.core.dom.ReturnStatement) Javadoc(org.eclipse.jdt.core.dom.Javadoc) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) SuperMethodInvocation(org.eclipse.jdt.core.dom.SuperMethodInvocation) IPackageBinding(org.eclipse.jdt.core.dom.IPackageBinding) Expression(org.eclipse.jdt.core.dom.Expression) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ReturnStatement(org.eclipse.jdt.core.dom.ReturnStatement) Block(org.eclipse.jdt.core.dom.Block) FieldAccess(org.eclipse.jdt.core.dom.FieldAccess)

Aggregations

SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)124 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)41 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)39 Type (org.eclipse.jdt.core.dom.Type)37 Block (org.eclipse.jdt.core.dom.Block)35 ASTNode (org.eclipse.jdt.core.dom.ASTNode)33 AST (org.eclipse.jdt.core.dom.AST)32 ArrayList (java.util.ArrayList)29 List (java.util.List)27 SimpleName (org.eclipse.jdt.core.dom.SimpleName)27 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)27 VariableDeclarationStatement (org.eclipse.jdt.core.dom.VariableDeclarationStatement)26 Expression (org.eclipse.jdt.core.dom.Expression)22 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)20 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)18 ImportRewriteContext (org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext)18 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)17 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)16 ReturnStatement (org.eclipse.jdt.core.dom.ReturnStatement)16 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)16