Search in sources :

Example 11 with ITypeBinding

use of org.eclipse.jdt.core.dom.ITypeBinding in project j2objc by google.

the class JdtExecutableElement method getTypeParameters.

@Override
public List<? extends TypeParameterElement> getTypeParameters() {
    List<TypeParameterElement> typeParams = new ArrayList<>();
    for (ITypeBinding tp : ((IMethodBinding) binding).getTypeParameters()) {
        Element tpe = BindingConverter.getElement(tp);
        assert tpe instanceof TypeParameterElement;
        typeParams.add((TypeParameterElement) tpe);
    }
    return typeParams;
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement) Element(javax.lang.model.element.Element) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement) TypeParameterElement(javax.lang.model.element.TypeParameterElement) ArrayList(java.util.ArrayList) TypeParameterElement(javax.lang.model.element.TypeParameterElement)

Example 12 with ITypeBinding

use of org.eclipse.jdt.core.dom.ITypeBinding in project j2objc by google.

the class JdtIntersectionType method fromJdtIntersection.

static JdtIntersectionType fromJdtIntersection(ITypeBinding t) {
    List<TypeMirror> bounds = new ArrayList<>();
    ITypeBinding superclass = t.getSuperclass();
    if (superclass != null) {
        bounds.add(BindingConverter.getType(superclass));
    }
    for (ITypeBinding intrface : t.getInterfaces()) {
        bounds.add(BindingConverter.getType(intrface));
    }
    return new JdtIntersectionType(t, bounds);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ArrayList(java.util.ArrayList)

Example 13 with ITypeBinding

use of org.eclipse.jdt.core.dom.ITypeBinding in project j2objc by google.

the class JdtTypeElement method getTypeParameters.

@Override
public List<? extends TypeParameterElement> getTypeParameters() {
    List<TypeParameterElement> typeParams = new ArrayList<>();
    for (ITypeBinding typeParam : ((ITypeBinding) binding).getTypeParameters()) {
        TypeParameterElement tpe = (TypeParameterElement) BindingConverter.getElement(typeParam);
        typeParams.add(tpe);
    }
    return typeParams;
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ArrayList(java.util.ArrayList) TypeParameterElement(javax.lang.model.element.TypeParameterElement)

Example 14 with ITypeBinding

use of org.eclipse.jdt.core.dom.ITypeBinding in project j2objc by google.

the class TreeConverter method convertAbstractTypeDeclaration.

private static TreeNode convertAbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration node, AbstractTypeDeclaration newNode) {
    convertBodyDeclaration(node, newNode);
    ITypeBinding typeBinding = node.resolveBinding();
    Set<IMethodBinding> declaredInAst = new HashSet<>();
    for (Object bodyDecl : node.bodyDeclarations()) {
        if (bodyDecl instanceof org.eclipse.jdt.core.dom.MethodDeclaration) {
            declaredInAst.add(((org.eclipse.jdt.core.dom.MethodDeclaration) bodyDecl).resolveBinding());
        }
        newNode.addBodyDeclaration((BodyDeclaration) convert(bodyDecl));
    }
    for (IMethodBinding method : typeBinding.getDeclaredMethods()) {
        if (method.isConstructor() && method.getParameterTypes().length == 0 && !declaredInAst.contains(method)) {
            MethodDeclaration defaultConstructor = new MethodDeclaration(BindingConverter.getExecutableElement(method)).setBody(new Block());
            addImplicitSuperCall(defaultConstructor);
            newNode.addBodyDeclaration(0, defaultConstructor);
            break;
        }
    }
    return newNode.setName((SimpleName) convert(node.getName())).setTypeElement(BindingConverter.getTypeElement(typeBinding));
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) MethodDeclaration(com.google.devtools.j2objc.ast.MethodDeclaration) SimpleName(com.google.devtools.j2objc.ast.SimpleName) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) Block(com.google.devtools.j2objc.ast.Block) HashSet(java.util.HashSet)

Example 15 with ITypeBinding

use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.

the class ContextSensitiveImportRewriteContext method findInContext.

