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?
}
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;
}
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;
}
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));
}
}
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;
}
Aggregations