Java Code Examples for com.sun.tools.javac.code.Flags#VARARGS

The following examples show how to use com.sun.tools.javac.code.Flags#VARARGS . 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: TreeConverter.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private TreeNode convertSingleVariable(VariableTree node, TreePath parent) {
  TreePath path = getTreePath(parent, node);
  VariableElement element = (VariableElement) getElement(path);
  SourcePosition pos = getPosition(node);
  boolean isVarargs = (((VarSymbol) element).flags() & Flags.VARARGS) > 0;
  Type newType = convertType(getTypeMirror(path), pos, isVarargs);
  return new SingleVariableDeclaration()
      .setType(newType)
      .setIsVarargs(isVarargs)
      .setAnnotations(convertAnnotations(node.getModifiers(), path))
      .setVariableElement(element)
      .setInitializer((Expression) convert(node.getInitializer(), path));
}
 
Example 2
Source File: TreeConverter.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private VariableDeclarationExpression convertVariableExpression(
    VariableTree node, TreePath parent) {
  TreePath path = getTreePath(parent, node);
  VariableElement element = (VariableElement) getElement(path);
  boolean isVarargs = (((JCVariableDecl) node).sym.flags() & Flags.VARARGS) > 0;
  Type newType = convertType(getTypeMirror(path), getPosition(node), isVarargs);
  VariableDeclarationFragment fragment = new VariableDeclarationFragment();
  fragment
      .setVariableElement(element)
      .setInitializer((Expression) convert(node.getInitializer(), path));
  return new VariableDeclarationExpression().setType(newType).addFragment(fragment);
}
 
Example 3
Source File: ExecutableMemberDocImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return true if this method was declared to take a variable number
 * of arguments.
 */
public boolean isVarArgs() {
    return ((sym.flags() & Flags.VARARGS) != 0
            && !env.legacyDoclet);
}
 
Example 4
Source File: ExecutableMemberDocImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return true if this method was declared to take a variable number
 * of arguments.
 */
public boolean isVarArgs() {
    return ((sym.flags() & Flags.VARARGS) != 0
            && !env.legacyDoclet);
}
 
Example 5
Source File: ExecutableMemberDocImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return true if this method was declared to take a variable number
 * of arguments.
 */
public boolean isVarArgs() {
    return ((sym.flags() & Flags.VARARGS) != 0
            && !env.legacyDoclet);
}
 
Example 6
Source File: ExecutableMemberDocImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return true if this method was declared to take a variable number
 * of arguments.
 */
public boolean isVarArgs() {
    return ((sym.flags() & Flags.VARARGS) != 0
            && !env.legacyDoclet);
}
 
Example 7
Source File: ExecutableMemberDocImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return true if this method was declared to take a variable number
 * of arguments.
 */
public boolean isVarArgs() {
    return ((sym.flags() & Flags.VARARGS) != 0
            && !env.legacyDoclet);
}
 
