Search in sources :

Example 81 with IVariableBinding

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

the class InferTypeArgumentsConstraintCreator method endVisit.

@Override
public void endVisit(SimpleName node) {
    if (node.resolveBoxing()) {
        ImmutableTypeVariable2 boxed = fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
        setConstraintVariable(node, boxed);
        return;
    }
    IBinding binding = node.resolveBinding();
    if (binding instanceof IVariableBinding) {
        //TODO: code is similar to handling of method return value
        IVariableBinding variableBinding = (IVariableBinding) binding;
        ITypeBinding declaredVariableType = variableBinding.getVariableDeclaration().getType();
        if (declaredVariableType.isTypeVariable()) {
            Expression receiver = getSimpleNameReceiver(node);
            if (receiver != null) {
                ConstraintVariable2 receiverCv = getConstraintVariable(receiver);
                // the type variable must come from the receiver!
                Assert.isNotNull(receiverCv);
                ConstraintVariable2 elementCv = fTCModel.getElementVariable(receiverCv, declaredVariableType);
                // [retVal] =^= Elem[receiver]:
                setConstraintVariable(node, elementCv);
                return;
            }
        } else if (declaredVariableType.isParameterizedType()) {
            Expression receiver = getSimpleNameReceiver(node);
            if (receiver != null) {
                ConstraintVariable2 receiverCv = getConstraintVariable(receiver);
                if (receiverCv != null) {
                    //						ITypeBinding genericVariableType= declaredVariableType.getTypeDeclaration();
                    ConstraintVariable2 returnTypeCv = fTCModel.makeParameterizedTypeVariable(declaredVariableType);
                    setConstraintVariable(node, returnTypeCv);
                    // Elem[retVal] =^= Elem[receiver]
                    TType declaredVariableTType = fTCModel.createTType(declaredVariableType);
                    fTCModel.createTypeVariablesEqualityConstraints(receiverCv, Collections.<String, IndependentTypeVariable2>emptyMap(), returnTypeCv, declaredVariableTType);
                    return;
                }
            }
        } else {
        //TODO: array...
        //logUnexpectedNode(node, null);
        }
        // default:
        VariableVariable2 cv = fTCModel.makeVariableVariable(variableBinding);
        setConstraintVariable(node, cv);
    }
// TODO else?
}
Also used : ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) IBinding(org.eclipse.jdt.core.dom.IBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) VariableVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.VariableVariable2) IndependentTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.IndependentTypeVariable2)

Example 82 with IVariableBinding

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

the class PromoteTempToFieldRefactoring method getRefactoringDescriptor.

private ConvertLocalVariableDescriptor getRefactoringDescriptor() {
    final Map<String, String> arguments = new HashMap<String, String>();
    String project = null;
    IJavaProject javaProject = fCu.getJavaProject();
    if (javaProject != null)
        project = javaProject.getElementName();
    final IVariableBinding binding = fTempDeclarationNode.resolveBinding();
    final String description = Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(binding.getName()));
    final String header = Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_descriptor_description, new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(binding.getDeclaringMethod(), JavaElementLabels.ALL_FULLY_QUALIFIED) });
    final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
    comment.addSetting(Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
    comment.addSetting(Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_field_pattern, BasicElementLabels.getJavaElementName(fFieldName)));
    switch(fInitializeIn) {
        case INITIALIZE_IN_CONSTRUCTOR:
            comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_initialize_constructor);
            break;
        case INITIALIZE_IN_FIELD:
            comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_initialize_declaration);
            break;
        case INITIALIZE_IN_METHOD:
            comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_initialize_method);
            break;
    }
    String visibility = JdtFlags.getVisibilityString(fVisibility);
    if (//$NON-NLS-1$
    "".equals(visibility))
        visibility = RefactoringCoreMessages.PromoteTempToFieldRefactoring_default_visibility;
    comment.addSetting(Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_visibility_pattern, visibility));
    if (fDeclareFinal && fDeclareStatic)
        comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_declare_final_static);
    else if (fDeclareFinal)
        comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_declare_final);
    else if (fDeclareStatic)
        comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_declare_static);
    final ConvertLocalVariableDescriptor descriptor = RefactoringSignatureDescriptorFactory.createConvertLocalVariableDescriptor(project, description, comment.asString(), arguments, RefactoringDescriptor.STRUCTURAL_CHANGE);
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fCu));
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fFieldName);
    //$NON-NLS-1$
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString());
    arguments.put(ATTRIBUTE_STATIC, Boolean.valueOf(fDeclareStatic).toString());
    arguments.put(ATTRIBUTE_FINAL, Boolean.valueOf(fDeclareFinal).toString());
    arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString());
    arguments.put(ATTRIBUTE_INITIALIZE, new Integer(fInitializeIn).toString());
    return descriptor;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) ConvertLocalVariableDescriptor(org.eclipse.jdt.core.refactoring.descriptors.ConvertLocalVariableDescriptor) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)

Example 83 with IVariableBinding

use of org.eclipse.jdt.core.dom.IVariableBinding 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 84 with IVariableBinding

use of org.eclipse.jdt.core.dom.IVariableBinding 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 85 with IVariableBinding

use of org.eclipse.jdt.core.dom.IVariableBinding 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)

Aggregations

IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)106 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)49 IBinding (org.eclipse.jdt.core.dom.IBinding)48 SimpleName (org.eclipse.jdt.core.dom.SimpleName)43 ASTNode (org.eclipse.jdt.core.dom.ASTNode)30 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)29 Expression (org.eclipse.jdt.core.dom.Expression)24 ArrayList (java.util.ArrayList)22 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)16 Name (org.eclipse.jdt.core.dom.Name)13 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)13 Assignment (org.eclipse.jdt.core.dom.Assignment)12 CastExpression (org.eclipse.jdt.core.dom.CastExpression)12 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)12 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)12 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)12 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)12 FieldAccess (org.eclipse.jdt.core.dom.FieldAccess)11 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)11 PrefixExpression (org.eclipse.jdt.core.dom.PrefixExpression)11