org.eclipse.jdt.core.dom.ITypeBinding#getSuperclass ( )源码实例Demo

下面列出了org.eclipse.jdt.core.dom.ITypeBinding#getSuperclass ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: eclipse.jdt.ls   文件: FlowContext.java
boolean isExceptionCaught(ITypeBinding excpetionType) {
	for (Iterator<List<CatchClause>> exceptions= fExceptionStack.iterator(); exceptions.hasNext(); ) {
		for (Iterator<CatchClause> catchClauses= exceptions.next().iterator(); catchClauses.hasNext(); ) {
			SingleVariableDeclaration caughtException= catchClauses.next().getException();
			IVariableBinding binding= caughtException.resolveBinding();
			if (binding == null) {
				continue;
			}
			ITypeBinding caughtype= binding.getType();
			while (caughtype != null) {
				if (caughtype == excpetionType) {
					return true;
				}
				caughtype= caughtype.getSuperclass();
			}
		}
	}
	return false;
}
 
源代码2 项目: JDeodorant   文件: PDGNode.java
public boolean instantiatesLocalVariable(AbstractVariable variable) {
	if(variable instanceof PlainVariable && this.definesLocalVariable(variable)) {
		PlainVariable plainVariable = (PlainVariable)variable;
		String variableType = plainVariable.getVariableType();
		for(CreationObject creation : createdTypes) {
			if(creation instanceof ClassInstanceCreationObject) {
				ITypeBinding createdTypeBinding = ((ClassInstanceCreationObject)creation).getClassInstanceCreation().resolveTypeBinding();
				String superclassName = createdTypeBinding.getSuperclass() != null ? createdTypeBinding.getSuperclass().getQualifiedName() : null;
				Set<String> implementedInterfaces = new LinkedHashSet<String>();
				for(ITypeBinding implementedInterface : createdTypeBinding.getInterfaces()) {
					implementedInterfaces.add(implementedInterface.getQualifiedName());
				}
				if(variableType.equals(createdTypeBinding.getQualifiedName()) || variableType.equals(superclassName) || implementedInterfaces.contains(variableType))
					return true;
			}
		}
	}
	return false;
}
 
源代码3 项目: JDeodorant   文件: PreconditionExaminer.java
private Set<IVariableBinding> getDeclaredFields(ITypeBinding typeBinding) {
	Set<IVariableBinding> declaredFields = new LinkedHashSet<IVariableBinding>();
	//first add the directly declared methods
	for(IVariableBinding variableBinding : typeBinding.getDeclaredFields()) {
		declaredFields.add(variableBinding);
	}
	ITypeBinding superclassTypeBinding = typeBinding.getSuperclass();
	if(superclassTypeBinding != null) {
		declaredFields.addAll(getDeclaredFields(superclassTypeBinding));
	}
	ITypeBinding[] interfaces = typeBinding.getInterfaces();
	for(ITypeBinding interfaceTypeBinding : interfaces) {
		declaredFields.addAll(getDeclaredFields(interfaceTypeBinding));
	}
	return declaredFields;
}
 
/**
 * Finds the method specified by <code>methodName</code> and </code>parameters</code> in
 * the type hierarchy denoted by the given type. Returns <code>null</code> if no such method
 * exists. If the method is defined in more than one super type only the first match is
 * returned. First the super class is examined and then the implemented interfaces.
 * 
 * @param type The type to search the method in
 * @param methodName The name of the method to find
 * @param parameters The parameter types of the method to find. If <code>null</code> is passed, only the name is matched and parameters are ignored.
 * @return the method binding representing the method
 */
public static IMethodBinding findMethodInHierarchy(ITypeBinding type, String methodName, ITypeBinding[] parameters) {
	IMethodBinding method= findMethodInType(type, methodName, parameters);
	if (method != null)
		return method;
	ITypeBinding superClass= type.getSuperclass();
	if (superClass != null) {
		method= findMethodInHierarchy(superClass, methodName, parameters);
		if (method != null)
			return method;
	}
	ITypeBinding[] interfaces= type.getInterfaces();
	for (int i= 0; i < interfaces.length; i++) {
		method= findMethodInHierarchy(interfaces[i], methodName, parameters);
		if (method != null)
			return method;
	}
	return null;
}
 
