use of com.intellij.struts2.dom.struts.strutspackage.ResultType in project intellij-plugins by JetBrains.
the class ResultImpl method getEffectiveResultType.
@Nullable
public ResultType getEffectiveResultType() {
final GenericAttributeValue<ResultType> typeAttribute = getType();
if (DomUtil.hasXml(typeAttribute)) {
return typeAttribute.getValue();
}
final StrutsPackage strutsPackage = getParentOfType(StrutsPackage.class, true);
return strutsPackage != null ? strutsPackage.searchDefaultResultType() : null;
}
use of com.intellij.struts2.dom.struts.strutspackage.ResultType in project intellij-plugins by JetBrains.
the class ResultTypeResolvingConverterImpl method getVariants.
@NotNull
public Collection<? extends ResultType> getVariants(final ConvertContext context) {
final List<ResultType> results = new SmartList<>();
final Processor<StrutsPackage> processor = strutsPackage -> {
results.addAll(strutsPackage.getResultTypes());
return true;
};
final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(ConverterUtil.getCurrentStrutsPackage(context), processor);
walker.walkUp();
return results;
}
use of com.intellij.struts2.dom.struts.strutspackage.ResultType in project intellij-plugins by JetBrains.
the class StrutsPackageImpl method searchDefaultResultType.
@Nullable
public ResultType searchDefaultResultType() {
if (myCachedDefaultResultType == null) {
final PsiFile containingFile = getContainingFile();
if (containingFile == null) {
return null;
}
myCachedDefaultResultType = CachedValuesManager.getManager(containingFile.getProject()).createCachedValue(() -> {
final Ref<ResultType> result = new Ref<>();
final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(this, strutsPackage -> {
final List<ResultType> resultTypes = strutsPackage.getResultTypes();
for (final ResultType resultType : resultTypes) {
final GenericAttributeValue<Boolean> defaultAttribute = resultType.getDefault();
if (DomUtil.hasXml(defaultAttribute) && defaultAttribute.getValue() == Boolean.TRUE) {
result.set(resultType);
return false;
}
}
return true;
});
walker.walkUp();
return CachedValueProvider.Result.createSingleDependency(result.get(), PsiModificationTracker.MODIFICATION_COUNT);
}, false);
}
return myCachedDefaultResultType.getValue();
}
use of com.intellij.struts2.dom.struts.strutspackage.ResultType in project intellij-plugins by JetBrains.
the class StrutsResultContributor method getNamespace.
/**
* Gets the current namespace for the given element.
*
* @param psiElement Current element.
* @return {@code null} on XML errors or if {@link #matchesResultType(String)} returns {@code false}.
*/
@Nullable
protected final String getNamespace(@NotNull final PsiElement psiElement) {
final DomElement resultElement = DomUtil.getDomElement(psiElement);
if (resultElement == null) {
// XML syntax error
return null;
}
assert resultElement instanceof HasResultType : "not instance of HasResultType: " + resultElement + ", text: " + psiElement.getText();
final ResultType effectiveResultType = ((HasResultType) resultElement).getEffectiveResultType();
if (effectiveResultType == null) {
return null;
}
final String resultType = effectiveResultType.getName().getStringValue();
if (resultType == null || !matchesResultType(resultType)) {
return null;
}
final StrutsPackage strutsPackage = resultElement.getParentOfType(StrutsPackage.class, true);
if (strutsPackage == null) {
// XML syntax error
return null;
}
return strutsPackage.searchNamespace();
}
Aggregations