mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -852,7 +852,7 @@ binding.setVariable("buildWinLauncher", { String ch, String inputPath, String ou
|
||||
launcherProperties = launcherPropertiesTemp
|
||||
}
|
||||
|
||||
ant.java(classname: "com.pme.launcher.LauncherGeneratorMain", fork: "true") {
|
||||
ant.java(classname: "com.pme.launcher.LauncherGeneratorMain", fork: "true", failonerror: "true") {
|
||||
sysproperty(key: "java.awt.headless", value: "true")
|
||||
arg(value: inputPath)
|
||||
arg(value: appInfo)
|
||||
|
||||
+101
-6
@@ -19,12 +19,18 @@ import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.components.StoragePathMacros;
|
||||
import com.intellij.openapi.util.Couple;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.java.generate.exception.TemplateResourceException;
|
||||
import org.jetbrains.java.generate.template.TemplateResource;
|
||||
import org.jetbrains.java.generate.template.TemplatesManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
@State(
|
||||
name = "EqualsHashCodeTemplates",
|
||||
@@ -36,6 +42,23 @@ import java.io.IOException;
|
||||
public class EqualsHashCodeTemplatesManager extends TemplatesManager {
|
||||
private static final String DEFAULT_EQUALS = "/com/intellij/codeInsight/generation/defaultEquals.vm";
|
||||
private static final String DEFAULT_HASH_CODE = "/com/intellij/codeInsight/generation/defaultHashCode.vm";
|
||||
private static final String APACHE3_EQUALS = "/com/intellij/codeInsight/generation/apacheEqualsBuilder3.vm";
|
||||
private static final String APACHE3_HASH_CODE = "/com/intellij/codeInsight/generation/apacheHashCodeBuilder3.vm";
|
||||
private static final String APACHE_EQUALS = "/com/intellij/codeInsight/generation/apacheEqualsBuilder.vm";
|
||||
private static final String APACHE_HASH_CODE = "/com/intellij/codeInsight/generation/apacheHashCodeBuilder.vm";
|
||||
private static final String GUAVA_EQUALS = "/com/intellij/codeInsight/generation/guavaEquals.vm";
|
||||
private static final String GUAVA_HASH_CODE = "/com/intellij/codeInsight/generation/guavaHashCode.vm";
|
||||
private static final String OBJECTS_EQUALS = "/com/intellij/codeInsight/generation/objectsEquals.vm";
|
||||
private static final String OBJECTS_HASH_CODE = "/com/intellij/codeInsight/generation/objectsHashCode.vm";
|
||||
|
||||
private static final String EQUALS_SUFFIX = "equals";
|
||||
private static final String HASH_CODE_SUFFIX = "hashCode";
|
||||
|
||||
@NonNls public static final String INTELLI_J_DEFAULT = "IntelliJ Default";
|
||||
@NonNls public static final String EQUALS_HASH_CODE_BUILDER_APACHE_COMMONS_LANG = "Equals/HashCodeBuilder (Apache commons-lang)";
|
||||
@NonNls public static final String EQUALS_HASH_CODE_BUILDER_APACHE_COMMONS_LANG_3 = "Equals/HashCodeBuilder (Apache commons-lang 3)";
|
||||
@NonNls public static final String OBJECTS_EQUAL_AND_HASH_CODE_GUAVA = "Objects.equal and hashCode (Guava)";
|
||||
@NonNls public static final String JAVA_UTIL_OBJECTS_EQUALS_AND_HASH_CODE = "java.util.Objects.equals and hashCode (java 7+)";
|
||||
|
||||
|
||||
public static EqualsHashCodeTemplatesManager getInstance() {
|
||||
@@ -46,8 +69,20 @@ public class EqualsHashCodeTemplatesManager extends TemplatesManager {
|
||||
public TemplateResource[] getDefaultTemplates() {
|
||||
try {
|
||||
return new TemplateResource[] {
|
||||
new TemplateResource("Default equals", readFile(DEFAULT_EQUALS), true),
|
||||
new TemplateResource("Default hashCode", readFile(DEFAULT_HASH_CODE), true),
|
||||
new TemplateResource(toEqualsName(INTELLI_J_DEFAULT), readFile(DEFAULT_EQUALS), true),
|
||||
new TemplateResource(toHashCodeName(INTELLI_J_DEFAULT), readFile(DEFAULT_HASH_CODE), true),
|
||||
|
||||
new TemplateResource(toEqualsName(EQUALS_HASH_CODE_BUILDER_APACHE_COMMONS_LANG), readFile(APACHE_EQUALS), true),
|
||||
new TemplateResource(toHashCodeName(EQUALS_HASH_CODE_BUILDER_APACHE_COMMONS_LANG), readFile(APACHE_HASH_CODE), true),
|
||||
|
||||
new TemplateResource(toEqualsName(EQUALS_HASH_CODE_BUILDER_APACHE_COMMONS_LANG_3), readFile(APACHE3_EQUALS), true),
|
||||
new TemplateResource(toHashCodeName(EQUALS_HASH_CODE_BUILDER_APACHE_COMMONS_LANG_3), readFile(APACHE3_HASH_CODE), true),
|
||||
|
||||
new TemplateResource(toEqualsName(OBJECTS_EQUAL_AND_HASH_CODE_GUAVA), readFile(GUAVA_EQUALS), true),
|
||||
new TemplateResource(toHashCodeName(OBJECTS_EQUAL_AND_HASH_CODE_GUAVA), readFile(GUAVA_HASH_CODE), true),
|
||||
|
||||
new TemplateResource(toEqualsName(JAVA_UTIL_OBJECTS_EQUALS_AND_HASH_CODE), readFile(OBJECTS_EQUALS), true),
|
||||
new TemplateResource(toHashCodeName(JAVA_UTIL_OBJECTS_EQUALS_AND_HASH_CODE), readFile(OBJECTS_HASH_CODE), true)
|
||||
};
|
||||
}
|
||||
catch (IOException e) {
|
||||
@@ -60,15 +95,35 @@ public class EqualsHashCodeTemplatesManager extends TemplatesManager {
|
||||
}
|
||||
|
||||
public TemplateResource getDefaultEqualsTemplate() {
|
||||
return getDefaultEqualsTemplate("equals", "hashCode");
|
||||
return getEqualsTemplate(getDefaultTemplate());
|
||||
}
|
||||
|
||||
public TemplateResource getDefaultHashcodeTemplate() {
|
||||
return getDefaultEqualsTemplate("hashCode", "equals");
|
||||
return getHashcodeTemplate(getDefaultTemplate());
|
||||
}
|
||||
|
||||
private TemplateResource getDefaultEqualsTemplate(String selfSuffix, String oppositeSuffix) {
|
||||
final TemplateResource defaultTemplate = getDefaultTemplate();
|
||||
public TemplateResource getEqualsTemplate(TemplateResource template) {
|
||||
return getDefaultTemplate(EQUALS_SUFFIX, HASH_CODE_SUFFIX, template);
|
||||
}
|
||||
|
||||
public TemplateResource getHashcodeTemplate(TemplateResource template) {
|
||||
return getDefaultTemplate(HASH_CODE_SUFFIX, EQUALS_SUFFIX, template);
|
||||
}
|
||||
|
||||
public String[] getTemplateNames() {
|
||||
final Set<String> names = new LinkedHashSet<String>();
|
||||
for (TemplateResource resource : getAllTemplates()) {
|
||||
names.add(getTemplateBaseName(resource));
|
||||
}
|
||||
return ArrayUtil.toStringArray(names);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getTemplateBaseName(TemplateResource resource) {
|
||||
return StringUtil.trimEnd(StringUtil.trimEnd(resource.getFileName(), EQUALS_SUFFIX), HASH_CODE_SUFFIX).trim();
|
||||
}
|
||||
|
||||
private TemplateResource getDefaultTemplate(String selfSuffix, String oppositeSuffix, TemplateResource defaultTemplate) {
|
||||
final String fileName = defaultTemplate.getFileName();
|
||||
if (fileName.endsWith(selfSuffix)) {
|
||||
return defaultTemplate;
|
||||
@@ -82,4 +137,44 @@ public class EqualsHashCodeTemplatesManager extends TemplatesManager {
|
||||
assert false : selfSuffix + " template for " + fileName + " not found";
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setDefaultTemplate(String name) {
|
||||
Set<String> fullNames = ContainerUtil.newHashSet(toEqualsName(name), toHashCodeName(name));
|
||||
for (TemplateResource resource : getAllTemplates()) {
|
||||
if (fullNames.contains(resource.getFileName())) {
|
||||
setDefaultTemplate(resource);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getDefaultTemplateBaseName() {
|
||||
return getTemplateBaseName(getDefaultTemplate());
|
||||
}
|
||||
|
||||
public static String toEqualsName(String name) {
|
||||
return name + " " + EQUALS_SUFFIX;
|
||||
}
|
||||
|
||||
public static String toHashCodeName(String name) {
|
||||
return name + " " + HASH_CODE_SUFFIX;
|
||||
}
|
||||
|
||||
public Collection<Couple<TemplateResource>> getTemplateCouples() {
|
||||
final LinkedHashMap<String, Couple<TemplateResource>> resources = new LinkedHashMap<String, Couple<TemplateResource>>();
|
||||
for (TemplateResource resource : getAllTemplates()) {
|
||||
final String baseName = getTemplateBaseName(resource);
|
||||
TemplateResource eq = toEqualsName(baseName).equals(resource.getFileName()) ? resource : null;
|
||||
TemplateResource hc = toHashCodeName(baseName).equals(resource.getFileName()) ? resource : null;
|
||||
final Couple<TemplateResource> couple = resources.get(baseName);
|
||||
if (couple != null) {
|
||||
resources.put(baseName, Couple.of(couple.first != null ? couple.first : eq,
|
||||
couple.second != null ? couple.second : hc));
|
||||
}
|
||||
else {
|
||||
resources.put(baseName, Couple.of(eq, hc));
|
||||
}
|
||||
}
|
||||
return resources.values();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,8 +159,16 @@ public class GenerateEqualsHelper implements Runnable {
|
||||
.velocityGenerateCode(myClass, equalsFields, myNonNullSet, new HashMap<String, String>(), contextMap,
|
||||
EqualsHashCodeTemplatesManager.getInstance().getDefaultEqualsTemplate().getTemplate(), 0, false);
|
||||
buffer.append(methodText);
|
||||
PsiMethod result = myFactory.createMethodFromText(buffer.toString(), myClass);
|
||||
final PsiParameter parameter = result.getParameterList().getParameters()[0];
|
||||
PsiMethod result;
|
||||
try {
|
||||
result = myFactory.createMethodFromText(buffer.toString(), myClass);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
return null;
|
||||
}
|
||||
final PsiParameter[] parameters = result.getParameterList().getParameters();
|
||||
if (parameters.length != 1) return null;
|
||||
final PsiParameter parameter = parameters[0];
|
||||
PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, styleSettings.GENERATE_FINAL_PARAMETERS);
|
||||
|
||||
PsiMethod method = (PsiMethod)myCodeStyleManager.reformat(result);
|
||||
@@ -190,7 +198,13 @@ public class GenerateEqualsHelper implements Runnable {
|
||||
.velocityGenerateCode(myClass, Arrays.asList(myHashCodeFields), myNonNullSet, new HashMap<String, String>(), contextMap,
|
||||
EqualsHashCodeTemplatesManager.getInstance().getDefaultHashcodeTemplate().getTemplate(), 0, false);
|
||||
buffer.append(methodText);
|
||||
PsiMethod hashCode = myFactory.createMethodFromText(buffer.toString(), null);
|
||||
PsiMethod hashCode;
|
||||
try {
|
||||
hashCode = myFactory.createMethodFromText(buffer.toString(), null);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
return null;
|
||||
}
|
||||
hashCode = (PsiMethod)myJavaCodeStyleManager.shortenClassReferences(hashCode);
|
||||
return (PsiMethod)myCodeStyleManager.reformat(hashCode);
|
||||
}
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.generation;
|
||||
|
||||
import org.apache.velocity.exception.ResourceNotFoundException;
|
||||
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class VelocityIncludesClassLoader extends ClasspathResourceLoader {
|
||||
@Override
|
||||
public InputStream getResourceStream(String name) throws ResourceNotFoundException {
|
||||
return super.getResourceStream("com/intellij/codeInsight/generation/" + name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#parse("equalsHelper.vm")
|
||||
public boolean equals(##
|
||||
#if ($settings.generateFinalParameters)
|
||||
final ##
|
||||
#end
|
||||
Object $paramName){
|
||||
if(this == $paramName) return true;
|
||||
|
||||
#addInstanceOfToText()
|
||||
|
||||
#addClassInstance()
|
||||
|
||||
return new org.apache.commons.lang.builder.EqualsBuilder()
|
||||
#if($superHasEquals)
|
||||
.appendSuper(super.equals($paramName))
|
||||
#end
|
||||
#foreach($field in $members)
|
||||
.append($field.name, ${classInstanceName}.$field.name)
|
||||
#end
|
||||
.isEquals();
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#parse("equalsHelper.vm")
|
||||
public boolean equals(##
|
||||
#if ($settings.generateFinalParameters)
|
||||
final ##
|
||||
#end
|
||||
Object $paramName){
|
||||
if(this == $paramName) return true;
|
||||
|
||||
#addInstanceOfToText()
|
||||
|
||||
#addClassInstance()
|
||||
|
||||
return new org.apache.commons.lang3.builder.EqualsBuilder()
|
||||
#if($superHasEquals)
|
||||
.appendSuper(super.equals($paramName))
|
||||
#end
|
||||
#foreach($field in $members)
|
||||
.append($field.name, ${classInstanceName}.$field.name)
|
||||
#end
|
||||
.isEquals();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
public int hashCode() {
|
||||
return new org.apache.commons.lang.builder.HashCodeBuilder(17, 37)
|
||||
#if($superHasHashCode)
|
||||
.appendSuper(super.hashCode())
|
||||
#end
|
||||
#foreach($field in $members)
|
||||
.append($field.name)
|
||||
#end
|
||||
.toHashCode();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
public int hashCode() {
|
||||
return new org.apache.commons.lang3.builder.HashCodeBuilder(17, 37)
|
||||
#if($superHasHashCode)
|
||||
.appendSuper(super.hashCode())
|
||||
#end
|
||||
#foreach($field in $members)
|
||||
.append($field.name)
|
||||
#end
|
||||
.toHashCode();
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
#set($classInstanceName = $helper.getUniqueLocalVarName($instanceName, $members, $settings))
|
||||
#set($paramName = $helper.getUniqueLocalVarName($baseParamName, $members, $settings))
|
||||
#parse("equalsHelper.vm")
|
||||
public boolean equals(##
|
||||
#if ($settings.generateFinalParameters)
|
||||
final ##
|
||||
@@ -11,20 +10,18 @@ Object $paramName){
|
||||
#addClassInstance()
|
||||
|
||||
#foreach($field in $members)
|
||||
#if (!$field.static)
|
||||
#if ($field.array)
|
||||
#addArrayEquals($field)
|
||||
#elseif ($field.primitive)
|
||||
#if ($field.double || $field.float)
|
||||
#addDoubleFieldComparison($field)
|
||||
#else
|
||||
#addPrimitiveFieldComparison($field)
|
||||
#end
|
||||
#elseif ($field.enum)
|
||||
#if ($field.array)
|
||||
#addArrayEquals($field)
|
||||
#elseif ($field.primitive)
|
||||
#if ($field.double || $field.float)
|
||||
#addDoubleFieldComparison($field)
|
||||
#else
|
||||
#addPrimitiveFieldComparison($field)
|
||||
#else
|
||||
#addFieldComparison($field)
|
||||
#end
|
||||
#elseif ($field.enum)
|
||||
#addPrimitiveFieldComparison($field)
|
||||
#else
|
||||
#addFieldComparison($field)
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
@@ -32,31 +29,6 @@ Object $paramName){
|
||||
return true;
|
||||
}
|
||||
##
|
||||
#macro(addClassInstance)
|
||||
#if ($settings.generateFinalLocals)
|
||||
final ##
|
||||
#end
|
||||
$classname $classInstanceName = ($classname)$paramName;
|
||||
#end
|
||||
##
|
||||
#macro(addEqualsPrologue)
|
||||
if(this == $paramName) return true;
|
||||
#if (!$superHasEquals)
|
||||
#addInstanceOfToText()
|
||||
#else
|
||||
#addInstanceOfToText()
|
||||
if(!super.equals($paramName)) return false;
|
||||
#end
|
||||
#end
|
||||
##
|
||||
#macro(addInstanceOfToText)
|
||||
#if ($checkParameterWithInstanceof)
|
||||
if(!($paramName instanceof $classname)) return false;
|
||||
#else
|
||||
if($paramName == null || getClass() != ${paramName}.getClass()) return false;
|
||||
#end
|
||||
#end
|
||||
##
|
||||
#macro(addPrimitiveFieldComparison $field)
|
||||
if($field.name != ${classInstanceName}.$field.name) return false;
|
||||
#end
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#set($classInstanceName = $helper.getUniqueLocalVarName($instanceName, $members, $settings))
|
||||
#set($paramName = $helper.getUniqueLocalVarName($baseParamName, $members, $settings))
|
||||
#macro(addClassInstance)
|
||||
#if ($settings.generateFinalLocals)
|
||||
final ##
|
||||
#end
|
||||
$classname $classInstanceName = ($classname)$paramName;
|
||||
#end
|
||||
##
|
||||
#macro(addEqualsPrologue)
|
||||
if(this == $paramName) return true;
|
||||
#addInstanceOfToText()
|
||||
#if ($superHasEquals)
|
||||
if(!super.equals($paramName)) return false;
|
||||
#end
|
||||
#end
|
||||
##
|
||||
#macro(addInstanceOfToText)
|
||||
#if ($checkParameterWithInstanceof)
|
||||
if(!($paramName instanceof $classname)) return false;
|
||||
#else
|
||||
if($paramName == null || getClass() != ${paramName}.getClass()) return false;
|
||||
#end
|
||||
#end
|
||||
@@ -0,0 +1,27 @@
|
||||
#parse("equalsHelper.vm")
|
||||
public boolean equals(##
|
||||
#if ($settings.generateFinalParameters)
|
||||
final ##
|
||||
#end
|
||||
Object $paramName){
|
||||
#addEqualsPrologue()
|
||||
#addClassInstance()
|
||||
return ##
|
||||
#set($i = 0)
|
||||
#foreach($field in $members)
|
||||
#if ($i > 0)
|
||||
&&
|
||||
#end
|
||||
#set($i = $i + 1)
|
||||
#if ($field.array)
|
||||
#if ($field.nestedArray)
|
||||
java.util.Arrays.deepEquals($field.name, ${classInstanceName}.$field.name)##
|
||||
#else
|
||||
java.util.Arrays.equals($field.name, ${classInstanceName}.$field.name)##
|
||||
#end
|
||||
#else
|
||||
com.google.common.base.Objects.equal($field.name, ${classInstanceName}.$field.name)##
|
||||
#end
|
||||
#end
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
public int hashCode() {
|
||||
return com.google.common.base.Objects.hashCode(##
|
||||
#set($i = 0)
|
||||
#if($superHasHashCode)
|
||||
super.hashCode() ##
|
||||
#set($i = 1)
|
||||
#end
|
||||
#foreach($member in $members)
|
||||
#if (!$member.static)
|
||||
#if ($i > 0)
|
||||
, ##
|
||||
#end
|
||||
$member.name ##
|
||||
#set($i = $i + 1)
|
||||
#end
|
||||
#end
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#parse("equalsHelper.vm")
|
||||
public boolean equals(##
|
||||
#if ($settings.generateFinalParameters)
|
||||
final ##
|
||||
#end
|
||||
Object $paramName){
|
||||
#addEqualsPrologue()
|
||||
#addClassInstance()
|
||||
return ##
|
||||
#set($i = 0)
|
||||
#foreach($field in $members)
|
||||
#if ($i > 0)
|
||||
&&
|
||||
#end
|
||||
#set($i = $i + 1)
|
||||
#if ($field.array)
|
||||
#if ($field.nestedArray)
|
||||
java.util.Arrays.deepEquals($field.name, ${classInstanceName}.$field.name)##
|
||||
#else
|
||||
java.util.Arrays.equals($field.name, ${classInstanceName}.$field.name)##
|
||||
#end
|
||||
#else
|
||||
java.util.Objects.equals($field.name, ${classInstanceName}.$field.name)##
|
||||
#end
|
||||
#end
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
public int hashCode() {
|
||||
return java.util.Objects.hash(##
|
||||
#set($i = 0)
|
||||
#if($superHasHashCode)
|
||||
super.hashCode() ##
|
||||
#set($i = 1)
|
||||
#end
|
||||
#foreach($member in $members)
|
||||
#if (!$member.static)
|
||||
#if ($i > 0)
|
||||
, ##
|
||||
#end
|
||||
$member.name ##
|
||||
#set($i = $i + 1)
|
||||
#end
|
||||
#end
|
||||
);
|
||||
}
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.generation.ui;
|
||||
|
||||
import com.intellij.codeInsight.generation.EqualsHashCodeTemplatesManager;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.UnnamedConfigurable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.NamedItemsListEditor;
|
||||
import com.intellij.openapi.ui.Namer;
|
||||
import com.intellij.openapi.ui.Splitter;
|
||||
import com.intellij.openapi.util.Cloner;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Couple;
|
||||
import com.intellij.openapi.util.Factory;
|
||||
import com.intellij.ui.TitledSeparator;
|
||||
import gnu.trove.Equality;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.java.generate.template.TemplateResource;
|
||||
import org.jetbrains.java.generate.view.GenerateTemplateConfigurable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EqualsHashCodeTemplatesPanel extends NamedItemsListEditor<Couple<TemplateResource>> {
|
||||
private static final Namer<Couple<TemplateResource>> NAMER = new Namer<Couple<TemplateResource>>() {
|
||||
|
||||
@Override
|
||||
public String getName(Couple<TemplateResource> couple) {
|
||||
return EqualsHashCodeTemplatesManager.getTemplateBaseName(couple.first);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRename(Couple<TemplateResource> item) {
|
||||
return !item.first.isDefault();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(Couple<TemplateResource> couple, String name) {
|
||||
couple.first.setFileName(EqualsHashCodeTemplatesManager.toEqualsName(name));
|
||||
couple.second.setFileName(EqualsHashCodeTemplatesManager.toHashCodeName(name));
|
||||
}
|
||||
};
|
||||
|
||||
private static final Factory<Couple<TemplateResource>> FACTORY = new Factory<Couple<TemplateResource>>() {
|
||||
@Override
|
||||
public Couple<TemplateResource> create() {
|
||||
return Couple.of(new TemplateResource(), new TemplateResource());
|
||||
}
|
||||
};
|
||||
|
||||
private static final Cloner<Couple<TemplateResource>> CLONER = new Cloner<Couple<TemplateResource>>() {
|
||||
@Override
|
||||
public Couple<TemplateResource> cloneOf(Couple<TemplateResource> couple) {
|
||||
if (couple.first.isDefault()) return couple;
|
||||
return copyOf(couple);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Couple<TemplateResource> copyOf(Couple<TemplateResource> couple) {
|
||||
return Couple.of(copyOf(couple.first), copyOf(couple.second));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private TemplateResource copyOf(TemplateResource resource) {
|
||||
TemplateResource result = new TemplateResource();
|
||||
result.setFileName(resource.getFileName());
|
||||
result.setTemplate(resource.getTemplate());
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
private static final Equality<Couple<TemplateResource>> COMPARER = new Equality<Couple<TemplateResource>>() {
|
||||
@Override
|
||||
public boolean equals(Couple<TemplateResource> o1, Couple<TemplateResource> o2) {
|
||||
return equals(o1.first, o2.first) && equals(o1.second, o2.second);
|
||||
}
|
||||
|
||||
private boolean equals(TemplateResource r1, TemplateResource r2) {
|
||||
return Comparing.equal(r1.getTemplate(), r2.getTemplate()) && Comparing.equal(r1.getFileName(), r2.getFileName());
|
||||
}
|
||||
};
|
||||
private final Project myProject;
|
||||
private final EqualsHashCodeTemplatesManager myManager;
|
||||
|
||||
public EqualsHashCodeTemplatesPanel(Project project, EqualsHashCodeTemplatesManager manager) {
|
||||
super(NAMER, FACTORY, CLONER, COMPARER, new ArrayList<Couple<TemplateResource>>(manager.getTemplateCouples()));
|
||||
myProject = project;
|
||||
myManager = manager;
|
||||
}
|
||||
|
||||
@Nls
|
||||
public String getDisplayName() {
|
||||
return "Templates";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String subjDisplayName() {
|
||||
return "template";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NonNls
|
||||
public String getHelpTopic() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return super.isModified() || !Comparing.equal(myManager.getDefaultTemplate(), getSelectedItem().first);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canDelete(Couple<TemplateResource> item) {
|
||||
return !item.first.isDefault();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UnnamedConfigurable createConfigurable(Couple<TemplateResource> item) {
|
||||
final GenerateTemplateConfigurable equalsConfigurable = new GenerateTemplateConfigurable(item.first, myProject);
|
||||
final GenerateTemplateConfigurable hashCodeConfigurable = new GenerateTemplateConfigurable(item.second, myProject);
|
||||
return new UnnamedConfigurable() {
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
final Splitter splitter = new Splitter(true);
|
||||
|
||||
final JPanel eqPanel = new JPanel(new BorderLayout());
|
||||
eqPanel.add(new TitledSeparator("Equals Template:"), BorderLayout.NORTH);
|
||||
final JComponent eqPane = equalsConfigurable.createComponent();
|
||||
eqPane.setPreferredSize(new Dimension(300, 200));
|
||||
eqPanel.add(eqPane, BorderLayout.CENTER);
|
||||
splitter.setFirstComponent(eqPanel);
|
||||
|
||||
final JPanel hcPanel = new JPanel(new BorderLayout());
|
||||
hcPanel.add(new TitledSeparator("HashCode Template:"), BorderLayout.NORTH);
|
||||
final JComponent hcPane = hashCodeConfigurable.createComponent();
|
||||
hcPane.setPreferredSize(new Dimension(300, 200));
|
||||
hcPanel.add(hcPane, BorderLayout.CENTER);
|
||||
splitter.setSecondComponent(hcPanel);
|
||||
|
||||
return splitter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return equalsConfigurable.isModified() || hashCodeConfigurable.isModified();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() throws ConfigurationException {
|
||||
equalsConfigurable.apply();
|
||||
hashCodeConfigurable.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
equalsConfigurable.reset();
|
||||
hashCodeConfigurable.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeUIResources() {
|
||||
equalsConfigurable.disposeUIResources();
|
||||
hashCodeConfigurable.disposeUIResources();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() throws ConfigurationException {
|
||||
super.apply();
|
||||
List<TemplateResource> resources = new ArrayList<TemplateResource>();
|
||||
for (Couple<TemplateResource> resource : getItems()) {
|
||||
resources.add(resource.first);
|
||||
resources.add(resource.second);
|
||||
}
|
||||
myManager.setTemplates(resources);
|
||||
|
||||
final Couple<TemplateResource> selection = getSelectedItem();
|
||||
if (selection != null) {
|
||||
myManager.setDefaultTemplate(selection.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+49
-3
@@ -18,12 +18,16 @@ package com.intellij.codeInsight.generation.ui;
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.NullableNotNullManager;
|
||||
import com.intellij.codeInsight.generation.EqualsHashCodeTemplatesManager;
|
||||
import com.intellij.codeInsight.generation.GenerateEqualsHelper;
|
||||
import com.intellij.ide.wizard.StepAdapter;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
import com.intellij.openapi.projectRoots.JavaVersionService;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.ui.ComponentWithBrowseButton;
|
||||
import com.intellij.openapi.ui.VerticalFlowLayout;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.classMembers.AbstractMemberInfoModel;
|
||||
@@ -38,9 +42,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.java.generate.psi.PsiAdapter;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
@@ -247,7 +253,7 @@ public class GenerateEqualsWizard extends AbstractGenerateEqualsWizard<PsiClass,
|
||||
@Override
|
||||
protected void addSteps() {
|
||||
if (myEqualsPanel != null) {
|
||||
addStep(new InstanceofOptionStep(myClass.hasModifierProperty(PsiModifier.FINAL)));
|
||||
addStep(new TemplateChooserStep(myClass.hasModifierProperty(PsiModifier.FINAL), myClass.getProject()));
|
||||
}
|
||||
super.addSteps();
|
||||
}
|
||||
@@ -331,10 +337,10 @@ public class GenerateEqualsWizard extends AbstractGenerateEqualsWizard<PsiClass,
|
||||
}
|
||||
}
|
||||
|
||||
private static class InstanceofOptionStep extends StepAdapter {
|
||||
private static class TemplateChooserStep extends StepAdapter {
|
||||
private final JComponent myPanel;
|
||||
|
||||
private InstanceofOptionStep(boolean isFinal) {
|
||||
private TemplateChooserStep(boolean isFinal, Project project) {
|
||||
final JCheckBox checkbox = new NonFocusableCheckBox(CodeInsightBundle.message("generate.equals.hashcode.accept.sublcasses"));
|
||||
checkbox.setSelected(!isFinal && CodeInsightSettings.getInstance().USE_INSTANCEOF_ON_EQUALS_PARAMETER);
|
||||
checkbox.setEnabled(!isFinal);
|
||||
@@ -345,6 +351,24 @@ public class GenerateEqualsWizard extends AbstractGenerateEqualsWizard<PsiClass,
|
||||
});
|
||||
|
||||
myPanel = new JPanel(new VerticalFlowLayout());
|
||||
final JPanel templateChooserPanel = new JPanel(new BorderLayout());
|
||||
final JLabel templateChooserLabel = new JLabel("Template:");
|
||||
templateChooserPanel.add(templateChooserLabel, BorderLayout.WEST);
|
||||
|
||||
final ComboBox comboBox = new ComboBox();
|
||||
final ComponentWithBrowseButton<ComboBox> comboBoxWithBrowseButton = new ComponentWithBrowseButton<ComboBox>(comboBox,
|
||||
new MyEditTemplatesListener(project, myPanel, comboBox));
|
||||
final EqualsHashCodeTemplatesManager manager = EqualsHashCodeTemplatesManager.getInstance();
|
||||
comboBox.setModel(new DefaultComboBoxModel(manager.getTemplateNames()));
|
||||
comboBox.setSelectedItem(manager.getDefaultTemplateBaseName());
|
||||
comboBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(@NotNull final ActionEvent M) {
|
||||
manager.setDefaultTemplate((String)comboBox.getSelectedItem());
|
||||
}
|
||||
});
|
||||
|
||||
templateChooserPanel.add(comboBoxWithBrowseButton, BorderLayout.CENTER);
|
||||
myPanel.add(templateChooserPanel);
|
||||
myPanel.add(checkbox);
|
||||
myPanel.add(new JLabel(CodeInsightBundle.message("generate.equals.hashcode.accept.sublcasses.explanation")));
|
||||
}
|
||||
@@ -353,5 +377,27 @@ public class GenerateEqualsWizard extends AbstractGenerateEqualsWizard<PsiClass,
|
||||
public JComponent getComponent() {
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
private static class MyEditTemplatesListener implements ActionListener {
|
||||
private final Project myProject;
|
||||
private final JComponent myParent;
|
||||
private final ComboBox myComboBox;
|
||||
|
||||
public MyEditTemplatesListener(Project project, JComponent panel, ComboBox comboBox) {
|
||||
myProject = project;
|
||||
myParent = panel;
|
||||
myComboBox = comboBox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final EqualsHashCodeTemplatesManager templatesManager = EqualsHashCodeTemplatesManager.getInstance();
|
||||
final EqualsHashCodeTemplatesPanel ui = new EqualsHashCodeTemplatesPanel(myProject, EqualsHashCodeTemplatesManager.getInstance());
|
||||
ui.selectNodeInTree(templatesManager.getDefaultTemplateBaseName());
|
||||
ShowSettingsUtil.getInstance().editConfigurable(myParent, ui);
|
||||
myComboBox.setModel(new DefaultComboBoxModel(templatesManager.getTemplateNames()));
|
||||
myComboBox.setSelectedItem(templatesManager.getDefaultTemplateBaseName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
class B {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
}
|
||||
class A extends B {
|
||||
Object[] a1;
|
||||
Object[][] a2;
|
||||
String[] a3;
|
||||
String[][] a4;
|
||||
int[] a5;
|
||||
int[][] a6;
|
||||
|
||||
byte a7;
|
||||
short a8;
|
||||
int a9;
|
||||
long a10;
|
||||
float a11;
|
||||
double a12;
|
||||
|
||||
Object a13;
|
||||
String a14;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
final A a = (A) o;
|
||||
|
||||
return new org.apache.commons.lang3.builder.EqualsBuilder()
|
||||
.appendSuper(super.equals(o))
|
||||
.append(a10, a.a10)
|
||||
.append(a11, a.a11)
|
||||
.append(a12, a.a12)
|
||||
.append(a7, a.a7)
|
||||
.append(a8, a.a8)
|
||||
.append(a9, a.a9)
|
||||
.append(a1, a.a1)
|
||||
.append(a13, a.a13)
|
||||
.append(a14, a.a14)
|
||||
.append(a2, a.a2)
|
||||
.append(a3, a.a3)
|
||||
.append(a4, a.a4)
|
||||
.append(a5, a.a5)
|
||||
.append(a6, a.a6)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new org.apache.commons.lang3.builder.HashCodeBuilder(17, 37)
|
||||
.appendSuper(super.hashCode())
|
||||
.append(a1)
|
||||
.append(a2)
|
||||
.append(a3)
|
||||
.append(a4)
|
||||
.append(a5)
|
||||
.append(a6)
|
||||
.append(a7)
|
||||
.append(a8)
|
||||
.append(a9)
|
||||
.append(a10)
|
||||
.append(a11)
|
||||
.append(a12)
|
||||
.append(a13)
|
||||
.append(a14)
|
||||
.toHashCode();
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
import java.util.Arrays;
|
||||
|
||||
class B {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
}
|
||||
class A extends B {
|
||||
Object[] a1;
|
||||
Object[][] a2;
|
||||
String[] a3;
|
||||
String[][] a4;
|
||||
int[] a5;
|
||||
int[][] a6;
|
||||
|
||||
byte a7;
|
||||
short a8;
|
||||
int a9;
|
||||
long a10;
|
||||
float a11;
|
||||
double a12;
|
||||
|
||||
Object a13;
|
||||
String a14;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
final A a = (A) o;
|
||||
return com.google.common.base.Objects.equal(a10, a.a10) &&
|
||||
com.google.common.base.Objects.equal(a11, a.a11) &&
|
||||
com.google.common.base.Objects.equal(a12, a.a12) &&
|
||||
com.google.common.base.Objects.equal(a7, a.a7) &&
|
||||
com.google.common.base.Objects.equal(a8, a.a8) &&
|
||||
com.google.common.base.Objects.equal(a9, a.a9) &&
|
||||
Arrays.equals(a1, a.a1) &&
|
||||
com.google.common.base.Objects.equal(a13, a.a13) &&
|
||||
com.google.common.base.Objects.equal(a14, a.a14) &&
|
||||
Arrays.deepEquals(a2, a.a2) &&
|
||||
Arrays.equals(a3, a.a3) &&
|
||||
Arrays.deepEquals(a4, a.a4) &&
|
||||
Arrays.equals(a5, a.a5) &&
|
||||
Arrays.deepEquals(a6, a.a6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return com.google.common.base.Objects.hashCode(super.hashCode(), a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
class B {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
}
|
||||
class A extends B {
|
||||
Object[] a1;
|
||||
Object[][] a2;
|
||||
String[] a3;
|
||||
String[][] a4;
|
||||
int[] a5;
|
||||
int[][] a6;
|
||||
|
||||
byte a7;
|
||||
short a8;
|
||||
int a9;
|
||||
long a10;
|
||||
float a11;
|
||||
double a12;
|
||||
|
||||
Object a13;
|
||||
String a14;
|
||||
|
||||
<caret>
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
class B {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
}
|
||||
class A extends B {
|
||||
Object[] a1;
|
||||
Object[][] a2;
|
||||
String[] a3;
|
||||
String[][] a4;
|
||||
int[] a5;
|
||||
int[][] a6;
|
||||
|
||||
byte a7;
|
||||
short a8;
|
||||
int a9;
|
||||
long a10;
|
||||
float a11;
|
||||
double a12;
|
||||
|
||||
Object a13;
|
||||
String a14;
|
||||
|
||||
<caret>
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.codeInsight.generation.EqualsHashCodeTemplatesManager;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.util.Function;
|
||||
|
||||
@@ -37,4 +38,22 @@ public class GenerateEquals15Test extends GenerateEqualsTestCase {
|
||||
doTest(Function.ID, Function.ID, Function.ID, true);
|
||||
}
|
||||
|
||||
public void testDifferentTypesSuperEqualsAndHashCodeApache3() throws Exception {
|
||||
doTestWithTemplate(EqualsHashCodeTemplatesManager.EQUALS_HASH_CODE_BUILDER_APACHE_COMMONS_LANG_3);
|
||||
}
|
||||
|
||||
public void testDifferentTypesSuperEqualsAndHashCodeGuava() throws Exception {
|
||||
doTestWithTemplate(EqualsHashCodeTemplatesManager.OBJECTS_EQUAL_AND_HASH_CODE_GUAVA);
|
||||
}
|
||||
|
||||
private void doTestWithTemplate(String templateName) throws Exception {
|
||||
try {
|
||||
EqualsHashCodeTemplatesManager.getInstance().setDefaultTemplate(templateName);
|
||||
doTest(Function.ID, Function.ID, Function.ID, true);
|
||||
}
|
||||
finally {
|
||||
EqualsHashCodeTemplatesManager.getInstance().setDefaultTemplate(EqualsHashCodeTemplatesManager.INTELLI_J_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.coverage;
|
||||
@@ -287,7 +299,8 @@ public class SrcFileAnnotator implements Disposable {
|
||||
// let's find old content in local history and build mapping from old lines to new one
|
||||
// local history doesn't index libraries, so let's distinguish libraries content with other one
|
||||
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
|
||||
final VirtualFile file = getVirtualFile();
|
||||
final VirtualFile file = psiFile.getVirtualFile();
|
||||
LOG.assertTrue(file != null);
|
||||
|
||||
final long fileTimeStamp = file.getTimeStamp();
|
||||
final long coverageTimeStamp = suite.getLastCoverageTimeStamp();
|
||||
|
||||
+7
-11
@@ -74,17 +74,13 @@ public class EditorSettingsManager extends FileDocumentManagerAdapter {
|
||||
|
||||
private <T> void applyConfigValueToUserData(VirtualFile file, Key<T> userDataKey, String editorConfigKey,
|
||||
String configValue, Map<String, T> configMap) {
|
||||
if (configValue.isEmpty()) {
|
||||
file.putUserData(userDataKey, null);
|
||||
}
|
||||
else {
|
||||
final T data = configMap.get(configValue);
|
||||
if (data == null) {
|
||||
Utils.invalidConfigMessage(myProject, configValue, editorConfigKey, file.getCanonicalPath());
|
||||
}
|
||||
else {
|
||||
file.putUserData(userDataKey, data);
|
||||
}
|
||||
if (configValue.isEmpty()) return;
|
||||
|
||||
final T data = configMap.get(configValue);
|
||||
if (data == null) {
|
||||
Utils.invalidConfigMessage(myProject, configValue, editorConfigKey, file.getCanonicalPath());
|
||||
} else {
|
||||
file.putUserData(userDataKey, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -15,10 +15,14 @@
|
||||
*/
|
||||
package org.jetbrains.java.generate.velocity;
|
||||
|
||||
import com.intellij.codeInsight.generation.VelocityIncludesClassLoader;
|
||||
import org.apache.commons.collections.ExtendedProperties;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
import org.apache.velocity.runtime.RuntimeConstants;
|
||||
import org.apache.velocity.runtime.log.SimpleLog4JLogSystem;
|
||||
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
|
||||
import org.apache.velocity.runtime.resource.loader.FileResourceLoader;
|
||||
|
||||
/**
|
||||
* Velocity factory.
|
||||
@@ -47,6 +51,8 @@ public class VelocityFactory {
|
||||
ExtendedProperties prop = new ExtendedProperties();
|
||||
prop.addProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, SimpleLog4JLogSystem.class.getName());
|
||||
prop.addProperty("runtime.log.logsystem.log4j.category", "GenerateToString");
|
||||
prop.addProperty(RuntimeConstants.RESOURCE_LOADER, "includes");
|
||||
prop.addProperty("includes.resource.loader.class", VelocityIncludesClassLoader.class.getName());
|
||||
VelocityEngine velocity = new VelocityEngine();
|
||||
velocity.setExtendedProperties(prop);
|
||||
velocity.init();
|
||||
|
||||
Reference in New Issue
Block a user