源代码5 项目: JDeodorant   文件: PreconditionExaminer.java
private static Set<ITypeBinding> getAllSuperTypesUpToCommonSuperclass(ITypeBinding typeBinding, ITypeBinding commonSuperclass) {
	Set<ITypeBinding> superTypes = new LinkedHashSet<ITypeBinding>();
	ITypeBinding superTypeBinding = typeBinding.getSuperclass();
	if(superTypeBinding != null && !superTypeBinding.isEqualTo(commonSuperclass)) {
		superTypes.add(superTypeBinding);
		superTypes.addAll(getAllSuperTypesUpToCommonSuperclass(superTypeBinding, commonSuperclass));
	}
	ITypeBinding[] superInterfaces = typeBinding.getInterfaces();
	for(ITypeBinding superInterface : superInterfaces) {
		if(!superInterface.isEqualTo(commonSuperclass)) {
			superTypes.add(superInterface);
			superTypes.addAll(getAllSuperTypesUpToCommonSuperclass(superInterface, commonSuperclass));
		}
	}
	return superTypes;
}
 
源代码6 项目: tassal   文件: JavaTypeHierarchyExtractor.java
private void getTypeBindingParents(ITypeBinding binding) {
	if (binding.isParameterizedType()) {
		binding = binding.getErasure();
	}
	final String bindingName = binding.isRecovered() ? binding
			.getName() : binding.getQualifiedName();
	final ITypeBinding superclassBinding = binding.getSuperclass();
	if (superclassBinding != null) {
		addTypes(
				superclassBinding.isRecovered() ? superclassBinding.getName()
						: superclassBinding.getQualifiedName(),
				bindingName);
		getTypeBindingParents(superclassBinding);
	}

	for (ITypeBinding iface : binding.getInterfaces()) {
		if (iface.isParameterizedType()) {
			iface = iface.getErasure();
		}
		addTypes(
				iface.isRecovered() ? iface.getName()
						: iface.getQualifiedName(), bindingName);
		getTypeBindingParents(iface);
	}
}
 
源代码7 项目: j2cl   文件: JdtUtils.java
public static IMethodBinding getMethodBinding(
    ITypeBinding typeBinding, String methodName, ITypeBinding... parameterTypes) {

  Queue<ITypeBinding> deque = new ArrayDeque<>();
  deque.add(typeBinding);

  while (!deque.isEmpty()) {
    typeBinding = deque.poll();
    for (IMethodBinding methodBinding : typeBinding.getDeclaredMethods()) {
      if (methodBinding.getName().equals(methodName)
          && Arrays.equals(methodBinding.getParameterTypes(), parameterTypes)) {
        return methodBinding;
      }
    }
    ITypeBinding superclass = typeBinding.getSuperclass();
    if (superclass != null) {
      deque.add(superclass);
    }

    ITypeBinding[] superInterfaces = typeBinding.getInterfaces();
    if (superInterfaces != null) {
      for (ITypeBinding superInterface : superInterfaces) {
        deque.add(superInterface);
      }
    }
  }
  return null;
}
 
源代码8 项目: j2cl   文件: JdtUtils.java
private static Set<IMethodBinding> getOverriddenMethodsInType(
    IMethodBinding methodBinding, ITypeBinding typeBinding) {
  Set<IMethodBinding> overriddenMethods = new HashSet<>();
  for (IMethodBinding declaredMethod : typeBinding.getDeclaredMethods()) {
    if (methodBinding.overrides(declaredMethod) && !methodBinding.isConstructor()) {
      checkArgument(!Modifier.isStatic(methodBinding.getModifiers()));
      overriddenMethods.add(declaredMethod);
    }
  }
  // Recurse into immediate super class and interfaces for overridden method.
  if (typeBinding.getSuperclass() != null) {
    overriddenMethods.addAll(
        getOverriddenMethodsInType(methodBinding, typeBinding.getSuperclass()));
  }
  for (ITypeBinding interfaceBinding : typeBinding.getInterfaces()) {
    overriddenMethods.addAll(getOverriddenMethodsInType(methodBinding, interfaceBinding));
  }

  ITypeBinding javaLangObjectTypeBinding = JdtUtils.javaLangObjectTypeBinding.get();
  if (typeBinding != javaLangObjectTypeBinding) {
    for (IMethodBinding objectMethodBinding : javaLangObjectTypeBinding.getDeclaredMethods()) {
      if (!isPolymorphic(objectMethodBinding)) {
        continue;
      }
      checkState(!getVisibility(objectMethodBinding).isPackagePrivate());
      if (methodBinding.isSubsignature(objectMethodBinding)) {
        overriddenMethods.add(objectMethodBinding);
      }
    }
  }

  return overriddenMethods;
}
 
源代码9 项目: xtext-eclipse   文件: JdtBasedTypeFactory.java
/**
 * @since 2.4
 */
