Java Code Examples for javax.lang.model.element.Name#length()

The following examples show how to use javax.lang.model.element.Name#length() . 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: FitProcessor.java    From fit with Apache License 2.0 6 votes vote down vote up
private boolean isGetter(Element method) {
  Name methodName = method.getSimpleName();
  if ((!methodName.toString().startsWith("get")) && !methodName.toString().startsWith("is")) {
    return false;
  }
  ExecutableType type = (ExecutableType) method.asType();
  //返回值为void
  if (TypeKind.VOID.equals(type.getReturnType().getKind())) {
    return false;
  }
  //有参数
  if (type.getParameterTypes().size() > 0) {
    return false;
  }

  if (methodName.length() < 4) {
    return false;
  }
  return true;
}
 
Example 2
Source File: FitProcessor.java    From fit with Apache License 2.0 6 votes vote down vote up
private boolean isSetter(Element method) {
  Name methodName = method.getSimpleName();
  if (!methodName.toString().startsWith("set")) {
    return false;
  }
  ExecutableType type = (ExecutableType) method.asType();
  //返回值不为void
  if (!TypeKind.VOID.equals(type.getReturnType().getKind())) {
    return false;
  }
  //有1个参数
  if (type.getParameterTypes().size() != 1) {
    return false;
  }

  if (methodName.length() < 4) {
    return false;
  }
  return true;
}
 
Example 3
Source File: FitProcessor.java    From fit with Apache License 2.0 6 votes vote down vote up
private boolean isGetter(Element method) {
  Name methodName = method.getSimpleName();
  if ((!methodName.toString().startsWith("get")) && !methodName.toString().startsWith("is")) {
    return false;
  }
  ExecutableType type = (ExecutableType) method.asType();
  //返回值为void
  if (TypeKind.VOID.equals(type.getReturnType().getKind())) {
    return false;
  }
  //有参数
  if (type.getParameterTypes().size() > 0) {
    return false;
  }

  if (methodName.length() < 4) {
    return false;
  }
  return true;
}
 
Example 4
Source File: FitProcessor.java    From fit with Apache License 2.0 6 votes vote down vote up
private boolean isSetter(Element method) {
  Name methodName = method.getSimpleName();
  if (!methodName.toString().startsWith("set")) {
    return false;
  }
  ExecutableType type = (ExecutableType) method.asType();
  //返回值不为void
  if (!TypeKind.VOID.equals(type.getReturnType().getKind())) {
    return false;
  }
  //有1个参数
  if (type.getParameterTypes().size() != 1) {
    return false;
  }

  if (methodName.length() < 4) {
    return false;
  }
  return true;
}
 
Example 5
Source File: DaoProcessor.java    From doma with Apache License 2.0 6 votes vote down vote up
protected String prefix() {
  String daoPackage = ctx.getOptions().getDaoPackage();
  if (daoPackage != null) {
    return daoPackage + ".";
  }
  PackageElement packageElement = ctx.getMoreElements().getPackageOf(typeElement);
  Name packageName = packageElement.getQualifiedName();
  String base = "";
  if (packageName.length() > 0) {
    base = packageName + ".";
  }
  String daoSubpackage = ctx.getOptions().getDaoSubpackage();
  if (daoSubpackage != null) {
    return base + daoSubpackage + ".";
  }
  return base;
}
 
Example 6
Source File: JavaInputAstVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
private boolean fillFirstArgument(
        ExpressionTree e,
        List<ExpressionTree> items,
        Indent indent) {
    // is there a trailing dereference?
    if (items.size() < 2) {
        return false;
    }
    // don't special-case calls nested inside expressions
    if (e.getKind() != METHOD_INVOCATION) {
        return false;
    }
    MethodInvocationTree methodInvocation = (MethodInvocationTree) e;
    Name name = getMethodName(methodInvocation);
    if (!(methodInvocation.getMethodSelect() instanceof IdentifierTree)
            || name.length() > 4
            || !methodInvocation.getTypeArguments().isEmpty()
            || methodInvocation.getArguments().size() != 1) {
        return false;
    }
    builder.open(ZERO);
    builder.open(indent);
    visit(name);
    token("(");
    ExpressionTree arg = getOnlyElement(methodInvocation.getArguments());
    scan(arg, null);
    builder.close();
    token(")");
    builder.close();
    return true;
}
 
