use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GrParameterImpl method setType.
@Override
public void setType(@Nullable PsiType type) {
final GrTypeElement typeElement = getTypeElementGroovy();
if (type == null) {
if (typeElement != null)
typeElement.delete();
return;
}
GrTypeElement newTypeElement;
try {
newTypeElement = GroovyPsiElementFactory.getInstance(getProject()).createTypeElement(type);
} catch (IncorrectOperationException e) {
LOG.error(e);
return;
}
if (typeElement == null) {
final GrModifierList modifierList = getModifierList();
newTypeElement = (GrTypeElement) addAfter(newTypeElement, modifierList);
} else {
newTypeElement = (GrTypeElement) typeElement.replace(newTypeElement);
}
JavaCodeStyleManager.getInstance(getProject()).shortenClassReferences(newTypeElement);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GrTypeParameterListImpl method appendParenthesesIfNeeded.
private void appendParenthesesIfNeeded() {
PsiElement first = getFirstChild();
if (first == null) {
getNode().addLeaf(GroovyTokenTypes.mLT, "<", null);
}
PsiElement last = getLastChild();
if (last.getNode().getElementType() != GroovyTokenTypes.mGT) {
getNode().addLeaf(GroovyTokenTypes.mGT, ">", null);
}
PsiElement parent = getParent();
if (parent instanceof GrMethod) {
GrModifierList list = ((GrMethod) parent).getModifierList();
PsiElement[] modifiers = list.getModifiers();
if (modifiers.length == 0) {
list.setModifierProperty(GrModifier.DEF, true);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GrStubUtils method getAnnotationNames.
public static String[] getAnnotationNames(PsiModifierListOwner psi) {
List<String> annoNames = ContainerUtil.newArrayList();
final PsiModifierList modifierList = psi.getModifierList();
if (modifierList instanceof GrModifierList) {
for (GrAnnotation annotation : ((GrModifierList) modifierList).getRawAnnotations()) {
final String name = annotation.getShortName();
if (StringUtil.isNotEmpty(name)) {
annoNames.add(name);
}
}
}
return ArrayUtil.toStringArray(annoNames);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class CollectClassMembersUtil method processClass.
private static void processClass(@NotNull PsiClass aClass, @NotNull Map<String, CandidateInfo> allFields, @NotNull Map<String, List<CandidateInfo>> allMethods, @NotNull Map<String, CandidateInfo> allInnerClasses, @NotNull Set<PsiClass> visitedClasses, @NotNull PsiSubstitutor substitutor, boolean includeSynthetic) {
PsiUtilCore.ensureValid(aClass);
if (!visitedClasses.add(aClass))
return;
if (visitedClasses.size() == 1 || !GrTraitUtil.isTrait(aClass)) {
for (PsiField field : getFields(aClass, includeSynthetic)) {
String name = field.getName();
if (!allFields.containsKey(name)) {
allFields.put(name, new CandidateInfo(field, substitutor));
} else if (hasExplicitVisibilityModifiers(field)) {
final CandidateInfo candidateInfo = allFields.get(name);
final PsiElement element = candidateInfo.getElement();
if (element instanceof GrField) {
final GrModifierList modifierList = ((GrField) element).getModifierList();
if ((modifierList == null || !modifierList.hasExplicitVisibilityModifiers()) && aClass == ((GrField) element).getContainingClass()) {
//replace property-field with field with explicit visibilityModifier
allFields.put(name, new CandidateInfo(field, substitutor));
}
}
}
}
}
for (PsiMethod method : getMethods(aClass, includeSynthetic)) {
addMethod(allMethods, method, substitutor);
}
for (final PsiClass inner : getInnerClasses(aClass, includeSynthetic)) {
final String name = inner.getName();
if (name != null && !allInnerClasses.containsKey(name)) {
allInnerClasses.put(name, new CandidateInfo(inner, substitutor));
}
}
for (PsiClass superClass : getSupers(aClass, includeSynthetic)) {
final PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, aClass, substitutor);
processClass(superClass, allFields, allMethods, allInnerClasses, visitedClasses, superSubstitutor, includeSynthetic);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class ResolveUtil method isScriptField.
public static boolean isScriptField(GrVariable var) {
GrModifierList list = var.getModifierList();
if (list == null)
return false;
PsiFile containingFile = var.getContainingFile();
if (!(containingFile instanceof GroovyFile) || !((GroovyFile) containingFile).isScript())
return false;
GrMember member = PsiTreeUtil.getParentOfType(var, GrTypeDefinition.class, GrMethod.class);
if (member != null)
return false;
for (GrAnnotation annotation : list.getAnnotations()) {
String qualifiedName = annotation.getQualifiedName();
if (qualifiedName == null)
continue;
if (qualifiedName.equals(GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD))
return true;
}
return false;
}
Aggregations