Example usage for org.eclipse.jdt.core.dom IPackageBinding getName

List of usage examples for org.eclipse.jdt.core.dom IPackageBinding getName

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom IPackageBinding getName.

Prototype

@Override
public String getName();

Source Link

Document

Returns the name of the package represented by this binding.

Usage

From source file:astview.Binding.java

License:Open Source License

@Override
public String getLabel() {
    StringBuffer buf = new StringBuffer(fLabel);
    buf.append(": "); //$NON-NLS-1$
    if (fBinding != null) {
        switch (fBinding.getKind()) {
        case IBinding.VARIABLE:
            IVariableBinding variableBinding = (IVariableBinding) fBinding;
            if (!variableBinding.isField()) {
                buf.append(variableBinding.getName());
            } else {
                if (variableBinding.getDeclaringClass() == null) {
                    buf.append("<some array type>"); //$NON-NLS-1$
                } else {
                    buf.append(variableBinding.getDeclaringClass().getName());
                }// w ww  .  j a v a2s .c  o  m
                buf.append('.');
                buf.append(variableBinding.getName());
            }
            break;
        case IBinding.PACKAGE:
            IPackageBinding packageBinding = (IPackageBinding) fBinding;
            buf.append(packageBinding.getName());
            break;
        case IBinding.TYPE:
            ITypeBinding typeBinding = (ITypeBinding) fBinding;
            appendAnnotatedQualifiedName(buf, typeBinding);
            break;
        case IBinding.METHOD:
            IMethodBinding methodBinding = (IMethodBinding) fBinding;
            buf.append(methodBinding.getDeclaringClass().getName());
            buf.append('.');
            buf.append(methodBinding.getName());
            buf.append('(');
            ITypeBinding[] parameters = methodBinding.getParameterTypes();
            for (int i = 0; i < parameters.length; i++) {
                if (i > 0) {
                    buf.append(", "); //$NON-NLS-1$
                }
                ITypeBinding parameter = parameters[i];
                buf.append(parameter.getName());
            }
            buf.append(')');
            break;
        case IBinding.ANNOTATION:
        case IBinding.MEMBER_VALUE_PAIR:
            buf.append(fBinding.toString());
            break;
        }

    } else {
        buf.append("null"); //$NON-NLS-1$
    }
    return buf.toString();

}

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

/**
 * @param binding/*from   w w w .j  av a2 s.  c om*/
 * @return
 */
private IElement convertBinding(final IPackageBinding binding) {
    ASTCrawler.checkForNull(binding);
    return FlyweightElementFactory.getElement(Category.PACKAGE, binding.getName());
}

From source file:cideplus.ui.astview.Binding.java

License:Open Source License

public String getLabel() {
    StringBuffer buf = new StringBuffer(fLabel);
    buf.append(": "); //$NON-NLS-1$
    if (fBinding != null) {
        switch (fBinding.getKind()) {
        case IBinding.VARIABLE:
            IVariableBinding variableBinding = (IVariableBinding) fBinding;
            if (!variableBinding.isField()) {
                buf.append(variableBinding.getName());
            } else if (variableBinding.getDeclaringClass() == null) {
                buf.append("array type"); //$NON-NLS-1$
            } else {
                buf.append(variableBinding.getDeclaringClass().getName());
                buf.append('.');
                buf.append(variableBinding.getName());
            }/*from   w  ww. j a  va  2  s  .  co m*/
            break;
        case IBinding.PACKAGE:
            IPackageBinding packageBinding = (IPackageBinding) fBinding;
            buf.append(packageBinding.getName());
            break;
        case IBinding.TYPE:
            ITypeBinding typeBinding = (ITypeBinding) fBinding;
            buf.append(typeBinding.getQualifiedName());
            break;
        case IBinding.METHOD:
            IMethodBinding methodBinding = (IMethodBinding) fBinding;
            buf.append(methodBinding.getDeclaringClass().getName());
            buf.append('.');
            buf.append(methodBinding.getName());
            buf.append('(');
            ITypeBinding[] parameters = methodBinding.getParameterTypes();
            for (int i = 0; i < parameters.length; i++) {
                if (i > 0) {
                    buf.append(", "); //$NON-NLS-1$
                }
                ITypeBinding parameter = parameters[i];
                buf.append(parameter.getName());
            }
            buf.append(')');
            break;
        case IBinding.ANNOTATION:
        case IBinding.MEMBER_VALUE_PAIR:
            buf.append(fBinding.toString());
            break;
        }

    } else {
        buf.append("null"); //$NON-NLS-1$
    }
    return buf.toString();

}

