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

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

源代码1 项目: api-mining   文件: 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);
	}
}
 
@Override
public void endVisit(CompilationUnit node) {
	// If we don't had a static import to the field we don't
	// have to add any, even if we generated a setter or
	// getter access.
	if (!fRemoveStaticImport)
		return;

	ITypeBinding type= fFieldBinding.getDeclaringClass();
	String fieldName= fFieldBinding.getName();
	String typeName= type.getQualifiedName();
	if (fRemoveStaticImport) {
		fImportRewriter.removeStaticImport(typeName + "." + fieldName); //$NON-NLS-1$
	}
	if (fReferencingGetter) {
		fImportRewriter.addStaticImport(typeName, fGetter, false);
	}
	if (fReferencingSetter) {
		fImportRewriter.addStaticImport(typeName, fSetter, false);
	}
}
 
/**
 * Returns the new type node representing the return type of <code>lambdaExpression</code>
 * including the extra dimensions.
 * 
 * @param lambdaExpression the lambda expression
 * @param ast the AST to create the return type with
 * @param importRewrite the import rewrite to use, or <code>null</code>
 * @param context the import rewrite context, or <code>null</code>
 * @return a new type node created with the given AST representing the return type of
 *         <code>lambdaExpression</code>
 * 
 * @since 3.10
 */
public static Type newReturnType(LambdaExpression lambdaExpression, AST ast, ImportRewrite importRewrite, ImportRewriteContext context) {
	IMethodBinding method= lambdaExpression.resolveMethodBinding();
	if (method != null) {
		ITypeBinding returnTypeBinding= method.getReturnType();
		if (importRewrite != null) {
			return importRewrite.addImport(returnTypeBinding, ast);
		} else {
			String qualifiedName= returnTypeBinding.getQualifiedName();
			if (qualifiedName.length() > 0) {
				return newType(ast, qualifiedName);
			}
		}
	}
	// fall-back
	return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
 
源代码4 项目: JDeodorant   文件: ASTReader.java
private void processFieldDeclaration(final ClassObject classObject, FieldDeclaration fieldDeclaration) {
	Type fieldType = fieldDeclaration.getType();
	ITypeBinding binding = fieldType.resolveBinding();
	List<CommentObject> fieldDeclarationComments = new ArrayList<CommentObject>();
	int fieldDeclarationStartPosition = fieldDeclaration.getStartPosition();
	int fieldDeclarationEndPosition = fieldDeclarationStartPosition + fieldDeclaration.getLength();
	for(CommentObject comment : classObject.commentList) {
		int commentStartPosition = comment.getStartPosition();
		int commentEndPosition = commentStartPosition + comment.getLength();
		if(fieldDeclarationStartPosition <= commentStartPosition && fieldDeclarationEndPosition >= commentEndPosition) {
			fieldDeclarationComments.add(comment);
		}
	}
	List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments();
	for(VariableDeclarationFragment fragment : fragments) {
		String qualifiedName = binding.getQualifiedName();
		TypeObject typeObject = TypeObject.extractTypeObject(qualifiedName);
		typeObject.setArrayDimension(typeObject.getArrayDimension() + fragment.getExtraDimensions());
		FieldObject fieldObject = new FieldObject(typeObject, fragment.getName().getIdentifier());
		fieldObject.setClassName(classObject.getName());
		fieldObject.setVariableDeclarationFragment(fragment);
		fieldObject.addComments(fieldDeclarationComments);
		
		int fieldModifiers = fieldDeclaration.getModifiers();
		if((fieldModifiers & Modifier.PUBLIC) != 0)
			fieldObject.setAccess(Access.PUBLIC);
		else if((fieldModifiers & Modifier.PROTECTED) != 0)
			fieldObject.setAccess(Access.PROTECTED);
		else if((fieldModifiers & Modifier.PRIVATE) != 0)
			fieldObject.setAccess(Access.PRIVATE);
		else
			fieldObject.setAccess(Access.NONE);
		
		if((fieldModifiers & Modifier.STATIC) != 0)
			fieldObject.setStatic(true);
		
		classObject.addField(fieldObject);
	}
}
 
源代码5 项目: xtext-eclipse   文件: TypeURIHelper.java
public String getQualifiedName(ITypeBinding binding) {
	if (binding.isParameterizedType()) {
		return getQualifiedName(binding.getErasure());
	}
	if (binding.isArray()) {
		return getQualifiedName(binding.getComponentType(), new StringBuilder()).append("[]").toString();
	}
	if (binding.isTopLevel() || binding.isTypeVariable() || binding.isPrimitive())
		return binding.getQualifiedName();
	return getQualifiedName(binding.getDeclaringClass(), new StringBuilder()).append('$').append(binding.getName()).toString();
}
 
public static String[] getParameterTypeNamesForSeeTag(IMethodBinding binding) {
	ITypeBinding[] typeBindings= binding.getParameterTypes();
	String[] result= new String[typeBindings.length];
	for (int i= 0; i < result.length; i++) {
		ITypeBinding curr= typeBindings[i];
		curr= curr.getErasure(); // Javadoc references use erased type
		result[i]= curr.getQualifiedName();
	}
	return result;
}
 
源代码7 项目: windup   文件: ReferenceResolvingVisitor.java
private ClassReference processTypeAsEnum(ITypeBinding typeBinding, Expression expression, ResolutionStatus resolutionStatus, int lineNumber, int columnNumber, int length, String line)
{
    if (expression == null)
        return null;

    String fullExpression = null;
    String enumPackage = null;
    String enumClassName = null;
    if (typeBinding != null)
    {
        fullExpression = typeBinding.getQualifiedName();
        enumPackage = typeBinding.getPackage().getName();
        enumClassName = typeBinding.getName();
    }

    if (expression instanceof Name)
    {
        if (StringUtils.isNotBlank(fullExpression))
            fullExpression += ".";

        if (expression instanceof QualifiedName)
            fullExpression += ((QualifiedName) expression).getName();
        else
            fullExpression += ((Name) expression).getFullyQualifiedName();
    }

    ClassReference reference = new ClassReference(fullExpression, enumPackage, enumClassName, null, resolutionStatus,
                TypeReferenceLocation.ENUM_CONSTANT,
                lineNumber,
                columnNumber,
                length,
                line);
    this.classReferences.add(reference);
    return reference;
}
 
源代码8 项目: 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 void generateInheritanceTrees(List<ITypeBinding> typeBindings) {
	for(ITypeBinding typeBinding : typeBindings) {
		ITypeBinding superType = extendsOrImplements(typeBinding, typeBindings);
		if(superType != null && !typeBinding.getQualifiedName().equals(superType.getQualifiedName())) {
			String childName = typeBinding.getQualifiedName();
			String parentName = superType.getQualifiedName();
			InheritanceTree childTree = getTree(childName);
			InheritanceTree parentTree = getTree(parentName);
			if(childTree == null && parentTree == null) {
				InheritanceTree tree = new InheritanceTree();
				tree.addChildToParent(childName, parentName);
				inheritanceTreeList.add(tree);
			}
			else if(childTree == null) {
				parentTree.addChildToParent(childName, parentName);
			}
			else if(parentTree == null) {
				childTree.addChildToParent(childName, parentName);
			}
			else if( !childTree.equals(parentTree) ) {
				parentTree.addChildRootNodeToParent(childTree.getRootNode(), parentName);
				inheritanceTreeList.remove(childTree);
			}
		}
		else if(getTree(typeBinding.getQualifiedName()) == null) {
			inheritanceTreeList.add(new InheritanceTree(typeBinding.getQualifiedName()));
		}
	}
}
 
static boolean isSynchronousInterface(ITypeBinding typeBinding) {
  String qualifiedName = typeBinding.getQualifiedName();
  if (qualifiedName.equals(REMOTE_SERVICE_QUALIFIED_NAME) ||
      qualifiedName.equals(RPC_SERVICE_QUALIFIED_NAME)) {
    // Ignore the RemoteService and RpcService marker interfaces
    return false;
  }

  ITypeBinding remoteServiceBinding = Bindings.findTypeInHierarchy(
      typeBinding, REMOTE_SERVICE_QUALIFIED_NAME);
  return remoteServiceBinding != null;
}
 
public static boolean isArrayCompatible(ITypeBinding definedType) {
	if (definedType.isTopLevel()) {
		if (definedType.isClass()) {
			return "Object".equals(definedType.getName()) && "java.lang".equals(definedType.getPackage().getName());  //$NON-NLS-1$//$NON-NLS-2$
		} else {
			String qualifiedName= definedType.getQualifiedName();
			return "java.io.Serializable".equals(qualifiedName) || "java.lang.Cloneable".equals(qualifiedName); //$NON-NLS-1$ //$NON-NLS-2$
		}
	}
	return false;
}
 
源代码12 项目: txtUML   文件: ElementTypeTeller.java
public static boolean isSpecificClassifier(TypeDeclaration classifierDeclaration) {
	ITypeBinding superclassBinding = classifierDeclaration.resolveBinding().getSuperclass();
	if (superclassBinding == null) {
		return false;
	}
	String superclassQualifiedName = superclassBinding.getQualifiedName();
	boolean extendsModelClass = superclassQualifiedName.equals(ModelClass.class.getCanonicalName());
	boolean extendsSignal = superclassQualifiedName.equals(Signal.class.getCanonicalName());

	return !extendsModelClass && !extendsSignal;
}
 
源代码13 项目: jdt2famix   文件: InJavaImporter.java
public Type ensureTypeFromTypeBinding(ITypeBinding binding) {
	String qualifiedName = binding.getQualifiedName();
	if (types.has(qualifiedName))
		return types.named(qualifiedName);
	Type type = createTypeFromTypeBinding(binding);
	type.setName(binding.getName());
	types.add(qualifiedName, type);
	type.setIsStub(true);
	extractBasicModifiersFromBinding(binding.getModifiers(), type);
	type.setContainer(ensureContainerEntityForTypeBinding(binding));
	if (binding.getSuperclass() != null)
		createInheritanceFromSubtypeToSuperTypeBinding(type, binding.getSuperclass());
	for (ITypeBinding interfaceBinding : binding.getInterfaces()) {
		createInheritanceFromSubtypeToSuperTypeBinding(type, interfaceBinding);
	}
	if (binding.isParameterizedType()) {
		/*
		 * This if duplicates the condition from the create method because we want to
		 * break possible infinite loops induced by the below ensure calls. This is
		 * achieved by having this condition after the addition of the type in the types
		 * map.
		 */
		ParameterizedType parameterizedType = ((ParameterizedType) type);
		if (ensureTypeFromTypeBinding(binding.getErasure()) instanceof ParameterizableClass)
			parameterizedType.setParameterizableClass(
					(ParameterizableClass) ensureTypeFromTypeBinding(binding.getErasure()));
		List<Type> arguments = Stream.of(binding.getTypeArguments()).map(arg -> ensureTypeFromTypeBinding(arg))
				.collect(Collectors.toList());
		parameterizedType.setArguments(arguments);
	}
	if (binding.isGenericType()) {
		ParameterizableClass parameterizableClass = (ParameterizableClass) type;
		Stream.of(binding.getTypeParameters())
				.forEach(p -> createParameterType(p.getName().toString(), parameterizableClass));
	}
	return type;
}
 
private IStatus checkExpressionCondition() {
	Expression expression= getForStatement().getExpression();
	if (!(expression instanceof MethodInvocation))
		return SEMANTIC_CHANGE_WARNING_STATUS;

	MethodInvocation invoc= (MethodInvocation)expression;
	IMethodBinding methodBinding= invoc.resolveMethodBinding();
	if (methodBinding == null)
		return ERROR_STATUS;

	ITypeBinding declaringClass= methodBinding.getDeclaringClass();
	if (declaringClass == null)
		return ERROR_STATUS;

	String qualifiedName= declaringClass.getQualifiedName();
	String methodName= invoc.getName().getIdentifier();
	if (qualifiedName.startsWith("java.util.Enumeration")) { //$NON-NLS-1$
		if (!methodName.equals("hasMoreElements")) //$NON-NLS-1$
			return SEMANTIC_CHANGE_WARNING_STATUS;
	} else if (qualifiedName.startsWith("java.util.Iterator")) { //$NON-NLS-1$
		if (!methodName.equals("hasNext")) //$NON-NLS-1$
			return SEMANTIC_CHANGE_WARNING_STATUS;
		return checkIteratorCondition();
	} else {
		return SEMANTIC_CHANGE_WARNING_STATUS;
	}

	return StatusInfo.OK_STATUS;
}
 
源代码15 项目: JDeodorant   文件: ASTNodeMatcher.java
private static boolean isNumberPrimitiveType(ITypeBinding typeBinding) {
	if(typeBinding.isPrimitive()) {
		String name = typeBinding.getQualifiedName();
		if(name.equals("byte") || name.equals("double") || name.equals("float") || name.equals("int") || name.equals("long") || name.equals("short"))
			return true;
	}
	return false;
}
 
public static MethodDeclaration createDelegationStub(ICompilationUnit unit, ASTRewrite rewrite, ImportRewrite imports, ImportRewriteContext context, IMethodBinding delegate, IVariableBinding delegatingField, CodeGenerationSettings settings) throws CoreException {
	Assert.isNotNull(delegate);
	Assert.isNotNull(delegatingField);
	Assert.isNotNull(settings);

	AST ast= rewrite.getAST();

	MethodDeclaration decl= ast.newMethodDeclaration();
	decl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, delegate.getModifiers() & ~Modifier.SYNCHRONIZED & ~Modifier.ABSTRACT & ~Modifier.NATIVE));

	decl.setName(ast.newSimpleName(delegate.getName()));
	decl.setConstructor(false);

	createTypeParameters(imports, context, ast, delegate, decl);

	decl.setReturnType2(imports.addImport(delegate.getReturnType(), ast, context));

	List<SingleVariableDeclaration> params= createParameters(unit.getJavaProject(), imports, context, ast, delegate, null, decl);

	createThrownExceptions(decl, delegate, imports, context, ast);

	Block body= ast.newBlock();
	decl.setBody(body);

	String delimiter= StubUtility.getLineDelimiterUsed(unit);

	Statement statement= null;
	MethodInvocation invocation= ast.newMethodInvocation();
	invocation.setName(ast.newSimpleName(delegate.getName()));
	List<Expression> arguments= invocation.arguments();
	for (int i= 0; i < params.size(); i++)
		arguments.add(ast.newSimpleName(params.get(i).getName().getIdentifier()));
	if (settings.useKeywordThis) {
		FieldAccess access= ast.newFieldAccess();
		access.setExpression(ast.newThisExpression());
		access.setName(ast.newSimpleName(delegatingField.getName()));
		invocation.setExpression(access);
	} else
		invocation.setExpression(ast.newSimpleName(delegatingField.getName()));
	if (delegate.getReturnType().isPrimitive() && delegate.getReturnType().getName().equals("void")) {//$NON-NLS-1$
		statement= ast.newExpressionStatement(invocation);
	} else {
		ReturnStatement returnStatement= ast.newReturnStatement();
		returnStatement.setExpression(invocation);
		statement= returnStatement;
	}
	body.statements().add(statement);

	ITypeBinding declaringType= delegatingField.getDeclaringClass();
	if (declaringType == null) { // can be null for
		return decl;
	}

	String qualifiedName= declaringType.getQualifiedName();
	IPackageBinding packageBinding= declaringType.getPackage();
	if (packageBinding != null) {
		if (packageBinding.getName().length() > 0 && qualifiedName.startsWith(packageBinding.getName()))
			qualifiedName= qualifiedName.substring(packageBinding.getName().length());
	}

	if (settings.createComments) {
		/*
		 * TODO: have API for delegate method comments This is an inlined
		 * version of
		 * {@link CodeGeneration#getMethodComment(ICompilationUnit, String, MethodDeclaration, IMethodBinding, String)}
		 */
		delegate= delegate.getMethodDeclaration();
		String declaringClassQualifiedName= delegate.getDeclaringClass().getQualifiedName();
		String linkToMethodName= delegate.getName();
		String[] parameterTypesQualifiedNames= StubUtility.getParameterTypeNamesForSeeTag(delegate);
		String string= StubUtility.getMethodComment(unit, qualifiedName, decl, delegate.isDeprecated(), linkToMethodName, declaringClassQualifiedName, parameterTypesQualifiedNames, true, delimiter);
		if (string != null) {
			Javadoc javadoc= (Javadoc) rewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
			decl.setJavadoc(javadoc);
		}
	}
	return decl;
}
 
