Java源码示例:com.intellij.lang.properties.IProperty

示例1
@Override
public void update(AnActionEvent anActionEvent) {
    final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(anActionEvent.getDataContext());

    boolean isProperty = false;
    boolean isPropertyFile = false;
    boolean isEncrypted = false;

    if (file != null) {
        isPropertyFile = "properties".equalsIgnoreCase(file.getExtension());
        if (isPropertyFile) {
            IProperty selectedProperty = getSelectedProperty(anActionEvent.getDataContext());
            if (selectedProperty != null) {
                String propertyValue = selectedProperty.getValue();
                isEncrypted = (propertyValue.startsWith("![") && propertyValue.endsWith("]"));
                isProperty = true;
            }
        }
    }
    anActionEvent.getPresentation().setEnabled(isPropertyFile && isEncrypted && isProperty);
    anActionEvent.getPresentation().setVisible(isPropertyFile && isProperty);
}
 
示例2
@Override
public void update(AnActionEvent anActionEvent)
{
    final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(anActionEvent.getDataContext());

    boolean isProperty = false;
    boolean isPropertyFile = false;
    boolean isEncrypted = false;

    if (file != null)
    {
        isPropertyFile = "properties".equalsIgnoreCase(file.getExtension());
        if (isPropertyFile) {

            IProperty selectedProperty = getSelectedProperty(anActionEvent.getDataContext());
            if (selectedProperty != null) {
                String propertyValue = selectedProperty.getValue();
                isEncrypted = (propertyValue.startsWith("![") && propertyValue.endsWith("]"));
                isProperty = true;
            }
        }
    }

    anActionEvent.getPresentation().setEnabled(isPropertyFile && !isEncrypted && isProperty);
    anActionEvent.getPresentation().setVisible(isPropertyFile && isProperty);
}
 
示例3
@Override
protected void addCompletions(final CompletionParameters completionParameters,
        final ProcessingContext processingContext, final CompletionResultSet resultSet) {

    final PsiElement element = completionParameters.getPosition();
    if (!LeafPsiElement.class.isInstance(element)) {
        return; // ignore comment
    }

    final Project project = element.getProject();
    final Module module = findModule(element);
    final SuggestionService service = ServiceManager.getService(project, SuggestionService.class);
    if ((module == null || !service.isSupported(completionParameters))) { // limit suggestion to Messages
        return;
    }

    if (PropertyValueImpl.class.isInstance(element)) {
        ofNullable(PropertyValueImpl.class.cast(element).getPrevSibling())
                .map(PsiElement::getPrevSibling)
                .map(PsiElement::getText)
                .ifPresent(text -> resultSet.addAllElements(service.computeValueSuggestions(text)));
    } else if (PropertyKeyImpl.class.isInstance(element)) {
        final List<String> containerElements = PropertiesFileImpl.class
                .cast(element.getContainingFile())
                .getProperties()
                .stream()
                .filter(p -> !Objects.equals(p.getKey(), element.getText()))
                .map(IProperty::getKey)
                .collect(toList());
        resultSet
                .addAllElements(service
                        .computeKeySuggestions(project, module, getPropertiesPackage(module, completionParameters),
                                containerElements, truncateIdeaDummyIdentifier(element)));
    }
}
 
示例4
public static List<PsiElement> findPropertiesPsiElement(Project project, Collection<VirtualFile> virtualFiles, String key) {
    List<PsiElement> result = new ArrayList<>();
    for (VirtualFile virtualFile : virtualFiles) {
        PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
        List<IProperty> iProperties = ((PropertiesFileImpl) psiFile).getProperties();
        iProperties.forEach(iProperty -> {
            if (iProperty.getKey().equals(key)) {
                result.add(iProperty.getPsiElement());
            }
        });
    }
    return result;
}
 
示例5
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
    final Project project = (Project) anActionEvent.getData(CommonDataKeys.PROJECT);

    PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE);

    IProperty selectedProperty = getSelectedProperty(anActionEvent.getDataContext());

    final EncryptDialog form = new EncryptDialog();
    form.setTitle("Decrypt Property: " + selectedProperty.getKey());
    form.show();
    boolean isOk = form.getExitCode() == DialogWrapper.OK_EXIT_CODE;

    logger.debug("**** ALGORITHM " + form.getAlgorithm().getSelectedItem());
    logger.debug("**** MODE " + form.getMode().getSelectedItem());

    if (isOk) {
        new WriteCommandAction.Simple(project, psiFile) {
            @Override
            protected void run() throws Throwable {
                EncryptionAlgorithm algorithm = (EncryptionAlgorithm) form.getAlgorithm().getSelectedItem();
                EncryptionMode mode = (EncryptionMode) form.getMode().getSelectedItem();

                try {
                    String originalValue = selectedProperty.getValue();
                    String encryptedProperty = originalValue.substring(2, originalValue.length() - 1);

                    byte[] decryptedBytes = algorithm.getBuilder().forKey(form.getEncryptionKey().getText()).using(mode)
                            .build().decrypt(Base64.decode(encryptedProperty));

                    selectedProperty.setValue(new String(decryptedBytes));
                } catch (Exception e) {
                    Notification notification = MuleUIUtils.MULE_NOTIFICATION_GROUP.createNotification("Unable to decrypt property",
                            "Property '" + selectedProperty.getKey() + "' cannot be decrypted : " + e, NotificationType.ERROR, null);
                    Notifications.Bus.notify(notification, project);
                }
            }
        }.execute();
    }
}
 
示例6
@Override
    public void actionPerformed(AnActionEvent anActionEvent)
    {
        final Project project = (Project)anActionEvent.getData(CommonDataKeys.PROJECT);

        PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE);

        IProperty selectedProperty = getSelectedProperty(anActionEvent.getDataContext());
        if (selectedProperty == null)
            return;

        final EncryptDialog form = new EncryptDialog();
        form.setTitle("Encrypt Property: " + selectedProperty.getKey());
        form.show();
        boolean isOk = form.getExitCode() == DialogWrapper.OK_EXIT_CODE;

//        System.out.println("******** IS OK " + isOk);
        logger.debug("**** ALGORITHM " + form.getAlgorithm().getSelectedItem());
        logger.debug("**** MODE " + form.getMode().getSelectedItem());

        if (isOk) {
            new WriteCommandAction.Simple(project, psiFile) {
                @Override
                protected void run() throws Throwable {
                    EncryptionAlgorithm algorithm = (EncryptionAlgorithm) form.getAlgorithm().getSelectedItem();
                    EncryptionMode mode = (EncryptionMode) form.getMode().getSelectedItem();

                    byte[] encryptedBytes = algorithm.getBuilder().forKey(form.getEncryptionKey().getText()).using(mode)
                            .build().encrypt(selectedProperty.getValue().getBytes());
                    StringBuilder result = new StringBuilder();
                    result.append(ENCRYPT_PREFIX);
                    result.append(new String(Base64.encode(encryptedBytes)));
                    result.append(ENCRYPT_SUFFIX);
                    selectedProperty.setValue(result.toString());
                }
            }.execute();
        }
    }