本文整理匯總了Java中org.eclipse.jdt.core.dom.ITypeBinding.isParameterizedType方法的典型用法代碼示例。如果您正苦於以下問題:Java ITypeBinding.isParameterizedType方法的具體用法?Java ITypeBinding.isParameterizedType怎麽用?Java ITypeBinding.isParameterizedType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.ITypeBinding
的用法示例。
在下文中一共展示了ITypeBinding.isParameterizedType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: containsTypeVariables
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public static boolean containsTypeVariables(ITypeBinding type) {
if (type.isTypeVariable()) {
return true;
}
if (type.isArray()) {
return containsTypeVariables(type.getElementType());
}
if (type.isCapture()) {
return containsTypeVariables(type.getWildcard());
}
if (type.isParameterizedType()) {
return containsTypeVariables(type.getTypeArguments());
}
if (type.isWildcardType() && type.getBound() != null) {
return containsTypeVariables(type.getBound());
}
return false;
}
示例2: newCreationType
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
* Create a Type suitable as the creationType in a ClassInstanceCreation expression.
* @param ast The AST to create the nodes for.
* @param typeBinding binding representing the given class type
* @param importRewrite the import rewrite to use
* @param importContext the import context used to determine which (null) annotations to consider
* @return a Type suitable as the creationType in a ClassInstanceCreation expression.
*/
public static Type newCreationType(AST ast, ITypeBinding typeBinding, ImportRewrite importRewrite, ImportRewriteContext importContext) {
if (typeBinding.isParameterizedType()) {
Type baseType= newCreationType(ast, typeBinding.getTypeDeclaration(), importRewrite, importContext);
IAnnotationBinding[] typeAnnotations= importContext.removeRedundantTypeAnnotations(typeBinding.getTypeAnnotations(), TypeLocation.NEW, typeBinding);
for (IAnnotationBinding typeAnnotation : typeAnnotations) {
((AnnotatableType)baseType).annotations().add(importRewrite.addAnnotation(typeAnnotation, ast, importContext));
}
ParameterizedType parameterizedType= ast.newParameterizedType(baseType);
for (ITypeBinding typeArgument : typeBinding.getTypeArguments()) {
typeArgument= StubUtility2.replaceWildcardsAndCaptures(typeArgument);
parameterizedType.typeArguments().add(importRewrite.addImport(typeArgument, ast, importContext, TypeLocation.TYPE_ARGUMENT));
}
return parameterizedType;
} else {
return importRewrite.addImport(typeBinding, ast, importContext, TypeLocation.NEW);
}
}
示例3: 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;
}
});
}
示例4: 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;
}
示例5: pinDownInner
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
* A method to pin down inner of the qualifiers of a generic type
*
*/
private void pinDownInner() {
// TODO Auto-generated method stub
TM tm = currentTM.copyTypeMapping(currentTM.getKey());
for (Variable var : tm.keySet()) {
if(var instanceof TACNewExpr){
TACNewExpr newExprVar = (TACNewExpr)var;
ITypeBinding instantiatedType = newExprVar.resolveType();
if(instantiatedType.isParameterizedType()){
Set<OType> varSet = new HashSet<OType>(tm.getAnalysisResult(var));
if(varSet.size()>1){
RankingStrategy ranking = RankingStrategy.getInstance();
OType highestQualifier = ranking.pickFromSet(varSet, null);
varSet.clear();
varSet.add(highestQualifier);
tm.putTypeMapping(var, varSet);
TM newTM = runTFs(tm);
if(!newTM.isDiscarded){
currentTM = newTM;
}
}
}
}
}
}
示例6: getRawName
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public static String getRawName(ITypeBinding binding) {
String name= binding.getName();
if (binding.isParameterizedType() || binding.isGenericType()) {
int idx= name.indexOf('<');
if (idx != -1) {
return name.substring(0, idx);
}
}
return name;
}
示例7: 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()]);
}
示例8: changeBackCompletedOprs
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public void changeBackCompletedOprs(TM tm){
List<BaseOperation> completedOprs = context.getCompletedOprs();
for (BaseOperation opr : completedOprs) {
// Skip auto-stuff
if(opr.isImplicit() || opr.getRefID().startsWith("Auto")) {
continue;
}
for (Variable var : opr.getVars() ) {
Set<OType> variableSet = null;
// For heuristics respect the owner only
if(opr instanceof InferOwnedHeuristic || opr instanceof InferPDHeuristic){
ITypeBinding varType = var.resolveType();
String declaringClass = Utils.getDeclaringClass(var);
boolean isMain = declaringClass.equals(Config.MAINCLASS);
String oprOwner = opr.getOprOwner(var);
if(varType.isParameterizedType()){
variableSet = tm.initParametrizedTypeMapping(oprOwner, isMain);
}
else{
variableSet = tm.initRespectTypeMapping(oprOwner, isMain);
}
}
// For refinements respect both owner and alpha
// else{
// variableSet = opr.getVarSet(var);
// }
tm.putTypeMapping(var, variableSet);
}
}
}
示例9: visit
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
@Override
public boolean visit(VariableDeclarationStatement param) {
ITypeBinding type = param.getType().resolveBinding();
if (hasAnnotation(param.modifiers()) && !type.isPrimitive()) {
List<VariableDeclarationFragment> L = param.fragments();
for (VariableDeclarationFragment oo : L) {
SingleMemberAnnotation annotation = getAnnotation(param.modifiers());
Expression value = annotation.getValue();
if (value instanceof StringLiteral) { //@Domain("D")
StringLiteral annotValue = (StringLiteral)value;
String parserInput = annotValue.getLiteralValue();
AnnotationInfo annotInfo = AnnotationInfo.parseAnnotation(parserInput);
DomainParams annot = annotInfo.getAnnotation();
boolean b = annot.isObjectPublicDomain();
if (b)
{
b = true;
}
boolean isDom = false;
boolean isDomPars = false;
String qualifiedName = "";
// if (oo.resolveBinding().getDeclaringMethod() != null) {
// qualifiedName = oo.resolveBinding().getDeclaringMethod().getDeclaringClass().getQualifiedName();
//
// isDom = isDomain(oo.resolveBinding().getDeclaringMethod().getDeclaringClass(), annot);
// isDomPars = isDomainParams(oo.resolveBinding().getDeclaringMethod().getDeclaringClass(),annot);
//
//
// }
// else
{
qualifiedName = currentType.resolveBinding().getQualifiedName();
isDom = isDomain(currentType.resolveBinding(), annot);
isDomPars = isDomainParams(currentType.resolveBinding() , annot);
}
ObjectMetricItem archMetricItem = new ObjectMetricItem(oo.resolveBinding().getKey(),oo.resolveBinding().getName().toString(),
param.getType().resolveBinding().getQualifiedName().toString(),
parserInput,
qualifiedName,
oo.toString(),
Modifier.isStatic(param.getModifiers()),
"LocalVariable",
type.isArray(),
type.isEnum(),
type.isParameterizedType(),
isDom,
isDomPars,
annot.isObjectPublicDomain()
);
if (!objectsHashtable.containsKey(archMetricItem.toString())) {
objectsHashtable.put(archMetricItem.toString(), archMetricItem);
}
// TODO: src.triplets for Local variables
}
}
}
return super.visit(param);
}
示例10: QualifiedClassName
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public QualifiedClassName(ITypeBinding cBinding, QualifiedClassName cTHIS) {
// this(cBinding);
// substActualGenerics(cTHIS, typeDecl);
if (cTHIS != null && cTHIS.getTypeBinding() != null && cBinding != null && cBinding.isParameterizedType()) {
this.classBinding = GenHelper.translateFtoA(cBinding, cTHIS.getTypeBinding());
if(classBinding == null ) {
System.err.println("WARNING: null ITypeBinding for " + cTHIS);
}
ast.TypeDeclaration.createFrom(this.classBinding);
} else {
this.classBinding = cBinding;
}
this.cthis = cTHIS;
if (classBinding != null) {
this.type = Type.createFrom(classBinding);
} else if (cBinding != null) {
this.type = Type.createFrom(cBinding);
}
if (cBinding == null && cTHIS == null) {
this.type = new Type("DUMMY");
}
// TORAD: Look into this.
// this.fullyQualifiedTypeName = classBinding.getQualifiedName();
// else if (cBinding!=null)
// this.fullyQualifiedTypeName = cBinding.getQualifiedName();
// else
// this.fullyQualifiedTypeName = "NEWWWType";
}
示例11: computeTypeArgumentProposals
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private String[] computeTypeArgumentProposals(CompletionProposal proposal) {
try {
IType type = (IType) resolveJavaElement(
compilationUnit.getJavaProject(), proposal);
if (type == null) {
return new String[0];
}
ITypeParameter[] parameters = type.getTypeParameters();
if (parameters.length == 0) {
return new String[0];
}
String[] arguments = new String[parameters.length];
ITypeBinding expectedTypeBinding = getExpectedTypeForGenericParameters();
if (expectedTypeBinding != null && expectedTypeBinding.isParameterizedType()) {
// in this case, the type arguments we propose need to be compatible
// with the corresponding type parameters to declared type
IType expectedType= (IType) expectedTypeBinding.getJavaElement();
IType[] path= TypeProposalUtils.computeInheritancePath(type, expectedType);
if (path == null) {
// proposed type does not inherit from expected type
// the user might be looking for an inner type of proposed type
// to instantiate -> do not add any type arguments
return new String[0];
}
int[] indices= new int[parameters.length];
for (int paramIdx= 0; paramIdx < parameters.length; paramIdx++) {
indices[paramIdx]= TypeProposalUtils.mapTypeParameterIndex(path, path.length - 1, paramIdx);
}
// for type arguments that are mapped through to the expected type's
// parameters, take the arguments of the expected type
ITypeBinding[] typeArguments= expectedTypeBinding.getTypeArguments();
for (int paramIdx= 0; paramIdx < parameters.length; paramIdx++) {
if (indices[paramIdx] != -1) {
// type argument is mapped through
ITypeBinding binding= typeArguments[indices[paramIdx]];
arguments[paramIdx]= computeTypeProposal(binding, parameters[paramIdx]);
}
}
}
// for type arguments that are not mapped through to the expected type,
// take the lower bound of the type parameter
for (int i = 0; i < arguments.length; i++) {
if (arguments[i] == null) {
arguments[i] = computeTypeProposal(parameters[i]);
}
}
return arguments;
} catch (JavaModelException e) {
return new String[0];
}
}
示例12: getExplicitCast
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
* Returns the type to which an inlined variable initializer should be cast, or
* <code>null</code> if no cast is necessary.
*
* @param initializer the initializer expression of the variable to inline
* @param reference the reference to the variable (which is to be inlined)
* @return a type binding to which the initializer should be cast, or <code>null</code> iff no cast is necessary
* @since 3.6
*/
public static ITypeBinding getExplicitCast(Expression initializer, Expression reference) {
ITypeBinding initializerType= initializer.resolveTypeBinding();
ITypeBinding referenceType= reference.resolveTypeBinding();
if (initializerType == null || referenceType == null) {
return null;
}
if (initializerType.isPrimitive() && referenceType.isPrimitive() && ! referenceType.isEqualTo(initializerType)) {
return referenceType;
} else if (initializerType.isPrimitive() && ! referenceType.isPrimitive()) { // initializer is autoboxed
ITypeBinding unboxedReferenceType= Bindings.getUnboxedTypeBinding(referenceType, reference.getAST());
if (!unboxedReferenceType.isEqualTo(initializerType)) {
return unboxedReferenceType;
} else if (needsExplicitBoxing(reference)) {
return referenceType;
}
} else if (! initializerType.isPrimitive() && referenceType.isPrimitive()) { // initializer is autounboxed
ITypeBinding unboxedInitializerType= Bindings.getUnboxedTypeBinding(initializerType, reference.getAST());
if (!unboxedInitializerType.isEqualTo(referenceType)) {
return referenceType;
}
} else if (initializerType.isRawType() && referenceType.isParameterizedType()) {
return referenceType; // don't lose the unchecked conversion
} else if (initializer instanceof LambdaExpression || initializer instanceof MethodReference) {
if (isTargetAmbiguous(reference, isExplicitlyTypedLambda(initializer))) {
return referenceType;
} else {
ITypeBinding targetType= getTargetType(reference);
if (targetType == null || targetType != referenceType) {
return referenceType;
}
}
} else if (! TypeRules.canAssign(initializerType, referenceType)) {
if (!Bindings.containsTypeVariables(referenceType)) {
return referenceType;
}
}
return null;
}
示例13: traverseFields
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private void traverseFields(TypeDeclaration declaration) {
FieldDeclaration[] fieldDeclarations = declaration.getFields();
for (int i = 0; i < fieldDeclarations.length; i++) {
FieldDeclaration fieldDeclaration = fieldDeclarations[i];
ITypeBinding type = fieldDeclaration.getType().resolveBinding();
if (hasAnnotation(fieldDeclaration.modifiers()) && !type.isPrimitive()) {
List ff = fieldDeclaration.fragments();
for (Object ff1 : ff) {
VariableDeclaration V = (VariableDeclaration) ff1;
String key = V.resolveBinding().getKey();
String name = V.getName().getIdentifier();
String objectType = fieldDeclaration.getType().resolveBinding().getQualifiedName();
String enclosingType = declaration.resolveBinding().getQualifiedName();
String ast = fieldDeclaration.getAST().toString();
boolean isStatic = Modifier.isStatic(fieldDeclaration.getModifiers());
//
SingleMemberAnnotation annotation = getAnnotation(fieldDeclaration.modifiers());
Expression value = annotation.getValue();
if (value instanceof StringLiteral) { //@Domain("D")
StringLiteral annotValue = (StringLiteral)value;
String parserInput = annotValue.getLiteralValue();
AnnotationInfo annotInfo = AnnotationInfo.parseAnnotation(parserInput);
DomainParams annot = annotInfo.getAnnotation();
boolean isDomainParam = isDomainParams(declaration.resolveBinding(), annot);
boolean isDomain = isDomain(declaration.resolveBinding(), annot);
ObjectMetricItem archMetricItem = new ObjectMetricItem(key,name,
objectType,
parserInput,
enclosingType,
ast,
isStatic,
"Field",
type.isArray(),
type.isEnum(),
type.isParameterizedType(),
isDomain,
isDomainParam,
annot.isObjectPublicDomain()
);
// TODO: Do we need the following two lines?
archMetricItem.setDomainParams(isDomainParam);
archMetricItem.setDomain(isDomain);
if (!objectsHashtable.containsKey(archMetricItem.toString())) {
objectsHashtable.put(archMetricItem.toString(), archMetricItem);
}
// TODO: src.triplets for Field
}
else
{
//this should not happen
System.out.println("Error in field declaration: "+ value);
}
}
}
}
}
示例14: apply
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
@Override
public boolean apply(TM tm, TMSolutionType solIndex){
boolean isHeuristicApplied = false;
boolean isPublicParam = false;
Set<Entry<Variable, Set<OType>>> entrySet = tm.entrySet();
Set<OType> newSourceTyping = new HashSet<OType>();
// XXX. Can we replace iteration with just 1 lookup: entrySet.get()?
for (Entry<Variable, Set<OType>> entry : entrySet) {
Variable var = entry.getKey();
if(var.equals(this.changedVar) /*au.isTypeEqual(auType) && au.isEnclosingTypeEqual(auEnclosingType)*/){
if(var instanceof TACVariable || var instanceof SourceVariable){
Variable srcVariable = null;
IVariableBinding srcVariableBinding = null;
if(var instanceof TACVariable){
srcVariable = (TACVariable)var;
srcVariableBinding = ((TACVariable)srcVariable).getVarDecl();
if(srcVariableBinding.isParameter()){
if(Modifier.isPublic(srcVariableBinding.getModifiers())){
isPublicParam = true;
}
}
}
else{
srcVariable = (SourceVariable)var;
srcVariableBinding = ((SourceVariable)srcVariable).getBinding();
}
if(!isPublicParam){
boolean isMain = srcVariableBinding.getDeclaringClass().getQualifiedName().equals(Config.MAINCLASS);
String solAlpha = SolutionManager.getSolution(solIndex, this.getRefinementType(), isMain);
if(solAlpha != null ) {
OType newSrcTyping = null;
ITypeBinding sourceType = srcVariableBinding.getType();
if(sourceType.isParameterizedType()){
ITypeBinding[] typeArguments = sourceType.getTypeArguments();
for (ITypeBinding iTypeBinding : typeArguments) {
for (Variable paramTypeAu : tm.keySet()) {
if(paramTypeAu.resolveType().equals(iTypeBinding)){
Set<OType> paramAUTyping = tm.getTypeMapping(paramTypeAu);
for (OType oType : paramAUTyping) {
newSrcTyping = new OType("this.owned", oType.getOwner(), oType.getAlpha());
newSourceTyping.add(newSrcTyping);
}
break;
}
}
}
}
else{
newSrcTyping = new OType("this.owned", solAlpha);
newSourceTyping.add(newSrcTyping);
}
Set<OType> analysisResult = new HashSet<OType>(newSourceTyping);
tm.putTypeMapping(var, analysisResult);
// Record the AU being modified directly based on the refinement
//this.addAU(au);
this.putVariableMap(var, newSourceTyping);
// Record the new set of typings
this.setNewTyping(solIndex, newSrcTyping);
isHeuristicApplied = true;
}
}
}
}
}
return isHeuristicApplied;
}
示例15: translateFtoA
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
* Translate a typeBinding with a formal type parameter into one with fully substituted type
* based on the enclosing type
* @param typeBinding: e.g., virtual field of type <E extends java.lang.Object>
* @param actualBinding: the enclosing type, e.g., class ArrayList<courses.Course>
* where the generic type declaration is class ArrayList<E> {...}
* @return typeBinding with the type substitution performed, e.g., courses.Course
*/
public static ITypeBinding translateFtoA(ITypeBinding typeBinding, ITypeBinding actualBinding) {
ITypeBinding toTypeBindingActual = typeBinding;
// HACK: Introduced bugs!
// Check that it is a generic type, to avoid generating a type that does not exist!
// if(!typeBinding.isGenericType()) {
// return typeBinding;
// }
// HACK: Introduced bugs!
if (typeBinding.isEqualTo(actualBinding)) {
return typeBinding;
}
// Instantiate generic types...
if (actualBinding.isParameterizedType()) {
ITypeBinding[] typeParameters = actualBinding.getErasure().getTypeParameters();
int pIndex = -1;
int index = 0;
for(ITypeBinding typeParameter : typeParameters ) {
if ( typeParameter.isEqualTo(typeBinding) ) {
pIndex = index;
break;
}
index++;
}
ITypeBinding[] typeArguments = actualBinding.getTypeArguments();
if ( typeBinding.isTypeVariable() && typeArguments != null && pIndex != -1 && pIndex < typeArguments.length) {
toTypeBindingActual = typeArguments[pIndex];
}
else {
String[] typeArgumentString = getParameters(typeArguments);
String bindingKey = BindingKey.createParameterizedTypeBindingKey(typeBinding.getKey(), typeArgumentString);
toTypeBindingActual = GenHelper.mapBindingKeyToTypeBinding(bindingKey);
}
}
return toTypeBindingActual;
}