From source file:com.dforensic.plugin.manal.model.ApiDescriptor.java

License:Open Source License

public ApiDescriptor(MethodInvocation method) {
    IMethodBinding methodBinding = method.resolveMethodBinding();
    if (methodBinding != null) {
        mMethodName = methodBinding.getName();
        ITypeBinding[] argMethods = methodBinding.getParameterTypes();
        ITypeBinding retMethod = methodBinding.getReturnType();
        boolean isConstructor = methodBinding.isConstructor();
        ITypeBinding declaringClass = methodBinding.getDeclaringClass();

        MethodType methodType = MethodType.NORMAL;
        if (isConstructor) {
            methodType = MethodType.CONSTRUCTOR;
        }/*from www .  j  a va  2s. c o m*/
        mMethodType = methodType;

        if (declaringClass != null) {
            mClassName = declaringClass.getName();
            IPackageBinding pckg = declaringClass.getPackage();
            if (pckg != null) {
                mPackageName = pckg.getName();
            } else {
                System.out.println(">>inf: package is not specified.");
            }
        } else {
            System.out.println(">>inf: class is not specified.");
        }
        if (retMethod != null) {
            mReturnType = retMethod.getName();
        } else {
            System.out.println(">>inf: return type is not specified.");
        }
        if (argMethods != null) {
            mParams = new ArrayList<ParameterDescriptor>(argMethods.length);
            int pos = 1;
            for (ITypeBinding param : argMethods) {
                if (param != null) {
                    String paramName = param.getName();
                    ITypeBinding paramType = param.getTypeDeclaration();
                    String paramTypeName = null;
                    if (paramType != null) {
                        paramTypeName = paramType.getName();
                    }
                    mParams.add(new ParameterDescriptor(paramName, paramTypeName, pos));
                    pos++;
                } else {
                    System.out.println(">>error: parameter is NULL.");
                }
            }
        } else {
            System.out.println(">>inf: method parameters are not specified.");
        }
    } else {
        System.out.println(">>warning: method binding can't be resolved.");
    }
}

From source file:com.dforensic.plugin.manal.model.ApiDescriptor.java

License:Open Source License

