use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.
the class IdReferenceProvider method getReferencesByElement.
@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
if (element instanceof XmlAttributeValue) {
final XmlExtension extension = XmlExtension.getExtensionByElement(element);
if (extension != null && extension.hasDynamicComponents(element)) {
return PsiReference.EMPTY_ARRAY;
}
final PsiElement parentElement = element.getParent();
if (!(parentElement instanceof XmlAttribute))
return PsiReference.EMPTY_ARRAY;
final String name = ((XmlAttribute) parentElement).getName();
final String ns = ((XmlAttribute) parentElement).getParent().getNamespace();
final boolean jsfNs = Arrays.asList(XmlUtil.JSF_CORE_URIS).contains(ns) || Arrays.asList(XmlUtil.JSF_HTML_URIS).contains(ns);
if (FOR_ATTR_NAME.equals(name)) {
return new PsiReference[] { jsfNs && element.getText().indexOf(':') == -1 ? new IdRefReference(element) : new IdRefReference(element) {
@Override
public boolean isSoft() {
final XmlAttributeDescriptor descriptor = ((XmlAttribute) parentElement).getDescriptor();
return descriptor != null && !descriptor.hasIdRefType();
}
} };
} else {
final boolean allowReferences = !ourNamespacesWithoutNameReference.contains(ns);
if (ID_ATTR_NAME.equals(name) && allowReferences || STYLE_ID_ATTR_NAME.equals(name) || NAME_ATTR_NAME.equals(name) && allowReferences) {
final AttributeValueSelfReference attributeValueSelfReference;
if (jsfNs) {
attributeValueSelfReference = new AttributeValueSelfReference(element);
} else {
if (hasOuterLanguageElement(element))
return PsiReference.EMPTY_ARRAY;
attributeValueSelfReference = new GlobalAttributeValueSelfReference(element, true);
}
return new PsiReference[] { attributeValueSelfReference };
}
}
}
return PsiReference.EMPTY_ARRAY;
}
use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.
the class CheckEmptyTagInspection method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new XmlElementVisitor() {
@Override
public void visitXmlTag(final XmlTag tag) {
if (!isTagWithEmptyEndNotAllowed(tag)) {
return;
}
final ASTNode child = XmlChildRole.EMPTY_TAG_END_FINDER.findChild(tag.getNode());
if (child == null) {
return;
}
final LocalQuickFix fix = new MyLocalQuickFix();
holder.registerProblem(tag, XmlBundle.message("html.inspections.check.empty.script.message"), tag.getContainingFile().getContext() != null ? ProblemHighlightType.INFORMATION : ProblemHighlightType.GENERIC_ERROR_OR_WARNING, fix);
}
};
}
use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.
the class HtmlFileReferenceHelper method getContexts.
@NotNull
@Override
public Collection<PsiFileSystemItem> getContexts(Project project, @NotNull VirtualFile vFile) {
final PsiFile file = PsiManager.getInstance(project).findFile(vFile);
final Module module = file != null ? ModuleUtilCore.findModuleForPsiElement(file) : null;
if (module == null || !(file instanceof XmlFile))
return Collections.emptyList();
final String basePath = HtmlUtil.getHrefBase((XmlFile) file);
if (basePath != null && !HtmlUtil.hasHtmlPrefix(basePath)) {
for (VirtualFile virtualFile : getBaseRoots(module)) {
final VirtualFile base = virtualFile.findFileByRelativePath(basePath);
final PsiDirectory result = base != null ? PsiManager.getInstance(project).findDirectory(base) : null;
if (result != null) {
return Collections.<PsiFileSystemItem>singletonList(result);
}
}
}
return Collections.emptyList();
}
use of org.jetbrains.annotations.NotNull in project Main by SpartanRefactoring.
the class SpartanizerAnnotator method annotate.
@Override
public void annotate(@NotNull final PsiElement e, @NotNull AnnotationHolder h) {
try {
if (!Spartanizer.canTip(e) || e.getContainingFile().getName().contains("Spartanizer"))
return;
Annotation annotation = h.createInfoAnnotation(e, "Spartanize This!");
annotation.registerFix(new IntentionAction() {
@SuppressWarnings("unchecked")
@Nls
@NotNull
@Override
public String getText() {
return Toolbox.getInstance().getTipper(e).description(e);
}
@Nls
@NotNull
@Override
public String getFamilyName() {
return "SpartanizerAction";
}
@Override
public boolean isAvailable(@NotNull Project __, Editor e, PsiFile f) {
return true;
}
@Override
public void invoke(@NotNull Project p, Editor ed, PsiFile f) throws IncorrectOperationException {
Spartanizer.spartanizeElement(e);
}
@Override
public boolean startInWriteAction() {
return false;
}
});
TextAttributesKey.createTextAttributesKey("");
annotation.setEnforcedTextAttributes((new TextAttributes(null, null, JBColor.BLUE, EffectType.WAVE_UNDERSCORE, 0)));
} catch (Throwable t) {
Logger l = new Logger(this.getClass());
l.error("", t);
}
}
use of org.jetbrains.annotations.NotNull in project kotlin by JetBrains.
the class OverridingUtil method isOverridableByWithoutExternalConditions.
@NotNull
public OverrideCompatibilityInfo isOverridableByWithoutExternalConditions(@NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor, boolean checkReturnType) {
OverrideCompatibilityInfo basicOverridability = getBasicOverridabilityProblem(superDescriptor, subDescriptor);
if (basicOverridability != null)
return basicOverridability;
List<KotlinType> superValueParameters = compiledValueParameters(superDescriptor);
List<KotlinType> subValueParameters = compiledValueParameters(subDescriptor);
List<TypeParameterDescriptor> superTypeParameters = superDescriptor.getTypeParameters();
List<TypeParameterDescriptor> subTypeParameters = subDescriptor.getTypeParameters();
if (superTypeParameters.size() != subTypeParameters.size()) {
for (int i = 0; i < superValueParameters.size(); ++i) {
// TODO: compare erasure
if (!KotlinTypeChecker.DEFAULT.equalTypes(superValueParameters.get(i), subValueParameters.get(i))) {
return OverrideCompatibilityInfo.incompatible("Type parameter number mismatch");
}
}
return OverrideCompatibilityInfo.conflict("Type parameter number mismatch");
}
KotlinTypeChecker typeChecker = createTypeChecker(superTypeParameters, subTypeParameters);
for (int i = 0; i < superTypeParameters.size(); i++) {
if (!areTypeParametersEquivalent(superTypeParameters.get(i), subTypeParameters.get(i), typeChecker)) {
return OverrideCompatibilityInfo.incompatible("Type parameter bounds mismatch");
}
}
for (int i = 0; i < superValueParameters.size(); i++) {
if (!areTypesEquivalent(superValueParameters.get(i), subValueParameters.get(i), typeChecker)) {
return OverrideCompatibilityInfo.incompatible("Value parameter type mismatch");
}
}
if (superDescriptor instanceof FunctionDescriptor && subDescriptor instanceof FunctionDescriptor && ((FunctionDescriptor) superDescriptor).isSuspend() != ((FunctionDescriptor) subDescriptor).isSuspend()) {
return OverrideCompatibilityInfo.conflict("Incompatible suspendability");
}
if (checkReturnType) {
KotlinType superReturnType = superDescriptor.getReturnType();
KotlinType subReturnType = subDescriptor.getReturnType();
if (superReturnType != null && subReturnType != null) {
boolean bothErrors = subReturnType.isError() && superReturnType.isError();
if (!bothErrors && !typeChecker.isSubtypeOf(subReturnType, superReturnType)) {
return OverrideCompatibilityInfo.conflict("Return type mismatch");
}
}
}
return OverrideCompatibilityInfo.success();
}
Aggregations