Search in sources :

Example 16 with TObjectIntHashMap

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

the class FormSourceCodeGenerator method _generate.

private void _generate(final LwRootContainer rootContainer, final Module module) throws CodeGenerationException, IncorrectOperationException {
    myBuffer = new StringBuffer();
    myIsFirstParameterStack = new Stack<>();
    final HashMap<LwComponent, String> component2variable = new HashMap<>();
    final TObjectIntHashMap<String> class2variableIndex = new TObjectIntHashMap<>();
    final HashMap<String, LwComponent> id2component = new HashMap<>();
    if (rootContainer.getComponentCount() != 1) {
        throw new CodeGenerationException(null, UIDesignerBundle.message("error.one.toplevel.component.required"));
    }
    final LwComponent topComponent = (LwComponent) rootContainer.getComponent(0);
    String id = Utils.findNotEmptyPanelWithXYLayout(topComponent);
    if (id != null) {
        throw new CodeGenerationException(id, UIDesignerBundle.message("error.nonempty.xy.panels.found"));
    }
    final PsiClass classToBind = FormEditingUtil.findClassToBind(module, rootContainer.getClassToBind());
    if (classToBind == null) {
        throw new ClassToBindNotFoundException(UIDesignerBundle.message("error.class.to.bind.not.found", rootContainer.getClassToBind()));
    }
    final boolean haveCustomCreateComponents = Utils.getCustomCreateComponentCount(rootContainer) > 0;
    if (haveCustomCreateComponents) {
        if (FormEditingUtil.findCreateComponentsMethod(classToBind) == null) {
            throw new CodeGenerationException(null, UIDesignerBundle.message("error.no.custom.create.method"));
        }
        myBuffer.append(AsmCodeGenerator.CREATE_COMPONENTS_METHOD_NAME).append("();");
    }
    generateSetupCodeForComponent(topComponent, component2variable, class2variableIndex, id2component, module, classToBind);
    generateComponentReferenceProperties(topComponent, component2variable, class2variableIndex, id2component, classToBind);
    generateButtonGroups(rootContainer, component2variable, class2variableIndex, id2component, classToBind);
    final String methodText = myBuffer.toString();
    final PsiManager psiManager = PsiManager.getInstance(module.getProject());
    final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory();
    PsiClass newClass = (PsiClass) classToBind.copy();
    cleanup(newClass);
    // [anton] the comments are written according to the SCR 26896  
    final PsiClass fakeClass = elementFactory.createClassFromText("{\n" + "// GUI initializer generated by " + ApplicationNamesInfo.getInstance().getFullProductName() + " GUI Designer\n" + "// >>> IMPORTANT!! <<<\n" + "// DO NOT EDIT OR ADD ANY CODE HERE!\n" + "" + AsmCodeGenerator.SETUP_METHOD_NAME + "();\n" + "}\n" + "\n" + "/** Method generated by " + ApplicationNamesInfo.getInstance().getFullProductName() + " GUI Designer\n" + " * >>> IMPORTANT!! <<<\n" + " * DO NOT edit this method OR call it in your code!\n" + " * @noinspection ALL\n" + " */\n" + "private void " + AsmCodeGenerator.SETUP_METHOD_NAME + "()\n" + "{\n" + methodText + "}\n", null);
    final CodeStyleManager formatter = CodeStyleManager.getInstance(module.getProject());
    final JavaCodeStyleManager styler = JavaCodeStyleManager.getInstance(module.getProject());
    PsiMethod method = (PsiMethod) newClass.add(fakeClass.getMethods()[0]);
    // don't generate initializer block if $$$setupUI$$$() is called explicitly from one of the constructors
    boolean needInitializer = true;
    boolean needSetupUI = false;
    for (PsiMethod constructor : newClass.getConstructors()) {
        if (containsMethodIdentifier(constructor, method)) {
            needInitializer = false;
        } else if (haveCustomCreateComponents && hasCustomComponentAffectingReferences(constructor, newClass, rootContainer, null)) {
            needInitializer = false;
            needSetupUI = true;
        }
    }
    if (needSetupUI) {
        for (PsiMethod constructor : newClass.getConstructors()) {
            addSetupUICall(constructor, rootContainer, method);
        }
    }
    if (needInitializer) {
        newClass.addBefore(fakeClass.getInitializers()[0], method);
    }
    @NonNls final String grcMethodText = "/** @noinspection ALL */ public javax.swing.JComponent " + AsmCodeGenerator.GET_ROOT_COMPONENT_METHOD_NAME + "() { return " + topComponent.getBinding() + "; }";
    generateMethodIfRequired(newClass, method, AsmCodeGenerator.GET_ROOT_COMPONENT_METHOD_NAME, grcMethodText, topComponent.getBinding() != null);
    final String loadButtonTextMethodText = getLoadMethodText(AsmCodeGenerator.LOAD_BUTTON_TEXT_METHOD, AbstractButton.class, module);
    generateMethodIfRequired(newClass, method, AsmCodeGenerator.LOAD_BUTTON_TEXT_METHOD, loadButtonTextMethodText, myNeedLoadButtonText);
    final String loadLabelTextMethodText = getLoadMethodText(AsmCodeGenerator.LOAD_LABEL_TEXT_METHOD, JLabel.class, module);
    generateMethodIfRequired(newClass, method, AsmCodeGenerator.LOAD_LABEL_TEXT_METHOD, loadLabelTextMethodText, myNeedLoadLabelText);
    newClass = (PsiClass) styler.shortenClassReferences(newClass);
    newClass = (PsiClass) formatter.reformat(newClass);
    if (!lexemsEqual(classToBind, newClass)) {
        classToBind.replace(newClass);
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) JavaCodeStyleManager(com.intellij.psi.codeStyle.JavaCodeStyleManager) CodeStyleManager(com.intellij.psi.codeStyle.CodeStyleManager) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) JavaCodeStyleManager(com.intellij.psi.codeStyle.JavaCodeStyleManager)