@Override
public boolean visit(TypeDeclaration changedType) {
  if (!changedType.isInterface()) {
    return true;
  }

  ITypeBinding typeBinding = changedType.resolveBinding();
  if (typeBinding == null) {
    return true;
  }

  PairedInterfaceValidator validator;
  String typeQualifiedName = typeBinding.getQualifiedName();
  TypeDeclaration dependentType = null;

  String dependentTypeQualifiedName;

  if (RemoteServiceUtilities.isSynchronousInterface(typeBinding)) {
    dependentTypeQualifiedName = RemoteServiceUtilities.computeAsyncTypeName(typeQualifiedName);
    dependentType = JavaASTUtils.findTypeDeclaration(javaProject,
        dependentTypeQualifiedName);
    validator = synchronousInterfaceValidator;
  } else {
    validator = asynchronousInterfaceValidator;
    dependentTypeQualifiedName = RemoteServiceUtilities.computeSyncTypeName(typeQualifiedName);
    if (dependentTypeQualifiedName == null) {
      // Not an async interface...
      return true;
    }

    dependentType = JavaASTUtils.findTypeDeclaration(javaProject,
        dependentTypeQualifiedName);
  }

  // Add the type dependency (even if the type doesn't yet resolve)
  dependentTypes.add(dependentTypeQualifiedName);

  ITypeBinding dependentTypeBinding = null;
  if (dependentType != null) {
    dependentTypeBinding = dependentType.resolveBinding();
  }

  problems.addAll(validator.validate(changedType, dependentTypeBinding));

  return true;
}
 
