org.sonar.java.model.declaration.ModifiersTreeImpl Maven / Gradle / Ivy
/*
* SonarQube Java
* Copyright (C) 2012-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Sonar Source-Available License for more details.
*
* You should have received a copy of the Sonar Source-Available License
* along with this program; if not, see https://sonarsource.com/license/ssal/
*/
package org.sonar.java.model.declaration;
import java.util.ArrayList;
import org.sonar.java.ast.parser.ListTreeImpl;
import org.sonar.plugins.java.api.tree.AnnotationTree;
import org.sonar.plugins.java.api.tree.ModifierKeywordTree;
import org.sonar.plugins.java.api.tree.ModifierTree;
import org.sonar.plugins.java.api.tree.ModifiersTree;
import org.sonar.plugins.java.api.tree.TreeVisitor;
import java.util.Collections;
import java.util.List;
public class ModifiersTreeImpl extends ListTreeImpl implements ModifiersTree {
private final List modifiers;
private final List annotations;
public ModifiersTreeImpl(List javaTrees) {
super(javaTrees);
List modifiersList = new ArrayList<>();
List annotationsList = new ArrayList<>();
for (ModifierTree modifierTree : this) {
if (modifierTree.is(Kind.ANNOTATION)) {
annotationsList.add((AnnotationTree) modifierTree);
} else {
modifiersList.add((ModifierKeywordTree) modifierTree);
}
}
this.annotations = Collections.unmodifiableList(annotationsList);
this.modifiers = Collections.unmodifiableList(modifiersList);
}
public static ModifiersTreeImpl emptyModifiers() {
return new ModifiersTreeImpl(Collections.emptyList());
}
@Override
public Kind kind() {
return Kind.MODIFIERS;
}
@Override
public List modifiers() {
return modifiers;
}
@Override
public List annotations() {
return annotations;
}
@Override
public void accept(TreeVisitor visitor) {
visitor.visitModifier(this);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy