Search in sources :

Example 1 with TIntArrayList

use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.

the class CutCopyPasteSupport method loadComponentsToPaste.

private static boolean loadComponentsToPaste(final GuiEditor editor, final String serializedComponents, final TIntArrayList xs, final TIntArrayList ys, final ArrayList<RadComponent> componentsToPaste) {
    final PsiPropertiesProvider provider = new PsiPropertiesProvider(editor.getModule());
    try {
        //noinspection HardCodedStringLiteral
        final Document document = SAX_BUILDER.build(new StringReader(serializedComponents), "UTF-8");
        final Element rootElement = document.getRootElement();
        if (!rootElement.getName().equals(ELEMENT_SERIALIZED)) {
            return false;
        }
        final List children = rootElement.getChildren();
        for (final Object aChildren : children) {
            final Element e = (Element) aChildren;
            // we need to add component to a container in order to read them
            final LwContainer container = new LwContainer(JPanel.class.getName());
            final String parentLayout = e.getAttributeValue(ATTRIBUTE_PARENT_LAYOUT);
            if (parentLayout != null) {
                container.setLayoutManager(parentLayout);
            }
            final int x = Integer.parseInt(e.getAttributeValue(ATTRIBUTE_X));
            final int y = Integer.parseInt(e.getAttributeValue(ATTRIBUTE_Y));
            xs.add(x);
            ys.add(y);
            final Element componentElement = (Element) e.getChildren().get(0);
            final LwComponent lwComponent = LwContainer.createComponentFromTag(componentElement);
            container.addComponent(lwComponent);
            lwComponent.read(componentElement, provider);
            // pasted components should have no bindings
            FormEditingUtil.iterate(lwComponent, new FormEditingUtil.ComponentVisitor<LwComponent>() {

                public boolean visit(final LwComponent c) {
                    if (c.getBinding() != null && FormEditingUtil.findComponentWithBinding(editor.getRootContainer(), c.getBinding()) != null) {
                        c.setBinding(null);
                    }
                    c.setId(FormEditingUtil.generateId(editor.getRootContainer()));
                    return true;
                }
            });
            final ClassLoader loader = LoaderFactory.getInstance(editor.getProject()).getLoader(editor.getFile());
            final RadComponent radComponent = XmlReader.createComponent(editor, lwComponent, loader, editor.getStringDescriptorLocale());
            componentsToPaste.add(radComponent);
        }
    } catch (Exception e) {
        return false;
    }
    return true;
}
Also used : Element(org.jdom.Element) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) LwContainer(com.intellij.uiDesigner.lw.LwContainer) Document(org.jdom.Document) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) TIntArrayList(gnu.trove.TIntArrayList) List(java.util.List) LwComponent(com.intellij.uiDesigner.lw.LwComponent)

Example 2 with TIntArrayList

use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.

the class GriffonFramework method getInstalledPluginNameByPath.

