boolean isExternalLocal(IBinding binding) { if (binding instanceof IVariableBinding) { IVariableBinding variable = (IVariableBinding)binding; if (!variable.isField()) { return variable.getDeclaringMethod() != _currentMethodBinding; } } return false; } });
private void captureNeededVariables(CSAnonymousClassBuilder builder) { IMethodBinding currentMethod = currentMethodDeclarationBinding(); for (IVariableBinding variable : builder.capturedVariables()) { IMethodBinding method = variable.getDeclaringMethod(); if (method != currentMethod) { _capturedVariables.add(variable); } } }
private static void getLocalVariableLabel(IVariableBinding binding, long flags, StringBuffer buffer) { if (((flags & JavaElementLabels.F_PRE_TYPE_SIGNATURE) != 0)) { getTypeLabel(binding.getType(), (flags & JavaElementLabels.T_TYPE_PARAMETERS), buffer); buffer.append(' '); } if (((flags & JavaElementLabels.F_FULLY_QUALIFIED) != 0)) { IMethodBinding declaringMethod= binding.getDeclaringMethod(); if (declaringMethod != null) { getMethodLabel(declaringMethod, flags, buffer); buffer.append('.'); } } buffer.append(binding.getName()); if (((flags & JavaElementLabels.F_APP_TYPE_SIGNATURE) != 0)) { buffer.append(JavaElementLabels.DECL_STRING); getTypeLabel(binding.getType(), (flags & JavaElementLabels.T_TYPE_PARAMETERS), buffer); } }
private static void getLocalVariableLabel(IVariableBinding binding, long flags, StringBuffer buffer) { if (((flags & JavaElementLabels.F_PRE_TYPE_SIGNATURE) != 0)) { getTypeLabel(binding.getType(), (flags & JavaElementLabels.T_TYPE_PARAMETERS), buffer); buffer.append(' '); } if (((flags & JavaElementLabels.F_FULLY_QUALIFIED) != 0)) { IMethodBinding declaringMethod= binding.getDeclaringMethod(); if (declaringMethod != null) { getMethodLabel(declaringMethod, flags, buffer); buffer.append('.'); } } buffer.append(binding.getName()); if (((flags & JavaElementLabels.F_APP_TYPE_SIGNATURE) != 0)) { buffer.append(JavaElementLabels.DECL_STRING); getTypeLabel(binding.getType(), (flags & JavaElementLabels.T_TYPE_PARAMETERS), buffer); } }
private static void getLocalVariableLabel(IVariableBinding binding, long flags, StringBuffer buffer) { if (((flags & JavaElementLabels.F_PRE_TYPE_SIGNATURE) != 0)) { getTypeLabel(binding.getType(), (flags & JavaElementLabels.T_TYPE_PARAMETERS), buffer); buffer.append(' '); } if (((flags & JavaElementLabels.F_FULLY_QUALIFIED) != 0)) { IMethodBinding declaringMethod= binding.getDeclaringMethod(); if (declaringMethod != null) { getMethodLabel(declaringMethod, flags, buffer); buffer.append('.'); } } buffer.append(binding.getName()); if (((flags & JavaElementLabels.F_APP_TYPE_SIGNATURE) != 0)) { buffer.append(JavaElementLabels.DECL_STRING); getTypeLabel(binding.getType(), (flags & JavaElementLabels.T_TYPE_PARAMETERS), buffer); } }
private static void getLocalVariableLabel(IVariableBinding binding, long flags, StringBuffer buffer) { if (((flags & JavaElementLabelsCore.F_PRE_TYPE_SIGNATURE) != 0)) { getTypeLabel(binding.getType(), (flags & JavaElementLabelsCore.T_TYPE_PARAMETERS), buffer); buffer.append(' '); } if (((flags & JavaElementLabelsCore.F_FULLY_QUALIFIED) != 0)) { IMethodBinding declaringMethod= binding.getDeclaringMethod(); if (declaringMethod != null) { getMethodLabel(declaringMethod, flags, buffer); buffer.append('.'); } } buffer.append(binding.getName()); if (((flags & JavaElementLabelsCore.F_APP_TYPE_SIGNATURE) != 0)) { buffer.append(JavaElementLabelsCore.DECL_STRING); getTypeLabel(binding.getType(), (flags & JavaElementLabelsCore.T_TYPE_PARAMETERS), buffer); } }
private void evaluateVariableBinding(final IVariableBinding b) { if ((b == null) || !matchesVarname(b) || isVartypeKnown()) { return; } res.type = toTypeName(b.getType()).orNull(); if (res.kind != null) { // warning? return; } if (b.isParameter()) { res.kind = Kind.PARAMETER; final IMethodName method = BindingUtils.toMethodName(b.getDeclaringMethod()).orNull(); if (method != null) { res.definition = method; } } else if (b.isField()) { res.kind = Kind.FIELD; } else { res.kind = Kind.UNKNOWN; } }
private IBinding getEnclosingDeclaration(ASTNode node) { while (node != null) { if (node instanceof AbstractTypeDeclaration) { return ((AbstractTypeDeclaration) node).resolveBinding(); } else if (node instanceof AnonymousClassDeclaration) { return ((AnonymousClassDeclaration) node).resolveBinding(); } else if (node instanceof MethodDeclaration) { return ((MethodDeclaration) node).resolveBinding(); } else if (node instanceof FieldDeclaration) { List<?> fragments = ((FieldDeclaration) node).fragments(); if (fragments.size() > 0) { return ((VariableDeclarationFragment) fragments.get(0)).resolveBinding(); } } else if (node instanceof VariableDeclarationFragment) { IVariableBinding variableBinding = ((VariableDeclarationFragment) node).resolveBinding(); if (variableBinding.getDeclaringMethod() != null || variableBinding.getDeclaringClass() != null) { return variableBinding; // workaround for incomplete wiring of DOM bindings: keep searching when variableBinding is unparented } } node = node.getParent(); } return null; }
public static IBinding getEnclosingDeclaration(ASTNode node) { while(node != null) { if (node instanceof AbstractTypeDeclaration) { return ((AbstractTypeDeclaration)node).resolveBinding(); } else if (node instanceof AnonymousClassDeclaration) { return ((AnonymousClassDeclaration)node).resolveBinding(); } else if (node instanceof MethodDeclaration) { return ((MethodDeclaration)node).resolveBinding(); } else if (node instanceof FieldDeclaration) { List<?> fragments= ((FieldDeclaration)node).fragments(); if (fragments.size() > 0) return ((VariableDeclarationFragment)fragments.get(0)).resolveBinding(); } else if (node instanceof VariableDeclarationFragment) { IVariableBinding variableBinding= ((VariableDeclarationFragment)node).resolveBinding(); if (variableBinding.getDeclaringMethod() != null || variableBinding.getDeclaringClass() != null) return variableBinding; // workaround for incomplete wiring of DOM bindings: keep searching when variableBinding is unparented } node= node.getParent(); } return null; }
private static boolean isVariableDefinedInContext(IBinding binding, ITypeBinding typeVariable) { if (binding.getKind() == IBinding.VARIABLE) { IVariableBinding var= (IVariableBinding) binding; binding= var.getDeclaringMethod(); if (binding == null) { binding= var.getDeclaringClass(); } } if (binding instanceof IMethodBinding) { if (binding == typeVariable.getDeclaringMethod()) { return true; } binding= ((IMethodBinding) binding).getDeclaringClass(); } while (binding instanceof ITypeBinding) { if (binding == typeVariable.getDeclaringClass()) { return true; } if (Modifier.isStatic(binding.getModifiers())) { break; } binding= ((ITypeBinding) binding).getDeclaringClass(); } return false; }
private static boolean isVariableDefinedInContext(IBinding binding, ITypeBinding typeVariable) { if (binding.getKind() == IBinding.VARIABLE) { IVariableBinding var= (IVariableBinding) binding; binding= var.getDeclaringMethod(); if (binding == null) { binding= var.getDeclaringClass(); } } if (binding instanceof IMethodBinding) { if (binding == typeVariable.getDeclaringMethod()) { return true; } binding= ((IMethodBinding) binding).getDeclaringClass(); } while (binding instanceof ITypeBinding) { if (binding == typeVariable.getDeclaringClass()) { return true; } if (Modifier.isStatic(binding.getModifiers())) { break; } binding= ((ITypeBinding) binding).getDeclaringClass(); } return false; }
private static boolean isVariableDefinedInContext(IBinding binding, ITypeBinding typeVariable) { if (binding.getKind() == IBinding.VARIABLE) { IVariableBinding var= (IVariableBinding) binding; binding= var.getDeclaringMethod(); if (binding == null) { binding= var.getDeclaringClass(); } } if (binding instanceof IMethodBinding) { if (binding == typeVariable.getDeclaringMethod()) { return true; } binding= ((IMethodBinding) binding).getDeclaringClass(); } while (binding instanceof ITypeBinding) { if (binding == typeVariable.getDeclaringClass()) { return true; } if (Modifier.isStatic(binding.getModifiers())) { break; } binding= ((ITypeBinding) binding).getDeclaringClass(); } return false; }
private void appendVariableQualification(IVariableBinding variable, long flags) { if (variable.isField()) { appendTypeBindingLabel(variable.getDeclaringClass(), flags); } else { IMethodBinding declaringMethod= variable.getDeclaringMethod(); if (declaringMethod != null) { IBinding declaringMember= declaringMethod.getDeclaringMember(); if (declaringMember != null) { appendLambdaLabel(declaringMethod, flags); fBuffer.append(' '); appendMethodBindingLabel(declaringMethod.getMethodDeclaration(), (flags & QUALIFIER_FLAGS) | M_ALL_QUALIFIED); } else { appendMethodBindingLabel(declaringMethod, flags | M_ALL_QUALIFIED); } } else { // workaround for: local variable inside initializer doesn't yet expose the #getDeclaringMethod(); IJavaElement element= variable.getJavaElement(); if (element != null && element.getParent() != null) appendElementLabel(element.getParent(), flags); else fBuffer.append(MISSING_LABEL); } } }
private void appendVariableQualification(IVariableBinding variable, long flags) { if (variable.isField()) { appendTypeBindingLabel(variable.getDeclaringClass(), flags); } else { IMethodBinding declaringMethod= variable.getDeclaringMethod(); if (declaringMethod != null) { IBinding declaringMember= declaringMethod.getDeclaringMember(); if (declaringMember != null) { appendLambdaLabel(declaringMethod, flags); fBuffer.append(' '); appendMethodBindingLabel(declaringMethod.getMethodDeclaration(), (flags & QUALIFIER_FLAGS) | M_ALL_QUALIFIED); } else { appendMethodBindingLabel(declaringMethod, flags | M_ALL_QUALIFIED); } } else { // workaround for: local variable inside initializer doesn't yet expose the #getDeclaringMethod(); IJavaElement element= variable.getJavaElement(); if (element != null && element.getParent() != null) appendElementLabel(element.getParent(), flags); else fBuffer.append(MISSING_LABEL); } } }
public final ASTNode getArgumentNode(final IVariableBinding binding, final boolean last) throws JavaModelException { Assert.isNotNull(binding); final SingleVariableDeclaration variable= ast.newSingleVariableDeclaration(); final ITypeBinding type= binding.getType(); adjustTypeVisibility(type); variable.setName(ast.newSimpleName(binding.getName())); variable.modifiers().addAll(ast.newModifiers(binding.getModifiers())); final IMethodBinding method= binding.getDeclaringMethod(); if (last && method != null && method.isVarargs()) { variable.setVarargs(true); String name= null; if (type.isArray()) { name= type.getElementType().getName(); if (PrimitiveType.toCode(name) != null) variable.setType(ast.newPrimitiveType(PrimitiveType.toCode(name))); else variable.setType(ast.newSimpleType(ast.newSimpleName(name))); } else { name= type.getName(); if (PrimitiveType.toCode(name) != null) variable.setType(ast.newPrimitiveType(PrimitiveType.toCode(name))); else variable.setType(ast.newSimpleType(ast.newSimpleName(name))); } } else variable.setType(rewriter.getImportRewrite().addImport(type, ast)); return variable; }
@Override public final ASTNode getArgumentNode(final IVariableBinding binding, final boolean last) throws JavaModelException { Assert.isNotNull(binding); final SingleVariableDeclaration variable= ast.newSingleVariableDeclaration(); final ITypeBinding type= binding.getType(); adjustTypeVisibility(type); variable.setName(ast.newSimpleName(binding.getName())); variable.modifiers().addAll(ast.newModifiers(binding.getModifiers())); final IMethodBinding method= binding.getDeclaringMethod(); if (last && method != null && method.isVarargs()) { variable.setVarargs(true); String name= null; if (type.isArray()) { name= type.getElementType().getName(); if (PrimitiveType.toCode(name) != null) variable.setType(ast.newPrimitiveType(PrimitiveType.toCode(name))); else variable.setType(ast.newSimpleType(ast.newSimpleName(name))); } else { name= type.getName(); if (PrimitiveType.toCode(name) != null) variable.setType(ast.newPrimitiveType(PrimitiveType.toCode(name))); else variable.setType(ast.newSimpleType(ast.newSimpleName(name))); } } else variable.setType(rewriter.getImportRewrite().addImport(type, ast)); return variable; }
@Override public final ASTNode getArgumentNode(final IVariableBinding binding, final boolean last) throws JavaModelException { Assert.isNotNull(binding); final SingleVariableDeclaration variable= ast.newSingleVariableDeclaration(); final ITypeBinding type= binding.getType(); adjustTypeVisibility(type); variable.setName(ast.newSimpleName(binding.getName())); variable.modifiers().addAll(ast.newModifiers(binding.getModifiers())); final IMethodBinding method= binding.getDeclaringMethod(); if (last && method != null && method.isVarargs()) { variable.setVarargs(true); String name= null; if (type.isArray()) { name= type.getElementType().getName(); if (PrimitiveType.toCode(name) != null) variable.setType(ast.newPrimitiveType(PrimitiveType.toCode(name))); else variable.setType(ast.newSimpleType(ast.newSimpleName(name))); } else { name= type.getName(); if (PrimitiveType.toCode(name) != null) variable.setType(ast.newPrimitiveType(PrimitiveType.toCode(name))); else variable.setType(ast.newSimpleType(ast.newSimpleName(name))); } } else variable.setType(rewriter.getImportRewrite().addImport(type, ast)); return variable; }
/** * Creates a variable type variable. * * @param binding the variable binding * @return the created variable variable */ public final ConstraintVariable2 createVariableVariable(final IVariableBinding binding) { ITypeBinding type= binding.getType(); if (type.isArray()) type= type.getElementType(); if (isConstrainedType(type)) { ConstraintVariable2 variable= null; final IVariableBinding declaration= binding.getVariableDeclaration(); if (declaration.isField()) { final ITypeBinding declaring= declaration.getDeclaringClass(); if (!declaring.isFromSource()) variable= new ImmutableTypeVariable2(createTType(type)); } else { final IMethodBinding declaring= declaration.getDeclaringMethod(); if (declaring != null && !declaring.getDeclaringClass().isFromSource()) variable= new ImmutableTypeVariable2(createTType(type)); } if (variable == null) variable= new VariableVariable2(createTType(type), declaration); return (ConstraintVariable2) fConstraintVariables.addExisting(variable); } return null; }
/** * Creates a variable type variable. * * @param binding the variable binding * @return the created variable variable, or <code>null</code> */ public final ConstraintVariable2 createVariableVariable(final IVariableBinding binding) { ITypeBinding type= binding.getType(); if (type.isArray()) type= type.getElementType(); if (isConstrainedType(type)) { ConstraintVariable2 variable= null; final IVariableBinding declaration= binding.getVariableDeclaration(); if (declaration.isField()) { final ITypeBinding declaring= declaration.getDeclaringClass(); if (!declaring.isFromSource()) variable= new ImmutableTypeVariable2(createTType(type)); } else { final IMethodBinding declaring= declaration.getDeclaringMethod(); if (declaring != null && !declaring.getDeclaringClass().isFromSource()) variable= new ImmutableTypeVariable2(createTType(type)); } if (variable == null) variable= new VariableVariable2(createTType(type), declaration); return fConstraintVariables.addExisting(variable); } return null; }
/** * Creates a variable type variable. * * @param binding the variable binding * @return the created variable variable, or <code>null</code> */ public final ConstraintVariable2 createVariableVariable(final IVariableBinding binding) { ITypeBinding type= binding.getType(); if (type.isArray()) type= type.getElementType(); if (isConstrainedType(type)) { ConstraintVariable2 variable= null; final IVariableBinding declaration= binding.getVariableDeclaration(); if (declaration.isField()) { final ITypeBinding declaring= declaration.getDeclaringClass(); if (!declaring.isFromSource()) variable= new ImmutableTypeVariable2(createTType(type)); } else { final IMethodBinding declaring= declaration.getDeclaringMethod(); if (declaring != null && !declaring.getDeclaringClass().isFromSource()) variable= new ImmutableTypeVariable2(createTType(type)); } if (variable == null) variable= new VariableVariable2(createTType(type), declaration); return fConstraintVariables.addExisting(variable); } return null; }