Java Code Examples for com.github.javaparser.ast.body.FieldDeclaration#getVariables()

The following examples show how to use com.github.javaparser.ast.body.FieldDeclaration#getVariables() . 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: LocationSearcher.java    From meghanada-server with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("try")
private static Location getFieldLocation(
    SearchContext context, File targetFile, FieldDeclaration declaration) throws IOException {

  try (TelemetryUtils.ScopedSpan scope =
      TelemetryUtils.startScopedSpan("LocationSearcher.getFieldLocation")) {

    TelemetryUtils.ScopedSpan.addAnnotation(
        TelemetryUtils.annotationBuilder().put("targetFile", targetFile.getPath()).build("args"));

    final List<VariableDeclarator> variables = declaration.getVariables();
    for (final VariableDeclarator variable : variables) {
      final SimpleName simpleName = variable.getName();
      final String name = simpleName.getIdentifier();
      final Optional<Position> begin = simpleName.getBegin();
      if (name.equals(context.name) && begin.isPresent()) {
        final Position position = begin.get();
        return new Location(targetFile.getCanonicalPath(), position.line, position.column);
      }
    }
    return null;
  }
}
 
Example 2
Source File: ClassCodeAnalyser.java    From CodeDefenders with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void extractResultsFromFieldDeclaration(FieldDeclaration f, CodeAnalysisResult result) {
    final boolean compileTimeConstant = f.isFinal() && ((f.getCommonType() instanceof PrimitiveType) || (String.class.getSimpleName().equals(f.getElementType().asString())));
    for (VariableDeclarator v : f.getVariables()) {
        for (int line = v.getBegin().get().line; line <= v.getEnd().get().line; line++) {
            if (compileTimeConstant) {
                logger.debug("Found compile-time constant " + v);
                // compile time targets are non coverable, too
                result.compileTimeConstant(line);
                result.nonCoverableCode(line);
            }
            if (!v.getInitializer().isPresent()) {
                // non initialized fields are non coverable
                result.nonInitializedField(line);
                result.nonCoverableCode(line);
            }
        }
    }
}
 
Example 3
Source File: ResourceOptimism.java    From TestSmellDetector with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(FieldDeclaration n, Void arg) {
    for (VariableDeclarator variableDeclarator : n.getVariables()) {
        if (variableDeclarator.getType().equals("File")) {
            classVariables.add(variableDeclarator.getNameAsString());
        }
    }
    super.visit(n, arg);
}
 
Example 4
Source File: FieldIndexer.java    From jql with MIT License 5 votes vote down vote up
public void index(FieldDeclaration fieldDeclaration, int typeId) {
    List<VariableDeclarator> variables = fieldDeclaration.getVariables();
    for (VariableDeclarator variable : variables) {
        String name = variable.getNameAsString();
        fieldDao.save(new Field(name, fieldDeclaration.getElementType().asString(),
                fieldDeclaration.isPublic(), fieldDeclaration.isStatic(), fieldDeclaration.isFinal(), fieldDeclaration.isTransient(), typeId));
    }
}
 
Example 5
Source File: MigrateJCas.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private boolean hasTypeFields(NodeList<BodyDeclaration<?>> members) {
    boolean hasType = false;
    boolean hasTypeId = false;
    for (BodyDeclaration<?> bd : members) {
      if (bd instanceof FieldDeclaration) {
        FieldDeclaration f = (FieldDeclaration)bd;
        EnumSet<Modifier> m = f.getModifiers();
        if (m.contains(Modifier.PUBLIC) &&
            m.contains(Modifier.STATIC) &&
            m.contains(Modifier.FINAL) 
//            &&
//            getTypeName(f.getType()).equals("int")
            ) {
          List<VariableDeclarator> vds = f.getVariables();
          for (VariableDeclarator vd : vds) {
            if (vd.getType().equals(intType)) {
              String n = vd.getNameAsString();
              if (n.equals("type")) hasType = true;
              if (n.equals("typeIndexID")) hasTypeId = true;
              if (hasTypeId && hasType) {
                return true;
              }
            }
          }
        }
      }
    } // end of for
    return false;
  }