Search in sources :

Example 1 with Result

use of com.intellij.struts2.dom.struts.action.Result in project intellij-plugins by JetBrains.

the class ResultActionPropertyReferenceProvider method getReferencesByElement.

@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull final PsiElement psiElement, @NotNull final ProcessingContext processingContext) {
    final Result result = (Result) DomUtil.getDomElement(psiElement);
    assert result != null : psiElement.getText();
    final Action action = result.getParentOfType(Action.class, true);
    assert action != null : psiElement.getText();
    final PsiClass actionClass = action.searchActionClass();
    if (actionClass == null) {
        return PsiReference.EMPTY_ARRAY;
    }
    final int tagValueStartOffset = ElementManipulators.getOffsetInElement(result.getXmlTag());
    PsiReference[] references = new PsiReference[1];
    final String stringValue = result.getStringValue();
    if (!StringUtil.isNotEmpty(stringValue)) {
        return PsiReference.EMPTY_ARRAY;
    }
    final String resultText = StringUtil.replace(stringValue, "&", "&");
    final int lastExpressionEnd = // missing '}'
    Math.max(// missing '}'
    resultText.length(), resultText.lastIndexOf(EXPRESSION_START));
    int startOffset = 0;
    while (startOffset < lastExpressionEnd) {
        startOffset = resultText.indexOf(EXPRESSION_START, startOffset);
        if (startOffset == -1) {
            break;
        }
        startOffset += EXPRESSION_START.length();
        final int closingBraceIdx = resultText.indexOf(EXPRESSION_END, startOffset);
        final int length = (closingBraceIdx != -1 ? closingBraceIdx : resultText.length()) - startOffset;
        final String expressionString = resultText.substring(startOffset, startOffset + length);
        // we only "fake" OGNL here, skip method call expressions for now
        if (StringUtil.containsChar(expressionString, '(')) {
            continue;
        }
        final BeanPropertyPathReferenceSet propertyPathReferenceSet = new BeanPropertyPathReferenceSet(expressionString, psiElement, startOffset, '.', actionClass, true) {

            // CTOR creates references eagerly, so we have to subclass here
            @Override
            public boolean isSoft() {
                return false;
            }

            @NotNull
            @Override
            protected BeanPropertyPathReference createReference(final TextRange range, final int index) {
                final TextRange shift = TextRange.from(range.getStartOffset() + tagValueStartOffset, // shift range to XmlTag value range
                range.getLength());
                return createBeanPropertyPathReference(shift, index);
            }
        };
        references = ArrayUtil.mergeArrays(references, propertyPathReferenceSet.getPsiReferences());
    }
    return references;
}
Also used : Action(com.intellij.struts2.dom.struts.action.Action) TextRange(com.intellij.openapi.util.TextRange) BeanPropertyPathReferenceSet(com.intellij.struts2.reference.common.BeanPropertyPathReferenceSet) Result(com.intellij.struts2.dom.struts.action.Result) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Result

use of com.intellij.struts2.dom.struts.action.Result in project intellij-plugins by JetBrains.

the class GoToPackageSymbolProvider method addItems.

protected void addItems(@NotNull final Module module, final String name, final List<NavigationItem> result) {
    final StrutsModel strutsModel = StrutsManager.getInstance(module.getProject()).getCombinedModel(module);
    if (strutsModel == null) {
        return;
    }
    final List<StrutsPackage> strutsPackageList = strutsModel.getStrutsPackages();
    for (final StrutsPackage strutsPackage : strutsPackageList) {
        if (Comparing.strEqual(name, strutsPackage.getName().getStringValue())) {
            final NavigationItem item = createNavigationItem(strutsPackage.getXmlTag(), name, StrutsIcons.STRUTS_PACKAGE);
            result.add(item);
        }
    }
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)

Example 3 with Result

use of com.intellij.struts2.dom.struts.action.Result in project intellij-plugins by JetBrains.

the class ResultNode method getIcon.

@NotNull
public Icon getIcon() {
    final Result result = getIdentifyingElement();
    if (!result.isValid()) {
        return UNKNOWN_RESULT_ICON;
    }
    final PathReference pathReference = result.getValue();
    if (pathReference == null) {
        return UNKNOWN_RESULT_ICON;
    }
    if (pathReference.resolve() == null) {
        return UNKNOWN_RESULT_ICON;
    }
    final Icon pathReferenceIcon = pathReference.getIcon();
    return pathReferenceIcon != null ? pathReferenceIcon : UNKNOWN_RESULT_ICON;
}
Also used : PathReference(com.intellij.openapi.paths.PathReference) Result(com.intellij.struts2.dom.struts.action.Result) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with Result

use of com.intellij.struts2.dom.struts.action.Result in project intellij-plugins by JetBrains.

the class InterceptorRefResolveConverterImpl method fromString.

public InterceptorOrStackBase fromString(@Nullable @NonNls final String name, final ConvertContext context) {
    if (name == null) {
        return null;
    }
    final Condition<InterceptorOrStackBase> nameCondition = interceptorOrStackBase -> name.equals(interceptorOrStackBase.getName().getStringValue());
    final Ref<InterceptorOrStackBase> resolveResult = new Ref<>();
    final Processor<StrutsPackage> processor = strutsPackage -> {
        final InterceptorOrStackBase result = ContainerUtil.find(getAllInterceptors(strutsPackage), nameCondition);
        if (result != null) {
            resolveResult.set(result);
            return false;
        }
        return true;
    };
    final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(ConverterUtil.getCurrentStrutsPackage(context), processor);
    walker.walkUp();
    return resolveResult.get();
}
Also used : Collection(java.util.Collection) NonNls(org.jetbrains.annotations.NonNls) InterceptorOrStackBase(com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SmartList(com.intellij.util.SmartList) Processor(com.intellij.util.Processor) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ConverterUtil(com.intellij.struts2.dom.ConverterUtil) InterceptorRefResolveConverter(com.intellij.struts2.dom.struts.strutspackage.InterceptorRefResolveConverter) ConvertContext(com.intellij.util.xml.ConvertContext) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Condition(com.intellij.openapi.util.Condition) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Ref(com.intellij.openapi.util.Ref) InterceptorOrStackBase(com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)

Example 5 with Result

use of com.intellij.struts2.dom.struts.action.Result in project intellij-plugins by JetBrains.

the class ResultTypeResolvingConverterImpl method fromString.

public ResultType fromString(@Nullable @NonNls final String name, final ConvertContext context) {
    if (StringUtil.isEmpty(name)) {
        return null;
    }
    final Condition<ResultType> nameCondition = resultType -> Comparing.equal(name, resultType.getName().getStringValue());
    final Ref<ResultType> resolveResult = new Ref<>();
    final Processor<StrutsPackage> processor = strutsPackage -> {
        final ResultType result = ContainerUtil.find(strutsPackage.getResultTypes(), nameCondition);
        if (result != null) {
            resolveResult.set(result);
            return false;
        }
        return true;
    };
    final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(ConverterUtil.getCurrentStrutsPackage(context), processor);
    walker.walkUp();
    return resolveResult.get();
}
Also used : StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Comparing(com.intellij.openapi.util.Comparing) SmartList(com.intellij.util.SmartList) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) Processor(com.intellij.util.Processor) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ConverterUtil(com.intellij.struts2.dom.ConverterUtil) ResultTypeResolvingConverter(com.intellij.struts2.dom.struts.action.ResultTypeResolvingConverter) ConvertContext(com.intellij.util.xml.ConvertContext) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Condition(com.intellij.openapi.util.Condition) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Ref(com.intellij.openapi.util.Ref) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)10 Result (com.intellij.struts2.dom.struts.action.Result)9 Action (com.intellij.struts2.dom.struts.action.Action)8 StrutsModel (com.intellij.struts2.dom.struts.model.StrutsModel)8 PathReference (com.intellij.openapi.paths.PathReference)6 Ref (com.intellij.openapi.util.Ref)6 StrutsPackage (com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)6 StrutsPackageHierarchyWalker (com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker)6 Nullable (org.jetbrains.annotations.Nullable)6 Processor (com.intellij.util.Processor)5 List (java.util.List)5 NonNls (org.jetbrains.annotations.NonNls)5 ResultType (com.intellij.struts2.dom.struts.strutspackage.ResultType)4 Condition (com.intellij.openapi.util.Condition)3 DefaultClassRef (com.intellij.struts2.dom.struts.strutspackage.DefaultClassRef)3 SmartList (com.intellij.util.SmartList)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 ConvertContext (com.intellij.util.xml.ConvertContext)3 Collection (java.util.Collection)3 NavigationItem (com.intellij.navigation.NavigationItem)2