Java Code Examples for org.eclipse.jdt.core.dom.ITypeBinding#isTopLevel()

The following examples show how to use org.eclipse.jdt.core.dom.ITypeBinding#isTopLevel() . 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: Binding2JavaModel.java    From lapse-plus with GNU General Public License v3.0 6 votes vote down vote up
public static ICompilationUnit findCompilationUnit(ITypeBinding typeBinding, IJavaProject project) throws JavaModelException {
    if (!typeBinding.isFromSource()) {
        return null;
    }
    while (typeBinding != null && !typeBinding.isTopLevel()) {
        typeBinding= typeBinding.getDeclaringClass();
    }
    if (typeBinding != null) {
        IPackageBinding pack= typeBinding.getPackage();
        String packageName= pack.isUnnamed() ? "" : pack.getName(); //$NON-NLS-1$
        IType type= project.findType(packageName, typeBinding.getName());
        if (type != null) {
            return type.getCompilationUnit();
        }
    }
    return null;
}
 
Example 2
Source File: NewCUUsingWizardProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Fill-in the "Super Class" and "Super Interfaces" fields.
 * @param page the wizard page.
 */
private void fillInWizardPageSuperTypes(NewTypeWizardPage page) {
	ITypeBinding type= getPossibleSuperTypeBinding(fNode);
	type= Bindings.normalizeTypeBinding(type);
	if (type != null) {
		if (type.isArray()) {
			type= type.getElementType();
		}
		if (type.isTopLevel() || type.isMember()) {
			if (type.isClass() && (fTypeKind == K_CLASS)) {
				page.setSuperClass(type.getQualifiedName(), true);
			} else if (type.isInterface()) {
				List<String> superInterfaces= new ArrayList<String>();
				superInterfaces.add(type.getQualifiedName());
				page.setSuperInterfaces(superInterfaces, true);
			}
		}
	}
}
 
Example 3
Source File: TypeURIHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public String getQualifiedName(ITypeBinding binding) {
	if (binding.isParameterizedType()) {
		return getQualifiedName(binding.getErasure());
	}
	if (binding.isArray()) {
		return getQualifiedName(binding.getComponentType(), new StringBuilder()).append("[]").toString();
	}
	if (binding.isTopLevel() || binding.isTypeVariable() || binding.isPrimitive())
		return binding.getQualifiedName();
	return getQualifiedName(binding.getDeclaringClass(), new StringBuilder()).append('$').append(binding.getName()).toString();
}
 
Example 4
Source File: TypeURIHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.4
 */
public StringBuilder getQualifiedName(ITypeBinding binding, StringBuilder stringBuilder) {
	if (binding.isParameterizedType()) {
		getQualifiedName(binding.getErasure(), stringBuilder);
	}
	else if (binding.isArray()) {
		getQualifiedName(binding.getComponentType(), stringBuilder).append("[]");
	}
	else if (binding.isTopLevel() || binding.isTypeVariable() || binding.isPrimitive()) {
		stringBuilder.append(binding.getQualifiedName());
	} else {
		getQualifiedName(binding.getDeclaringClass(), stringBuilder).append('$').append(binding.getName());
	}
	return stringBuilder;
}
 
Example 5
Source File: TypeURIHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.4
 */
protected SegmentSequence.Builder getQualifiedName(ITypeBinding binding, SegmentSequence.Builder builder) {
	if (binding.isParameterizedType()) {
		getQualifiedName(binding.getErasure(), builder);
	}
	else if (binding.isArray()) {
		getQualifiedName(binding.getComponentType(), builder).append("[]");
	}
	else if (binding.isTopLevel() || binding.isTypeVariable() || binding.isPrimitive()) {
		builder.append(binding.getQualifiedName());
	} else {
		getQualifiedName(binding.getDeclaringClass(), builder).append('$').append(binding.getName());
	}
	return builder;
}
 
Example 6
Source File: TType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 7
Source File: TypeRules.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isArrayCompatible(ITypeBinding definedType) {
	if (definedType.isTopLevel()) {
		if (definedType.isClass()) {
			return "Object".equals(definedType.getName()) && "java.lang".equals(definedType.getPackage().getName());  //$NON-NLS-1$//$NON-NLS-2$
		} else {
			String qualifiedName= definedType.getQualifiedName();
			return "java.io.Serializable".equals(qualifiedName) || "java.lang.Cloneable".equals(qualifiedName); //$NON-NLS-1$ //$NON-NLS-2$
		}
	}
	return false;
}
 
Example 8
Source File: OrganizeImportsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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: TypeRules.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isJavaLangObject(ITypeBinding definedType) {
	return definedType.isTopLevel() && definedType.isClass() && "Object".equals(definedType.getName()) && "java.lang".equals(definedType.getPackage().getName());  //$NON-NLS-1$//$NON-NLS-2$
}