private boolean compareAttributes(String name, ITypeBinding declaringClass, ITypeBinding[] args,
        ITypeBinding ret, boolean isConstructor) {
    boolean matched = false;
    if (mMethodName != null) {
        if (mMethodName.equals(name)) {
            matched = true;//from  w w  w.j a  va 2 s.c  o  m
        } else {
            System.out.println(">>inf: method names are not matched.");
            return false;
        }
    } else {
        System.out.println(">>inf: method name is not specified.");
    }
    MethodType methodType = MethodType.NORMAL;
    if (isConstructor) {
        methodType = MethodType.CONSTRUCTOR;
    }
    if (mMethodType.equals(methodType)) {
        matched = true;
    } else {
        System.out.println(">>inf: method type is not matched.");
        return false;
    }
    if ((mClassName != null) && declaringClass != null) {
        if (mClassName.equals(declaringClass.getName())) {
            matched = true;
        } else {
            System.out.println(">>inf: class names are not matched.");
            return false;
        }
        IPackageBinding pckg = declaringClass.getPackage();
        if ((mPackageName != null) && pckg != null) {
            if (mPackageName.equals(pckg.getName())) {
                matched = true;
            } else {
                System.out.println(">>inf: package names are not matched.");
                return false;
            }
        } else {
            System.out.println(">>inf: package is not specified.");
        }
    } else {
        System.out.println(">>inf: class is not specified.");
    }
    if ((mReturnType != null) && (ret != null)) {
        if (mReturnType.equals(ret.getName())) {
            matched = true;
        } else {
            System.out.println(">>inf: return types are not matched.");
            return false;
        }
    } else {
        System.out.println(">>inf: return type is not specified.");
    }
    if ((mParams != null) && (args != null)) {
        for (ParameterDescriptor param : mParams) {
            if ((param != null) && (param.getPos() >= 0) && (param.getPos() < args.length)) {
                String paramName = param.getName();
                if ((paramName != null) && paramName.equals(args[param.getPos()].getName())) {
                    matched = true;
                } else {
                    System.out.println(">>inf: parameters are not matched.");
                    return false;
                }
            } else {
                System.out.println(">>error: bad configuration of parameters.");
            }
        }
    } else {
        System.out.println(">>inf: method parameters are not specified.");
    }

    return matched;
}

From source file:com.google.dart.java2dart.util.JavaUtils.java

License:Open Source License

/**
 * @param binding the {@link ITypeBinding} to analyze.
 * @param runtime flag <code>true</code> if we need name for class loading, <code>false</code> if
 *          we need name for source generation.
 * @param withGenerics flag <code>true</code> if generics type arguments should be appended.
 * @return the fully qualified name of given {@link ITypeBinding}, or
 *         {@link #NO_TYPE_BINDING_NAME} .
 *///from ww w.j a  v  a 2s  . co m
public static String getFullyQualifiedName(ITypeBinding binding, boolean runtime, boolean withGenerics) {
    // check if no binding
    if (binding == null) {
        return NO_TYPE_BINDING_NAME;
    }
    // check for primitive type
    if (binding.isPrimitive()) {
        return binding.getName();
    }
    // array
    if (binding.isArray()) {
        StringBuilder sb = new StringBuilder();
        // append element type qualified name
        ITypeBinding elementType = binding.getElementType();
        String elementTypeQualifiedName = getFullyQualifiedName(elementType, runtime);
        sb.append(elementTypeQualifiedName);
        // append dimensions
        for (int i = 0; i < binding.getDimensions(); i++) {
            sb.append("[]");
        }
        // done
        return sb.toString();
    }
    // object
    {
        String scope;
        ITypeBinding declaringType = binding.getDeclaringClass();
        if (declaringType == null) {
            IPackageBinding packageBinding = binding.getPackage();
            if (packageBinding == null || packageBinding.isUnnamed()) {
                scope = "";
            } else {
                scope = packageBinding.getName() + ".";
            }
        } else if (binding.isTypeVariable()) {
            return binding.getName();
        } else {
            // use '$', because we use this class name for loading class
            scope = getFullyQualifiedName(declaringType, runtime);
            if (runtime) {
                scope += "$";
            } else {
                scope += ".";
            }
        }
        // prepare "simple" name, without scope
        String jdtName = binding.getName();
        String name = StringUtils.substringBefore(jdtName, "<");
        if (withGenerics) {
            ITypeBinding[] typeArguments = binding.getTypeArguments();
            if (typeArguments.length != 0) {
                StringBuilder sb = new StringBuilder(name);
                sb.append("<");
                for (ITypeBinding typeArgument : typeArguments) {
                    if (sb.charAt(sb.length() - 1) != '<') {
                        sb.append(",");
                    }
                    String typeArgumentName = getFullyQualifiedName(typeArgument, runtime, withGenerics);
                    sb.append(typeArgumentName);
                }
                sb.append(">");
                name = sb.toString();
            }
        }
        // qualified name is scope plus "simple" name
        return scope + name;
    }
}