Example 7
Source File: DependencyCollector.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void addDependency(TypeMirror t) {
    Collection<DeclaredType> declaredTypes = new ArrayList<DeclaredType>(7);
    DeclaredTypeCollector.INSTANCE.visit(t, declaredTypes);
    for (DeclaredType dt : declaredTypes) {
        TypeElement te = (TypeElement)dt.asElement();
        
        if (outermostClass != null ) {
            TypeElement outermost = info.getElementUtilities().outermostTypeElement(te);
            if (outermost == outermostClass) {
                return;
            }
        }
        
        Name qn = ((TypeElement) dt.asElement()).getQualifiedName();
        if (qn.length() > 5) {
            if (qn.subSequence(0, 4).equals("java")) { // NOI18N
                // java. or javax.
                if (qn.charAt(4) == '.' || (qn.length() > 6 && qn.charAt(4) == 'x' && qn.charAt(5) == '.')) {
                    if (ignoreJavaLibraries) {
                        return;
                    }
                }
            }
        }
        if (!ignoreQNames.contains(qn)) {
            seenQNames.add(qn);
        }
    }
}
 
Example 8
Source File: JavaInputAstVisitor.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private boolean fillFirstArgument(
        ExpressionTree e,
        List<ExpressionTree> items,
        Indent indent) {
    // is there a trailing dereference?
    if (items.size() < 2) {
        return false;
    }
    // don't special-case calls nested inside expressions
    if (e.getKind() != METHOD_INVOCATION) {
        return false;
    }
    MethodInvocationTree methodInvocation = (MethodInvocationTree) e;
    Name name = getMethodName(methodInvocation);
    if (!(methodInvocation.getMethodSelect() instanceof IdentifierTree)
            || name.length() > 4
            || !methodInvocation.getTypeArguments().isEmpty()
            || methodInvocation.getArguments().size() != 1) {
        return false;
    }
    builder.open(ZERO);
    builder.open(indent);
    visit(name);
    token("(");
    ExpressionTree arg = getOnlyElement(methodInvocation.getArguments());
    scan(arg, null);
    builder.close();
    token(")");
    builder.close();
    return true;
}
 
Example 9
Source File: JavaInputAstVisitor.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
private boolean fillFirstArgument(ExpressionTree e, List<ExpressionTree> items, Indent indent) {
  // is there a trailing dereference?
  if (items.size() < 2) {
    return false;
  }
  // don't special-case calls nested inside expressions
  if (e.getKind() != METHOD_INVOCATION) {
    return false;
  }
  MethodInvocationTree methodInvocation = (MethodInvocationTree) e;
  Name name = getMethodName(methodInvocation);
  if (!(methodInvocation.getMethodSelect() instanceof IdentifierTree)
      || name.length() > 4
      || !methodInvocation.getTypeArguments().isEmpty()
      || methodInvocation.getArguments().size() != 1) {
    return false;
  }
  builder.open(ZERO);
  builder.open(indent);
  visit(name);
  token("(");
  ExpressionTree arg = getOnlyElement(methodInvocation.getArguments());
  scan(arg, null);
  builder.close();
  token(")");
  builder.close();
  return true;
}
 
Example 10
Source File: TreeBackedElements.java    From buck with Apache License 2.0 5 votes vote down vote up
private Name getFullyQualifiedName(
    @Nullable QualifiedNameable enclosingElement, Name simpleName) {
  for (int i = 0; i < simpleName.length(); i++) {
    if (simpleName.charAt(i) == '.') {
      throw new IllegalArgumentException(String.format("%s is not a simple name", simpleName));
    }
  }

  if (enclosingElement == null || enclosingElement.getQualifiedName().length() == 0) {
    return simpleName;
  } else {
    return getName(String.format("%s.%s", enclosingElement.getQualifiedName(), simpleName));
  }
}