예제 #1
0
  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);
        }
      }
    }
  }
  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);
    }
  }
 private boolean isEmptyRefs(@NotNull Collection<VcsRef> refs, int head) {
   if (refs.isEmpty()) {
     if (!myErrorWasReported.containsKey(head)) {
       myErrorWasReported.put(head, head);
       LOG.error(
           "No references found at head "
               + head
               + " which corresponds to hash "
               + myHashGetter.fun(head));
     }
     return true;
   }
   return false;
 }
예제 #4
0
  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;
  }
예제 #5
0
파일: TestMethods.java 프로젝트: jexp/idea2
 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);
 }
예제 #6
0
  private void doTest() {
    final LinkedHashMap<Integer, String> caretOffsetToExpectedResult =
        DartTestUtils.extractPositionMarkers(getProject(), myFixture.getEditor().getDocument());

    for (Map.Entry<Integer, String> entry : caretOffsetToExpectedResult.entrySet()) {
      final Integer caretOffset = entry.getKey();
      final String expectedResult = entry.getValue();

      final int line = myFixture.getEditor().getDocument().getLineNumber(caretOffset);
      final int column = caretOffset - myFixture.getEditor().getDocument().getLineStartOffset(line);
      final String fileNameAndPosition =
          myFixture.getFile().getName() + ":" + (line + 1) + ":" + (column + 1);

      final PsiReference reference = myFixture.getFile().findReferenceAt(caretOffset);
      assertNotNull("No reference in " + fileNameAndPosition, reference);

      final PsiElement resolve = reference.resolve();
      final String actualElementPosition = getPresentableElementPosition(resolve);
      assertEquals(
          "Incorrect resolve for element in " + fileNameAndPosition,
          expectedResult,
          actualElementPosition);
    }
  }
예제 #7
0
 private synchronized void initPropertyBindings(Class<?> beanClass) {
   for (Accessor accessor : getAccessors(beanClass)) {
     myPropertyBindings.put(createBindingByAccessor(accessor), accessor);
   }
 }