@Override
public String getInstalledPluginNameByPath(Project project, @NotNull VirtualFile pluginPath) {
    String nameFromPluginXml = super.getInstalledPluginNameByPath(project, pluginPath);
    if (nameFromPluginXml != null) {
        return nameFromPluginXml;
    }
    VirtualFile pluginJson = pluginPath.findChild("plugin.json");
    if (pluginJson != null) {
        // pluginName-version
        String pluginAndVersion = pluginPath.getName();
        TIntArrayList separatorIndexes = new TIntArrayList();
        int start = -1;
        while (true) {
            start = pluginAndVersion.indexOf('-', start + 1);
            if (start == -1)
                break;
            separatorIndexes.add(start);
        }
        if (separatorIndexes.size() == 1) {
            return pluginAndVersion.substring(0, separatorIndexes.get(0));
        }
        if (!separatorIndexes.isEmpty()) {
            String json;
            try {
                json = VfsUtil.loadText(pluginJson);
            } catch (IOException e) {
                return null;
            }
            for (int i = 0; i < separatorIndexes.size(); i++) {
                int idx = separatorIndexes.get(i);
                String name = pluginAndVersion.substring(0, idx);
                String version = pluginAndVersion.substring(idx + 1);
                if (hasValue(PLUGIN_NAME_JSON_PATTERN, json, name) && hasValue(PLUGIN_VERSION_JSON_PATTERN, json, version)) {
                    return name;
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) TIntArrayList(gnu.trove.TIntArrayList)

Example 3 with TIntArrayList

use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.

the class TypeProvider method inferMethodParameters.

@NotNull
private PsiType[] inferMethodParameters(@NotNull GrMethod method) {
    PsiType[] psiTypes = inferredTypes.get(method);
    if (psiTypes != null)
        return psiTypes;
    final GrParameter[] parameters = method.getParameters();
    final TIntArrayList paramInds = new TIntArrayList(parameters.length);
    final PsiType[] types = PsiType.createArray(parameters.length);
    for (int i = 0; i < parameters.length; i++) {
        if (parameters[i].getTypeElementGroovy() == null) {
            paramInds.add(i);
        } else {
            types[i] = parameters[i].getType();
        }
    }
    if (!paramInds.isEmpty()) {
        final GrClosureSignature signature = GrClosureSignatureUtil.createSignature(method, PsiSubstitutor.EMPTY);
        MethodReferencesSearch.search(method, true).forEach(psiReference -> {
            final PsiElement element = psiReference.getElement();
            final PsiManager manager = element.getManager();
            final GlobalSearchScope resolveScope = element.getResolveScope();
            if (element instanceof GrReferenceExpression) {
                final GrCall call = (GrCall) element.getParent();
                final GrClosureSignatureUtil.ArgInfo<PsiElement>[] argInfos = GrClosureSignatureUtil.mapParametersToArguments(signature, call);
                if (argInfos == null)
                    return true;
                paramInds.forEach(new TIntProcedure() {

                    @Override
                    public boolean execute(int i) {
                        PsiType type = GrClosureSignatureUtil.getTypeByArg(argInfos[i], manager, resolveScope);
                        types[i] = TypesUtil.getLeastUpperBoundNullable(type, types[i], manager);
                        return true;
                    }
                });
            }
            return true;
        });
    }
    paramInds.forEach(new TIntProcedure() {

        @Override
        public boolean execute(int i) {
            if (types[i] == null || types[i] == PsiType.NULL) {
                types[i] = parameters[i].getType();
            }
            return true;
        }
    });
    inferredTypes.put(method, types);
    return types;
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) TIntArrayList(gnu.trove.TIntArrayList) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with TIntArrayList

use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.

the class XmlAttributeImpl method getDisplayValue.

@Override
public String getDisplayValue() {
    String displayText = myDisplayText;
    if (displayText != null)
        return displayText;
    XmlAttributeValue value = getValueElement();
    if (value == null)
        return null;
    PsiElement firstChild = value.getFirstChild();
    if (firstChild == null)
        return null;
    ASTNode child = firstChild.getNode();
    TextRange valueTextRange = new TextRange(0, value.getTextLength());
    if (child != null && child.getElementType() == XmlTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER) {
        valueTextRange = new TextRange(child.getTextLength(), valueTextRange.getEndOffset());
        child = child.getTreeNext();
    }
    final TIntArrayList gapsStarts = new TIntArrayList();
    final TIntArrayList gapsShifts = new TIntArrayList();
    StringBuilder buffer = new StringBuilder(getTextLength());
    while (child != null) {
        final int start = buffer.length();
        IElementType elementType = child.getElementType();
        if (elementType == XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER) {
            valueTextRange = new TextRange(valueTextRange.getStartOffset(), child.getTextRange().getStartOffset() - value.getTextRange().getStartOffset());
            break;
        }
        if (elementType == XmlTokenType.XML_CHAR_ENTITY_REF) {
            buffer.append(XmlUtil.getCharFromEntityRef(child.getText()));
        } else if (elementType == XmlElementType.XML_ENTITY_REF) {
            buffer.append(XmlUtil.getEntityValue((XmlEntityRef) child));
        } else {
            appendChildToDisplayValue(buffer, child);
        }
        int end = buffer.length();
        int originalLength = child.getTextLength();
        if (end - start != originalLength) {
            gapsStarts.add(start);
            gapsShifts.add(originalLength - (end - start));
        }
        child = child.getTreeNext();
    }
    int[] gapDisplayStarts = ArrayUtil.newIntArray(gapsShifts.size());
    int[] gapPhysicalStarts = ArrayUtil.newIntArray(gapsShifts.size());
    int currentGapsSum = 0;
    for (int i = 0; i < gapDisplayStarts.length; i++) {
        currentGapsSum += gapsShifts.get(i);
        gapDisplayStarts[i] = gapsStarts.get(i);
        gapPhysicalStarts[i] = gapDisplayStarts[i] + currentGapsSum;
    }
    myGapDisplayStarts = gapDisplayStarts;
    myGapPhysicalStarts = gapPhysicalStarts;
    myValueTextRange = valueTextRange;
    return myDisplayText = buffer.toString();
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange) TIntArrayList(gnu.trove.TIntArrayList)

Example 5 with TIntArrayList

use of gnu.trove.TIntArrayList in project ideavim by JetBrains.

the class PsiHelper method findMethodOrClass.

private static int findMethodOrClass(@NotNull Editor editor, int offset, int count, boolean isStart) {
    PsiFile file = getFile(editor);
    if (file == null) {
        return -1;
    }
    StructureViewBuilder structureViewBuilder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(file);
    if (!(structureViewBuilder instanceof TreeBasedStructureViewBuilder))
        return -1;
    TreeBasedStructureViewBuilder builder = (TreeBasedStructureViewBuilder) structureViewBuilder;
    StructureViewModel model = builder.createStructureViewModel(editor);
    TIntArrayList navigationOffsets = new TIntArrayList();
    addNavigationElements(model.getRoot(), navigationOffsets, isStart);
    if (navigationOffsets.isEmpty()) {
        return -1;
    }
    navigationOffsets.sort();
    int index = navigationOffsets.size();
    for (int i = 0; i < navigationOffsets.size(); i++) {
        if (navigationOffsets.get(i) > offset) {
            index = i;
            if (count > 0)
                count--;
            break;
        } else if (navigationOffsets.get(i) == offset) {
            index = i;
            break;
        }
    }
    int resultIndex = index + count;
    if (resultIndex < 0) {
        resultIndex = 0;
    } else if (resultIndex >= navigationOffsets.size()) {
        resultIndex = navigationOffsets.size() - 1;
    }
    return navigationOffsets.get(resultIndex);
}
Also used : LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) PsiFile(com.intellij.psi.PsiFile) TIntArrayList(gnu.trove.TIntArrayList)

Aggregations

TIntArrayList (gnu.trove.TIntArrayList)104 NotNull (org.jetbrains.annotations.NotNull)34 ArrayList (java.util.ArrayList)9 List (java.util.List)7 Nullable (org.jetbrains.annotations.Nullable)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ArrangementMatchingRulesControl (com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl)3 StringSearcher (com.intellij.util.text.StringSearcher)3 TIntHashSet (gnu.trove.TIntHashSet)3 TIntProcedure (gnu.trove.TIntProcedure)3 IOException (java.io.IOException)3 IDevice (com.android.ddmlib.IDevice)2 ArrangementMatchingRulesModel (com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesModel)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 Project (com.intellij.openapi.project.Project)2 TextRange (com.intellij.openapi.util.TextRange)2 ElementToWorkOn (com.intellij.refactoring.introduceField.ElementToWorkOn)2 IntroduceParameterProcessor (com.intellij.refactoring.introduceParameter.IntroduceParameterProcessor)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)2