Java Code Examples for org.eclipse.jdt.core.dom.SingleVariableDeclaration#isVarargs()

The following examples show how to use org.eclipse.jdt.core.dom.SingleVariableDeclaration#isVarargs() . 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: JavaParseTreeBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String getSignature(MethodDeclaration node) {
    StringBuffer buffer= new StringBuffer();
    buffer.append(node.getName().toString());
    buffer.append('(');
    boolean first= true;
    Iterator<SingleVariableDeclaration> iterator= node.parameters().iterator();
    while (iterator.hasNext()) {
    	SingleVariableDeclaration svd= iterator.next();
        if (!first)
            buffer.append(", "); //$NON-NLS-1$
        buffer.append(getType(svd.getType()));
        if (svd.isVarargs())
            buffer.append("..."); //$NON-NLS-1$
        first= false;
    }
    buffer.append(')');
    return buffer.toString();
}
 
Example 2
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final SingleVariableDeclaration it) {
  if ((((it.getParent() instanceof MethodDeclaration) || (it.getParent() instanceof CatchClause)) || 
    (it.getParent() instanceof EnhancedForStatement))) {
    final Function1<IExtendedModifier, Boolean> _function = (IExtendedModifier it_1) -> {
      return Boolean.valueOf(it_1.isAnnotation());
    };
    this.appendModifiers(it, IterableExtensions.<IExtendedModifier>filter(Iterables.<IExtendedModifier>filter(it.modifiers(), IExtendedModifier.class), _function));
  } else {
    this.appendModifiers(it, it.modifiers());
  }
  it.getType().accept(this);
  this.appendExtraDimensions(it.getExtraDimensions());
  boolean _isVarargs = it.isVarargs();
  if (_isVarargs) {
    this.appendToBuffer("...");
  }
  this.appendSpaceToBuffer();
  it.getName().accept(this);
  Expression _initializer = it.getInitializer();
  boolean _tripleNotEquals = (_initializer != null);
  if (_tripleNotEquals) {
    this.appendToBuffer("=");
    it.getInitializer().accept(this);
  }
  return false;
}
 
Example 3
Source File: SrcTreeGenerator.java    From sahagin-java with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visit(MethodDeclaration node) {
    IMethodBinding methodBinding = node.resolveBinding();
    Pair<String, CaptureStyle> testDocPair = testDocIfSubMethod(methodBinding);
    if (testDocPair.getLeft() == null) {
        return super.visit(node);
    }

    ITypeBinding classBinding = methodBinding.getDeclaringClass();
    if (!classBinding.isClass() && !classBinding.isInterface()) {
        // enum method, etc
        return super.visit(node);
    }

    TestClass testClass = classBindingTestClass(classBinding);

    TestMethod testMethod = new TestMethod();
    testMethod.setKey(generateMethodKey(methodBinding, false));
    testMethod.setSimpleName(methodBinding.getName());
    testMethod.setTestDoc(testDocPair.getLeft());
    testMethod.setCaptureStyle(testDocPair.getRight());
    for (Object element : node.parameters()) {
        if (!(element instanceof SingleVariableDeclaration)) {
            throw new RuntimeException("not supported yet: " + element);
        }
        SingleVariableDeclaration varDecl = (SingleVariableDeclaration)element;
        testMethod.addArgVariable(varDecl.getName().getIdentifier());
        if (varDecl.isVarargs()) {
            testMethod.setVariableLengthArgIndex(testMethod.getArgVariables().size() - 1);
        }
    }
    testMethod.setTestClassKey(testClass.getKey());
    testMethod.setTestClass(testClass);
    subMethodTable.addTestMethod(testMethod);

    testClass.addTestMethodKey(testMethod.getKey());
    testClass.addTestMethod(testMethod);

    return super.visit(node);
}