Search in sources :

Example 41 with IBinding

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

the class FullConstraintCreator method create.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SuperFieldAccess)
	 */
@Override
public ITypeConstraint[] create(SuperFieldAccess access) {
    SimpleName name = access.getName();
    IBinding binding = name.resolveBinding();
    if (!(binding instanceof IVariableBinding))
        return new ITypeConstraint[0];
    IVariableBinding vb = (IVariableBinding) binding;
    return createConstraintsForAccessToField(vb, null, access);
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) IBinding(org.eclipse.jdt.core.dom.IBinding) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding)

Example 42 with IBinding

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

the class TypeEnvironment method createStandardType.

private StandardType createStandardType(String fullyQualifiedName, IJavaProject focus) {
    try {
        IType javaElementType = focus.findType(fullyQualifiedName);
        StandardType result = fStandardTypes.get(javaElementType);
        if (result != null)
            return result;
        ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
        parser.setProject(focus);
        IBinding[] bindings = parser.createBindings(new IJavaElement[] { javaElementType }, null);
        return createStandardType((ITypeBinding) bindings[0]);
    } catch (JavaModelException e) {
    // fall through
    }
    return null;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IBinding(org.eclipse.jdt.core.dom.IBinding) ASTParser(org.eclipse.jdt.core.dom.ASTParser) IType(org.eclipse.jdt.core.IType)

Example 43 with IBinding

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

the class ImportRemover method applyRemoves.

public void applyRemoves(ImportRewrite importRewrite) {
    IBinding[] bindings = getImportsToRemove();
    for (int i = 0; i < bindings.length; i++) {
        if (bindings[i] instanceof ITypeBinding) {
            ITypeBinding typeBinding = (ITypeBinding) bindings[i];
            importRewrite.removeImport(typeBinding.getTypeDeclaration().getQualifiedName());
        } else if (bindings[i] instanceof IMethodBinding) {
            IMethodBinding binding = (IMethodBinding) bindings[i];
            importRewrite.removeStaticImport(binding.getDeclaringClass().getQualifiedName() + '.' + binding.getName());
        } else if (bindings[i] instanceof IVariableBinding) {
            IVariableBinding binding = (IVariableBinding) bindings[i];
            importRewrite.removeStaticImport(binding.getDeclaringClass().getQualifiedName() + '.' + binding.getName());
        }
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) IBinding(org.eclipse.jdt.core.dom.IBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding)

Example 44 with IBinding

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

the class RemoveDeclarationCorrectionProposal method getName.

@Override
public String getName() {
    IBinding binding = fName.resolveBinding();
    String name = BasicElementLabels.getJavaElementName(fName.getIdentifier());
    switch(binding.getKind()) {
        case IBinding.TYPE:
            return Messages.format(CorrectionMessages.RemoveDeclarationCorrectionProposal_removeunusedtype_description, name);
        case IBinding.METHOD:
            if (((IMethodBinding) binding).isConstructor()) {
                return Messages.format(CorrectionMessages.RemoveDeclarationCorrectionProposal_removeunusedconstructor_description, name);
            } else {
                return Messages.format(CorrectionMessages.RemoveDeclarationCorrectionProposal_removeunusedmethod_description, name);
            }
        case IBinding.VARIABLE:
            if (((IVariableBinding) binding).isField()) {
                return Messages.format(CorrectionMessages.RemoveDeclarationCorrectionProposal_removeunusedfield_description, name);
            } else {
                return Messages.format(CorrectionMessages.RemoveDeclarationCorrectionProposal_removeunusedvar_description, name);
            }
        default:
            return super.getDisplayString();
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) IBinding(org.eclipse.jdt.core.dom.IBinding) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding)

Example 45 with IBinding

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

the class LazyGenericTypeProposal method getExpectedType.

/**
	 * Returns the type binding of the expected type as it is contained in the
	 * code completion context.
	 *
	 * @return the binding of the expected type
	 */
private ITypeBinding getExpectedType() {
    char[][] chKeys = fInvocationContext.getCoreContext().getExpectedTypesKeys();
    if (chKeys == null || chKeys.length == 0)
        return null;
    String[] keys = new String[chKeys.length];
    for (int i = 0; i < keys.length; i++) {
        keys[i] = String.valueOf(chKeys[0]);
    }
    final CheASTParser parser = CheASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
    parser.setProject(fCompilationUnit.getJavaProject());
    parser.setResolveBindings(true);
    parser.setStatementsRecovery(true);
    final Map<String, IBinding> bindings = new HashMap<String, IBinding>();
    ASTRequestor requestor = new ASTRequestor() {

        @Override
        public void acceptBinding(String bindingKey, IBinding binding) {
            bindings.put(bindingKey, binding);
        }
    };
    parser.createASTs(new ICompilationUnit[0], keys, requestor, null);
    if (bindings.size() > 0)
        return (ITypeBinding) bindings.get(keys[0]);
    return null;
}
Also used : HashMap(java.util.HashMap) IBinding(org.eclipse.jdt.core.dom.IBinding) ASTRequestor(org.eclipse.jdt.core.dom.ASTRequestor) CheASTParser(org.eclipse.jdt.core.dom.CheASTParser) Point(org.eclipse.swt.graphics.Point)

Aggregations

IBinding (org.eclipse.jdt.core.dom.IBinding)103 SimpleName (org.eclipse.jdt.core.dom.SimpleName)59 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)48 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)41 ASTNode (org.eclipse.jdt.core.dom.ASTNode)40 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)25 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)25 Name (org.eclipse.jdt.core.dom.Name)20 Expression (org.eclipse.jdt.core.dom.Expression)19 ArrayList (java.util.ArrayList)16 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)14 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)13 CastExpression (org.eclipse.jdt.core.dom.CastExpression)12 FieldAccess (org.eclipse.jdt.core.dom.FieldAccess)11 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)11 QualifiedName (org.eclipse.jdt.core.dom.QualifiedName)11 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)11 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)11 AST (org.eclipse.jdt.core.dom.AST)10 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)10