Java Code Examples for org.eclipse.jdt.core.dom.Type#accept()

The following examples show how to use org.eclipse.jdt.core.dom.Type#accept() . 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: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean visit(final TypeParameter node) {
  node.getName().accept(this);
  boolean _isEmpty = node.typeBounds().isEmpty();
  boolean _not = (!_isEmpty);
  if (_not) {
    this.appendToBuffer(" extends ");
    for (Iterator<Type> _it = node.typeBounds().iterator(); _it.hasNext();) {
      {
        Type t = _it.next();
        t.accept(this);
        boolean _hasNext = _it.hasNext();
        if (_hasNext) {
          this.appendToBuffer(" & ");
        }
      }
    }
  }
  return false;
}
 
Example 2
Source File: TreedBuilder.java    From compiler with Apache License 2.0 6 votes vote down vote up
@Override
public boolean visit(MethodInvocation node) {
	if (node.arguments().size() > 100) {
		if (node.getExpression() != null)
			node.getExpression().accept(this);
		if (node.typeArguments() != null && !node.typeArguments().isEmpty()) {
			for (Iterator<?> it = node.typeArguments().iterator(); it.hasNext(); ) {
				Type t = (Type) it.next();
				t.accept(this);
			}
		}
		node.getName().accept(this);
		return false;
	}
	return super.visit(node);
}
 
Example 3
Source File: PromoteTempToFieldRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkTempTypeForLocalTypeUsage(){
  	VariableDeclarationStatement vds= getTempDeclarationStatement();
  	if (vds == null)
  		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_cannot_promote);
  	Type type= 	vds.getType();
  	ITypeBinding binding= type.resolveBinding();
  	if (binding == null)
  		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_cannot_promote);

IMethodBinding declaringMethodBinding= getMethodDeclaration().resolveBinding();
ITypeBinding[] methodTypeParameters= declaringMethodBinding == null ? new ITypeBinding[0] : declaringMethodBinding.getTypeParameters();
LocalTypeAndVariableUsageAnalyzer analyzer= new LocalTypeAndVariableUsageAnalyzer(methodTypeParameters);
type.accept(analyzer);
boolean usesLocalTypes= ! analyzer.getUsageOfEnclosingNodes().isEmpty();
fTempTypeUsesClassTypeVariables= analyzer.getClassTypeVariablesUsed();
if (usesLocalTypes)
	return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_uses_type_declared_locally);
return null;
  }
 
Example 4
Source File: ExtractFieldRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private RefactoringStatus checkTempTypeForLocalTypeUsage() throws JavaModelException {
	Expression expression = getSelectedExpression().getAssociatedExpression();
	Type resultingType = null;
	ITypeBinding typeBinding = expression.resolveTypeBinding();
	AST ast = fCURewrite.getAST();

	if (expression instanceof ClassInstanceCreation && (typeBinding == null || typeBinding.getTypeArguments().length == 0)) {
		resultingType = ((ClassInstanceCreation) expression).getType();
	} else if (expression instanceof CastExpression) {
		resultingType = ((CastExpression) expression).getType();
	} else {
		if (typeBinding == null) {
			typeBinding = ASTResolving.guessBindingForReference(expression);
		}
		if (typeBinding != null) {
			typeBinding = Bindings.normalizeForDeclarationUse(typeBinding, ast);
			ImportRewrite importRewrite = fCURewrite.getImportRewrite();
			ImportRewriteContext context = new ContextSensitiveImportRewriteContext(expression, importRewrite);
			resultingType = importRewrite.addImport(typeBinding, ast, context, TypeLocation.LOCAL_VARIABLE);
		} else {
			resultingType = ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
		}
	}

	IMethodBinding declaringMethodBinding = getMethodDeclaration().resolveBinding();
	ITypeBinding[] methodTypeParameters = declaringMethodBinding == null ? new ITypeBinding[0] : declaringMethodBinding.getTypeParameters();
	LocalTypeAndVariableUsageAnalyzer analyzer = new LocalTypeAndVariableUsageAnalyzer(methodTypeParameters);
	resultingType.accept(analyzer);
	boolean usesLocalTypes = !analyzer.getUsageOfEnclosingNodes().isEmpty();
	if (usesLocalTypes) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractFieldRefactoring_uses_type_declared_locally);
	}
	return null;
}
 
Example 5
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final WildcardType node) {
  this.appendToBuffer("?");
  Type bound = node.getBound();
  if ((bound != null)) {
    boolean _isUpperBound = node.isUpperBound();
    if (_isUpperBound) {
      this.appendToBuffer(" extends ");
    } else {
      this.appendToBuffer(" super ");
    }
    bound.accept(this);
  }
  return false;
}