From source file:com.google.devtools.j2cpp.util.NameTable.java

License:Open Source License

public static String getFullName(ITypeBinding binding) {
    if (binding.isPrimitive()) {
        return primitiveTypeToCpp(binding.getName());
    }//from www.j  a va  2  s . c o m
    binding = Types.mapType(binding.getErasure()); // Make sure type variables aren't included.
    String suffix = binding.isEnum() ? "Enum" : "";
    String prefix = "";
    IMethodBinding outerMethod = binding.getDeclaringMethod();
    if (outerMethod != null && !binding.isAnonymous()) {
        prefix += "_" + outerMethod.getName();
    }
    ITypeBinding outerBinding = binding.getDeclaringClass();
    if (outerBinding != null) {
        while (outerBinding.isAnonymous()) {
            prefix += "_" + outerBinding.getName();
            outerBinding = outerBinding.getDeclaringClass();
        }
        String baseName = getFullName(outerBinding) + prefix + '_' + getName(binding);
        return outerBinding.isEnum() ? baseName : baseName + suffix;
    }
    IPackageBinding pkg = binding.getPackage();
    String pkgName = pkg != null ? getPrefix(pkg.getName()) : "";
    return pkgName + binding.getName() + suffix;
}

From source file:com.google.devtools.j2cpp.util.NameTableCpp.java

License:Open Source License

public static String getFullName(ITypeBinding binding) {
    if (binding.isPrimitive()) {
        return primitiveTypeToCpp(binding.getName());
    }/* w  w w .  j  ava2  s. co m*/
    binding = Types.mapType(binding.getErasure()); // Make sure type variables aren't included.
    String suffix = binding.isEnum() ? "Enum" : "";
    String prefix = "";
    IMethodBinding outerMethod = binding.getDeclaringMethod();
    if (outerMethod != null && !binding.isAnonymous()) {
        prefix += "_" + outerMethod.getName();
    }
    ITypeBinding outerBinding = binding.getDeclaringClass();
    if (outerBinding != null) {
        while (outerBinding.isAnonymous()) {
            prefix += "_" + outerBinding.getName();
            outerBinding = outerBinding.getDeclaringClass();
        }
        String baseName = getFullName(outerBinding) + prefix + '_' + NameTable.getName(binding);
        return outerBinding.isEnum() ? baseName : baseName + suffix;
    }
    IPackageBinding pkg = binding.getPackage();
    String pkgName = pkg != null ? NameTable.getPrefix(pkg.getName()) : "";
    return pkgName + binding.getName() + suffix;
}

From source file:com.google.devtools.j2objc.jdt.JdtPackageElement.java

License:Apache License

JdtPackageElement(IPackageBinding binding) {
    super(binding, binding.getName(), 0);
}

From source file:com.google.devtools.j2objc.util.NameTable.java

License:Open Source License

/**
 * Return the prefix for a specified package. If a prefix was specified
 * for the package, then that prefix is returned. Otherwise, a camel-cased
 * prefix is created from the package name.
 *//*  w  w  w . j  ava 2s .  c  o m*/
public String getPrefix(IPackageBinding packageBinding) {
    String packageName = packageBinding.getName();
    if (hasPrefix(packageName)) {
        return prefixMap.get(packageName);
    }

    for (IAnnotationBinding annotation : packageBinding.getAnnotations()) {
        if (annotation.getName().endsWith("ObjectiveCName")) {
            String prefix = (String) BindingUtil.getAnnotationValue(annotation, "value");
            prefixMap.put(packageName, prefix);
            // Don't return, as there may be a prefix annotation that overrides this value.
        }
    }

    String prefix = getPrefixFromPackageInfoSource(packageBinding);
    if (prefix == null) {
        prefix = getPrefixFromPackageInfoClass(packageName);
    }
    if (prefix == null) {
        prefix = camelCaseQualifiedName(packageName);
    }
    prefixMap.put(packageName, prefix);
    return prefix;
}