源代码18 项目: txtUML   文件: Utils.java
public static boolean isBasicType(ITypeBinding type, boolean isVoidAllowed) {

		String qualifedName = type.getQualifiedName();
		return AllowdBasicTypes.contains(qualifedName)
				|| (qualifedName.equals(void.class.getCanonicalName()) && isVoidAllowed);
	}
 
源代码19 项目: windup   文件: ReferenceResolvingVisitor.java
private AnnotationClassReference processAnnotation(ClassReference annotatedReference, Annotation node)
{
    final ITypeBinding typeBinding = node.resolveTypeBinding();
    final AnnotationClassReference reference;
    final String qualifiedName;
    final String packageName;
    final String className;
    final ResolutionStatus status;
    if (typeBinding != null)
    {
        status = ResolutionStatus.RESOLVED;
        qualifiedName = typeBinding.getQualifiedName();
        packageName = typeBinding.getPackage().getName();
        className = typeBinding.getName();
    }
    else
    {
        ResolveClassnameResult result = resolveClassname(node.getTypeName().toString());
        status = result.found ? ResolutionStatus.RECOVERED : ResolutionStatus.UNRESOLVED;
        qualifiedName = result.result;

        PackageAndClassName packageAndClassName = PackageAndClassName.parseFromQualifiedName(result.result);
        packageName = packageAndClassName.packageName;
        className = packageAndClassName.className;
    }

    reference = new AnnotationClassReference(
                annotatedReference,
                qualifiedName,
                packageName,
                className,
                status,
                compilationUnit.getLineNumber(node.getStartPosition()),
                compilationUnit.getColumnNumber(node.getStartPosition()),
                node.getLength(),
                node.toString());

    addAnnotationValues(annotatedReference, reference, node);

    return reference;
}
 
源代码20 项目: Eclipse-Postfix-Code-Completion   文件: Bindings.java
/**
 * Returns the fully qualified name of the specified type binding.
 * <p>
 * If the binding resolves to a generic type, the fully qualified name of the raw type is returned.
 *
 * @param type the type binding to get its fully qualified name
 * @return the fully qualified name
 */
public static String getFullyQualifiedName(ITypeBinding type) {
	String name= type.getQualifiedName();
	final int index= name.indexOf('<');
	if (index > 0)
		name= name.substring(0, index);
	return name;
}