List of usage examples for org.eclipse.jdt.core.dom Type isPrimitiveType
public final boolean isPrimitiveType()
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
protected String typeName(final org.eclipse.jdt.core.dom.Type t) { if (t.isArrayType()) return typeName((ArrayType) t); if (t.isParameterizedType()) return typeName((ParameterizedType) t); if (t.isPrimitiveType()) return typeName((PrimitiveType) t); if (t.isQualifiedType()) return typeName((QualifiedType) t); if (t.isIntersectionType()) return typeName((IntersectionType) t); if (t.isUnionType()) return typeName((UnionType) t); if (t.isWildcardType()) return typeName((WildcardType) t); return typeName((SimpleType) t); }
From source file:boa.datagen.util.JavaVisitor.java
License:Apache License
private String typeName(org.eclipse.jdt.core.dom.Type t) { if (t.isArrayType()) return typeName(((ArrayType) t).getComponentType()) + "[]"; if (t.isParameterizedType()) { String name = ""; for (Object o : ((ParameterizedType) t).typeArguments()) { if (name.length() > 0) name += ", "; name += typeName((org.eclipse.jdt.core.dom.Type) o); }// w ww. j a v a 2 s . c o m return typeName(((ParameterizedType) t).getType()) + "<" + name + ">"; } if (t.isPrimitiveType()) return ((PrimitiveType) t).getPrimitiveTypeCode().toString(); if (t.isQualifiedType()) return typeName(((QualifiedType) t).getQualifier()) + "." + ((QualifiedType) t).getName().getFullyQualifiedName(); if (t.isUnionType()) { String name = ""; for (Object o : ((UnionType) t).types()) { if (name.length() > 0) name += " | "; name += typeName((org.eclipse.jdt.core.dom.Type) o); } return name; } if (t.isWildcardType()) { String name = "?"; if (((WildcardType) t).getBound() != null) { name += " " + (((WildcardType) t).isUpperBound() ? "extends" : "super"); name += " " + typeName(((WildcardType) t).getBound()); } return name; } return ((SimpleType) t).getName().getFullyQualifiedName(); }
From source file:br.com.objectos.way.core.code.jdt.TypeWrapper.java
License:Apache License
public static TypeWrapper wrapperOf(Type someType) { if (someType.isPrimitiveType()) { PrimitiveType type = PrimitiveType.class.cast(someType); return new TypeWrapperPrimitive(type); }/*from w ww. j a va 2s . c o m*/ if (someType.isSimpleType()) { SimpleType type = SimpleType.class.cast(someType); return new TypeWrapperSimple(type); } throw new UnsupportedOperationException(); }
From source file:com.google.devtools.j2cpp.translate.Rewriter.java
License:Open Source License
/** * Remove private serialization methods and fields; since Java serialization * isn't supported, they only take up space. The list of methods is taken * from the java.io.Serialization javadoc comments. *//* w w w . java 2 s . c om*/ private void removeSerialization(List<BodyDeclaration> members) { for (Iterator<BodyDeclaration> iterator = members.iterator(); iterator.hasNext();) { BodyDeclaration member = iterator.next(); int mods = member.getModifiers(); if (member instanceof MethodDeclaration) { IMethodBinding binding = Types.getMethodBinding(member); String name = binding.getName(); ITypeBinding[] parameterTypes = binding.getParameterTypes(); ITypeBinding returnType = binding.getReturnType(); if (name.equals("readObject") && Modifier.isPrivate(mods) && parameterTypes.length == 1 && parameterTypes[0].getQualifiedName().equals("java.io.ObjectInputStream") && returnType.getBinaryName().equals("V")) { iterator.remove(); continue; } if (name.equals("writeObject") && Modifier.isPrivate(mods) && parameterTypes.length == 1 && parameterTypes[0].getQualifiedName().equals("java.io.ObjectOutputStream") && returnType.getBinaryName().equals("V")) { iterator.remove(); continue; } if (name.equals("readObjectNoData") && Modifier.isPrivate(mods) && parameterTypes.length == 0 && returnType.getBinaryName().equals("V")) { iterator.remove(); continue; } if ((name.equals("readResolve") || name.equals("writeResolve")) && Modifier.isPrivate(mods) && parameterTypes.length == 0 && returnType.getQualifiedName().equals("java.lang.Object")) { iterator.remove(); continue; } } else if (member instanceof FieldDeclaration) { FieldDeclaration field = (FieldDeclaration) member; Type type = field.getType(); VariableDeclarationFragment var = (VariableDeclarationFragment) field.fragments().get(0); if (var.getName().getIdentifier().equals("serialVersionUID") && type.isPrimitiveType() && ((PrimitiveType) type).getPrimitiveTypeCode() == PrimitiveType.LONG && Modifier.isPrivate(mods) && Modifier.isStatic(mods)) { iterator.remove(); continue; } } } }
From source file:com.google.gdt.eclipse.designer.builders.GwtBuilder.java
License:Open Source License
/** * @return the {@link Type} that extends {@link Object}, even if given is primitive. *///from ww w. j av a2 s.co m private static Type getObjectType(Type type) { if (type.isPrimitiveType()) { String identifier = ((PrimitiveType) type).getPrimitiveTypeCode().toString(); if (identifier.equals("int")) { identifier = "Integer"; } else { identifier = StringUtils.capitalize(identifier); } SimpleName typeName = type.getAST().newSimpleName(identifier); return type.getAST().newSimpleType(typeName); } else { return type; } }
From source file:com.halware.nakedide.eclipse.ext.annot.prop.NakedObjectProperty.java
License:Open Source License
public boolean isValueType() { MethodDeclaration declaration = getDeclaration(); Type returnType2 = declaration.getReturnType2(); if (returnType2.isPrimitiveType()) { return true; }//from w w w. j a va 2 s. com if (MethodUtils.isBuiltInValueType(declaration)) { return true; } return false; }
From source file:com.halware.nakedide.eclipse.ext.annot.utils.AstUtils.java
License:Open Source License
public static String asString(Type type) { if (type.isArrayType()) { ArrayType arrayType = (ArrayType) type; return asString(arrayType.getComponentType()) + "[]"; }/*w ww . j a v a 2s . c o m*/ if (type.isParameterizedType()) { ParameterizedType parameterizedType = (ParameterizedType) type; List<Type> typeArguments = Generics.asT(parameterizedType.typeArguments()); class TypeToString implements ClosureUtil.IClosure<Type, String> { public String eval(Type type) { return asString(type); } } return asString(parameterizedType.getType()) + "<" + StringUtil.join(ClosureUtil.forEach(typeArguments, new TypeToString()), ", ") + ">"; } if (type.isPrimitiveType()) { PrimitiveType primitiveType = (PrimitiveType) type; return primitiveType.getPrimitiveTypeCode().toString(); } if (type.isQualifiedType()) { QualifiedType qualifiedType = (QualifiedType) type; return qualifiedType.getName().getFullyQualifiedName(); } if (type.isSimpleType()) { SimpleType simpleType = (SimpleType) type; return simpleType.getName().getFullyQualifiedName(); } if (type.isWildcardType()) { WildcardType wildcardType = (WildcardType) type; Type boundType = wildcardType.getBound(); if (boundType != null) { if (wildcardType.isUpperBound()) { return "? extends " + asString(boundType); } else { return "? super " + asString(boundType); } } else { return "?"; } } return "(unknown type)"; }
From source file:com.halware.nakedide.eclipse.ext.annot.utils.AstUtils.java
License:Open Source License
/** * Doesn't support {@link SimpleType}s (so isn't much use). * /* www .jav a 2s .c o m*/ * @param type * @return */ public static boolean isValueType(Type type) { if (type.isArrayType()) { return false; } if (type.isParameterizedType()) { return false; } if (type.isPrimitiveType()) { return true; } if (type.isSimpleType()) { // because we can't tell which package the type is in :-( return false; } if (type.isQualifiedType()) { return MethodUtils.isBuiltInValueType(asString(type)); } if (type.isWildcardType()) { return false; } return false; }
From source file:com.kodebeagle.javaparser.TypeResolver.java
License:Apache License
/** * @param type//from w w w .ja v a 2 s. c om * @return */ protected String getNameOfType(final Type type) { String nameOfType = ""; if (type != null) { if (type.isPrimitiveType()) { nameOfType = type.toString(); } else if (type.isParameterizedType()) { nameOfType = getParametrizedType((ParameterizedType) type); } else if (type.isArrayType()) { final ArrayType array = (ArrayType) type; nameOfType = getNameOfType(array.getElementType()) /*+ "[]"*/; } else if (type.isUnionType()) { // TODO: this is used for exceptions till now // So we will just capture the first type that we encounter final UnionType uType = (UnionType) type; final StringBuffer sb = new StringBuffer(); for (final Object unionedType : uType.types()) { sb.append(getNameOfType(((Type) unionedType))); break; // sb.append(" | "); } // sb.delete(sb.length() - 3, sb.length()); nameOfType = sb.toString(); } else if (type.isWildcardType()) { final WildcardType wType = (WildcardType) type; nameOfType = (wType.isUpperBound() ? "? extends " : "? super ") + getNameOfType(wType.getBound()); } else { nameOfType = getFullyQualifiedNameFor(type.toString()); } } return nameOfType; }
From source file:com.servoy.eclipse.docgenerator.metamodel.TypeName.java
License:Open Source License
/** * Create an instance based on a JDT type. * /* w w w .j a va 2s . c o m*/ * The location, context and warnings parameters are used for raising warnings when the type bindings * cannot be resolved. */ public TypeName(Type t, boolean varargs, String location, String context, Set<DocumentationWarning> warnings) { this.varargs = varargs; // Try to resolve the binding. ITypeBinding binding = t.resolveBinding(); // If binding was resolved, then use it to extract the names. if (binding != null) { ITypeBinding inner = binding; if (varargs) { dimensions = 1; } else { int dims = 0; while (inner.isArray()) { inner = inner.getComponentType(); dims += 1; } dimensions = dims; } if (inner.isParameterizedType()) { inner = inner.getErasure(); } ITypeBinding parent = inner; int nesting = 0; while (parent.isNested()) { nesting++; parent = parent.getDeclaringClass(); } nestingLevel = nesting; primitive = inner.isPrimitive(); baseQualifiedName = adaptQualifiedName(inner.getQualifiedName()); baseBinaryName = inner.getBinaryName(); } // If the binding was not resolved, then use the type name anyway. // This may not be accurate, but is better than nothing. // Also raise a warning in this case. else { String rawName = t.toString(); int idx = rawName.indexOf("["); if (idx >= 0) { baseQualifiedName = rawName.substring(0, idx); String dimPart = rawName.substring(idx); dimensions = dimPart.length() / 2; } else { baseQualifiedName = rawName; dimensions = 0; } nestingLevel = 0; baseBinaryName = baseQualifiedName; primitive = t.isPrimitiveType(); DocumentationWarning dw = new DocumentationWarning(WarningType.UnresolvedBinding, location, "Cannot resolve binding for " + context + " type: '" + baseQualifiedName + "'."); warnings.add(dw); } shortName = buildShortName(); qualifiedName = buildQualifiedName(); binaryName = buildBinaryName(); }