protected void setSuperTypes(ITypeBinding binding, String qualifiedName, JvmDeclaredType result) {
	ITypeBinding superclass = binding.getSuperclass();
	InternalEList<JvmTypeReference> superTypes = (InternalEList<JvmTypeReference>)result.getSuperTypes();
	if (superclass != null) {
		superTypes.addUnique(createTypeReference(superclass));
	} 
	for (ITypeBinding intf : binding.getInterfaces()) {
		superTypes.addUnique(createTypeReference(intf));
	}
	if (superTypes.isEmpty() && !OBJECT_CLASS_NAME.equals(qualifiedName)) {
		superTypes.addUnique(createObjectClassReference());
	}
}
 
private static boolean isSubtype(ITypeBinding curr, ITypeBinding[] addedExceptions) {
	while (curr != null) {
		for (int i= 0; i < addedExceptions.length; i++) {
			if (curr == addedExceptions[i]) {
				return true;
			}
		}
		curr= curr.getSuperclass();
	}
	return false;
}
 
private static boolean isSubtype(ITypeBinding curr, ITypeBinding[] addedExceptions) {
	while (curr != null) {
		for (int i = 0; i < addedExceptions.length; i++) {
			if (curr == addedExceptions[i]) {
				return true;
			}
		}
		curr = curr.getSuperclass();
	}
	return false;
}
 
/**
 * @param type a type
 * @return the direct superclass and direct superinterfaces. Class Object is
 * included in the result if the root of the hierarchy is a top-level
 * interface.
 */
public Set<ITypeBinding> getDirectSuperTypes(ITypeBinding type){
	Set<ITypeBinding> result= new HashSet<ITypeBinding>();
	if (type.getSuperclass() != null){
		result.add(type.getSuperclass());
	}
	ITypeBinding[] interfaces= type.getInterfaces();
	for (int i=0; i < interfaces.length; i++){
		result.add(interfaces[i]);
	}
	if (fGeneralizeType.getOriginalType().isInterface() && type != fGeneralizeType.getObject()){
		result.add(fGeneralizeType.getObject());
	}
	return result;
}
 
private static boolean hasMethodWithName(ITypeBinding typeBinding, String name) {
	IVariableBinding[] fields= typeBinding.getDeclaredFields();
	for (int i= 0; i < fields.length; i++) {
		if (fields[i].getName().equals(name)) {
			return true;
		}
	}
	ITypeBinding superclass= typeBinding.getSuperclass();
	if (superclass != null) {
		return hasMethodWithName(superclass, name);
	}
	return false;
}
 
private ITypeBinding getSuperTypeBinding() {
	ITypeBinding types= fAnonymousInnerClassNode.resolveBinding();
	ITypeBinding[] interfaces= types.getInterfaces();
	if (interfaces.length > 0)
		return interfaces[0];
	else
		return types.getSuperclass();
}
 
源代码15 项目: ck   文件: DIT.java
private void calculate(ITypeBinding binding) {
	ITypeBinding father = binding.getSuperclass();
	if (father != null) {
		String fatherName = father.getQualifiedName();
		if (fatherName.endsWith("Object")) return;
		dit++;

		calculate(father);
	}

}
 
private static void getDelegatableMethods(List<IMethodBinding> methods, IVariableBinding fieldBinding, ITypeBinding typeBinding, ITypeBinding binding, List<DelegateEntry> result) {
	boolean match= false;
	if (typeBinding.isTypeVariable()) {
		ITypeBinding[] typeBounds= typeBinding.getTypeBounds();
		if (typeBounds.length > 0) {
			for (int i= 0; i < typeBounds.length; i++) {
				getDelegatableMethods(methods, fieldBinding, typeBounds[i], binding, result);
			}
		} else {
			ITypeBinding objectBinding= Bindings.findTypeInHierarchy(binding, "java.lang.Object"); //$NON-NLS-1$
			if (objectBinding != null) {
				getDelegatableMethods(methods, fieldBinding, objectBinding, binding, result);
			}
		}
	} else {
		IMethodBinding[] candidates= getDelegateCandidates(typeBinding, binding);
		for (int index= 0; index < candidates.length; index++) {
			match= false;
			final IMethodBinding methodBinding= candidates[index];
			for (int offset= 0; offset < methods.size() && !match; offset++) {
				if (Bindings.areOverriddenMethods(methods.get(offset), methodBinding))
					match= true;
			}
			if (!match) {
				result.add(new DelegateEntry(methodBinding, fieldBinding));
				methods.add(methodBinding);
			}
		}
		final ITypeBinding superclass= typeBinding.getSuperclass();
		if (superclass != null)
			getDelegatableMethods(methods, fieldBinding, superclass, binding, result);
		ITypeBinding[] superInterfaces= typeBinding.getInterfaces();
		for (int offset= 0; offset < superInterfaces.length; offset++)
			getDelegatableMethods(methods, fieldBinding, superInterfaces[offset], binding, result);
	}
}
 