Example 8
Source File: SrcClassUtil.java    From manifold with Apache License 2.0 4 votes vote down vote up
private void addMethod( IModule module, SrcClass srcClass, Symbol.MethodSymbol method, BasicJavacTask javacTask )
{
  String name = method.flatName().toString();
  SrcMethod srcMethod = new SrcMethod( srcClass, name.equals( "<init>" ) );
  addAnnotations( srcMethod, method );
  srcMethod.modifiers( method.getModifiers() );
  if( (method.flags() & Flags.VARARGS) != 0 )
  {
    srcMethod.modifiers( srcMethod.getModifiers() | 0x00000080 ); // Modifier.VARARGS
  }
  if( name.equals( "<clinit>" ) )
  {
    return;
  }
  if( !srcMethod.isConstructor() )
  {
    srcMethod.name( name );
    srcMethod.returns( makeSrcType( method.getReturnType(), method, TargetType.METHOD_RETURN, -1 ) );
  }
  for( Symbol.TypeVariableSymbol typeVar: method.getTypeParameters() )
  {
    srcMethod.addTypeVar( makeTypeVarType( typeVar ) );
  }
  List<Symbol.VarSymbol> parameters = method.getParameters();
  for( int i = 0; i < parameters.size(); i++ )
  {
    Symbol.VarSymbol param = parameters.get( i );
    SrcParameter srcParam = new SrcParameter( param.flatName().toString(), makeSrcType( param.type, method, TargetType.METHOD_FORMAL_PARAMETER, i ) );
    srcMethod.addParam( srcParam );
    addAnnotations( srcParam, param );
  }
  List<Type> thrownTypes = method.getThrownTypes();
  for( int i = 0; i < thrownTypes.size(); i++ )
  {
    Type throwType = thrownTypes.get( i );
    srcMethod.addThrowType( makeSrcType( throwType, method, TargetType.THROWS, i ) );
  }
  String bodyStmt;
  if( srcMethod.isConstructor() && !srcClass.isEnum() )
  {
    // Note we can't just throw an exception for the ctor body, the compiler will
    // still complain about the missing super() call if the super class does not have
    // an accessible default ctor. To appease the compiler we generate a super(...)
    // call to the first accessible constructor we can find in the super class.
    bodyStmt = genSuperCtorCall( module, srcClass, javacTask );
  }
  else
  {
    bodyStmt = "throw new RuntimeException();";
  }
  srcMethod.body( new SrcStatementBlock()
    .addStatement(
      new SrcRawStatement()
        .rawText( bodyStmt ) ) );
  srcClass.addMethod( srcMethod );
}
 
Example 9
Source File: ExecutableMemberDocImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return true if this method was declared to take a variable number
 * of arguments.
 */
public boolean isVarArgs() {
    return ((sym.flags() & Flags.VARARGS) != 0
            && !env.legacyDoclet);
}
 
Example 10
Source File: ExecutableMemberDocImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return true if this method was declared to take a variable number
 * of arguments.
 */
public boolean isVarArgs() {
    return ((sym.flags() & Flags.VARARGS) != 0
            && !env.legacyDoclet);
}
 
Example 11
Source File: ExecutableMemberDocImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return true if this method was declared to take a variable number
 * of arguments.
 */
public boolean isVarArgs() {
    return ((sym.flags() & Flags.VARARGS) != 0
            && !env.legacyDoclet);
}
 
Example 12
Source File: JavacHandlerUtil.java    From EasyMPermission with MIT License 4 votes vote down vote up
/**
 * Checks if there is a method with the provided name. In case of multiple methods (overloading), only
 * the first method decides if EXISTS_BY_USER or EXISTS_BY_LOMBOK is returned.
 * 
 * @param methodName the method name to check for.
 * @param node Any node that represents the Type (JCClassDecl) to look in, or any child node thereof.
 * @param caseSensitive If the search should be case sensitive.
 * @param params The number of parameters the method should have; varargs count as 0-*. Set to -1 to find any method with the appropriate name regardless of parameter count.
 */
public static MemberExistsResult methodExists(String methodName, JavacNode node, boolean caseSensitive, int params) {
	node = upToTypeNode(node);
	
	if (node != null && node.get() instanceof JCClassDecl) {
		top: for (JCTree def : ((JCClassDecl)node.get()).defs) {
			if (def instanceof JCMethodDecl) {
				JCMethodDecl md = (JCMethodDecl) def;
				String name = md.name.toString();
				boolean matches = caseSensitive ? name.equals(methodName) : name.equalsIgnoreCase(methodName);
				if (matches) {
					if (params > -1) {
						List<JCVariableDecl> ps = md.params;
						int minArgs = 0;
						int maxArgs = 0;
						if (ps != null && ps.length() > 0) {
							minArgs = ps.length();
							if ((ps.last().mods.flags & Flags.VARARGS) != 0) {
								maxArgs = Integer.MAX_VALUE;
								minArgs--;
							} else {
								maxArgs = minArgs;
							}
						}
						
						if (params < minArgs || params > maxArgs) continue;
					}
					
					List<JCAnnotation> annotations = md.getModifiers().getAnnotations();
					if (annotations != null) for (JCAnnotation anno : annotations) {
						if (typeMatches(Tolerate.class, node, anno.getAnnotationType())) continue top;
					}
					
					return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
				}
			}
		}
	}
	
	return MemberExistsResult.NOT_EXISTS;
}