本文整理匯總了Java中org.eclipse.jdt.core.dom.ITypeBinding.getTypeDeclaration方法的典型用法代碼示例。如果您正苦於以下問題:Java ITypeBinding.getTypeDeclaration方法的具體用法?Java ITypeBinding.getTypeDeclaration怎麽用?Java ITypeBinding.getTypeDeclaration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.ITypeBinding
的用法示例。
在下文中一共展示了ITypeBinding.getTypeDeclaration方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sortTypes
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private void sortTypes(ITypeBinding[] typeProposals) {
ITypeBinding oldType;
if (fBinding instanceof IMethodBinding) {
oldType= ((IMethodBinding) fBinding).getReturnType();
} else {
oldType= ((IVariableBinding) fBinding).getType();
}
if (! oldType.isParameterizedType()) {
return;
}
final ITypeBinding oldTypeDeclaration= oldType.getTypeDeclaration();
Arrays.sort(typeProposals, new Comparator<ITypeBinding>() {
@Override
public int compare(ITypeBinding o1, ITypeBinding o2) {
return rank(o2) - rank(o1);
}
private int rank(ITypeBinding type) {
if (type.getTypeDeclaration().equals(oldTypeDeclaration)) {
return 1;
}
return 0;
}
});
}
示例2: typeFtoA
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
* Perform generic type substitution...
* Currently, just uses string substitution.
* Could be problematic (e.g., if it constructs invalid types).
*
* @return
*/
public static String typeFtoA(ITypeBinding typeBinding) {
String formalType = "";
if(typeBinding.isParameterizedType()){
ITypeBinding genericTypeBinding = typeBinding.getTypeDeclaration();
ITypeBinding[] typeArguments = typeBinding.getTypeArguments();
ITypeBinding[] typeParameters = genericTypeBinding.getTypeParameters();
formalType = typeBinding.getQualifiedName();
int i =0;
for (ITypeBinding iTypeBinding : typeParameters) {
String typeParameterName = iTypeBinding.getQualifiedName();
String typeArgumentName = typeArguments[i].getQualifiedName();
formalType = formalType.replace(typeArgumentName, typeParameterName);
}
}
else{
formalType = typeBinding.getQualifiedName();
}
return formalType;
}
示例3: isSuperType
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
* Returns <code>true</code> if the given type is a super type of a candidate.
* <code>true</code> is returned if the two type bindings are identical (TODO)
* @param possibleSuperType the type to inspect
* @param type the type whose super types are looked at
* @param considerTypeArguments if <code>true</code>, consider type arguments of <code>type</code>
* @return <code>true</code> iff <code>possibleSuperType</code> is
* a super type of <code>type</code> or is equal to it
*/
public static boolean isSuperType(ITypeBinding possibleSuperType, ITypeBinding type, boolean considerTypeArguments) {
if (type.isArray() || type.isPrimitive()) {
return false;
}
if (! considerTypeArguments) {
type= type.getTypeDeclaration();
}
if (Bindings.equals(type, possibleSuperType)) {
return true;
}
ITypeBinding superClass= type.getSuperclass();
if (superClass != null) {
if (isSuperType(possibleSuperType, superClass, considerTypeArguments)) {
return true;
}
}
if (possibleSuperType.isInterface()) {
ITypeBinding[] superInterfaces= type.getInterfaces();
for (int i= 0; i < superInterfaces.length; i++) {
if (isSuperType(possibleSuperType, superInterfaces[i], considerTypeArguments)) {
return true;
}
}
}
return false;
}
示例4: add
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
* Tries to find the given type name and add it to the import structure.
* @param ref the name node
*/
public void add(SimpleName ref) {
String typeName= ref.getIdentifier();
if (fImportsAdded.contains(typeName)) {
return;
}
IBinding binding= ref.resolveBinding();
if (binding != null) {
if (binding.getKind() != IBinding.TYPE) {
return;
}
ITypeBinding typeBinding= (ITypeBinding) binding;
if (typeBinding.isArray()) {
typeBinding= typeBinding.getElementType();
}
typeBinding= typeBinding.getTypeDeclaration();
if (!typeBinding.isRecovered()) {
if (needsImport(typeBinding, ref)) {
fImpStructure.addImport(typeBinding);
fImportsAdded.add(typeName);
}
return;
}
} else {
if (fDoIgnoreLowerCaseNames && typeName.length() > 0) {
char ch= typeName.charAt(0);
if (Strings.isLowerCase(ch) && Character.isLetter(ch)) {
return;
}
}
}
fImportsAdded.add(typeName);
fUnresolvedTypes.put(typeName, new UnresolvedTypeData(ref));
}
示例5: getVariableNameSuggestions
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public static String[] getVariableNameSuggestions(int variableKind, IJavaProject project, ITypeBinding expectedType, Expression assignedExpression, Collection<String> excluded) {
LinkedHashSet<String> res= new LinkedHashSet<>(); // avoid duplicates but keep order
if (assignedExpression != null) {
String nameFromExpression= getBaseNameFromExpression(project, assignedExpression, variableKind);
if (nameFromExpression != null) {
add(getVariableNameSuggestions(variableKind, project, nameFromExpression, 0, excluded, false), res); // pass 0 as dimension, base name already contains plural.
}
String nameFromParent= getBaseNameFromLocationInParent(assignedExpression);
if (nameFromParent != null) {
add(getVariableNameSuggestions(variableKind, project, nameFromParent, 0, excluded, false), res); // pass 0 as dimension, base name already contains plural.
}
}
if (expectedType != null) {
expectedType= Bindings.normalizeTypeBinding(expectedType);
if (expectedType != null) {
int dim= 0;
if (expectedType.isArray()) {
dim= expectedType.getDimensions();
expectedType= expectedType.getElementType();
}
if (expectedType.isParameterizedType()) {
expectedType= expectedType.getTypeDeclaration();
}
String typeName= expectedType.getName();
if (typeName.length() > 0) {
add(getVariableNameSuggestions(variableKind, project, typeName, dim, excluded, false), res);
}
}
}
if (res.isEmpty()) {
return getDefaultVariableNameSuggestions(variableKind, excluded);
}
return res.toArray(new String[res.size()]);
}
示例6: addNewFieldProposals
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private static void addNewFieldProposals(ICompilationUnit cu, CompilationUnit astRoot, ITypeBinding binding,
ITypeBinding declaringTypeBinding, SimpleName simpleName, boolean isWriteAccess,
Collection<CUCorrectionProposal> proposals) throws JavaModelException {
// new variables
ICompilationUnit targetCU;
ITypeBinding senderDeclBinding;
if (binding != null) {
senderDeclBinding= binding.getTypeDeclaration();
targetCU= ASTResolving.findCompilationUnitForBinding(cu, astRoot, senderDeclBinding);
} else { // binding is null for accesses without qualifier
senderDeclBinding= declaringTypeBinding;
targetCU= cu;
}
if (!senderDeclBinding.isFromSource() || targetCU == null) {
return;
}
boolean mustBeConst= ASTResolving.isInsideModifiers(simpleName);
addNewFieldForType(targetCU, binding, senderDeclBinding, simpleName, isWriteAccess, mustBeConst, proposals);
if (binding == null && senderDeclBinding.isNested()) {
ASTNode anonymDecl= astRoot.findDeclaringNode(senderDeclBinding);
if (anonymDecl != null) {
ITypeBinding bind= Bindings.getBindingOfParentType(anonymDecl.getParent());
if (!bind.isAnonymous()) {
addNewFieldForType(targetCU, bind, bind, simpleName, isWriteAccess, mustBeConst, proposals);
}
}
}
}
示例7: isConflictingType
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private boolean isConflictingType(ITypeBinding binding, String qualifier, String name) {
binding= binding.getTypeDeclaration();
return !isSameType(binding, qualifier, name) && isConflicting(binding, name);
}
示例8: addSimilarTypeProposals
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private static void addSimilarTypeProposals(int kind, ICompilationUnit cu, Name node, int relevance,
Collection<CUCorrectionProposal> proposals) throws CoreException {
SimilarElement[] elements= SimilarElementsRequestor.findSimilarElement(cu, node, kind);
// try to resolve type in context -> highest severity
String resolvedTypeName= null;
ITypeBinding binding= ASTResolving.guessBindingForTypeReference(node);
if (binding != null) {
ITypeBinding simpleBinding= binding;
if (simpleBinding.isArray()) {
simpleBinding= simpleBinding.getElementType();
}
simpleBinding= simpleBinding.getTypeDeclaration();
if (!simpleBinding.isRecovered()) {
resolvedTypeName= simpleBinding.getQualifiedName();
CUCorrectionProposal proposal= createTypeRefChangeProposal(cu, resolvedTypeName, node, relevance + 2, elements.length);
proposals.add(proposal);
if (proposal instanceof AddImportCorrectionProposal) {
proposal.setRelevance(relevance + elements.length + 2);
}
if (binding.isParameterizedType()
&& (node.getParent() instanceof SimpleType || node.getParent() instanceof NameQualifiedType)
&& !(node.getParent().getParent() instanceof Type)) {
proposals.add(createTypeRefChangeFullProposal(cu, binding, node, relevance + 5));
}
}
} else {
ASTNode normalizedNode= ASTNodes.getNormalizedNode(node);
if (!(normalizedNode.getParent() instanceof Type) && node.getParent() != normalizedNode) {
ITypeBinding normBinding= ASTResolving.guessBindingForTypeReference(normalizedNode);
if (normBinding != null && !normBinding.isRecovered()) {
proposals.add(createTypeRefChangeFullProposal(cu, normBinding, normalizedNode, relevance + 5));
}
}
}
// add all similar elements
for (int i= 0; i < elements.length; i++) {
SimilarElement elem= elements[i];
if ((elem.getKind() & SimilarElementsRequestor.ALL_TYPES) != 0) {
String fullName= elem.getName();
if (!fullName.equals(resolvedTypeName)) {
proposals.add(createTypeRefChangeProposal(cu, fullName, node, relevance, elements.length));
}
}
}
}
示例9: addNewMethodProposals
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private static void addNewMethodProposals(ICompilationUnit cu, CompilationUnit astRoot, Expression sender,
List<Expression> arguments, boolean isSuperInvocation, ASTNode invocationNode, String methodName,
Collection<CUCorrectionProposal> proposals) throws JavaModelException {
ITypeBinding nodeParentType= Bindings.getBindingOfParentType(invocationNode);
ITypeBinding binding= null;
if (sender != null) {
binding= sender.resolveTypeBinding();
} else {
binding= nodeParentType;
if (isSuperInvocation && binding != null) {
binding= binding.getSuperclass();
}
}
if (binding != null && binding.isFromSource()) {
ITypeBinding senderDeclBinding= binding.getTypeDeclaration();
ICompilationUnit targetCU= ASTResolving.findCompilationUnitForBinding(cu, astRoot, senderDeclBinding);
if (targetCU != null) {
String label;
ITypeBinding[] parameterTypes= getParameterTypes(arguments);
if (parameterTypes != null) {
String sig = ASTResolving.getMethodSignature(methodName, parameterTypes, false);
boolean is18OrHigher= JavaModelUtil.is18OrHigher(targetCU.getJavaProject());
boolean isSenderBindingInterface= senderDeclBinding.isInterface();
if (nodeParentType == senderDeclBinding) {
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createmethod_description, sig);
} else {
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createmethod_other_description, new Object[] { sig, BasicElementLabels.getJavaElementName(senderDeclBinding.getName()) } );
}
if (is18OrHigher || !isSenderBindingInterface
|| (nodeParentType != senderDeclBinding && (!(sender instanceof SimpleName) || !((SimpleName) sender).getIdentifier().equals(senderDeclBinding.getName())))) {
proposals.add(new NewMethodCorrectionProposal(label, targetCU, invocationNode, arguments,
senderDeclBinding, IProposalRelevance.CREATE_METHOD));
}
if (senderDeclBinding.isNested() && cu.equals(targetCU) && sender == null && Bindings.findMethodInHierarchy(senderDeclBinding, methodName, (ITypeBinding[]) null) == null) { // no covering method
ASTNode anonymDecl= astRoot.findDeclaringNode(senderDeclBinding);
if (anonymDecl != null) {
senderDeclBinding= Bindings.getBindingOfParentType(anonymDecl.getParent());
isSenderBindingInterface= senderDeclBinding.isInterface();
if (!senderDeclBinding.isAnonymous()) {
if (is18OrHigher || !isSenderBindingInterface) {
String[] args = new String[] { sig,
ASTResolving.getTypeSignature(senderDeclBinding) };
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createmethod_other_description, args);
proposals.add(new NewMethodCorrectionProposal(label, targetCU, invocationNode,
arguments, senderDeclBinding, IProposalRelevance.CREATE_METHOD));
}
}
}
}
}
}
}
}