@Override
public int compare(IMethodBinding firstMethodBinding, IMethodBinding secondMethodBinding) {
	if (firstMethodBinding == null || secondMethodBinding == null) {
		return 0;
	}
	ITypeBinding firstMethodType= firstMethodBinding.getDeclaringClass();
	ITypeBinding secondMethodType= secondMethodBinding.getDeclaringClass();

	if (firstMethodType.equals(secondMethodType)) {
		return compareInTheSameType(firstMethodBinding, secondMethodBinding);
	}

	if (firstMethodType.equals(fTypeBinding)) {
		return 1;
	}
	if (secondMethodType.equals(fTypeBinding)) {
		return -1;
	}

	ITypeBinding type= fTypeBinding;
	int count= 0, firstCount= -1, secondCount= -1;
	while ((type= type.getSuperclass()) != null) {
		if (firstMethodType.equals(type)) {
			firstCount= count;
		}
		if (secondMethodType.equals(type)) {
			secondCount= count;
		}
		count++;
	}
	if (firstCount != -1 && secondCount != -1) {
		return (firstCount - secondCount);
	}
	if (firstCount != -1 && secondCount == -1) {
		return 1;
	}
	if (firstCount == -1 && secondCount != -1) {
		return -1;
	}

	ITypeBinding[] interfaces= fTypeBinding.getInterfaces();
	for (int i= 0; i < interfaces.length; i++) {
		if (firstMethodType.equals(interfaces[i])) {
			return 1;
		}
		if (secondMethodType.equals(interfaces[i])) {
			return -1;
		}
	}
	return 0;
}
 
源代码18 项目: jdt2famix   文件: AstVisitor.java
@SuppressWarnings("unchecked")
@Override
public boolean visit(TypeDeclaration node) {
	ITypeBinding binding = node.resolveBinding();
	if (binding == null) {
		logNullBinding("type declaration", node.getName(),
				((CompilationUnit) node.getRoot()).getLineNumber(node.getStartPosition()));
		return false;
	}
	Type type = importer.ensureTypeFromTypeBinding(binding);

	org.eclipse.jdt.core.dom.Type superclassType = node.getSuperclassType();
	/*
	 * This is an ugly patch. When the binding to the superclass or super interfaces
	 * cannot be resolved, we try to recover as much info as possible We do it here
	 * because it is hard to pass around the dom type
	 */
	if (binding.getSuperclass() == null && superclassType != null)
		importer.createInheritanceFromSubtypeToSuperDomType(type, superclassType);

	if (superclassType != null)
		type.getSuperInheritances().stream().filter(inheritance -> (inheritance.getSuperclass() instanceof Class
				&& !((Class) inheritance.getSuperclass()).getIsInterface())
				|| (inheritance.getSuperclass() instanceof ParameterizedType
						&& ((ParameterizedType) inheritance.getSuperclass()).getParameterizableClass() != null
						&& !((ParameterizedType) inheritance.getSuperclass()).getParameterizableClass()
								.getIsInterface()))
				.findFirst().ifPresent(in -> importer.createLightweightSourceAnchor(in, superclassType));

	if (binding.getInterfaces().length == 0 && !node.superInterfaceTypes().isEmpty())
		node.superInterfaceTypes().stream().forEach(t -> {
			importer.createInheritanceFromSubtypeToSuperDomType(type, (org.eclipse.jdt.core.dom.Type) t);
		});

	// create source anchors for implemented interfaces references
	createSourceAnchorsForInterfaceInheritance(node, type);

	type.setIsStub(false);
	importer.createSourceAnchor(type, node);
	importer.createLightweightSourceAnchor(type, node.getName());
	importer.ensureCommentFromBodyDeclaration(type, node);
	importer.pushOnContainerStack(type);
	return true;
}
 
源代码19 项目: txtUML   文件: ElementTypeTeller.java
public static boolean hasSuperClass(ITypeBinding type, String superClassName) {
	while (type != null && !type.getErasure().getQualifiedName().equals(superClassName)) {
		type = type.getSuperclass();
	}
	return type != null;
}
 
源代码20 项目: Eclipse-Postfix-Code-Completion   文件: Bindings.java
/**
 * Method to visit a super class hierarchy defined by a given type.
 * The given type itself is not visited.
 *
 * @param type the type whose super class hierarchy is to be visited
 * @param visitor the visitor
 * @return <code>true</code> if all types were visited,
 *         or <code>false</code> if the visiting got aborted because the <code>visit</code>
 *         method returned <code>false</code> for a type
 */
public static boolean visitSuperclasses(ITypeBinding type, TypeBindingVisitor visitor) {
	while ((type= type.getSuperclass()) != null) {
		if (!visitor.visit(type)) {
			return false;
		}
	}
	return true;
}