List of usage examples for org.eclipse.jdt.core.dom IMethodBinding isDefaultConstructor
public boolean isDefaultConstructor();
From source file:astview.Binding.java
License:Open Source License
@Override public Object[] getChildren() { try {//from ww w . jav a 2 s . co m if (fBinding != null) { fBinding.getKey(); } } catch (RuntimeException e) { return new Object[] { new Error(this, "BrokenBinding: " + fBinding, null) }; } if (fBinding != null) { ArrayList<ASTAttribute> res = new ArrayList<>(); res.add(new BindingProperty(this, "NAME", fBinding.getName(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "KEY", fBinding.getKey(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS RECOVERED", fBinding.isRecovered(), true)); //$NON-NLS-1$ switch (fBinding.getKind()) { case IBinding.VARIABLE: IVariableBinding variableBinding = (IVariableBinding) fBinding; res.add(new BindingProperty(this, "IS FIELD", variableBinding.isField(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS ENUM CONSTANT", variableBinding.isEnumConstant(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS PARAMETER", variableBinding.isParameter(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "VARIABLE ID", variableBinding.getVariableId(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "MODIFIERS", getModifiersString(fBinding.getModifiers(), false), //$NON-NLS-1$ true)); res.add(new Binding(this, "TYPE", variableBinding.getType(), true)); //$NON-NLS-1$ res.add(new Binding(this, "DECLARING CLASS", variableBinding.getDeclaringClass(), true)); //$NON-NLS-1$ res.add(new Binding(this, "DECLARING METHOD", variableBinding.getDeclaringMethod(), true)); //$NON-NLS-1$ res.add(new Binding(this, "VARIABLE DECLARATION", variableBinding.getVariableDeclaration(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "CONSTANT VALUE", variableBinding.getConstantValue(), true)); //$NON-NLS-1$ //$NON-NLS-2$ res.add(new BindingProperty(this, "IS EFFECTIVELY FINAL", variableBinding.isEffectivelyFinal(), //$NON-NLS-1$ true)); break; case IBinding.PACKAGE: IPackageBinding packageBinding = (IPackageBinding) fBinding; res.add(new BindingProperty(this, "IS UNNAMED", packageBinding.isUnnamed(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$ break; case IBinding.TYPE: ITypeBinding typeBinding = (ITypeBinding) fBinding; res.add(new BindingProperty(this, "QUALIFIED NAME", typeBinding.getQualifiedName(), true)); //$NON-NLS-1$ int typeKind = getTypeKind(typeBinding); boolean isRefType = isType(typeKind, REF_TYPE); final boolean isNonPrimitive = !isType(typeKind, PRIMITIVE_TYPE); StringBuffer kinds = new StringBuffer("KIND:"); //$NON-NLS-1$ if (typeBinding.isArray()) kinds.append(" isArray"); //$NON-NLS-1$ if (typeBinding.isCapture()) kinds.append(" isCapture"); //$NON-NLS-1$ if (typeBinding.isNullType()) kinds.append(" isNullType"); //$NON-NLS-1$ if (typeBinding.isPrimitive()) kinds.append(" isPrimitive"); //$NON-NLS-1$ if (typeBinding.isTypeVariable()) kinds.append(" isTypeVariable"); //$NON-NLS-1$ if (typeBinding.isWildcardType()) kinds.append(" isWildcardType"); //$NON-NLS-1$ // ref types if (typeBinding.isAnnotation()) kinds.append(" isAnnotation"); //$NON-NLS-1$ if (typeBinding.isClass()) kinds.append(" isClass"); //$NON-NLS-1$ if (typeBinding.isInterface()) kinds.append(" isInterface"); //$NON-NLS-1$ if (typeBinding.isEnum()) kinds.append(" isEnum"); //$NON-NLS-1$ res.add(new BindingProperty(this, kinds, true)); //$NON-NLS-1$ StringBuffer generics = new StringBuffer("GENERICS:"); //$NON-NLS-1$ if (typeBinding.isRawType()) generics.append(" isRawType"); //$NON-NLS-1$ if (typeBinding.isGenericType()) generics.append(" isGenericType"); //$NON-NLS-1$ if (typeBinding.isParameterizedType()) generics.append(" isParameterizedType"); //$NON-NLS-1$ if (!isType(typeKind, GENERIC | PARAMETRIZED)) { generics.append(" (non-generic, non-parameterized)"); } res.add(new BindingProperty(this, generics, isRefType)); //$NON-NLS-1$ res.add(new Binding(this, "ELEMENT TYPE", typeBinding.getElementType(), //$NON-NLS-1$ isType(typeKind, ARRAY_TYPE))); res.add(new Binding(this, "COMPONENT TYPE", typeBinding.getComponentType(), //$NON-NLS-1$ isType(typeKind, ARRAY_TYPE))); res.add(new BindingProperty(this, "DIMENSIONS", typeBinding.getDimensions(), //$NON-NLS-1$ isType(typeKind, ARRAY_TYPE))); final String createArrayTypeLabel = "CREATE ARRAY TYPE (+1)"; try { ITypeBinding arrayType = typeBinding.createArrayType(1); res.add(new Binding(this, createArrayTypeLabel, arrayType, true)); } catch (RuntimeException e) { String msg = e.getClass().getName() + ": " + e.getLocalizedMessage(); boolean isRelevant = !typeBinding.getName().equals(PrimitiveType.VOID.toString()) && !typeBinding.isRecovered(); if (isRelevant) { res.add(new Error(this, createArrayTypeLabel + ": " + msg, e)); } else { res.add(new BindingProperty(this, createArrayTypeLabel, msg, false)); } } StringBuffer origin = new StringBuffer("ORIGIN:"); //$NON-NLS-1$ if (typeBinding.isTopLevel()) origin.append(" isTopLevel"); //$NON-NLS-1$ if (typeBinding.isNested()) origin.append(" isNested"); //$NON-NLS-1$ if (typeBinding.isLocal()) origin.append(" isLocal"); //$NON-NLS-1$ if (typeBinding.isMember()) origin.append(" isMember"); //$NON-NLS-1$ if (typeBinding.isAnonymous()) origin.append(" isAnonymous"); //$NON-NLS-1$ res.add(new BindingProperty(this, origin, isRefType)); res.add(new BindingProperty(this, "IS FROM SOURCE", typeBinding.isFromSource(), //$NON-NLS-1$ isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE))); res.add(new Binding(this, "PACKAGE", typeBinding.getPackage(), isRefType)); //$NON-NLS-1$ res.add(new Binding(this, "DECLARING CLASS", typeBinding.getDeclaringClass(), //$NON-NLS-1$ isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE))); res.add(new Binding(this, "DECLARING METHOD", typeBinding.getDeclaringMethod(), //$NON-NLS-1$ isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE))); // res.add(new Binding(this, "DECLARING MEMBER", typeBinding.getDeclaringMember(), typeBinding.isLocal())); //$NON-NLS-1$ res.add(new BindingProperty(this, "MODIFIERS", getModifiersString(fBinding.getModifiers(), false), //$NON-NLS-1$ isRefType)); res.add(new BindingProperty(this, "BINARY NAME", typeBinding.getBinaryName(), true)); //$NON-NLS-1$ String isTypeDeclaration = typeBinding == typeBinding.getTypeDeclaration() ? " ( == this)" : " ( != this)"; res.add(new Binding(this, "TYPE DECLARATION" + isTypeDeclaration, typeBinding.getTypeDeclaration(), //$NON-NLS-1$ true)); String isErasure = typeBinding == typeBinding.getErasure() ? " ( == this)" : " ( != this)"; res.add(new Binding(this, "ERASURE" + isErasure, typeBinding.getErasure(), isNonPrimitive)); //$NON-NLS-1$ res.add(new BindingProperty(this, "TYPE PARAMETERS", typeBinding.getTypeParameters(), //$NON-NLS-1$ isType(typeKind, GENERIC))); res.add(new BindingProperty(this, "TYPE ARGUMENTS", typeBinding.getTypeArguments(), //$NON-NLS-1$ isType(typeKind, PARAMETRIZED))); res.add(new BindingProperty(this, "TYPE BOUNDS", typeBinding.getTypeBounds(), //$NON-NLS-1$ isType(typeKind, VARIABLE_TYPE | WILDCARD_TYPE | CAPTURE_TYPE))); res.add(new Binding(this, "BOUND", typeBinding.getBound(), isType(typeKind, WILDCARD_TYPE))); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS UPPERBOUND", typeBinding.isUpperbound(), //$NON-NLS-1$ isType(typeKind, WILDCARD_TYPE))); res.add(new Binding(this, "GENERIC TYPE OF WILDCARD TYPE", //$NON-NLS-1$ typeBinding.getGenericTypeOfWildcardType(), isType(typeKind, WILDCARD_TYPE))); res.add(new BindingProperty(this, "RANK", typeBinding.getRank(), isType(typeKind, WILDCARD_TYPE))); //$NON-NLS-1$ res.add(new Binding(this, "WILDCARD", typeBinding.getWildcard(), isType(typeKind, CAPTURE_TYPE))); //$NON-NLS-1$ res.add(new Binding(this, "SUPERCLASS", typeBinding.getSuperclass(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "INTERFACES", typeBinding.getInterfaces(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "DECLARED TYPES", typeBinding.getDeclaredTypes(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "DECLARED FIELDS", typeBinding.getDeclaredFields(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "DECLARED METHODS", typeBinding.getDeclaredMethods(), isRefType)); //$NON-NLS-1$ res.add(new Binding(this, "FUNCTIONAL INTERFACE METHOD", typeBinding.getFunctionalInterfaceMethod(), //$NON-NLS-1$ typeBinding.isInterface())); res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), isNonPrimitive)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "TYPE ANNOTATIONS", typeBinding.getTypeAnnotations(), true)); //$NON-NLS-1$ break; case IBinding.METHOD: IMethodBinding methodBinding = (IMethodBinding) fBinding; res.add(new BindingProperty(this, "IS CONSTRUCTOR", methodBinding.isConstructor(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEFAULT CONSTRUCTOR", methodBinding.isDefaultConstructor(), //$NON-NLS-1$ true)); res.add(new Binding(this, "DECLARING CLASS", methodBinding.getDeclaringClass(), true)); //$NON-NLS-1$ // res.add(new Binding(this, "DECLARING MEMBER", methodBinding.getDeclaringMember(), methodBinding.getDeclaringMember() != null)); //$NON-NLS-1$ res.add(new Binding(this, "RETURN TYPE", methodBinding.getReturnType(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "MODIFIERS", getModifiersString(fBinding.getModifiers(), true), //$NON-NLS-1$ true)); res.add(new BindingProperty(this, "PARAMETER TYPES", methodBinding.getParameterTypes(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS VARARGS", methodBinding.isVarargs(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "EXCEPTION TYPES", methodBinding.getExceptionTypes(), true)); //$NON-NLS-1$ StringBuffer genericsM = new StringBuffer("GENERICS:"); //$NON-NLS-1$ if (methodBinding.isRawMethod()) genericsM.append(" isRawMethod"); //$NON-NLS-1$ if (methodBinding.isGenericMethod()) genericsM.append(" isGenericMethod"); //$NON-NLS-1$ if (methodBinding.isParameterizedMethod()) genericsM.append(" isParameterizedMethod"); //$NON-NLS-1$ res.add(new BindingProperty(this, genericsM, true)); String isMethodDeclaration = methodBinding == methodBinding.getMethodDeclaration() ? " ( == this)" : " ( != this)"; res.add(new Binding(this, "METHOD DECLARATION" + isMethodDeclaration, //$NON-NLS-1$ methodBinding.getMethodDeclaration(), true)); res.add(new BindingProperty(this, "TYPE PARAMETERS", methodBinding.getTypeParameters(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "TYPE ARGUMENTS", methodBinding.getTypeArguments(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS ANNOTATION MEMBER", methodBinding.isAnnotationMember(), //$NON-NLS-1$ true)); res.add(Binding.createValueAttribute(this, "DEFAULT VALUE", methodBinding.getDefaultValue())); int parameterCount = methodBinding.getParameterTypes().length; BindingProperty[] parametersAnnotations = new BindingProperty[parameterCount]; for (int i = 0; i < parameterCount; i++) { parametersAnnotations[i] = new BindingProperty(this, "Parameter " + String.valueOf(i), methodBinding.getParameterAnnotations(i), true); } res.add(new BindingProperty(this, "PARAMETER ANNOTATIONS", parametersAnnotations, true)); break; case IBinding.ANNOTATION: IAnnotationBinding annotationBinding = (IAnnotationBinding) fBinding; res.add(new Binding(this, "ANNOTATION TYPE", annotationBinding.getAnnotationType(), true)); res.add(new BindingProperty(this, "DECLARED MEMBER VALUE PAIRS", annotationBinding.getDeclaredMemberValuePairs(), true)); res.add(new BindingProperty(this, "ALL MEMBER VALUE PAIRS", annotationBinding.getAllMemberValuePairs(), true)); break; case IBinding.MEMBER_VALUE_PAIR: IMemberValuePairBinding memberValuePairBinding = (IMemberValuePairBinding) fBinding; res.add(new Binding(this, "METHOD BINDING", memberValuePairBinding.getMethodBinding(), true)); res.add(new BindingProperty(this, "IS DEFAULT", memberValuePairBinding.isDefault(), true)); res.add(Binding.createValueAttribute(this, "VALUE", memberValuePairBinding.getValue())); break; } try { IAnnotationBinding[] annotations = fBinding.getAnnotations(); res.add(new BindingProperty(this, "ANNOTATIONS", annotations, true)); //$NON-NLS-1$ } catch (RuntimeException e) { String label = "Error in IBinding#getAnnotations() for \"" + fBinding.getKey() + "\""; res.add(new Error(this, label, e)); } try { IJavaElement javaElement = fBinding.getJavaElement(); } catch (RuntimeException e) { String label = ">java element: " + e.getClass().getName() + " for \"" + fBinding.getKey() + "\""; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ res.add(new Error(this, label, e)); } return res.toArray(); } return EMPTY; }
From source file:cideplus.ui.astview.Binding.java
License:Open Source License
public Object[] getChildren() { if (fBinding != null) { ArrayList res = new ArrayList(); res.add(new BindingProperty(this, "NAME", fBinding.getName(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "KEY", fBinding.getKey(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS RECOVERED", fBinding.isRecovered(), true)); //$NON-NLS-1$ switch (fBinding.getKind()) { case IBinding.VARIABLE: IVariableBinding variableBinding = (IVariableBinding) fBinding; res.add(new BindingProperty(this, "IS FIELD", variableBinding.isField(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS ENUM CONSTANT", variableBinding.isEnumConstant(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS PARAMETER", variableBinding.isParameter(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "VARIABLE ID", variableBinding.getVariableId(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "MODIFIERS", Flags.toString(fBinding.getModifiers()), true)); //$NON-NLS-1$ res.add(new Binding(this, "TYPE", variableBinding.getType(), true)); //$NON-NLS-1$ res.add(new Binding(this, "DECLARING CLASS", variableBinding.getDeclaringClass(), true)); //$NON-NLS-1$ res.add(new Binding(this, "DECLARING METHOD", variableBinding.getDeclaringMethod(), true)); //$NON-NLS-1$ res.add(new Binding(this, "VARIABLE DECLARATION", variableBinding.getVariableDeclaration(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "CONSTANT VALUE", variableBinding.getConstantValue(), true)); //$NON-NLS-1$ //$NON-NLS-2$ break; case IBinding.PACKAGE: IPackageBinding packageBinding = (IPackageBinding) fBinding; res.add(new BindingProperty(this, "IS UNNAMED", packageBinding.isUnnamed(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$ break; case IBinding.TYPE: if (1 == 1) { break;//no iremos mostrar todas essas informaes da classe }/* w w w . j ava 2s . co m*/ ITypeBinding typeBinding = (ITypeBinding) fBinding; res.add(new BindingProperty(this, "QUALIFIED NAME", typeBinding.getQualifiedName(), true)); //$NON-NLS-1$ int typeKind = getTypeKind(typeBinding); boolean isRefType = isType(typeKind, REF_TYPE); final boolean isNonPrimitive = !isType(typeKind, PRIMITIVE_TYPE); StringBuffer kinds = new StringBuffer("KIND:"); //$NON-NLS-1$ if (typeBinding.isArray()) kinds.append(" isArray"); //$NON-NLS-1$ if (typeBinding.isCapture()) kinds.append(" isCapture"); //$NON-NLS-1$ if (typeBinding.isNullType()) kinds.append(" isNullType"); //$NON-NLS-1$ if (typeBinding.isPrimitive()) kinds.append(" isPrimitive"); //$NON-NLS-1$ if (typeBinding.isTypeVariable()) kinds.append(" isTypeVariable"); //$NON-NLS-1$ if (typeBinding.isWildcardType()) kinds.append(" isWildcardType"); //$NON-NLS-1$ // ref types if (typeBinding.isAnnotation()) kinds.append(" isAnnotation"); //$NON-NLS-1$ if (typeBinding.isClass()) kinds.append(" isClass"); //$NON-NLS-1$ if (typeBinding.isInterface()) kinds.append(" isInterface"); //$NON-NLS-1$ if (typeBinding.isEnum()) kinds.append(" isEnum"); //$NON-NLS-1$ res.add(new BindingProperty(this, kinds, true)); //$NON-NLS-1$ StringBuffer generics = new StringBuffer("GENERICS:"); //$NON-NLS-1$ if (typeBinding.isRawType()) generics.append(" isRawType"); //$NON-NLS-1$ if (typeBinding.isGenericType()) generics.append(" isGenericType"); //$NON-NLS-1$ if (typeBinding.isParameterizedType()) generics.append(" isParameterizedType"); //$NON-NLS-1$ if (!isType(typeKind, GENERIC | PARAMETRIZED)) { generics.append(" (non-generic, non-parameterized)"); } res.add(new BindingProperty(this, generics, isRefType)); //$NON-NLS-1$ res.add(new Binding(this, "ELEMENT TYPE", typeBinding.getElementType(), //$NON-NLS-1$ isType(typeKind, ARRAY_TYPE))); res.add(new Binding(this, "COMPONENT TYPE", typeBinding.getComponentType(), //$NON-NLS-1$ isType(typeKind, ARRAY_TYPE))); res.add(new BindingProperty(this, "DIMENSIONS", typeBinding.getDimensions(), //$NON-NLS-1$ isType(typeKind, ARRAY_TYPE))); final String createArrayTypeLabel = "CREATE ARRAY TYPE (+1)"; try { ITypeBinding arrayType = typeBinding.createArrayType(1); res.add(new Binding(this, createArrayTypeLabel, arrayType, true)); } catch (RuntimeException e) { String msg = e.getClass().getName() + ": " + e.getLocalizedMessage(); boolean isRelevant = !typeBinding.getName().equals(PrimitiveType.VOID.toString()) && !typeBinding.isRecovered(); if (isRelevant) { res.add(new Error(this, createArrayTypeLabel + ": " + msg, e)); } else { res.add(new BindingProperty(this, createArrayTypeLabel, msg, false)); } } res.add(new BindingProperty(this, "TYPE BOUNDS", typeBinding.getTypeBounds(), //$NON-NLS-1$ isType(typeKind, VARIABLE_TYPE | CAPTURE_TYPE))); StringBuffer origin = new StringBuffer("ORIGIN:"); //$NON-NLS-1$ if (typeBinding.isTopLevel()) origin.append(" isTopLevel"); //$NON-NLS-1$ if (typeBinding.isNested()) origin.append(" isNested"); //$NON-NLS-1$ if (typeBinding.isLocal()) origin.append(" isLocal"); //$NON-NLS-1$ if (typeBinding.isMember()) origin.append(" isMember"); //$NON-NLS-1$ if (typeBinding.isAnonymous()) origin.append(" isAnonymous"); //$NON-NLS-1$ res.add(new BindingProperty(this, origin, isRefType)); res.add(new BindingProperty(this, "IS FROM SOURCE", typeBinding.isFromSource(), //$NON-NLS-1$ isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE))); res.add(new Binding(this, "PACKAGE", typeBinding.getPackage(), isRefType)); //$NON-NLS-1$ res.add(new Binding(this, "DECLARING CLASS", typeBinding.getDeclaringClass(), //$NON-NLS-1$ isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE))); res.add(new Binding(this, "DECLARING METHOD", typeBinding.getDeclaringMethod(), //$NON-NLS-1$ isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE))); res.add(new BindingProperty(this, "MODIFIERS", Flags.toString(fBinding.getModifiers()), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "BINARY NAME", typeBinding.getBinaryName(), true)); //$NON-NLS-1$ res.add(new Binding(this, "TYPE DECLARATION", typeBinding.getTypeDeclaration(), isNonPrimitive)); //$NON-NLS-1$ res.add(new Binding(this, "ERASURE", typeBinding.getErasure(), isNonPrimitive)); //$NON-NLS-1$ res.add(new BindingProperty(this, "TYPE PARAMETERS", typeBinding.getTypeParameters(), //$NON-NLS-1$ isType(typeKind, GENERIC))); res.add(new BindingProperty(this, "TYPE ARGUMENTS", typeBinding.getTypeArguments(), //$NON-NLS-1$ isType(typeKind, PARAMETRIZED))); res.add(new Binding(this, "BOUND", typeBinding.getBound(), isType(typeKind, WILDCARD_TYPE))); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS UPPERBOUND", typeBinding.isUpperbound(), //$NON-NLS-1$ isType(typeKind, WILDCARD_TYPE))); res.add(new Binding(this, "GENERIC TYPE OF WILDCARD TYPE", //$NON-NLS-1$ typeBinding.getGenericTypeOfWildcardType(), isType(typeKind, WILDCARD_TYPE))); res.add(new BindingProperty(this, "RANK", typeBinding.getRank(), isType(typeKind, WILDCARD_TYPE))); //$NON-NLS-1$ res.add(new Binding(this, "WILDCARD", typeBinding.getWildcard(), isType(typeKind, CAPTURE_TYPE))); //$NON-NLS-1$ res.add(new Binding(this, "SUPERCLASS", typeBinding.getSuperclass(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "INTERFACES", typeBinding.getInterfaces(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "DECLARED TYPES", typeBinding.getDeclaredTypes(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "DECLARED FIELDS", typeBinding.getDeclaredFields(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "DECLARED METHODS", typeBinding.getDeclaredMethods(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), isNonPrimitive)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), isRefType)); //$NON-NLS-1$ break; case IBinding.METHOD: IMethodBinding methodBinding = (IMethodBinding) fBinding; res.add(new BindingProperty(this, "IS CONSTRUCTOR", methodBinding.isConstructor(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEFAULT CONSTRUCTOR", methodBinding.isDefaultConstructor(), //$NON-NLS-1$ true)); res.add(new Binding(this, "DECLARING CLASS", methodBinding.getDeclaringClass(), true)); //$NON-NLS-1$ res.add(new Binding(this, "RETURN TYPE", methodBinding.getReturnType(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "MODIFIERS", Flags.toString(fBinding.getModifiers()), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "PARAMETER TYPES", methodBinding.getParameterTypes(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS VARARGS", methodBinding.isVarargs(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "EXCEPTION TYPES", methodBinding.getExceptionTypes(), true)); //$NON-NLS-1$ StringBuffer genericsM = new StringBuffer("GENERICS:"); //$NON-NLS-1$ if (methodBinding.isRawMethod()) genericsM.append(" isRawMethod"); //$NON-NLS-1$ if (methodBinding.isGenericMethod()) genericsM.append(" isGenericMethod"); //$NON-NLS-1$ if (methodBinding.isParameterizedMethod()) genericsM.append(" isParameterizedMethod"); //$NON-NLS-1$ res.add(new BindingProperty(this, genericsM, true)); res.add(new Binding(this, "METHOD DECLARATION", methodBinding.getMethodDeclaration(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "TYPE PARAMETERS", methodBinding.getTypeParameters(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "TYPE ARGUMENTS", methodBinding.getTypeArguments(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS ANNOTATION MEMBER", methodBinding.isAnnotationMember(), //$NON-NLS-1$ true)); res.add(Binding.createValueAttribute(this, "DEFAULT VALUE", methodBinding.getDefaultValue())); int parameterCount = methodBinding.getParameterTypes().length; GeneralAttribute[] parametersAnnotations = new GeneralAttribute[parameterCount]; for (int i = 0; i < parameterCount; i++) { parametersAnnotations[i] = new GeneralAttribute(this, "Parameter " + String.valueOf(i), methodBinding.getParameterAnnotations(i)); } res.add(new GeneralAttribute(this, "PARAMETER ANNOTATIONS", parametersAnnotations)); break; case IBinding.ANNOTATION: IAnnotationBinding annotationBinding = (IAnnotationBinding) fBinding; res.add(new Binding(this, "ANNOTATION TYPE", annotationBinding.getAnnotationType(), true)); res.add(new BindingProperty(this, "DECLARED MEMBER VALUE PAIRS", annotationBinding.getDeclaredMemberValuePairs(), true)); res.add(new BindingProperty(this, "ALL MEMBER VALUE PAIRS", annotationBinding.getAllMemberValuePairs(), true)); break; case IBinding.MEMBER_VALUE_PAIR: IMemberValuePairBinding memberValuePairBinding = (IMemberValuePairBinding) fBinding; res.add(new Binding(this, "METHOD BINDING", memberValuePairBinding.getMethodBinding(), true)); res.add(new BindingProperty(this, "IS DEFAULT", memberValuePairBinding.isDefault(), true)); res.add(Binding.createValueAttribute(this, "VALUE", memberValuePairBinding.getValue())); break; } try { IAnnotationBinding[] annotations = fBinding.getAnnotations(); res.add(new BindingProperty(this, "ANNOTATIONS", annotations, true)); //$NON-NLS-1$ } catch (RuntimeException e) { String label = "Error in IBinding#getAnnotations() for \"" + fBinding.getKey() + "\""; res.add(new Error(this, label, e)); ASTViewPlugin.log("Exception thrown in IBinding#getAnnotations() for \"" + fBinding.getKey() + "\"", e); } try { IJavaElement javaElement = fBinding.getJavaElement(); res.add(new JavaElement(this, javaElement)); } catch (RuntimeException e) { String label = ">java element: " + e.getClass().getName() + " for \"" + fBinding.getKey() + "\""; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ res.add(new Error(this, label, e)); ASTViewPlugin.log("Exception thrown in IBinding#getJavaElement() for \"" + fBinding.getKey() + "\"", e); } return res.toArray(); } return EMPTY; }
From source file:coloredide.astview.internal.Binding.java
License:Open Source License
public Object[] getChildren() { if (fBinding != null) { ArrayList res = new ArrayList(); res.add(new BindingProperty(this, "NAME", fBinding.getName(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "KEY", fBinding.getKey(), true)); //$NON-NLS-1$ switch (fBinding.getKind()) { case IBinding.VARIABLE: IVariableBinding variableBinding = (IVariableBinding) fBinding; res.add(new BindingProperty(this, "IS FIELD", variableBinding.isField(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS ENUM CONSTANT", variableBinding.isEnumConstant(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS PARAMETER", variableBinding.isParameter(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "VARIABLE ID", variableBinding.getVariableId(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "MODIFIERS", Flags.toString(fBinding.getModifiers()), true)); //$NON-NLS-1$ res.add(new Binding(this, "TYPE", variableBinding.getType(), true)); //$NON-NLS-1$ res.add(new Binding(this, "DECLARING CLASS", variableBinding.getDeclaringClass(), true)); //$NON-NLS-1$ res.add(new Binding(this, "DECLARING METHOD", variableBinding.getDeclaringMethod(), true)); //$NON-NLS-1$ res.add(new Binding(this, "VARIABLE DECLARATION", variableBinding.getVariableDeclaration(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$ Object constVal = variableBinding.getConstantValue(); res.add(new BindingProperty(this, "CONSTANT VALUE", constVal == null ? "null" : constVal.toString(), //$NON-NLS-1$//$NON-NLS-2$ true));/* w w w . ja va2s .c o m*/ break; case IBinding.PACKAGE: IPackageBinding packageBinding = (IPackageBinding) fBinding; res.add(new BindingProperty(this, "IS UNNAMED", packageBinding.isUnnamed(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$ break; case IBinding.TYPE: ITypeBinding typeBinding = (ITypeBinding) fBinding; res.add(new BindingProperty(this, "QUALIFIED NAME", typeBinding.getQualifiedName(), true)); //$NON-NLS-1$ int typeKind = getTypeKind(typeBinding); boolean isRefType = isType(typeKind, REF_TYPE); final boolean isNonPrimitive = !isType(typeKind, PRIMITIVE_TYPE); StringBuffer kinds = new StringBuffer("KIND:"); //$NON-NLS-1$ if (typeBinding.isArray()) kinds.append(" isArray"); //$NON-NLS-1$ if (typeBinding.isCapture()) kinds.append(" isCapture"); //$NON-NLS-1$ if (typeBinding.isNullType()) kinds.append(" isNullType"); //$NON-NLS-1$ if (typeBinding.isPrimitive()) kinds.append(" isPrimitive"); //$NON-NLS-1$ if (typeBinding.isTypeVariable()) kinds.append(" isTypeVariable"); //$NON-NLS-1$ if (typeBinding.isWildcardType()) kinds.append(" isWildcardType"); //$NON-NLS-1$ // ref types if (typeBinding.isAnnotation()) kinds.append(" isAnnotation"); //$NON-NLS-1$ if (typeBinding.isClass()) kinds.append(" isClass"); //$NON-NLS-1$ if (typeBinding.isInterface()) kinds.append(" isInterface"); //$NON-NLS-1$ if (typeBinding.isEnum()) kinds.append(" isEnum"); //$NON-NLS-1$ res.add(new BindingProperty(this, kinds, true)); //$NON-NLS-1$ StringBuffer generics = new StringBuffer("GENERICS:"); //$NON-NLS-1$ if (typeBinding.isRawType()) generics.append(" isRawType"); //$NON-NLS-1$ if (typeBinding.isGenericType()) generics.append(" isGenericType"); //$NON-NLS-1$ if (typeBinding.isParameterizedType()) generics.append(" isParameterizedType"); //$NON-NLS-1$ if (!isType(typeKind, GENERIC | PARAMETRIZED)) { generics.append(" (non-generic, non-parameterized)"); } res.add(new BindingProperty(this, generics, isRefType)); //$NON-NLS-1$ res.add(new Binding(this, "ELEMENT TYPE", typeBinding.getElementType(), //$NON-NLS-1$ isType(typeKind, ARRAY_TYPE))); res.add(new Binding(this, "COMPONENT TYPE", typeBinding.getComponentType(), //$NON-NLS-1$ isType(typeKind, ARRAY_TYPE))); res.add(new BindingProperty(this, "DIMENSIONS", typeBinding.getDimensions(), //$NON-NLS-1$ isType(typeKind, ARRAY_TYPE))); res.add(new BindingProperty(this, "TYPE BOUNDS", typeBinding.getTypeBounds(), //$NON-NLS-1$ isType(typeKind, VARIABLE_TYPE | CAPTURE_TYPE))); StringBuffer origin = new StringBuffer("ORIGIN:"); //$NON-NLS-1$ if (typeBinding.isTopLevel()) origin.append(" isTopLevel"); //$NON-NLS-1$ if (typeBinding.isNested()) origin.append(" isNested"); //$NON-NLS-1$ if (typeBinding.isLocal()) origin.append(" isLocal"); //$NON-NLS-1$ if (typeBinding.isMember()) origin.append(" isMember"); //$NON-NLS-1$ if (typeBinding.isAnonymous()) origin.append(" isAnonymous"); //$NON-NLS-1$ res.add(new BindingProperty(this, origin, isRefType)); res.add(new BindingProperty(this, "IS FROM SOURCE", typeBinding.isFromSource(), //$NON-NLS-1$ isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE))); res.add(new Binding(this, "PACKAGE", typeBinding.getPackage(), isRefType)); //$NON-NLS-1$ res.add(new Binding(this, "DECLARING CLASS", typeBinding.getDeclaringClass(), //$NON-NLS-1$ isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE))); res.add(new Binding(this, "DECLARING METHOD", typeBinding.getDeclaringMethod(), //$NON-NLS-1$ isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE))); res.add(new BindingProperty(this, "MODIFIERS", Flags.toString(fBinding.getModifiers()), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "BINARY NAME", typeBinding.getBinaryName(), true)); //$NON-NLS-1$ res.add(new Binding(this, "TYPE DECLARATION", typeBinding.getTypeDeclaration(), isNonPrimitive)); //$NON-NLS-1$ res.add(new Binding(this, "ERASURE", typeBinding.getErasure(), isNonPrimitive)); //$NON-NLS-1$ res.add(new BindingProperty(this, "TYPE PARAMETERS", typeBinding.getTypeParameters(), //$NON-NLS-1$ isType(typeKind, GENERIC))); res.add(new BindingProperty(this, "TYPE ARGUMENTS", typeBinding.getTypeArguments(), //$NON-NLS-1$ isType(typeKind, PARAMETRIZED))); res.add(new Binding(this, "BOUND", typeBinding.getBound(), isType(typeKind, WILDCARD_TYPE))); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS UPPERBOUND", typeBinding.isUpperbound(), //$NON-NLS-1$ isType(typeKind, WILDCARD_TYPE))); res.add(new Binding(this, "WILDCARD", typeBinding.getWildcard(), isType(typeKind, CAPTURE_TYPE))); //$NON-NLS-1$ res.add(new Binding(this, "SUPERCLASS", typeBinding.getSuperclass(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "INTERFACES", typeBinding.getInterfaces(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "DECLARED TYPES", typeBinding.getDeclaredTypes(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "DECLARED FIELDS", typeBinding.getDeclaredFields(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "DECLARED METHODS", typeBinding.getDeclaredMethods(), isRefType)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), isNonPrimitive)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), isRefType)); //$NON-NLS-1$ break; case IBinding.METHOD: IMethodBinding methodBinding = (IMethodBinding) fBinding; res.add(new BindingProperty(this, "IS CONSTRUCTOR", methodBinding.isConstructor(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEFAULT CONSTRUCTOR", methodBinding.isDefaultConstructor(), //$NON-NLS-1$ true)); res.add(new Binding(this, "DECLARING CLASS", methodBinding.getDeclaringClass(), true)); //$NON-NLS-1$ res.add(new Binding(this, "RETURN TYPE", methodBinding.getReturnType(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "MODIFIERS", Flags.toString(fBinding.getModifiers()), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "PARAMETER TYPES", methodBinding.getParameterTypes(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS VARARGS", methodBinding.isVarargs(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "EXCEPTION TYPES", methodBinding.getExceptionTypes(), true)); //$NON-NLS-1$ StringBuffer genericsM = new StringBuffer("GENERICS:"); //$NON-NLS-1$ if (methodBinding.isRawMethod()) genericsM.append(" isRawMethod"); //$NON-NLS-1$ if (methodBinding.isGenericMethod()) genericsM.append(" isGenericMethod"); //$NON-NLS-1$ if (methodBinding.isParameterizedMethod()) genericsM.append(" isParameterizedMethod"); //$NON-NLS-1$ res.add(new BindingProperty(this, genericsM, true)); res.add(new Binding(this, "METHOD DECLARATION", methodBinding.getMethodDeclaration(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "TYPE PARAMETERS", methodBinding.getTypeParameters(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "TYPE ARGUMENTS", methodBinding.getTypeArguments(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS ANNOTATION MEMBER", methodBinding.isAnnotationMember(), //$NON-NLS-1$ true)); res.add(Binding.createValueAttribute(this, "DEFAULT VALUE", methodBinding.getDefaultValue())); int parameterCount = methodBinding.getParameterTypes().length; GeneralAttribute[] parametersAnnotations = new GeneralAttribute[parameterCount]; for (int i = 0; i < parameterCount; i++) { parametersAnnotations[i] = new GeneralAttribute(this, "Parameter " + String.valueOf(i), methodBinding.getParameterAnnotations(i)); } res.add(new GeneralAttribute(this, "PARAMETER ANNOTATIONS", parametersAnnotations)); break; case IBinding.ANNOTATION: IAnnotationBinding annotationBinding = (IAnnotationBinding) fBinding; res.add(new Binding(this, "ANNOTATION TYPE", annotationBinding.getAnnotationType(), true)); res.add(new BindingProperty(this, "DECLARED MEMBER VALUE PAIRS", annotationBinding.getDeclaredMemberValuePairs(), true)); res.add(new BindingProperty(this, "ALL MEMBER VALUE PAIRS", annotationBinding.getAllMemberValuePairs(), true)); break; case IBinding.MEMBER_VALUE_PAIR: IMemberValuePairBinding memberValuePairBinding = (IMemberValuePairBinding) fBinding; res.add(new Binding(this, "METHOD BINDING", memberValuePairBinding.getMethodBinding(), true)); res.add(new BindingProperty(this, "IS DEFAULT", memberValuePairBinding.isDefault(), true)); res.add(Binding.createValueAttribute(this, "VALUE", memberValuePairBinding.getValue())); break; } try { IAnnotationBinding[] annotations = fBinding.getAnnotations(); res.add(new BindingProperty(this, "ANNOTATIONS", annotations, true)); //$NON-NLS-1$ } catch (RuntimeException e) { String label = "Error in IBinding#getAnnotations() for \"" + fBinding.getKey() + "\""; res.add(new Error(this, label, e)); ColoredIDEPlugin .log("Exception thrown in IBinding#getAnnotations() for \"" + fBinding.getKey() + "\"", e); } try { IJavaElement javaElement = fBinding.getJavaElement(); res.add(new JavaElement(this, javaElement)); } catch (RuntimeException e) { String label = ">java element: " + e.getClass().getName() + " for \"" + fBinding.getKey() + "\""; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ res.add(new Error(this, label, e)); ColoredIDEPlugin .log("Exception thrown in IBinding#getJavaElement() for \"" + fBinding.getKey() + "\"", e); } return res.toArray(); } return EMPTY; }
From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java
License:Open Source License
/** * //from w w w . j av a 2 s. co m * @param n * @param bodyDecls * @param enumConstants * @param typeBinding * @param name Used in creating default constructor, and passed into new ClassEntity() * @param context * @return */ private CAstEntity createClassDeclaration(ASTNode n, List/* <BodyDeclaration> */ bodyDecls, List/* EnumConstantDeclaration */ enumConstants, ITypeBinding typeBinding, String name, int modifiers, boolean isInterface, boolean isAnnotation, WalkContext context) { final List<CAstEntity> memberEntities = new ArrayList<CAstEntity>(); // find and collect all initializers (type Initializer) and field initializers (type VariableDeclarationFragment). // instance initializer code will be inserted into each constructors. // all static initializer code will be grouped together in its own entity. ArrayList<ASTNode> inits = new ArrayList<ASTNode>(); ArrayList<ASTNode> staticInits = new ArrayList<ASTNode>(); if (enumConstants != null) { for (Object decl : enumConstants) { EnumConstantDeclaration ecd = (EnumConstantDeclaration) decl; staticInits.add(ecd); // always (implicitly) static,final (actually, no modifiers allowed) } } for (Object decl : bodyDecls) { if (decl instanceof Initializer) { Initializer initializer = (Initializer) decl; boolean isStatic = ((initializer.getModifiers() & Modifier.STATIC) != 0); (isStatic ? staticInits : inits).add(initializer); } else if (decl instanceof FieldDeclaration) { FieldDeclaration fd = (FieldDeclaration) decl; for (Object f : fd.fragments()) { VariableDeclarationFragment frag = (VariableDeclarationFragment) f; if (frag.getInitializer() != null) { boolean isStatic = ((fd.getModifiers() & Modifier.STATIC) != 0); (isStatic ? staticInits : inits).add(frag); } } } } // process entities. initializers will be folded in here. if (enumConstants != null) { for (Object decl : enumConstants) { memberEntities.add(visit((EnumConstantDeclaration) decl, context)); } } for (Object d : bodyDecls) { BodyDeclaration decl = (BodyDeclaration) d; if (decl instanceof FieldDeclaration) { FieldDeclaration fieldDecl = (FieldDeclaration) decl; Collection<CAstQualifier> quals = JDT2CAstUtils.mapModifiersToQualifiers(fieldDecl.getModifiers(), false, false); for (Object f : fieldDecl.fragments()) { VariableDeclarationFragment fieldFrag = (VariableDeclarationFragment) f; IVariableBinding fieldBinding = fieldFrag.resolveBinding(); memberEntities .add(new FieldEntity(fieldFrag.getName().getIdentifier(), fieldBinding.getType(), quals, makePosition(fieldFrag.getStartPosition(), fieldFrag.getStartPosition() + fieldFrag.getLength()), handleAnnotations(fieldBinding))); } } else if (decl instanceof Initializer) { // Initializers are inserted into constructors when making constructors. } else if (decl instanceof MethodDeclaration) { MethodDeclaration metDecl = (MethodDeclaration) decl; if (typeBinding.isEnum() && metDecl.isConstructor()) memberEntities.add(createEnumConstructorWithParameters(metDecl.resolveBinding(), metDecl, context, inits, metDecl)); else { memberEntities.add(visit(metDecl, typeBinding, context, inits)); // /////////////// Java 1.5 "overridden with subtype" thing (covariant return type) /////////// Collection<IMethodBinding> overriddenMets = JDT2CAstUtils .getOverriddenMethod(metDecl.resolveBinding()); if (overriddenMets != null) { for (IMethodBinding overridden : overriddenMets) if (!JDT2CAstUtils.sameErasedSignatureAndReturnType(metDecl.resolveBinding(), overridden)) memberEntities.add(makeSyntheticCovariantRedirect(metDecl, metDecl.resolveBinding(), overridden, context)); } } } else if (decl instanceof AbstractTypeDeclaration) { memberEntities.add(visit((AbstractTypeDeclaration) decl, context)); } else if (decl instanceof AnnotationTypeMemberDeclaration) { // TODO: need to decide what to do with these } else { Assertions.UNREACHABLE("BodyDeclaration not Field, Initializer, or Method"); } } // add default constructor(s) if necessary // most default constructors have no parameters; however, those created by anonymous classes will have parameters // (they just call super with those parameters) for (Object m : typeBinding.getDeclaredMethods()) { IMethodBinding met = (IMethodBinding) m; if (met.isDefaultConstructor()) { if (typeBinding.isEnum()) memberEntities.add(createEnumConstructorWithParameters(met, n, context, inits, null)); else if (met.getParameterTypes().length > 0) memberEntities.add(createDefaultConstructorWithParameters(met, n, context, inits)); else memberEntities.add(createDefaultConstructor(name, typeBinding, context, inits, n)); } } if (typeBinding.isEnum() && !typeBinding.isAnonymous()) doEnumHiddenEntities(typeBinding, staticInits, memberEntities, context); // collect static inits if (!staticInits.isEmpty()) { Map<CAstNode, CAstEntity> childEntities = HashMapFactory.make(); final MethodContext newContext = new MethodContext(context, childEntities); // childEntities is the same one as in the ProcedureEntity. later visit(New), etc. may add to this. CAstNode[] bodyNodes = new CAstNode[staticInits.size()]; for (int i = 0; i < staticInits.size(); i++) bodyNodes[i] = visitFieldInitNode(staticInits.get(i), newContext); CAstNode staticInitAst = makeNode(newContext, fFactory, n, CAstNode.BLOCK_STMT, bodyNodes); memberEntities.add(new ProcedureEntity(staticInitAst, typeBinding, childEntities, newContext, null)); } Collection<CAstQualifier> quals = JDT2CAstUtils.mapModifiersToQualifiers(modifiers, isInterface, isAnnotation); Set<CAstAnnotation> annotations = handleAnnotations(typeBinding); return new ClassEntity(typeBinding, name, quals, memberEntities, makePosition(n), annotations); }
From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java
License:Open Source License
/** * @param n for positioning./*from ww w. ja v a2s. c o m*/ */ private CAstEntity createEnumConstructorWithParameters(IMethodBinding ctor, ASTNode n, WalkContext oldContext, ArrayList<ASTNode> inits, MethodDeclaration nonDefaultCtor) { // PART I: find super ctor to call ITypeBinding newType = ctor.getDeclaringClass(); ITypeBinding javalangenumType = newType.getSuperclass(); IMethodBinding superCtor = null; if (newType.isEnum()) { for (IMethodBinding met : javalangenumType.getDeclaredMethods()) if (met.isConstructor()) { superCtor = met; break; } } assert superCtor != null : "enum"; // PART II: make ctor with simply "super(a,b,c...)" // TODO: extra CAstNodes final Map<CAstNode, CAstEntity> memberEntities = new LinkedHashMap<CAstNode, CAstEntity>(); final MethodContext context = new MethodContext(oldContext, memberEntities); MethodDeclaration fakeCtor = ast.newMethodDeclaration(); fakeCtor.setConstructor(true); fakeCtor.setSourceRange(n.getStartPosition(), n.getLength()); fakeCtor.setBody(ast.newBlock()); // PART IIa: make a fake JDT constructor method with the proper number of args // Make fake args that will be passed String[] fakeArguments = new String[3 + ctor.getParameterTypes().length]; if (nonDefaultCtor == null) { for (int i = 3; i < fakeArguments.length; i++) fakeArguments[i] = "__wala_jdtcast_argument" + i; // this is in the case of an anonymous class with parameters, eg NORTH in // the following example: public enum A { NORTH("south") { ...} A(String // s){} } } else { for (int i = 3; i < fakeArguments.length; i++) fakeArguments[i] = ((SingleVariableDeclaration) nonDefaultCtor.parameters().get(i - 3)).getName() .getIdentifier(); } ArrayList<CAstType> paramTypes = new ArrayList<CAstType>(superCtor.getParameterTypes().length); fakeArguments[0] = "this"; fakeArguments[1] = "__wala_jdtcast_argument1"; // TODO FIXME: change to invalid name in the case that nonDefaultCtor != null fakeArguments[2] = "__wala_jdtcast_argument2"; // otherwise there will be conflicts if we name our variable // __wala_jdtcast_argument1!!! for (int i = 1; i < fakeArguments.length; i++) { // the name SingleVariableDeclaration svd = ast.newSingleVariableDeclaration(); svd.setName(ast.newSimpleName(fakeArguments[i])); fakeCtor.parameters().add(svd); // the type if (i == 1) paramTypes.add(fTypeDict.getCAstTypeFor(ast.resolveWellKnownType("java.lang.String"))); else if (i == 2) paramTypes.add(fTypeDict.getCAstTypeFor(ast.resolveWellKnownType("int"))); else paramTypes.add(fTypeDict.getCAstTypeFor(ctor.getParameterTypes()[i - 3])); } // PART IIb: create the statements in the constructor // one super() call plus the inits CAstNode[] bodyNodes; if (nonDefaultCtor == null) bodyNodes = new CAstNode[inits.size() + 1]; else bodyNodes = new CAstNode[inits.size() + 2]; // make super(...) call // this, call ref, args CAstNode[] children; if (ctor.isDefaultConstructor()) children = new CAstNode[4 + ctor.getParameterTypes().length]; // anonymous class' implicit constructors call constructors with // more than standard two enum args else children = new CAstNode[4]; // explicit constructor children[0] = makeNode(context, fFactory, n, CAstNode.SUPER); CallSiteReference callSiteRef = CallSiteReference.make(0, fIdentityMapper.getMethodRef(superCtor), IInvokeInstruction.Dispatch.SPECIAL); children[1] = fFactory.makeConstant(callSiteRef); children[2] = makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(fakeArguments[1]), fFactory.makeConstant(paramTypes.get(0))); children[3] = makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(fakeArguments[2]), fFactory.makeConstant(paramTypes.get(1))); if (ctor.isDefaultConstructor()) for (int i = 0; i < ctor.getParameterTypes().length; i++) children[i + 4] = makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(fakeArguments[i + 3]), fFactory.makeConstant(paramTypes.get(i + 2))); bodyNodes[0] = makeNode(context, fFactory, n, CAstNode.CALL, children); // QUESTION: no handleExceptions? for (int i = 0; i < inits.size(); i++) bodyNodes[i + 1] = visitFieldInitNode(inits.get(i), context); if (nonDefaultCtor != null) bodyNodes[bodyNodes.length - 1] = visitNode(nonDefaultCtor.getBody(), context); // finally, make the procedure entity CAstNode ast = makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, bodyNodes); return new ProcedureEntity(ast, fakeCtor, newType, memberEntities, context, paramTypes, null, handleAnnotations(ctor)); }
From source file:com.intel.ide.eclipse.mpt.ast.UnresolvedElementsSubProcessor.java
License:Open Source License
private static boolean isImplicitConstructor(IMethodBinding meth) { return meth.isDefaultConstructor(); }
From source file:edu.uci.ics.sourcerer.extractor.ast.ReferenceExtractorVisitor.java
License:Open Source License
/** * This method writes://from w w w . ja v a 2s . c o m * <ul> * <li>Non-anonymous class or interface entity to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Extends relation to <code>IRelationWriter</code>.</li> * <li>Implements relation to <code>IRelationWriter</code>.</li> * <li>Synthesized constructors to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Implicit superconstructor calls to <code>IRelationWriter</code>.</li> * </ul></li> * </ul></li> * </ul> * * Class/interface fully qualified names (FQNs) adhere to the following format: * <ul> * <li>Top-level: package fqn + . + simple name</li> * <li>Member: parent fqn + $ + simple name</li> * <li>Local: parent fqn + $local- + incrementing counter + - + simple name</li> * </ul> */ @SuppressWarnings("unchecked") @Override public boolean visit(TypeDeclaration node) { // Get the fqn String fqn = null; Entity type = null; ITypeBinding binding = node.resolveBinding(); if (binding == null && !bindingFree) { throw new IllegalStateException("Binding resolution appears to have failed!"); } if (node.isPackageMemberTypeDeclaration()) { fqn = fqnStack.getTypeFqn(node.getName().getIdentifier()); } else if (node.isMemberTypeDeclaration()) { if (node.getName().getIdentifier().length() > 0) { fqn = fqnStack.getMemberFqn(node.getName().getIdentifier()); } else { logger.severe("A type declaration should not declare an annonymous type!"); fqn = fqnStack.getAnonymousClassFqn(); } } else if (node.isLocalTypeDeclaration()) { if (binding == null) { fqn = getUnknownFqn(node.getName().getIdentifier()); } else { fqn = fqnStack.getLocalFqn(node.getName().getIdentifier(), binding); } } else { logger.severe("Unsure what type the declaration is!"); fqn = "(ERROR)" + node.getName().getIdentifier(); } // Write the entity Metrics metrics = MetricsCalculator.computeLinesOfCode(getSource(node)); if (node.isInterface()) { entityWriter.writeInterface(fqn, node.getModifiers(), metrics, getLocation(node)); type = Entity.INTERFACE; } else { entityWriter.writeClass(fqn, node.getModifiers(), metrics, getLocation(node)); type = Entity.CLASS; } // Write the inside relation relationWriter.writeInside(fqn, fqnStack.getFqn(), getUnknownLocation()); // Write the extends relation Type superType = node.getSuperclassType(); String superFqn = null; if (superType != null) { superFqn = getTypeFqn(superType); relationWriter.writeExtends(fqn, superFqn, getLocation(superType)); } // Write the implements relation List<Type> superInterfaceTypes = node.superInterfaceTypes(); for (Type superInterfaceType : superInterfaceTypes) { String superInterfaceFqn = getTypeFqn(superInterfaceType); relationWriter.writeImplements(fqn, superInterfaceFqn, getLocation(superInterfaceType)); } fqnStack.push(fqn, type); if (binding != null) { if (binding.isAnonymous()) { logger.log(Level.SEVERE, "A type declaration should not declare an annonymous type!"); } else { // Verify the fqn // String fqn2 = getTypeFqn(binding); // if (!fqn.equals(fqn2)) { // logger.log(Level.SEVERE, "Mismatch between " + fqn + " and " + fqn2); // } // Write out the synthesized constructors for (IMethodBinding method : binding.getDeclaredMethods()) { if (method.isDefaultConstructor()) { // Write the entity String constructorFqn = getMethodFqn(method, true); entityWriter.writeConstructor(constructorFqn, method.getModifiers(), MetricsCalculator.computeLinesOfCode(null), getUnknownLocation()); // Write the inside relation relationWriter.writeInside(constructorFqn, fqn, getUnknownLocation()); // Write the calls relation (implicit superconstructor call) if (superFqn == null) { relationWriter.writeCalls(constructorFqn, "java.lang.Object.<init>()", getUnknownLocation()); } else { relationWriter.writeCalls(constructorFqn, superFqn + ".<init>()", getUnknownLocation()); } } } } } accept(node.getJavadoc()); accept(node.typeParameters()); accept(node.getSuperclassType()); accept(node.superInterfaceTypes()); accept(node.bodyDeclarations()); return false; }
From source file:edu.uci.ics.sourcerer.extractor.ast.ReferenceExtractorVisitor.java
License:Open Source License
/** * This method writes:/*from w w w .ja va2 s .c om*/ * <ul> * <li>Enum entity to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Implements relation to <code>IRelationWriter</code>.</li> * <li>Parametrized by relation to <code>IRelationWriter</code>.</li> * <li>Synthesized constructors to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * </ul></li> * </ul></li> * </ul> * * Enum qualified names (FQNs) adhere to the following format: * <ul> * <li>Top-level: package fqn + . + simple name</li> * <li>Member: parent fqn + $ + simple name</li> * </ul> */ @SuppressWarnings("unchecked") @Override public boolean visit(EnumDeclaration node) { // Get the fqn String fqn = null; if (node.isPackageMemberTypeDeclaration()) { fqn = fqnStack.getTypeFqn(node.getName().getIdentifier()); } else if (node.isMemberTypeDeclaration()) { fqn = fqnStack.getFqn() + "$" + node.getName().getIdentifier(); } else if (node.isLocalTypeDeclaration()) { logger.log(Level.WARNING, "Can't have local enums! eclipse error"); fqnStack.push(null, null); return false; } else { logger.log(Level.SEVERE, "Unsure what type the declaration is!"); fqn = "(ERROR)"; } // Write the entity entityWriter.writeEnum(fqn, node.getModifiers(), MetricsCalculator.computeLinesOfCode(getSource(node)), getLocation(node)); // Write the inside relation relationWriter.writeInside(fqn, fqnStack.getFqn(), getUnknownLocation()); // Write the implements relation for (Type superInterfaceType : (List<Type>) node.superInterfaceTypes()) { relationWriter.writeImplements(fqn, getTypeFqn(superInterfaceType), getLocation(superInterfaceType)); } ITypeBinding binding = node.resolveBinding(); if (binding != null) { // Write out the synthesized constructors for (IMethodBinding method : binding.getDeclaredMethods()) { if (method.isDefaultConstructor()) { // Write the entity String constructorFqn = getMethodFqn(method, true); entityWriter.writeConstructor(constructorFqn, method.getModifiers(), MetricsCalculator.computeLinesOfCode(getSource(node)), getUnknownLocation()); // Write the inside relation relationWriter.writeInside(constructorFqn, fqn, getUnknownLocation()); } } } fqnStack.push(fqn, Entity.ENUM); accept(node.getJavadoc()); accept(node.enumConstants()); accept(node.bodyDeclarations()); return false; }
From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.ReferenceExtractorVisitor.java
License:Open Source License
/** * This method writes:/*from ww w .j a va 2 s . co m*/ * <ul> * <li>Non-anonymous class or interface entity to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Extends relation to <code>IRelationWriter</code>.</li> * <li>Implements relation to <code>IRelationWriter</code>.</li> * <li>Synthesized constructors to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Implicit superconstructor calls to <code>IRelationWriter</code>.</li> * </ul></li> * </ul></li> * </ul> * * Class/interface fully qualified names (FQNs) adhere to the following format: * <ul> * <li>Top-level: package fqn + . + simple name</li> * <li>Member: parent fqn + $ + simple name</li> * <li>Local: parent fqn + $ + incrementing counter + simple name</li> * </ul> */ @SuppressWarnings("unchecked") @Override public boolean visit(TypeDeclaration node) { // Get the fqn String parentFqn = null; String fqn = null; Entity type = null; ITypeBinding binding = node.resolveBinding(); if (binding == null && !bindingFree) { throw new IllegalStateException("Binding resolution appears to have failed!"); } if (node.isPackageMemberTypeDeclaration()) { EnclosingPackage enc = fqnStack.peek(EnclosingPackage.class); fqn = enc.getTypeFqn(node.getName().getIdentifier()); parentFqn = enc.getFqn(); } else if (node.isMemberTypeDeclaration()) { if (node.getName().getIdentifier().length() > 0) { EnclosingDeclaredType enc = fqnStack.peek(EnclosingDeclaredType.class); fqn = enc.getMemberFqn(node.getName().getIdentifier()); parentFqn = enc.getFqn(); } else { throw new IllegalStateException("A type declaration should not declare an annonymous type!"); } } else if (node.isLocalTypeDeclaration()) { EnclosingBlock enc = fqnStack.peek(EnclosingBlock.class); if (binding == null) { fqn = createUnknownFqn(node.getName().getIdentifier()); } else { fqn = enc.getLocalFqn(node.getName().getIdentifier(), binding); } parentFqn = enc.getFqn(); } else { throw new IllegalStateException("Unknown declaration: " + node); } if (node.isInterface()) { type = Entity.INTERFACE; } else { type = Entity.CLASS; } // Push the stack fqnStack.push(fqn, type); // Visit the children accept(node.getJavadoc()); accept(node.modifiers()); accept(node.typeParameters()); accept(node.getSuperclassType()); accept(node.superInterfaceTypes()); accept(node.bodyDeclarations()); // Write the contains relation relationWriter.writeRelation(Relation.CONTAINS, parentFqn, fqn, createUnknownLocation()); // Write the entity entityWriter.writeEntity(type, fqn, node.getModifiers(), createMetrics(node), createLocation(node)); // Write the extends relation Type superType = node.getSuperclassType(); String superFqn = null; if (superType == null) { if (!fqn.equals("java.lang.Object")) { superFqn = "java.lang.Object"; relationWriter.writeRelation(Relation.EXTENDS, fqn, superFqn, createUnknownLocation()); } } else { superFqn = getTypeFqn(superType); relationWriter.writeRelation(Relation.EXTENDS, fqn, superFqn, createLocation(superType)); } // Write the implements relation List<Type> superInterfaceTypes = node.superInterfaceTypes(); for (Type superInterfaceType : superInterfaceTypes) { String superInterfaceFqn = getTypeFqn(superInterfaceType); relationWriter.writeRelation(Relation.IMPLEMENTS, fqn, superInterfaceFqn, createLocation(superInterfaceType)); } if (binding != null) { if (binding.isAnonymous()) { logger.log(Level.SEVERE, "A type declaration should not declare an annonymous type!"); } else { // Write out the synthesized constructors for (IMethodBinding method : binding.getDeclaredMethods()) { if (method.isDefaultConstructor()) { // Write the entity String constructorFqn = getMethodName(method, true); entityWriter.writeEntity(Entity.CONSTRUCTOR, constructorFqn, "()", null, method.getModifiers(), null, createUnknownLocation()); constructorFqn += "()"; // Write the contains relation relationWriter.writeRelation(Relation.CONTAINS, fqn, constructorFqn, createUnknownLocation()); // Write the calls relation (implicit superconstructor call) if (superFqn == null) { relationWriter.writeRelation(Relation.CALLS, constructorFqn, "java.lang.Object.<init>()", createUnknownLocation()); } else { if (superType == null) { relationWriter.writeRelation(Relation.CALLS, constructorFqn, superFqn + ".<init>()", createUnknownLocation()); } else { relationWriter.writeRelation(Relation.CALLS, constructorFqn, getErasedTypeFqn(superType) + ".<init>()", createUnknownLocation()); } } } } } } fqnStack.pop(); return false; }
From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.ReferenceExtractorVisitor.java
License:Open Source License
/** * This method writes:// w ww .j a va 2s . c om * <ul> * <li>Enum entity to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Implements relation to <code>IRelationWriter</code>.</li> * <li>Parametrized by relation to <code>IRelationWriter</code>.</li> * <li>Synthesized constructors to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * </ul></li> * </ul></li> * </ul> * * Enum qualified names (FQNs) adhere to the following format: * <ul> * <li>Top-level: package fqn + . + simple name</li> * <li>Member: parent fqn + $ + simple name</li> * </ul> */ @SuppressWarnings("unchecked") @Override public boolean visit(EnumDeclaration node) { // Get the fqn String fqn = null; if (node.isPackageMemberTypeDeclaration()) { fqn = fqnStack.peek(EnclosingPackage.class).getTypeFqn(node.getName().getIdentifier()); } else if (node.isMemberTypeDeclaration()) { fqn = fqnStack.peek(EnclosingDeclaredType.class).getMemberFqn(node.getName().getIdentifier()); } else if (node.isLocalTypeDeclaration()) { throw new IllegalStateException("Can't have local enums!"); } else { logger.log(Level.SEVERE, "Unsure what type the declaration is!"); fqn = "(ERROR)"; } String parentFqn = fqnStack.getFqn(); fqnStack.push(fqn, Entity.ENUM); // Visit the children accept(node.getJavadoc()); accept(node.enumConstants()); accept(node.bodyDeclarations()); Location unknown = createUnknownLocation(); // Write the entity entityWriter.writeEntity(Entity.ENUM, fqn, node.getModifiers(), createMetrics(node), createLocation(node)); // Write the contains relation relationWriter.writeRelation(Relation.CONTAINS, parentFqn, fqn, unknown); // Write the implements relation for (Type superInterfaceType : (List<Type>) node.superInterfaceTypes()) { relationWriter.writeRelation(Relation.IMPLEMENTS, fqn, getTypeFqn(superInterfaceType), createLocation(superInterfaceType)); } // Write the extends relation relationWriter.writeRelation(Relation.EXTENDS, fqn, "java.lang.Enum<" + fqn + ">", unknown); ITypeBinding binding = node.resolveBinding(); if (binding != null) { // Write out the synthesized constructors for (IMethodBinding method : binding.getDeclaredMethods()) { if (method.isDefaultConstructor()) { // Write the entity String constructorFqn = getMethodName(method, true); entityWriter.writeEntity(Entity.CONSTRUCTOR, constructorFqn, "()", null, method.getModifiers(), createMetrics(node), unknown); constructorFqn += "()"; // Write the contains relation relationWriter.writeRelation(Relation.CONTAINS, fqn, constructorFqn, unknown); // Write the calls relation relationWriter.writeRelation(Relation.CALLS, constructorFqn, "java.lang.Enum.<init>(java.lang.String,int)", unknown); } } } // Write the values method { String methodFqn = fqn + ".values"; entityWriter.writeEntity(Entity.METHOD, methodFqn, "()", null, 9, null, unknown); methodFqn += "()"; relationWriter.writeRelation(Relation.CONTAINS, fqn, methodFqn, unknown); relationWriter.writeRelation(Relation.RETURNS, methodFqn, fqn + "[]", unknown); } // Write the valueOf method { String methodFqn = fqn + ".valueOf"; entityWriter.writeEntity(Entity.METHOD, methodFqn, "(java.lang.String)", null, 9, null, unknown); methodFqn += "(java.lang.String)"; relationWriter.writeRelation(Relation.CONTAINS, fqn, methodFqn, unknown); relationWriter.writeRelation(Relation.RETURNS, methodFqn, fqn, unknown); localVariableWriter.writeLocalVariable(LocalVariable.PARAM, "name", 0, "java.lang.String", unknown, methodFqn, 0, unknown); } fqnStack.pop(); return false; }