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