Example 17 with TObjectIntHashMap

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

the class ResolverTree method calculateDegree.

private TObjectIntHashMap<PsiTypeVariable> calculateDegree() {
    final TObjectIntHashMap<PsiTypeVariable> result = new TObjectIntHashMap<>();
    for (final Constraint constr : myConstraints) {
        final PsiTypeVarCollector collector = new PsiTypeVarCollector();
        setDegree(collector.getSet(constr.getRight()), result);
    }
    return result;
}
Also used : TObjectIntHashMap(gnu.trove.TObjectIntHashMap) Constraint(com.intellij.refactoring.typeCook.deductive.builder.Constraint)

Example 18 with TObjectIntHashMap

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

the class FrameworkDetectorRegistryImpl method loadDetectors.

private void loadDetectors() {
    Map<String, FrameworkDetector> newDetectors = new HashMap<>();
    for (FrameworkDetector detector : FrameworkDetector.EP_NAME.getExtensions()) {
        newDetectors.put(detector.getDetectorId(), detector);
    }
    myDetectorIds = new TObjectIntHashMap<>();
    final File file = getDetectorsRegistryFile();
    int maxId = REGISTRY_VERSION;
    if (file.exists()) {
        LOG.debug("loading framework detectors registry from " + file.getAbsolutePath());
        List<String> unknownIds = new ArrayList<>();
        boolean versionChanged = false;
        try {
            DataInputStream input = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
            try {
                input.readInt();
                myDetectorsVersion = input.readInt();
                int size = input.readInt();
                while (size-- > REGISTRY_VERSION) {
                    final String stringId = input.readUTF();
                    int intId = input.readInt();
                    maxId = Math.max(maxId, intId);
                    final int version = input.readInt();
                    final FrameworkDetector detector = newDetectors.remove(stringId);
                    if (detector != null) {
                        if (version != detector.getDetectorVersion()) {
                            LOG.info("Version of framework detector '" + stringId + "' changed: " + version + " -> " + detector.getDetectorVersion());
                            versionChanged = true;
                        }
                        myDetectorIds.put(stringId, intId);
                    } else {
                        unknownIds.add(stringId);
                    }
                }
            } finally {
                input.close();
            }
        } catch (IOException e) {
            LOG.info(e);
        }
        if (!unknownIds.isEmpty()) {
            LOG.debug("Unknown framework detectors: " + unknownIds);
        }
        if (versionChanged || !newDetectors.isEmpty()) {
            if (!newDetectors.isEmpty()) {
                LOG.info("New framework detectors: " + newDetectors.keySet());
            }
            myDetectorsVersion++;
            LOG.info("Framework detection index version changed to " + myDetectorsVersion);
        }
    }
    int nextId = maxId + 1;
    for (String newDetector : newDetectors.keySet()) {
        myDetectorIds.put(newDetector, nextId++);
    }
    myDetectorById = new TIntObjectHashMap<>();
    myDetectorsByFileType = new MultiMap<>();
    for (FrameworkDetector detector : FrameworkDetector.EP_NAME.getExtensions()) {
        final int id = myDetectorIds.get(detector.getDetectorId());
        myDetectorsByFileType.putValue(detector.getFileType(), id);
        myDetectorById.put(id, detector);
        LOG.debug("'" + detector.getDetectorId() + "' framework detector: id = " + id);
    }
}
Also used : TObjectIntHashMap(gnu.trove.TObjectIntHashMap) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) FrameworkDetector(com.intellij.framework.detection.FrameworkDetector)

Aggregations

TObjectIntHashMap (gnu.trove.TObjectIntHashMap)18 TIntObjectHashMap (gnu.trove.TIntObjectHashMap)4 NotNull (org.jetbrains.annotations.NotNull)4 ResourceType (com.android.resources.ResourceType)3 Pair (com.intellij.openapi.util.Pair)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 IntArrayWrapper (com.android.ide.common.resources.IntArrayWrapper)2 PsiClass (com.intellij.psi.PsiClass)2 THashMap (gnu.trove.THashMap)2 THashSet (gnu.trove.THashSet)2 Set (java.util.Set)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)1 Pair (com.android.util.Pair)1 QuickFixBundle (com.intellij.codeInsight.daemon.QuickFixBundle)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 TemplateBuilderImpl (com.intellij.codeInsight.template.TemplateBuilderImpl)1 TemplateManager (com.intellij.codeInsight.template.TemplateManager)1 OfflineProblemDescriptor (com.intellij.codeInspection.offline.OfflineProblemDescriptor)1 PsiFragment (com.intellij.dupLocator.util.PsiFragment)1