use of com.intellij.psi.impl.source.PsiExtensibleClass in project android by JetBrains.
the class AndroidPsiAugmentProvider method getAugments.
@SuppressWarnings("unchecked")
@NotNull
@Override
public <Psi extends PsiElement> List<Psi> getAugments(@NotNull PsiElement element, @NotNull Class<Psi> type) {
if ((type != PsiClass.class && type != PsiField.class) || !(element instanceof PsiExtensibleClass)) {
return Collections.emptyList();
}
final PsiExtensibleClass aClass = (PsiExtensibleClass) element;
final String className = aClass.getName();
final boolean rClassAugment = AndroidUtils.R_CLASS_NAME.equals(className) && type == PsiClass.class;
if (DumbService.isDumb(element.getProject())) {
if (rClassAugment) {
LOG.debug("R_CLASS_AUGMENT: empty because of dumb mode");
}
return Collections.emptyList();
}
final AndroidFacet facet = AndroidFacet.getInstance(element);
if (facet == null) {
if (rClassAugment) {
LOG.debug("R_CLASS_AUGMENT: empty because no facet");
}
return Collections.emptyList();
}
final PsiFile containingFile = element.getContainingFile();
if (containingFile == null) {
if (rClassAugment) {
LOG.debug("R_CLASS_AUGMENT: empty because of no containing file");
}
return Collections.emptyList();
}
if (type == PsiClass.class) {
if (AndroidUtils.R_CLASS_NAME.equals(className) && AndroidResourceUtil.isRJavaFile(facet, containingFile)) {
final Set<String> existingInnerClasses = getOwnInnerClasses(aClass);
final Set<ResourceType> types = ResourceReferenceConverter.getResourceTypesInCurrentModule(facet);
final List<Psi> result = new ArrayList<Psi>();
for (ResourceType resType : types) {
if (!existingInnerClasses.contains(resType.getName())) {
final AndroidLightClass resClass = new ResourceTypeClass(facet, resType.getName(), aClass);
result.add((Psi) resClass);
}
}
if (rClassAugment) {
LOG.debug("R_CLASS_AUGMENT: " + result.size() + " classes added");
}
return result;
} else if (AndroidUtils.MANIFEST_CLASS_NAME.equals(className) && AndroidResourceUtil.isManifestJavaFile(facet, containingFile)) {
return Arrays.asList((Psi) new PermissionClass(facet, aClass), (Psi) new PermissionGroupClass(facet, aClass));
}
if (rClassAugment) {
LOG.debug("R_CLASS_AUGMENT: empty because containing file is not actual R.java file");
}
} else if (type == PsiField.class && !(aClass instanceof AndroidLightClass)) {
// extend existing inner classes, not provided by this augment (ex. they can be generated by maven)
final PsiClass parentClass = aClass.getContainingClass();
if (parentClass != null && AndroidUtils.R_CLASS_NAME.equals(parentClass.getName()) && AndroidResourceUtil.isRJavaFile(facet, containingFile)) {
final String resClassName = aClass.getName();
if (resClassName != null && ResourceType.getEnum(resClassName) != null) {
final Set<String> existingFields = getOwnFields(aClass);
final PsiField[] newFields = ResourceTypeClass.buildLocalResourceFields(facet, resClassName, aClass);
final List<Psi> result = new ArrayList<Psi>();
for (PsiField field : newFields) {
if (!existingFields.contains(field.getName())) {
result.add((Psi) field);
}
}
return result;
}
}
}
return Collections.emptyList();
}
Aggregations