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;
}
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;
}
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;
}
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();
}
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);
}
Aggregations