@Override
public int findInContext(String qualifier, String name, int kind) {
    IBinding[] declarationsInScope = getDeclarationsInScope();
    for (int i = 0; i < declarationsInScope.length; i++) {
        if (declarationsInScope[i] instanceof ITypeBinding) {
            ITypeBinding typeBinding = (ITypeBinding) declarationsInScope[i];
            if (isSameType(typeBinding, qualifier, name)) {
                return RES_NAME_FOUND;
            } else if (isConflicting(typeBinding, name)) {
                return RES_NAME_CONFLICT;
            }
        } else if (declarationsInScope[i] != null) {
            if (isConflicting(declarationsInScope[i], name)) {
                return RES_NAME_CONFLICT;
            }
        }
    }
    Name[] names = getImportedNames();
    for (int i = 0; i < names.length; i++) {
        IBinding binding = names[i].resolveBinding();
        if (binding instanceof ITypeBinding && !binding.isRecovered()) {
            ITypeBinding typeBinding = (ITypeBinding) binding;
            if (isConflictingType(typeBinding, qualifier, name)) {
                return RES_NAME_CONFLICT;
            }
        }
    }
    List<AbstractTypeDeclaration> list = fCompilationUnit.types();
    for (Iterator<AbstractTypeDeclaration> iter = list.iterator(); iter.hasNext(); ) {
        AbstractTypeDeclaration type = iter.next();
        ITypeBinding binding = type.resolveBinding();
        if (binding != null) {
            if (isSameType(binding, qualifier, name)) {
                return RES_NAME_FOUND;
            } else {
                ITypeBinding decl = containingDeclaration(binding, qualifier, name);
                while (decl != null && !decl.equals(binding)) {
                    int modifiers = decl.getModifiers();
                    if (Modifier.isPrivate(modifiers))
                        return RES_NAME_CONFLICT;
                    decl = decl.getDeclaringClass();
                }
            }
        }
    }
    String[] addedImports = fImportRewrite.getAddedImports();
    String qualifiedName = JavaModelUtil.concatenateName(qualifier, name);
    for (int i = 0; i < addedImports.length; i++) {
        String addedImport = addedImports[i];
        if (qualifiedName.equals(addedImport)) {
            return RES_NAME_FOUND;
        } else {
            if (isConflicting(name, addedImport))
                return RES_NAME_CONFLICT;
        }
    }
    if (qualifier.equals("java.lang")) {
        //$NON-NLS-1$
        //No explicit import statement required
        ITypeRoot typeRoot = fCompilationUnit.getTypeRoot();
        if (typeRoot != null) {
            IPackageFragment packageFragment = (IPackageFragment) typeRoot.getParent();
            try {
                ICompilationUnit[] compilationUnits = packageFragment.getCompilationUnits();
                for (int i = 0; i < compilationUnits.length; i++) {
                    ICompilationUnit cu = compilationUnits[i];
                    IType[] allTypes = cu.getAllTypes();
                    for (int j = 0; j < allTypes.length; j++) {
                        IType type = allTypes[j];
                        String packageTypeName = type.getFullyQualifiedName();
                        if (isConflicting(name, packageTypeName))
                            return RES_NAME_CONFLICT;
                    }
                }
            } catch (JavaModelException e) {
            }
        }
    }
    return fImportRewrite.getDefaultImportRewriteContext().findInContext(qualifier, name, kind);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) JavaModelException(org.eclipse.jdt.core.JavaModelException) IBinding(org.eclipse.jdt.core.dom.IBinding) ITypeRoot(org.eclipse.jdt.core.ITypeRoot) SimpleName(org.eclipse.jdt.core.dom.SimpleName) Name(org.eclipse.jdt.core.dom.Name) IType(org.eclipse.jdt.core.IType) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

Aggregations

ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)388 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)110 ASTNode (org.eclipse.jdt.core.dom.ASTNode)72 Expression (org.eclipse.jdt.core.dom.Expression)69 Type (org.eclipse.jdt.core.dom.Type)55 SimpleName (org.eclipse.jdt.core.dom.SimpleName)52 ArrayList (java.util.ArrayList)50 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)49 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)49 AST (org.eclipse.jdt.core.dom.AST)43 IBinding (org.eclipse.jdt.core.dom.IBinding)41 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)40 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)36 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)35 CastExpression (org.eclipse.jdt.core.dom.CastExpression)33 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)32 Name (org.eclipse.jdt.core.dom.Name)31 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)29 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)29 ContextSensitiveImportRewriteContext (org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext)26