Java Code Examples for org.eclipse.jdt.core.dom.ITypeBinding#getModifiers()
The following examples show how to use
org.eclipse.jdt.core.dom.ITypeBinding#getModifiers() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Resolver.java From DesigniteJava with Apache License 2.0 | 6 votes |
private void inferPrimitiveType(SM_Project parentProject, TypeInfo typeInfo, ITypeBinding iType) { if (iType != null && iType.isFromSource() && iType.getModifiers() != 0 && !iType.isWildcardType()) { SM_Type inferredType = findType(iType.getName(), iType.getPackage().getName(), parentProject); if (inferredType != null) { typeInfo.setTypeObj(inferredType); typeInfo.setPrimitiveType(false); } else { typeInfo.setObjPrimitiveType(iType.getName()); typeInfo.setPrimitiveType(true); } } else { if (iType == null) typeInfo.setObjPrimitiveType("wildcard"); else typeInfo.setObjPrimitiveType(iType.getName()); typeInfo.setPrimitiveType(true); } }
Example 2
Source File: Resolver.java From DesigniteJava with Apache License 2.0 | 6 votes |
private void addNonPrimitiveParameters(SM_Project parentProject, TypeInfo typeInfo, ITypeBinding iType) { if (iType.isFromSource() && iType.getModifiers() != 0) { SM_Type inferredBasicType = findType(iType.getName(), iType.getPackage().getName(), parentProject); addParameterIfNotAlreadyExists(typeInfo, inferredBasicType); } for (ITypeBinding typeParameter : iType.getTypeArguments()) { if (typeParameter.isParameterizedType()) { addNonPrimitiveParameters(parentProject, typeInfo, typeParameter); } else { if (typeParameter.isFromSource() && typeParameter.getModifiers() != 0) { SM_Type inferredType = findType(typeParameter.getName(), typeParameter.getPackage().getName(), parentProject); if (inferredType != null) { addParameterIfNotAlreadyExists(typeInfo, inferredType); } } } } }
Example 3
Source File: SemanticHighlightings.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public boolean consumes(SemanticToken token) { // 1: match types SimpleName name= token.getNode(); ASTNode node= name.getParent(); int nodeType= node.getNodeType(); if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.THIS_EXPRESSION && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.TYPE_DECLARATION && nodeType != ASTNode.METHOD_INVOCATION) return false; while (nodeType == ASTNode.QUALIFIED_NAME) { node= node.getParent(); nodeType= node.getNodeType(); if (nodeType == ASTNode.IMPORT_DECLARATION) return false; } // 2: match classes IBinding binding= token.getBinding(); if (binding instanceof ITypeBinding) { ITypeBinding typeBinding= (ITypeBinding) binding; // see also ClassHighlighting return typeBinding.isClass() && (typeBinding.getModifiers() & Modifier.ABSTRACT) != 0; } return false; }
Example 4
Source File: SemanticHighlightings.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public boolean consumes(SemanticToken token) { // 1: match types SimpleName name = token.getNode(); ASTNode node = name.getParent(); int nodeType = node.getNodeType(); if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.THIS_EXPRESSION && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.TYPE_DECLARATION && nodeType != ASTNode.METHOD_INVOCATION) { return false; } while (nodeType == ASTNode.QUALIFIED_NAME) { node = node.getParent(); nodeType = node.getNodeType(); if (nodeType == ASTNode.IMPORT_DECLARATION) { return false; } } // 2: match classes IBinding binding = token.getBinding(); if (binding instanceof ITypeBinding) { ITypeBinding typeBinding = (ITypeBinding) binding; // see also ClassHighlighting return typeBinding.isClass() && (typeBinding.getModifiers() & Modifier.ABSTRACT) != 0; } return false; }
Example 5
Source File: ExtractClassRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean shouldParamClassBeStatic(TypeDeclaration enclosingTypeDecl) { if (enclosingTypeDecl.isPackageMemberTypeDeclaration()) { return true; } ITypeBinding binding= enclosingTypeDecl.resolveBinding(); int modifiers= binding != null ? binding.getModifiers() : enclosingTypeDecl.getModifiers(); return Modifier.isStatic(modifiers); }
Example 6
Source File: ParameterObjectFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static Type importBinding(ITypeBinding typeBinding, CompilationUnitRewrite cuRewrite) { int declaredModifiers= typeBinding.getModifiers(); AST ast= cuRewrite.getAST(); if (Modifier.isPrivate(declaredModifiers) || Modifier.isProtected(declaredModifiers)) { return ast.newSimpleType(ast.newSimpleName(typeBinding.getName())); } Type type= cuRewrite.getImportRewrite().addImport(typeBinding, cuRewrite.getAST()); cuRewrite.getImportRemover().registerAddedImports(type); return type; }
Example 7
Source File: TType.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Initialized the type from the given binding * * @param binding the binding to initialize from */ protected void initialize(ITypeBinding binding) { fBindingKey= binding.getKey(); Assert.isNotNull(fBindingKey); fModifiers= binding.getModifiers(); if (binding.isClass()) { fFlags= F_IS_CLASS; // the annotation test has to be done before test for interface // since annotations are interfaces as well. } else if (binding.isAnnotation()) { fFlags= F_IS_ANNOTATION | F_IS_INTERFACE; } else if (binding.isInterface()) { fFlags= F_IS_INTERFACE; } else if (binding.isEnum()) { fFlags= F_IS_ENUM; } if (binding.isTopLevel()) { fFlags|= F_IS_TOP_LEVEL; } else if (binding.isNested()) { fFlags|= F_IS_NESTED; if (binding.isMember()) { fFlags|= F_IS_MEMBER; } else if (binding.isLocal()) { fFlags|= F_IS_LOCAL; } else if (binding.isAnonymous()) { fFlags|= F_IS_ANONYMOUS; } } }
Example 8
Source File: OrganizeImportsOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean needsImport(ITypeBinding typeBinding, SimpleName ref) { if (!typeBinding.isTopLevel() && !typeBinding.isMember() || typeBinding.isRecovered()) { return false; // no imports for anonymous, local, primitive types or parameters types } int modifiers= typeBinding.getModifiers(); if (Modifier.isPrivate(modifiers)) { return false; // imports for privates are not required } ITypeBinding currTypeBinding= Bindings.getBindingOfParentType(ref); if (currTypeBinding == null) { if (ASTNodes.getParent(ref, ASTNode.PACKAGE_DECLARATION) != null) { return true; // reference in package-info.java } return false; // not in a type } if (!Modifier.isPublic(modifiers)) { if (!currTypeBinding.getPackage().getName().equals(typeBinding.getPackage().getName())) { return false; // not visible } } ASTNode parent= ref.getParent(); while (parent instanceof Type) { parent= parent.getParent(); } if (parent instanceof AbstractTypeDeclaration && parent.getParent() instanceof CompilationUnit) { return true; } if (typeBinding.isMember()) { if (fAnalyzer.isDeclaredInScope(typeBinding, ref, ScopeAnalyzer.TYPES | ScopeAnalyzer.CHECK_VISIBILITY)) return false; } return true; }
Example 9
Source File: JdtBasedTypeFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.4 */ protected JvmDeclaredType createType(ITypeBinding typeBinding, String handleIdentifier, List<String> path, StringBuilder fqn) { if (typeBinding.isAnonymous() || typeBinding.isSynthetic()) throw new IllegalStateException("Cannot create type for anonymous or synthetic classes"); // Creates the right type of instance based on the type of binding. // JvmGenericType jvmGenericType; JvmDeclaredType result; if (typeBinding.isAnnotation()) { jvmGenericType = null; result = TypesFactory.eINSTANCE.createJvmAnnotationType(); } else if (typeBinding.isEnum()) { jvmGenericType = null; result = TypesFactory.eINSTANCE.createJvmEnumerationType(); } else { result = jvmGenericType = TypesFactory.eINSTANCE.createJvmGenericType(); jvmGenericType.setInterface(typeBinding.isInterface()); } // Populate the information computed from the modifiers. // int modifiers = typeBinding.getModifiers(); setTypeModifiers(result, modifiers); result.setDeprecated(typeBinding.isDeprecated()); setVisibility(result, modifiers); // Determine the simple name and compose the fully qualified name and path, remembering the fqn length and path size so we can reset them. // String simpleName = typeBinding.getName(); fqn.append(simpleName); int length = fqn.length(); int size = path.size(); path.add(simpleName); String qualifiedName = fqn.toString(); result.internalSetIdentifier(qualifiedName); result.setSimpleName(simpleName); // Traverse the nested types using '$' as the qualified name separator. // fqn.append('$'); createNestedTypes(typeBinding, result, handleIdentifier, path, fqn); // Traverse the methods using '.'as the qualifed name separator. // fqn.setLength(length); fqn.append('.'); createMethods(typeBinding, handleIdentifier, path, fqn, result); createFields(typeBinding, fqn, result); // Set the super types. // setSuperTypes(typeBinding, qualifiedName, result); // If this is for a generic type, populate the type parameters. // if (jvmGenericType != null) { ITypeBinding[] typeParameterBindings = typeBinding.getTypeParameters(); if (typeParameterBindings.length > 0) { InternalEList<JvmTypeParameter> typeParameters = (InternalEList<JvmTypeParameter>)jvmGenericType.getTypeParameters(); for (ITypeBinding variable : typeParameterBindings) { typeParameters.addUnique(createTypeParameter(variable, result)); } } } // Populate the annotation values. // createAnnotationValues(typeBinding, result); // Restore the path. // path.remove(size); return result; }
Example 10
Source File: ElementTypeTeller.java From txtUML with Eclipse Public License 1.0 | 4 votes |
public static boolean isAbstract(ITypeBinding type) { return (type.getModifiers() & Modifier.ABSTRACT) != 0; }
Example 11
Source File: TypeRules.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Tests if a two types are cast compatible * @param castType The binding of the type to cast to * @param bindingToCast The binding ef the expression to cast. * @return boolean Returns true if (castType) bindingToCast is a valid cast expression (can be unnecessary, but not invalid). */ public static boolean canCast(ITypeBinding castType, ITypeBinding bindingToCast) { //see bug 80715 String voidName= PrimitiveType.VOID.toString(); if (castType.isAnonymous() || castType.isNullType() || voidName.equals(castType.getName())) { throw new IllegalArgumentException(); } if (castType == bindingToCast) { return true; } if (voidName.equals(bindingToCast.getName())) { return false; } if (bindingToCast.isArray()) { if (!castType.isArray()) { return isArrayCompatible(castType); // can not cast an arraytype to a non array type (except to Object, Serializable...) } int toCastDim= bindingToCast.getDimensions(); int castTypeDim= castType.getDimensions(); if (toCastDim == castTypeDim) { bindingToCast= bindingToCast.getElementType(); castType= castType.getElementType(); if (castType.isPrimitive() && castType != bindingToCast) { return false; // can't assign arrays of different primitive types to each other } // fall through } else if (toCastDim < castTypeDim) { return isArrayCompatible(bindingToCast.getElementType()); } else { return isArrayCompatible(castType.getElementType()); } } if (castType.isPrimitive()) { if (!bindingToCast.isPrimitive()) { return false; } String boolName= PrimitiveType.BOOLEAN.toString(); return (!boolName.equals(castType.getName()) && !boolName.equals(bindingToCast.getName())); } else { if (bindingToCast.isPrimitive()) { return false; } if (castType.isArray()) { return isArrayCompatible(bindingToCast); } if (castType.isInterface()) { if ((bindingToCast.getModifiers() & Modifier.FINAL) != 0) { return Bindings.isSuperType(castType, bindingToCast); } else { return true; } } if (bindingToCast.isInterface()) { if ((castType.getModifiers() & Modifier.FINAL) != 0) { return Bindings.isSuperType(bindingToCast, castType); } else { return true; } } if (isJavaLangObject(castType)) { return true; } return Bindings.isSuperType(bindingToCast, castType) || Bindings.isSuperType(castType, bindingToCast); } }