本文整理匯總了Java中org.eclipse.jdt.core.dom.ITypeBinding.isPrimitive方法的典型用法代碼示例。如果您正苦於以下問題:Java ITypeBinding.isPrimitive方法的具體用法?Java ITypeBinding.isPrimitive怎麽用?Java ITypeBinding.isPrimitive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.ITypeBinding
的用法示例。
在下文中一共展示了ITypeBinding.isPrimitive方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addNewTypeBinding
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
protected void addNewTypeBinding(ITypeBinding typeBinding) {
// Skip over primitive types, which includes void
if (typeBinding == null || typeBinding.isPrimitive()) {
return;
}
String key = typeBinding.getKey();
if (!mapKeyToType.containsKey(key)) {
mapKeyToType.put(key, typeBinding);
}
String qualifiedName = typeBinding.getQualifiedName();
if (!mapNameToType.containsKey(qualifiedName)) {
mapNameToType.put(qualifiedName, typeBinding);
}
// Add supertypes, and implemented interfaces as well!
ITypeBinding superclassType = typeBinding.getSuperclass();
if ( superclassType != null ) {
addNewTypeBinding(superclassType);
}
ITypeBinding[] interfaces = typeBinding.getInterfaces();
for(ITypeBinding itfBinding : interfaces) {
addNewTypeBinding(itfBinding);
}
}
示例2: isIntegerType
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private static boolean isIntegerType(ITypeBinding binding) {
if (binding == null) {
return false;
}
if (!binding.isPrimitive()) {
return false;
}
String name= binding.getName();
if (isIntegerNumber(name)) {
return true;
}
return false;
}
示例3: annotateMethodReturnType
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
* @param rewrite
* @param methodDeclaration
*/
private void annotateMethodReturnType(ASTRewrite rewrite, MethodDeclaration methodDeclaration) {
Type returnType2 = methodDeclaration.getReturnType2();
if (returnType2 != null) {
ITypeBinding resolveBinding = returnType2.resolveBinding();
if ( !resolveBinding.isPrimitive()) {
String annotation = "";
if (HARD_CODE_STATICS && Modifier.isStatic(methodDeclaration.getModifiers())) {
annotation = "shared<shared>"; // only thing a static can be
}
else {
annotation = strategy.getAnnotationForMethodReturn(methodDeclaration);
}
SingleMemberAnnotation currentAnnotation = getCurrentAnnotation(methodDeclaration.modifiers());
if(currentAnnotation == null ) {
setReturnTypeAnnotation(rewrite, methodDeclaration, annotation);
}
else {
updateReturnTypeAnnotation(rewrite, methodDeclaration, annotation, currentAnnotation);
}
String srcType = resolveBinding.getQualifiedName();
String dstType = methodDeclaration.resolveBinding().getDeclaringClass().getQualifiedName();
// XXX. Come up with a better key
trackChanges(returnType2.toString(), annotation, getValue(currentAnnotation), CSVConst.METHOD_RETURN, srcType, dstType);
}
}
}
示例4: findFieldInType
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
* Finds the field specified by <code>fieldName</code> in
* the given <code>type</code>. Returns <code>null</code> if no such field exists.
* @param type the type to search the field in
* @param fieldName the field name
* @return the binding representing the field or <code>null</code>
*/
public static IVariableBinding findFieldInType(ITypeBinding type, String fieldName) {
if (type.isPrimitive()) {
return null;
}
IVariableBinding[] fields= type.getDeclaredFields();
for (int i= 0; i < fields.length; i++) {
IVariableBinding field= fields[i];
if (field.getName().equals(fieldName)) {
return field;
}
}
return null;
}
示例5: annotateFieldDeclarations
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private void annotateFieldDeclarations(ASTRewrite rewrite, TypeDeclaration declaration) {
FieldDeclaration[] fieldDeclarations = declaration.getFields();
for (int i = 0; i < fieldDeclarations.length; i++) {
FieldDeclaration fieldDeclaration = fieldDeclarations[i];
ITypeBinding type = fieldDeclaration.getType().resolveBinding();
if (!type.isPrimitive()) {
String annotation = "";
if (HARD_CODE_STATICS && Modifier.isStatic(fieldDeclaration.getModifiers())) {
// XXX. Avoid unique fields. Use shared.
annotation = "shared<shared>";
}
else {
annotation = strategy.getAnnotationForFieldDeclaration(fieldDeclaration);
}
SingleMemberAnnotation currentAnnotation = getCurrentAnnotation(fieldDeclaration.modifiers());
if (currentAnnotation == null) {
setFieldAnnotation(rewrite, fieldDeclaration, annotation);
}
else {
updateFieldAnnotation(rewrite, fieldDeclaration, annotation, currentAnnotation);
}
String srcType = type.getQualifiedName();
String dstType = declaration.getName().getFullyQualifiedName();
// XXX. Come up with a better key
trackChanges(fieldDeclaration.toString(), annotation, getValue(currentAnnotation), CSVConst.FIELD, srcType, dstType);
}
}
}
示例6: transfer
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
@Override
public OOGContext transfer(SourceVariableDeclaration instr, OOGContext value) {
boolean isLent = false;
boolean isUnique = false;
SourceVariable declaredVariable = instr.getDeclaredVariable();
IVariableBinding binding = declaredVariable.getBinding();
ITypeBinding typebinding = binding.getType();
if(!typebinding.isPrimitive()){
value.putAllBindingKeyToVariableMap(binding.getKey(), declaredVariable);
String enclosingClass = "";
if(binding.isParameter()){
enclosingClass = declaredVariable.getBinding().getDeclaringMethod().getDeclaringClass().getQualifiedName();
this.tm.addBindingKeyToVariable(binding.getKey(), declaredVariable);
isLent = true;
}
else if(binding.isField()){
enclosingClass = declaredVariable.getBinding().getDeclaringClass().getQualifiedName();
}
else{
enclosingClass = declaredVariable.getBinding().getDeclaringMethod().getDeclaringClass().getQualifiedName();
isLent = true;
isUnique = true;
}
Set<OType> declaredVariableTypingSet = this.tm.getTypeMapping(declaredVariable);
if(declaredVariableTypingSet==null){
boolean isMainClass = enclosingClass.equals(Config.MAINCLASS);
declaredVariableTypingSet = this.tm.initTypeMapping(isMainClass,declaredVariable,isLent,isUnique);
this.tm.putTypeMapping(declaredVariable, declaredVariableTypingSet);
}
}
return value;
}
示例7: visit
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
@Override
public boolean visit(CatchClause node) {
SingleVariableDeclaration param = node.getException();
ITypeBinding type = param.resolveBinding().getType();
if (!hasAnnotation(param.modifiers())) {
if (!type.isPrimitive()) {
if (type.getName().compareTo("String") != 0) {
setParameterAnnotation(rewrite, param, "lent");
}
}
}
return super.visit(node);
}
示例8: 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;
}
示例9: newDefaultExpression
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
* Returns an expression that is assignable to the given type binding. <code>null</code> is
* returned if the type is the 'void' type.
*
* @param ast The AST to create the expression for
* @param type The type binding to which the returned expression is compatible to
* @return the Null-literal for reference types, a boolean-literal for a boolean type, a number
* literal for primitive types or <code>null</code> if the type is void.
*/
public static Expression newDefaultExpression(AST ast, ITypeBinding type) {
if (type.isPrimitive()) {
String name= type.getName();
if ("boolean".equals(name)) { //$NON-NLS-1$
return ast.newBooleanLiteral(false);
} else if ("void".equals(name)) { //$NON-NLS-1$
return null;
} else {
return ast.newNumberLiteral("0"); //$NON-NLS-1$
}
}
return ast.newNullLiteral();
}
示例10: boxUnboxPrimitives
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public static ITypeBinding boxUnboxPrimitives(ITypeBinding castType, ITypeBinding toCast, AST ast) {
/*
* e.g:
* void m(toCast var) {
* castType i= var;
* }
*/
if (castType.isPrimitive() && !toCast.isPrimitive()) {
return Bindings.getBoxedTypeBinding(castType, ast);
} else if (!castType.isPrimitive() && toCast.isPrimitive()) {
return Bindings.getUnboxedTypeBinding(castType, ast);
} else {
return castType;
}
}
示例11: visit
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
@Override
/**
* Annotate local variables by visiting the enclosing statement.
*
* Handles both VariableDeclarationStatement and VariableDeclarationExpression
*/
public boolean visit(VariableDeclarationFragment varDecl) {
ASTNode parent = varDecl.getParent();
Type declaredType = null;
List parentMods = null;
if(parent instanceof VariableDeclarationStatement ) {
VariableDeclarationStatement varDeclStmt = (VariableDeclarationStatement)parent;
parent = varDeclStmt;
declaredType = varDeclStmt.getType();
parentMods = varDeclStmt.modifiers();
}
else if (parent instanceof VariableDeclarationExpression ) {
VariableDeclarationExpression varDeclExpr = (VariableDeclarationExpression)parent;
parent = varDeclExpr;
declaredType = varDeclExpr.getType();
// Not allowed to call varExpr.modifiers();
parentMods = null;
}
else {
parent = null;
// We handle FieldDeclaration elsewhere...
return false;
}
ITypeBinding type = declaredType.resolveBinding();
// XXX. Why would type be null here? Need to investigate.
if (type != null && !type.isPrimitive()) {
String annotation = "lent"; // XXX. Bad hard-coded default. What about <p>?
if (HARD_CODE_STATICS && isStaticScope(parent)) {
annotation = "shared<shared>";
}
else {
annotation = strategy.getAnnotationForLocalVariable(varDecl);
}
ChildListPropertyDescriptor property = parent instanceof VariableDeclarationStatement ?
VariableDeclarationStatement.MODIFIERS2_PROPERTY
: VariableDeclarationExpression.MODIFIERS2_PROPERTY;
SingleMemberAnnotation currentAnnotation = getCurrentAnnotation(parentMods);
if (currentAnnotation == null) {
setVariableAnnotation2(parent, annotation, property);
}
else {
updateVariableAnnotation2(parent, annotation, currentAnnotation, property);
}
// XXX. Lookup enclosing type declaration from local variable
String srcType = type.getQualifiedName();
String dstType = Utils.getEnclosingTypeName(varDecl);
// XXX. Come up with a better key
trackChanges(varDecl.toString(), annotation, getValue(currentAnnotation), CSVConst.VARIABLE, srcType, dstType);
}
return super.visit(varDecl);
}
示例12: compute
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public void compute(Set<IEdge> allEdges) {
edgeInfos = new HashSet<EdgeInfo>();
ReverseTraceabilityMap instance = ReverseTraceabilityMap.getInstance();
Map<FieldAccess, Set<IElement>> fieldReadMap = instance.getFieldReadMap();
String domain = "";
Crystal crystal = Crystal.getInstance();
if (fieldReadMap != null) {
for (Entry<FieldAccess, Set<IElement>> entry : fieldReadMap.entrySet()) {
FieldAccess fieldRead = entry.getKey();
Set<IElement> elems = entry.getValue();
Set<String> edgeSet = new HashSet<String>();
// Field declaration corresponding to the field read
// Why not use the annotations of the receiver? Well, We dont have it!
FieldDeclaration fieldDeclr = fieldRead.fieldDeclaration;
// Get the ITypeBinding. No domain info for Primitive types.
ITypeBinding fieldReadTypeBinding = crystal.getTypeBindingFromName(fieldDeclr.fieldType.getFullyQualifiedName());
if (fieldReadTypeBinding != null && !fieldReadTypeBinding.isPrimitive()) {
// The domain info of associated field declaration
domain = Util.getDomainString(fieldDeclr.annotation);
}
for (IElement element : elems) {
if (element instanceof ODFEdge) {
ODFEdge edge = (ODFEdge) element;
edgeSet.add(edge.toString());
}
}
HowManyEdges edgeInfo = new HowManyEdges();
edgeInfo.fieldRead = fieldRead;
edgeInfo.edgeSet = edgeSet;
edgeInfo.elems = elems;
edgeInfos.add(edgeInfo);
edgeInfo.domains = domain;
}
}
}
示例13: sameParameter
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private static boolean sameParameter(ITypeBinding type, String candidate, IType scope) throws JavaModelException {
if (type.getDimensions() != Signature.getArrayCount(candidate)) {
return false;
}
// Normalizes types
if (type.isArray()) {
type= type.getElementType();
}
candidate= Signature.getElementType(candidate);
if ((Signature.getTypeSignatureKind(candidate) == Signature.BASE_TYPE_SIGNATURE) != type.isPrimitive()) {
return false;
}
if (type.isPrimitive() || type.isTypeVariable()) {
return type.getName().equals(Signature.toString(candidate));
} else {
// normalize (quick hack until binding.getJavaElement works)
candidate= Signature.getTypeErasure(candidate);
type= type.getErasure();
if (candidate.charAt(Signature.getArrayCount(candidate)) == Signature.C_RESOLVED) {
return Signature.toString(candidate).equals(Bindings.getFullyQualifiedName(type));
} else {
String[][] qualifiedCandidates= scope.resolveType(Signature.toString(candidate));
if (qualifiedCandidates == null || qualifiedCandidates.length == 0) {
return false;
}
String packageName= type.getPackage().isUnnamed() ? "" : type.getPackage().getName(); //$NON-NLS-1$
String typeName= getTypeQualifiedName(type);
for (int i= 0; i < qualifiedCandidates.length; i++) {
String[] qualifiedCandidate= qualifiedCandidates[i];
if ( qualifiedCandidate[0].equals(packageName) &&
qualifiedCandidate[1].equals(typeName)) {
return true;
}
}
}
}
return false;
}
示例14: compute
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public void compute(Set<IEdge> allEdges) {
edgeInfos = new HashSet<EdgeInfo>();
ReverseTraceabilityMap instance = ReverseTraceabilityMap.getInstance();
Map<MethodInvocation, Set<IElement>> methodInvkMap = instance.getMethodInvokMap();
Crystal crystal = Crystal.getInstance();
List<String> argDomain = new ArrayList<String>();
if (methodInvkMap != null) {
for (Entry<MethodInvocation, Set<IElement>> entry : methodInvkMap.entrySet()) {
MethodInvocation methodInvok = entry.getKey();
Set<IElement> elems = entry.getValue();
Set<String> argEdgeSet = new HashSet<String>();
MethodInvocation metInv_RetType = null;
// TOSUM: Must I go to the method declaration and get the arguments? I think not.
List<Type> argumentTypes = methodInvok.argumentTypes;
Type recvType = methodInvok.recvType;
// Get domain Info Arg Types
for (Type arg : argumentTypes) {
ITypeBinding argTypeBinding = crystal.getTypeBindingFromName(arg.getFullyQualifiedName());
if (argTypeBinding != null && !argTypeBinding.isPrimitive()
&& methodInvok.argumentAnnotations != null) {
argDomain = methodInvok.argumentAnnotations;
}
}
for (IElement element : elems) {
if (element instanceof ODFEdge) {
ODFEdge edge = (ODFEdge) element;
// Get the flow object
Type flowObjType = edge.getFlow().getC();
String flag = edge.getFlag().toString();
// Export edges and must have arguments.
if (flag.equals("Export") && recvType != null && !argumentTypes.isEmpty()) {
// For every argument in the list, check the subcompatiblity with flow object
for (Type paramType : argumentTypes) {
// Add a condition that the type of flow objects are not the same as arguments
// If not this measure is not useful, I will always have an edge.
if (paramType != flowObjType) {
if (Util.isSubtypeCompatible(flowObjType, paramType)
|| Util.isSubtypeCompatible(paramType, flowObjType)) {
argEdgeSet.add(edge.toString());
metInv_RetType = methodInvok;
}
}
}
}
}
}
if (metInv_RetType != null) {
HowManyEdges_MIArgType edgeInfo = new HowManyEdges_MIArgType();
edgeInfo.methodInvok = metInv_RetType;
edgeInfo.domains = argDomain;
edgeInfo.argEdgeSet = argEdgeSet;
edgeInfo.elems = elems;
edgeInfos.add(edgeInfo);
}
}
}
}
示例15: 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;
}