Java Code Examples for org.eclipse.jdt.core.dom.Name#resolveTypeBinding()

The following examples show how to use org.eclipse.jdt.core.dom.Name#resolveTypeBinding() . 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: ExtractConstantRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static boolean canReplace(IASTFragment fragment) {
	ASTNode node = fragment.getAssociatedNode();
	ASTNode parent = node.getParent();
	if (parent instanceof VariableDeclarationFragment) {
		VariableDeclarationFragment vdf = (VariableDeclarationFragment) parent;
		if (node.equals(vdf.getName())) {
			return false;
		}
	}
	if (parent instanceof ExpressionStatement) {
		return false;
	}
	if (parent instanceof SwitchCase) {
		if (node instanceof Name) {
			Name name = (Name) node;
			ITypeBinding typeBinding = name.resolveTypeBinding();
			if (typeBinding != null) {
				return !typeBinding.isEnum();
			}
		}
	}
	return true;
}
 
Example 2
Source File: ExtractConstantRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean canReplace(IASTFragment fragment) {
	ASTNode node= fragment.getAssociatedNode();
	ASTNode parent= node.getParent();
	if (parent instanceof VariableDeclarationFragment) {
		VariableDeclarationFragment vdf= (VariableDeclarationFragment) parent;
		if (node.equals(vdf.getName()))
			return false;
	}
	if (parent instanceof ExpressionStatement)
		return false;
	if (parent instanceof SwitchCase) {
		if (node instanceof Name) {
			Name name= (Name) node;
			ITypeBinding typeBinding= name.resolveTypeBinding();
			if (typeBinding != null) {
				return !typeBinding.isEnum();
			}
		}
	}
	return true;
}
 
Example 3
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(ThisExpression node) {
	final Name qualifier= node.getQualifier();
	if (qualifier != null) {
		final ITypeBinding binding= qualifier.resolveTypeBinding();
		if (binding != null && binding != fCurrentType.getTypeDeclaration()) {
			fSimpleNames.add(qualifier);
		}
	}
	return super.visit(node);
}
 
Example 4
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ASTNode getNewQualifiedNameNode(ITypeBinding[] parameters, Name name) {
	final AST ast= name.getAST();
	boolean raw= false;
	final ITypeBinding binding= name.resolveTypeBinding();
	if (binding != null && binding.isRawType())
		raw= true;
	if (parameters != null && parameters.length > 0 && !raw) {
		final ParameterizedType type= ast.newParameterizedType(ast.newSimpleType(ast.newName(fQualifiedTypeName)));
		for (int index= 0; index < parameters.length; index++)
			type.typeArguments().add(ast.newSimpleType(ast.newSimpleName(parameters[index].getName())));
		return type;
	}
	return ast.newName(fQualifiedTypeName);
}
 
Example 5
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ASTNode getNewUnqualifiedTypeNode(ITypeBinding[] parameters, Name name) {
	final AST ast= name.getAST();
	boolean raw= false;
	final ITypeBinding binding= name.resolveTypeBinding();
	if (binding != null && binding.isRawType())
		raw= true;
	if (parameters != null && parameters.length > 0 && !raw) {
		final ParameterizedType type= ast.newParameterizedType(ast.newSimpleType(ast.newSimpleName(fType.getElementName())));
		for (int index= 0; index < parameters.length; index++)
			type.typeArguments().add(ast.newSimpleType(ast.newSimpleName(parameters[index].getName())));
		return type;
	}
	return ast.newSimpleType(ast.newSimpleName(fType.getElementName()));
}
 
Example 6
Source File: SuperTypeConstraintsModel.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates an exception variable.
 *
 * @param name the name of the thrown exception
 * @return the created exception variable, or <code>null</code>
 */
public final ConstraintVariable2 createExceptionVariable(final Name name) {
	final ITypeBinding binding= name.resolveTypeBinding();
	if (isConstrainedType(binding))
		return fConstraintVariables.addExisting(new TypeVariable2(createTType(binding), new CompilationUnitRange(RefactoringASTParser.getCompilationUnit(name), name)));
	return null;
}
 
Example 7
Source File: AbstractLoopUtilities.java    From JDeodorant with MIT License 5 votes vote down vote up
public static boolean isLengthFieldAccess(Expression expression)
{
	SimpleName name          = null;
	ITypeBinding typeBinding = null;
	if (expression instanceof QualifiedName)
	{
		QualifiedName qualifiedName = (QualifiedName) expression;
		name                        = qualifiedName.getName();
		Name qualifier              = qualifiedName.getQualifier();
		typeBinding                 = qualifier.resolveTypeBinding();
	}
	else if (expression instanceof FieldAccess)
	{
		FieldAccess fieldAccess           = (FieldAccess)expression;
		name                              = fieldAccess.getName();
		Expression fieldAsccessExpression = fieldAccess.getExpression();
		typeBinding                       = fieldAsccessExpression.resolveTypeBinding();
	}
	if (name != null && typeBinding != null)
	{
		IBinding nameBinding = name.resolveBinding();
		if (nameBinding != null && nameBinding.getKind() == IBinding.VARIABLE && typeBinding != null)
		{
			IVariableBinding nameVariableBinding = (IVariableBinding) nameBinding;
			return (nameVariableBinding.getName().equals("length") && typeBinding.isArray());
		}
	}
	return false;
}