public void serializeInto( @NotNull Object o, @NotNull Element element, @NotNull SerializationFilter filter) { for (Binding binding : myPropertyBindings.keySet()) { Accessor accessor = myPropertyBindings.get(binding); if (!filter.accepts(accessor, o)) { continue; } // todo: optimize. Cache it. Property property = accessor.getAnnotation(Property.class); if (property != null && property.filter() != SerializationFilter.class) { try { if (!ReflectionUtil.newInstance(property.filter()).accepts(accessor, o)) { continue; } } catch (RuntimeException e) { throw new XmlSerializationException(e); } } Object node = binding.serialize(o, element, filter); if (node != null) { if (node instanceof org.jdom.Attribute) { element.setAttribute((org.jdom.Attribute) node); } else { JDOMUtil.addContent(element, node); } } } }
public Object deserializeInto(@NotNull Object result, @NotNull Element element) { Set<Binding> bindings = myPropertyBindings.keySet(); MultiMap<Binding, Object> data = MultiMap.createSmartList(); nextNode: for (Object child : ContainerUtil.concat(element.getContent(), element.getAttributes())) { if (XmlSerializerImpl.isIgnoredNode(child)) { continue; } for (Binding binding : bindings) { if (binding.isBoundTo(child)) { data.putValue(binding, child); continue nextNode; } } final String message = "Format error: no binding for " + child + " inside " + this; LOG.debug(message); Logger.getInstance(myBeanClass.getName()).debug(message); Logger.getInstance("#" + myBeanClass.getName()).debug(message); } for (Binding binding : data.keySet()) { binding.deserialize(result, ArrayUtil.toObjectArray(data.get(binding))); } return result; }
private void altCommitToOriginal(@NotNull DocumentEvent e) { final PsiFile origPsiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myOrigDocument); String newText = myNewDocument.getText(); // prepare guarded blocks LinkedHashMap<String, String> replacementMap = new LinkedHashMap<String, String>(); int count = 0; for (RangeMarker o : ContainerUtil.reverse(((DocumentEx) myNewDocument).getGuardedBlocks())) { String replacement = o.getUserData(REPLACEMENT_KEY); String tempText = "REPLACE" + (count++) + Long.toHexString(StringHash.calc(replacement)); newText = newText.substring(0, o.getStartOffset()) + tempText + newText.substring(o.getEndOffset()); replacementMap.put(tempText, replacement); } // run preformat processors final int hostStartOffset = myAltFullRange.getStartOffset(); myEditor.getCaretModel().moveToOffset(hostStartOffset); for (CopyPastePreProcessor preProcessor : Extensions.getExtensions(CopyPastePreProcessor.EP_NAME)) { newText = preProcessor.preprocessOnPaste(myProject, origPsiFile, myEditor, newText, null); } myOrigDocument.replaceString(hostStartOffset, myAltFullRange.getEndOffset(), newText); // replace temp strings for guarded blocks for (String tempText : replacementMap.keySet()) { int idx = CharArrayUtil.indexOf( myOrigDocument.getCharsSequence(), tempText, hostStartOffset, myAltFullRange.getEndOffset()); myOrigDocument.replaceString(idx, idx + tempText.length(), replacementMap.get(tempText)); } // JAVA: fix occasional char literal concatenation fixDocumentQuotes(myOrigDocument, hostStartOffset - 1); fixDocumentQuotes(myOrigDocument, myAltFullRange.getEndOffset()); // reformat PsiDocumentManager.getInstance(myProject).commitDocument(myOrigDocument); Runnable task = () -> { try { CodeStyleManager.getInstance(myProject) .reformatRange(origPsiFile, hostStartOffset, myAltFullRange.getEndOffset(), true); } catch (IncorrectOperationException e1) { // LOG.error(e); } }; DocumentUtil.executeInBulk(myOrigDocument, true, task); PsiElement newInjected = InjectedLanguageManager.getInstance(myProject) .findInjectedElementAt(origPsiFile, hostStartOffset); DocumentWindow documentWindow = newInjected == null ? null : InjectedLanguageUtil.getDocumentWindow(newInjected); if (documentWindow != null) { myEditor.getCaretModel().moveToOffset(documentWindow.injectedToHost(e.getOffset())); myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); } }
protected void initialize() throws ExecutionException { defaultInitialize(); final JUnitConfiguration.Data data = myConfiguration.getPersistentData(); RunConfigurationModule module = myConfiguration.getConfigurationModule(); final Project project = module.getProject(); addJUnit4Parameter(data, project); final ExecutionException[] exception = new ExecutionException[1]; ApplicationManager.getApplication() .runReadAction( new Runnable() { public void run() { try { myConfiguration.configureClasspath(myJavaParameters); } catch (CantRunException e) { exception[0] = e; } } }); if (exception[0] != null) throw exception[0]; final LinkedHashMap<PsiMethod, TestInfo> methods = new LinkedHashMap<PsiMethod, TestInfo>(); for (AbstractTestProxy failedTest : myFailedTests) { Location location = failedTest.getLocation(project); if (!(location instanceof MethodLocation)) continue; PsiElement psiElement = location.getPsiElement(); LOG.assertTrue(psiElement instanceof PsiMethod); PsiMethod method = (PsiMethod) psiElement; methods.put(method, ((TestProxy) failedTest).getInfo()); } addClassesListToJavaParameters( methods.keySet(), new Function<PsiElement, String>() { public String fun(PsiElement element) { if (element instanceof PsiMethod) { final PsiMethod method = (PsiMethod) element; final TestInfo testInfo = methods.get(method); return JavaExecutionUtil.getRuntimeQualifiedName( ((MethodLocation) testInfo.getLocation(project)).getContainingClass()) + "," + testInfo.getName(); } return null; } }, data.getPackageName(), true, false); }