Merge remote branch 'origin/master'

This commit is contained in:
irengrig
2012-09-06 14:52:21 +04:00
283 changed files with 5024 additions and 3875 deletions
-26
View File
@@ -1,26 +0,0 @@
<component name="ArtifactManager">
<artifact type="jar" name="jps">
<output-path>$PROJECT_DIR$/out/artifacts/jps</output-path>
<root id="archive" name="jps.jar">
<element id="module-output" name="jps" />
<element id="module-output" name="antlayout" />
<element id="module-output" name="jps-model" />
<element id="module-output" name="util" />
<element id="module-output" name="platform-resources-en" />
<element id="module-output" name="annotations" />
<element id="module-output" name="javac2" />
<element id="module-output" name="forms-compiler" />
<element id="module-output" name="forms_rt" />
<element id="module-output" name="instrumentation-util" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/jna-utils.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/jna.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/jdom.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/picocontainer.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/trove4j.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/asm.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/asm-commons.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/oromatcher.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/jgoodies-forms.jar" path-in-jar="/" />
</root>
</artifact>
</component>
+3
View File
@@ -349,6 +349,9 @@
<inspection_tool class="PointlessBitwiseExpressionJS" enabled="false" level="WARNING" enabled_by_default="false">
<option name="m_ignoreExpressionsContainingConstants" value="false" />
</inspection_tool>
<inspection_tool class="PointlessBooleanExpression" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_ignoreExpressionsContainingConstants" value="true" />
</inspection_tool>
<inspection_tool class="PointlessBooleanExpressionJS" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="ProtectedMemberInFinalClass" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="PublicFieldAccessedInSynchronizedContext" enabled="true" level="WARNING" enabled_by_default="true" />
@@ -513,6 +513,9 @@
<inspection_tool class="PointlessArithmeticExpression" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_ignoreExpressionsContainingConstants" value="true" />
</inspection_tool>
<inspection_tool class="PointlessBooleanExpression" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_ignoreExpressionsContainingConstants" value="true" />
</inspection_tool>
<inspection_tool class="PointlessArithmeticExpressionJS" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="PointlessBinding" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="PointlessBitwiseExpressionJS" enabled="false" level="WARNING" enabled_by_default="false">
+2 -1
View File
@@ -50,6 +50,8 @@
<module fileurl="file://$PROJECT_DIR$/plugins/git4idea/rt/git4idea-rt.iml" filepath="$PROJECT_DIR$/plugins/git4idea/rt/git4idea-rt.iml" group="plugins/VCS" />
<module fileurl="file://$PROJECT_DIR$/plugins/github/github.iml" filepath="$PROJECT_DIR$/plugins/github/github.iml" group="plugins" />
<module fileurl="file://$PROJECT_DIR$/plugins/gradle/gradle.iml" filepath="$PROJECT_DIR$/plugins/gradle/gradle.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/groovy/jps-plugin/groovy-jps-plugin.iml" filepath="$PROJECT_DIR$/plugins/groovy/jps-plugin/groovy-jps-plugin.iml" group="plugins/Groovy" />
<module fileurl="file://$PROJECT_DIR$/plugins/groovy/rt-constants/groovy-rt-constants.iml" filepath="$PROJECT_DIR$/plugins/groovy/rt-constants/groovy-rt-constants.iml" group="plugins/Groovy" />
<module fileurl="file://$PROJECT_DIR$/plugins/groovy/rt/groovy_rt.iml" filepath="$PROJECT_DIR$/plugins/groovy/rt/groovy_rt.iml" group="plugins/Groovy" />
<module fileurl="file://$PROJECT_DIR$/plugins/hg4idea/hg4idea.iml" filepath="$PROJECT_DIR$/plugins/hg4idea/hg4idea.iml" group="plugins/VCS" />
<module fileurl="file://$PROJECT_DIR$/platform/icons/icons.iml" filepath="$PROJECT_DIR$/platform/icons/icons.iml" group="platform" />
@@ -73,7 +75,6 @@
<module fileurl="file://$PROJECT_DIR$/jps/jps.iml" filepath="$PROJECT_DIR$/jps/jps.iml" group="jps" />
<module fileurl="file://$PROJECT_DIR$/jps/plugins/appLauncher/jps-appLauncher.iml" filepath="$PROJECT_DIR$/jps/plugins/appLauncher/jps-appLauncher.iml" group="jps" />
<module fileurl="file://$PROJECT_DIR$/jps/jps-builders/jps-builders.iml" filepath="$PROJECT_DIR$/jps/jps-builders/jps-builders.iml" group="jps" />
<module fileurl="file://$PROJECT_DIR$/jps/model/jps-model.iml" filepath="$PROJECT_DIR$/jps/model/jps-model.iml" group="jps" />
<module fileurl="file://$PROJECT_DIR$/jps/model-api/jps-model-api.iml" filepath="$PROJECT_DIR$/jps/model-api/jps-model-api.iml" group="jps" />
<module fileurl="file://$PROJECT_DIR$/jps/model-impl/jps-model-impl.iml" filepath="$PROJECT_DIR$/jps/model-impl/jps-model-impl.iml" group="jps" />
<module fileurl="file://$PROJECT_DIR$/jps/model-serialization/jps-model-serialization.iml" filepath="$PROJECT_DIR$/jps/model-serialization/jps-model-serialization.iml" group="jps" />
Binary file not shown.
Binary file not shown.
+11 -4
View File
@@ -159,7 +159,6 @@ def layoutFull(String home, String targetDirectory, String patchedDescriptorDir
jar("jps-server.jar") {
module("jps-builders")
module("jps-model")
}
fileset(dir: "$home/jps/lib") {
@@ -335,8 +334,17 @@ public def layoutCommunityPlugins(String home) {
exclude(name: "standardDsls/**")
}
}
jar("groovy_rt.jar") {module("groovy_rt")}
//layout of groovy jars must be consistent with GroovyBuilder.getGroovyRtRoot method
dir("jps") {
jar("groovy-jps-plugin.jar") {
module("groovy-jps-plugin")
module("groovy-rt-constants")
}
}
jar("groovy_rt.jar") {
module("groovy_rt")
module("groovy-rt-constants")
}
dir("standardDsls") {
fileset(dir: "$home/plugins/groovy/resources/standardDsls")
}
@@ -516,7 +524,6 @@ def layout_jps(String target) {
module("util")
}
jar("jps-model.jar") {
module("jps-model")
module("jps-model-api")
module("jps-model-impl")
module("jps-model-serialization")
-1
View File
@@ -14,7 +14,6 @@ public class ImagesIcons {
}
public static final Icon EditExternaly = load("/org/intellij/images/icons/EditExternaly.png"); // 16x16
public static final Icon ImagesConfigurable = load("/org/intellij/images/icons/ImagesConfigurable.png"); // 32x32
public static final Icon ImagesFileType = load("/org/intellij/images/icons/ImagesFileType.png"); // 18x18
public static final Icon ThumbnailBlank = load("/org/intellij/images/icons/ThumbnailBlank.png"); // 75x86
public static final Icon ThumbnailDirectory = load("/org/intellij/images/icons/ThumbnailDirectory.png"); // 75x82
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

@@ -56,6 +56,10 @@ import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile;
import org.jetbrains.jps.model.java.impl.compiler.ProcessorConfigProfileImpl;
import org.jetbrains.jps.model.serialization.java.compiler.AnnotationProcessorProfileSerializer;
import org.jetbrains.jps.model.serialization.java.compiler.JpsJavaCompilerConfigurationSerializer;
import java.io.File;
import java.util.*;
@@ -71,16 +75,6 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.CompilerConfiguration");
@NonNls public static final String TESTS_EXTERNAL_COMPILER_HOME_PROPERTY_NAME = "tests.external.compiler.home";
public static final int DEPENDENCY_FORMAT_VERSION = 55;
private static final Comparator<String> ALPHA_COMPARATOR = new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.compareToIgnoreCase(o2);
}
};
private static final String ENTRY = "entry";
private static final String NAME = "name";
private static final String ENABLED = "enabled";
private static final String MODULE = "module";
@SuppressWarnings({"WeakerAccess"}) public String DEFAULT_COMPILER;
@NotNull private BackendCompiler myDefaultJavaCompiler;
@@ -104,7 +98,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
}
private boolean myAddNotNullAssertions = true;
private final ProcessorConfigProfile myDefaultProcessorsProfile = new ProcessorConfigProfile("Default");
private final ProcessorConfigProfile myDefaultProcessorsProfile = new ProcessorConfigProfileImpl("Default");
private final List<ProcessorConfigProfile> myModuleProcessorProfiles = new ArrayList<ProcessorConfigProfile>();
// the map is calculated by module processor profiles list for faster access to module settings
@@ -597,35 +591,27 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
return true;
}
// property names
private static final String EXCLUDE_FROM_COMPILE = "excludeFromCompile";
private static final String RESOURCE_EXTENSIONS = "resourceExtensions";
private static final String ANNOTATION_PROCESSING = "annotationProcessing";
private static final String BYTECODE_TARGET_LEVEL = "bytecodeTargetLevel";
private static final String WILDCARD_RESOURCE_PATTERNS = "wildcardResourcePatterns";
private static final String ADD_NOTNULL_ASSERTIONS = "addNotNullAssertions";
public void readExternal(Element parentNode) throws InvalidDataException {
DefaultJDOMExternalizer.readExternal(this, parentNode);
final Element notNullAssertions = parentNode.getChild(ADD_NOTNULL_ASSERTIONS);
final Element notNullAssertions = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.ADD_NOTNULL_ASSERTIONS);
if (notNullAssertions != null) {
myAddNotNullAssertions = Boolean.valueOf(notNullAssertions.getAttributeValue(ENABLED, "true"));
myAddNotNullAssertions = Boolean.valueOf(notNullAssertions.getAttributeValue(JpsJavaCompilerConfigurationSerializer.ENABLED, "true"));
}
Element node = parentNode.getChild(EXCLUDE_FROM_COMPILE);
Element node = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.EXCLUDE_FROM_COMPILE);
if (node != null) {
myExcludedEntriesConfiguration.readExternal(node);
}
try {
removeRegexpPatterns();
node = parentNode.getChild(RESOURCE_EXTENSIONS);
node = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.RESOURCE_EXTENSIONS);
if (node != null) {
for (final Object o : node.getChildren(ENTRY)) {
for (final Object o : node.getChildren(JpsJavaCompilerConfigurationSerializer.ENTRY)) {
Element element = (Element)o;
String pattern = element.getAttributeValue(NAME);
String pattern = element.getAttributeValue(JpsJavaCompilerConfigurationSerializer.NAME);
if (!StringUtil.isEmpty(pattern)) {
addRegexpPattern(pattern);
}
@@ -633,12 +619,12 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
}
removeWildcardPatterns();
node = parentNode.getChild(WILDCARD_RESOURCE_PATTERNS);
node = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.WILDCARD_RESOURCE_PATTERNS);
if (node != null) {
myWildcardPatternsInitialized = true;
for (final Object o : node.getChildren(ENTRY)) {
for (final Object o : node.getChildren(JpsJavaCompilerConfigurationSerializer.ENTRY)) {
final Element element = (Element)o;
String pattern = element.getAttributeValue(NAME);
String pattern = element.getAttributeValue(JpsJavaCompilerConfigurationSerializer.NAME);
if (!StringUtil.isEmpty(pattern)) {
addWildcardResourcePattern(pattern);
}
@@ -653,7 +639,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
myModuleProcessorProfiles.clear();
myProcessorsProfilesMap = null;
final Element annotationProcessingSettings = parentNode.getChild(ANNOTATION_PROCESSING);
final Element annotationProcessingSettings = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.ANNOTATION_PROCESSING);
if (annotationProcessingSettings != null) {
final List profiles = annotationProcessingSettings.getChildren("profile");
if (!profiles.isEmpty()) {
@@ -661,11 +647,11 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
final Element profileElement = (Element)elem;
final boolean isDefault = "true".equals(profileElement.getAttributeValue("default"));
if (isDefault) {
myDefaultProcessorsProfile.readExternal(profileElement);
AnnotationProcessorProfileSerializer.readExternal(myDefaultProcessorsProfile, profileElement);
}
else {
final ProcessorConfigProfile profile = new ProcessorConfigProfile("");
profile.readExternal(profileElement);
final ProcessorConfigProfile profile = new ProcessorConfigProfileImpl("");
AnnotationProcessorProfileSerializer.readExternal(profile, profileElement);
myModuleProcessorProfiles.add(profile);
}
}
@@ -678,15 +664,15 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
myBytecodeTargetLevel = null;
myModuleBytecodeTarget.clear();
final Element bytecodeTargetElement = parentNode.getChild(BYTECODE_TARGET_LEVEL);
final Element bytecodeTargetElement = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.BYTECODE_TARGET_LEVEL);
if (bytecodeTargetElement != null) {
myBytecodeTargetLevel = bytecodeTargetElement.getAttributeValue("target");
for (Element elem : (Collection<Element>)bytecodeTargetElement.getChildren(MODULE)) {
final String name = elem.getAttributeValue(NAME);
myBytecodeTargetLevel = bytecodeTargetElement.getAttributeValue(JpsJavaCompilerConfigurationSerializer.TARGET_ATTRIBUTE);
for (Element elem : (Collection<Element>)bytecodeTargetElement.getChildren(JpsJavaCompilerConfigurationSerializer.MODULE)) {
final String name = elem.getAttributeValue(JpsJavaCompilerConfigurationSerializer.NAME);
if (name == null) {
continue;
}
final String target = elem.getAttributeValue("target");
final String target = elem.getAttributeValue(JpsJavaCompilerConfigurationSerializer.TARGET_ATTRIBUTE);
if (target == null) {
continue;
}
@@ -697,7 +683,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
private void loadProfilesFromOldFormat(Element processing) {
// collect data
final boolean isEnabled = Boolean.parseBoolean(processing.getAttributeValue(ENABLED, "false"));
final boolean isEnabled = Boolean.parseBoolean(processing.getAttributeValue(JpsJavaCompilerConfigurationSerializer.ENABLED, "false"));
final boolean isUseClasspath = Boolean.parseBoolean(processing.getAttributeValue("useClasspath", "true"));
final StringBuilder processorPath = new StringBuilder();
final Set<String> optionPairs = new HashSet<String>();
@@ -717,7 +703,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
for (Object child : processing.getChildren("processor")) {
final Element processorElement = (Element)child;
final String proc = processorElement.getAttributeValue(NAME, (String)null);
final String proc = processorElement.getAttributeValue(JpsJavaCompilerConfigurationSerializer.NAME, (String)null);
if (proc != null) {
processors.add(proc);
}
@@ -730,7 +716,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
for (Object child : processing.getChildren("processModule")) {
final Element moduleElement = (Element)child;
final String name = moduleElement.getAttributeValue(NAME, (String)null);
final String name = moduleElement.getAttributeValue(JpsJavaCompilerConfigurationSerializer.NAME, (String)null);
if (name == null) {
continue;
}
@@ -769,7 +755,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
int profileIndex = 0;
for (Map.Entry<String, Set<String>> entry : dirNameToModulesMap.entrySet()) {
final String dirName = entry.getKey();
final ProcessorConfigProfile profile = new ProcessorConfigProfile(myDefaultProcessorsProfile);
final ProcessorConfigProfile profile = new ProcessorConfigProfileImpl(myDefaultProcessorsProfile);
profile.setName("Profile" + (++profileIndex));
profile.setEnabled(isEnabled);
profile.setGeneratedSourcesDirectoryName(dirName);
@@ -784,44 +770,47 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
DefaultJDOMExternalizer.writeExternal(this, parentNode);
if (myAddNotNullAssertions != true) {
addChild(parentNode, ADD_NOTNULL_ASSERTIONS).setAttribute(ENABLED, String.valueOf(myAddNotNullAssertions));
addChild(parentNode, JpsJavaCompilerConfigurationSerializer.ADD_NOTNULL_ASSERTIONS).setAttribute(
JpsJavaCompilerConfigurationSerializer.ENABLED, String.valueOf(myAddNotNullAssertions));
}
if(myExcludedEntriesConfiguration.getExcludeEntryDescriptions().length > 0) {
myExcludedEntriesConfiguration.writeExternal(addChild(parentNode, EXCLUDE_FROM_COMPILE));
myExcludedEntriesConfiguration.writeExternal(addChild(parentNode, JpsJavaCompilerConfigurationSerializer.EXCLUDE_FROM_COMPILE));
}
final Element newChild = addChild(parentNode, RESOURCE_EXTENSIONS);
final Element newChild = addChild(parentNode, JpsJavaCompilerConfigurationSerializer.RESOURCE_EXTENSIONS);
for (final String pattern : getRegexpPatterns()) {
addChild(newChild, ENTRY).setAttribute(NAME, pattern);
addChild(newChild, JpsJavaCompilerConfigurationSerializer.ENTRY).setAttribute(JpsJavaCompilerConfigurationSerializer.NAME, pattern);
}
if (myWildcardPatternsInitialized || !myWildcardPatterns.isEmpty()) {
final Element wildcardPatterns = addChild(parentNode, WILDCARD_RESOURCE_PATTERNS);
final Element wildcardPatterns = addChild(parentNode, JpsJavaCompilerConfigurationSerializer.WILDCARD_RESOURCE_PATTERNS);
for (final String wildcardPattern : myWildcardPatterns) {
addChild(wildcardPatterns, ENTRY).setAttribute(NAME, wildcardPattern);
addChild(wildcardPatterns, JpsJavaCompilerConfigurationSerializer.ENTRY).setAttribute(JpsJavaCompilerConfigurationSerializer.NAME, wildcardPattern);
}
}
final Element annotationProcessingSettings = addChild(parentNode, ANNOTATION_PROCESSING);
myDefaultProcessorsProfile.writeExternal(addChild(annotationProcessingSettings, "profile").setAttribute("default", "true"));
final Element annotationProcessingSettings = addChild(parentNode, JpsJavaCompilerConfigurationSerializer.ANNOTATION_PROCESSING);
AnnotationProcessorProfileSerializer
.writeExternal(myDefaultProcessorsProfile, addChild(annotationProcessingSettings, "profile").setAttribute("default", "true"));
for (ProcessorConfigProfile profile : myModuleProcessorProfiles) {
profile.writeExternal(addChild(annotationProcessingSettings, "profile").setAttribute("default", "false"));
AnnotationProcessorProfileSerializer
.writeExternal(profile, addChild(annotationProcessingSettings, "profile").setAttribute("default", "false"));
}
if (!StringUtil.isEmpty(myBytecodeTargetLevel) || !myModuleBytecodeTarget.isEmpty()) {
final Element bytecodeTarget = addChild(parentNode, BYTECODE_TARGET_LEVEL);
final Element bytecodeTarget = addChild(parentNode, JpsJavaCompilerConfigurationSerializer.BYTECODE_TARGET_LEVEL);
if (!StringUtil.isEmpty(myBytecodeTargetLevel)) {
bytecodeTarget.setAttribute("target", myBytecodeTargetLevel);
bytecodeTarget.setAttribute(JpsJavaCompilerConfigurationSerializer.TARGET_ATTRIBUTE, myBytecodeTargetLevel);
}
if (!myModuleBytecodeTarget.isEmpty()) {
final List<String> moduleNames = new ArrayList<String>(myModuleBytecodeTarget.keySet());
Collections.sort(moduleNames, ALPHA_COMPARATOR);
Collections.sort(moduleNames, String.CASE_INSENSITIVE_ORDER);
for (String name : moduleNames) {
final Element moduleElement = addChild(bytecodeTarget, MODULE);
moduleElement.setAttribute(NAME, name);
final Element moduleElement = addChild(bytecodeTarget, JpsJavaCompilerConfigurationSerializer.MODULE);
moduleElement.setAttribute(JpsJavaCompilerConfigurationSerializer.NAME, name);
final String value = myModuleBytecodeTarget.get(name);
moduleElement.setAttribute("target", value != null? value : "");
moduleElement.setAttribute(JpsJavaCompilerConfigurationSerializer.TARGET_ATTRIBUTE, value != null? value : "");
}
}
}
@@ -15,7 +15,7 @@
*/
package com.intellij.compiler.actions;
import com.intellij.compiler.AnnotationProcessingConfiguration;
import org.jetbrains.jps.model.java.compiler.AnnotationProcessingConfiguration;
import com.intellij.compiler.CompilerConfiguration;
import com.intellij.compiler.impl.FileSetCompileScope;
import com.intellij.compiler.impl.ModuleCompileScope;
@@ -41,6 +41,7 @@ import com.intellij.rt.compiler.JavacRunner;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.java.compiler.AnnotationProcessingConfiguration;
import java.io.*;
import java.util.*;
@@ -22,6 +22,7 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.util.Chunk;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions;
import java.nio.charset.Charset;
import java.util.ArrayList;
@@ -29,13 +30,7 @@ import java.util.Collection;
import java.util.List;
import java.util.StringTokenizer;
public class JavacSettings {
public boolean DEBUGGING_INFO = true;
public boolean GENERATE_NO_WARNINGS = false;
public boolean DEPRECATION = true;
public String ADDITIONAL_OPTIONS_STRING = "";
public int MAXIMUM_HEAP_SIZE = 128;
public class JavacSettings extends JpsJavaCompilerOptions {
private boolean myTestsUseExternalCompiler = false;
public Collection<String> getOptions(Chunk<Module> chunk) {
@@ -17,13 +17,13 @@ package com.intellij.compiler.options;
import com.intellij.compiler.CompilerConfiguration;
import com.intellij.compiler.CompilerConfigurationImpl;
import com.intellij.compiler.ProcessorConfigProfile;
import com.intellij.compiler.server.BuildManager;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile;
import javax.swing.*;
import java.util.List;
@@ -15,7 +15,7 @@
*/
package com.intellij.compiler.options;
import com.intellij.compiler.ProcessorConfigProfile;
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnActionEvent;
@@ -38,6 +38,7 @@ import com.intellij.ui.components.JBList;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.ui.EditableTreeModel;
import com.intellij.util.ui.tree.TreeUtil;
import org.jetbrains.jps.model.java.impl.compiler.ProcessorConfigProfileImpl;
import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
@@ -55,7 +56,7 @@ import java.util.List;
*/
@SuppressWarnings({"unchecked", "UseOfObsoleteCollectionType"})
public class AnnotationProcessorsPanel extends JPanel {
private final ProcessorConfigProfile myDefaultProfile = new ProcessorConfigProfile("");
private final ProcessorConfigProfile myDefaultProfile = new ProcessorConfigProfileImpl("");
private final List<ProcessorConfigProfile> myModuleProfiles = new ArrayList<ProcessorConfigProfile>();
private final Map<String, Module> myAllModulesMap = new HashMap<String, Module>();
private final Project myProject;
@@ -170,7 +171,7 @@ public class AnnotationProcessorsPanel extends JPanel {
myDefaultProfile.initFrom(defaultProfile);
myModuleProfiles.clear();
for (ProcessorConfigProfile profile : moduleProfiles) {
ProcessorConfigProfile copy = new ProcessorConfigProfile("");
ProcessorConfigProfile copy = new ProcessorConfigProfileImpl("");
copy.initFrom(profile);
myModuleProfiles.add(copy);
}
@@ -252,7 +253,7 @@ public class AnnotationProcessorsPanel extends JPanel {
}
});
if (newProfileName != null) {
final ProcessorConfigProfile profile = new ProcessorConfigProfile(newProfileName);
final ProcessorConfigProfile profile = new ProcessorConfigProfileImpl(newProfileName);
myModuleProfiles.add(profile);
((DataSynchronizable)getRoot()).sync();
final DefaultMutableTreeNode object = TreeUtil.findNodeWithObject((DefaultMutableTreeNode)getRoot(), profile);
@@ -15,7 +15,7 @@
*/
package com.intellij.compiler.options;
import com.intellij.compiler.ProcessorConfigProfile;
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.java.compiler.AnnotationProcessingConfiguration;
public abstract class CompilerConfiguration {
// need this flag for profiling purposes. In production code is always set to 'true'
@@ -268,7 +268,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
for (int i = 0; i < lambdaParameters.length; i++) {
PsiParameter lambdaParameter = lambdaParameters[i];
if (!TypeConversionUtil.isAssignable(resolveResult.getSubstitutor().substitute(parameters[i].getType()), lambdaParameter.getType())) {
if (!TypeConversionUtil.isAssignable(LambdaUtil.getSubstitutor(interfaceMethod, resolveResult).substitute(parameters[i].getType()), lambdaParameter.getType())) {
myHolder.add(HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, lambdaParameter, incompatibleTypesMessage));
break;
}
@@ -77,19 +77,29 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaLocalInspectionTool
if (methods.length == 1) {
final PsiCodeBlock body = methods[0].getBody();
if (body != null) {
final boolean [] recursive = new boolean[1];
final boolean [] bodyContainsForbiddenRefs = new boolean[1];
body.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitMethodCallExpression(PsiMethodCallExpression methodCallExpression) {
super.visitMethodCallExpression(methodCallExpression);
if (methodCallExpression.resolveMethod() == methods[0]) {
recursive[0] = true;
bodyContainsForbiddenRefs[0] = true;
}
}
@Override
public void visitThisExpression(PsiThisExpression expression) {
bodyContainsForbiddenRefs[0] = true;
}
@Override
public void visitSuperExpression(PsiSuperExpression expression) {
bodyContainsForbiddenRefs[0] = true;
}
});
if (!recursive[0]) {
if (!bodyContainsForbiddenRefs[0]) {
holder.registerProblem(aClass.getBaseClassReference(), "Anonymous #ref #loc can be replaced with lambda",
ProblemHighlightType.LIKE_UNUSED_SYMBOL, new ReplaceWithLambdaFix());
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new ReplaceWithLambdaFix());
}
}
}
@@ -96,6 +96,7 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
private WeakUnreferencedFilter myFilter;
private DeadHTMLComposer myComposer;
@NonNls public static final String SHORT_NAME = "UnusedDeclaration";
@NonNls private static final String ALTERNATIVE_ID = "unused";
private static final String COMMENT_OUT_QUICK_FIX = InspectionsBundle.message("inspection.dead.code.comment.quickfix");
private static final String DELETE_QUICK_FIX = InspectionsBundle.message("inspection.dead.code.safe.delete.quickfix");
@@ -351,7 +352,7 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
PsiFile file = refElement.getContainingFile();
if (file == null) return;
final boolean isSuppressed = refElement.isSuppressed(getShortName());
final boolean isSuppressed = refElement.isSuppressed(getShortName(), ALTERNATIVE_ID);
if (!getContext().isToCheckFile(file, UnusedDeclarationInspection.this) || isSuppressed) {
if (isSuppressed || !scope.contains(file)) {
getEntryPointsManager().addEntryPoint(refElement, false);
@@ -45,14 +45,15 @@ public class JavaArrangementVisitor extends JavaElementVisitor {
MODIFIERS.put(PsiModifier.ABSTRACT, ArrangementModifier.ABSTRACT);
}
private final Stack<JavaElementArrangementEntry> myStack = new Stack<JavaElementArrangementEntry>();
@NotNull private final Stack<JavaElementArrangementEntry> myStack = new Stack<JavaElementArrangementEntry>();
@NotNull private final Map<PsiElement, JavaElementArrangementEntry> myEntries = new HashMap<PsiElement, JavaElementArrangementEntry>();
@NotNull private final List<JavaElementArrangementEntry> myRootEntries;
@NotNull private Document myDocument;
@NotNull private Collection<TextRange> myRanges;
@Nullable private Document myDocument;
public JavaArrangementVisitor(@NotNull List<JavaElementArrangementEntry> entries,
@NotNull Document document,
@Nullable Document document,
@NotNull Collection<TextRange> ranges)
{
myRootEntries = entries;
@@ -69,16 +70,16 @@ public class JavaArrangementVisitor extends JavaElementVisitor {
else if (aClass.isInterface()) {
type = ArrangementEntryType.INTERFACE;
}
JavaElementArrangementEntry entry = createNewEntry(aClass.getTextRange(), type, aClass.getName(), true);
JavaElementArrangementEntry entry = createNewEntry(aClass, type, aClass.getName(), true);
processEntry(entry, aClass, aClass);
}
@Override
public void visitAnonymousClass(PsiAnonymousClass aClass) {
JavaElementArrangementEntry entry = createNewEntry(aClass.getTextRange(), ArrangementEntryType.CLASS, aClass.getName(), false);
JavaElementArrangementEntry entry = createNewEntry(aClass, ArrangementEntryType.CLASS, aClass.getName(), false);
processEntry(entry, null, aClass);
}
@Override
public void visitJavaFile(PsiJavaFile file) {
for (PsiClass psiClass : file.getClasses()) {
@@ -88,13 +89,43 @@ public class JavaArrangementVisitor extends JavaElementVisitor {
@Override
public void visitField(PsiField field) {
JavaElementArrangementEntry entry = createNewEntry(field.getTextRange(), ArrangementEntryType.FIELD, field.getName(), true);
JavaElementArrangementEntry entry = createNewEntry(field, ArrangementEntryType.FIELD, field.getName(), true);
processEntry(entry, field, field.getInitializer());
}
@Override
public void visitClassInitializer(PsiClassInitializer initializer) {
JavaElementArrangementEntry entry = createNewEntry(initializer, ArrangementEntryType.FIELD, null, true);
if (entry == null) {
return;
}
PsiElement classLBrace = null;
PsiClass clazz = initializer.getContainingClass();
if (clazz != null) {
classLBrace = clazz.getLBrace();
}
for (PsiElement e = initializer.getPrevSibling(); e != null; e = e.getPrevSibling()) {
JavaElementArrangementEntry prevEntry;
if (e == classLBrace) {
prevEntry = myEntries.get(clazz);
}
else {
prevEntry = myEntries.get(e);
}
if (prevEntry != null) {
entry.addDependency(prevEntry);
}
if (!(e instanceof PsiWhiteSpace)) {
break;
}
}
}
@Override
public void visitMethod(PsiMethod method) {
JavaElementArrangementEntry entry = createNewEntry(method.getTextRange(), ArrangementEntryType.METHOD, method.getName(), true);
ArrangementEntryType type = method.isConstructor() ? ArrangementEntryType.CONSTRUCTOR : ArrangementEntryType.METHOD;
JavaElementArrangementEntry entry = createNewEntry(method, type, method.getName(), true);
processEntry(entry, method, method.getBody());
}
@@ -110,7 +141,7 @@ public class JavaArrangementVisitor extends JavaElementVisitor {
return;
}
JavaElementArrangementEntry entry =
createNewEntry(anonymousClass.getTextRange(), ArrangementEntryType.CLASS, anonymousClass.getName(), false);
createNewEntry(anonymousClass, ArrangementEntryType.CLASS, anonymousClass.getName(), false);
processEntry(entry, null, anonymousClass);
}
@@ -151,31 +182,33 @@ public class JavaArrangementVisitor extends JavaElementVisitor {
}
@Nullable
private JavaElementArrangementEntry createNewEntry(@NotNull TextRange range,
private JavaElementArrangementEntry createNewEntry(@NotNull PsiElement element,
@NotNull ArrangementEntryType type,
@Nullable String name,
boolean canArrange)
{
TextRange range = element.getTextRange();
if (!isWithinBounds(range)) {
return null;
}
DefaultArrangementEntry current = getCurrent();
JavaElementArrangementEntry entry;
if (canArrange) {
TextRange expandedRange = ArrangementUtil.expandToLine(range, myDocument.getCharsSequence());
TextRange expandedRange = myDocument == null ? null : ArrangementUtil.expandToLine(range, myDocument.getCharsSequence());
TextRange rangeToUse = expandedRange == null ? range : expandedRange;
entry = new JavaElementArrangementEntry(current, rangeToUse, type, name, expandedRange != null);
entry = new JavaElementArrangementEntry(current, rangeToUse, type, name, myDocument == null || expandedRange != null);
}
else {
entry = new JavaElementArrangementEntry(current, range, type, name, false);
}
myEntries.put(element, entry);
if (current == null) {
myRootEntries.add(entry);
}
else {
current.addChild(entry);
}
return entry;
}
@@ -26,6 +26,8 @@ import java.util.EnumSet;
import java.util.Set;
/**
* Not thread-safe.
*
* @author Denis Zhdanov
* @since 7/20/12 4:50 PM
*/
@@ -58,6 +60,9 @@ public class JavaElementArrangementEntry extends DefaultArrangementEntry
super(parent, startOffset, endOffset, canBeArranged);
myType = type;
myTypes = EnumSet.of(type);
if (myType == ArrangementEntryType.CONSTRUCTOR) {
myTypes.add(ArrangementEntryType.METHOD);
}
myName = name;
}
@@ -45,7 +45,7 @@ public class JavaRearranger implements Rearranger<JavaElementArrangementEntry>,
{
// Type
@NotNull private static final Set<ArrangementEntryType> SUPPORTED_TYPES = EnumSet.of(INTERFACE, CLASS, ENUM, FIELD, METHOD);
@NotNull private static final Set<ArrangementEntryType> SUPPORTED_TYPES = EnumSet.of(INTERFACE, CLASS, ENUM, FIELD, METHOD, CONSTRUCTOR);
// Modifier
@NotNull private static final Set<ArrangementModifier> SUPPORTED_MODIFIERS = EnumSet.of(
@@ -68,6 +68,7 @@ public class JavaRearranger implements Rearranger<JavaElementArrangementEntry>,
MODIFIERS_BY_TYPE.put(INTERFACE, visibilityModifiers);
MODIFIERS_BY_TYPE.put(CLASS, concat(commonModifiers, ABSTRACT));
MODIFIERS_BY_TYPE.put(METHOD, concat(commonModifiers, SYNCHRONIZED, ABSTRACT));
MODIFIERS_BY_TYPE.put(CONSTRUCTOR, concat(commonModifiers, SYNCHRONIZED));
MODIFIERS_BY_TYPE.put(FIELD, concat(commonModifiers, TRANSIENT, VOLATILE));
}
@@ -86,9 +87,12 @@ public class JavaRearranger implements Rearranger<JavaElementArrangementEntry>,
for (ArrangementModifier modifier : visibility) {
and(FIELD, modifier);
}
and(CONSTRUCTOR);
and(METHOD, STATIC);
and(METHOD);
and(ENUM);
and(INTERFACE);
and(CLASS, STATIC);
and(CLASS);
}
@@ -114,11 +118,19 @@ public class JavaRearranger implements Rearranger<JavaElementArrangementEntry>,
return result;
}
@Nullable
@Override
public JavaElementArrangementEntry wrap(@NotNull PsiElement element) {
List<JavaElementArrangementEntry> result = new ArrayList<JavaElementArrangementEntry>();
element.accept(new JavaArrangementVisitor(result, null, Collections.singleton(element.getTextRange())));
return result.size() == 1 ? result.get(0) : null;
}
@NotNull
@Override
public Collection<JavaElementArrangementEntry> parse(@NotNull PsiElement root,
@NotNull Document document,
@NotNull Collection<TextRange> ranges)
public List<JavaElementArrangementEntry> parse(@NotNull PsiElement root,
@Nullable Document document,
@NotNull Collection<TextRange> ranges)
{
// Following entries are subject to arrangement: class, interface, field, method.
List<JavaElementArrangementEntry> result = new ArrayList<JavaElementArrangementEntry>();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -19,6 +19,8 @@ import com.intellij.ide.fileTemplates.FileTemplate;
import com.intellij.ide.fileTemplates.FileTemplateManager;
import com.intellij.ide.fileTemplates.JavaTemplateUtil;
import com.intellij.lang.ASTNode;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.module.Module;
@@ -32,6 +34,7 @@ import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.arrangement.MemberOrderService;
import com.intellij.psi.impl.compiled.ClsClassImpl;
import com.intellij.psi.impl.source.codeStyle.ImportHelper;
import com.intellij.psi.search.GlobalSearchScope;
@@ -174,43 +177,43 @@ public class JavaPsiImplementationHelperImpl extends JavaPsiImplementationHelper
return importHelper.getDefaultAnchor(list, statement);
}
@Nullable
@Override
public PsiElement getDefaultMemberAnchor(PsiClass aClass, PsiMember member) {
public PsiElement getDefaultMemberAnchor(@NotNull PsiClass aClass, @NotNull PsiMember member) {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(aClass.getProject());
MemberOrderService service = ServiceManager.getService(MemberOrderService.class);
PsiElement anchor = service.getAnchor(member, settings.getCommonSettings(JavaLanguage.INSTANCE), aClass);
int order = getMemberOrderWeight(member, settings);
if (order < 0) return null;
PsiElement lastMember = null;
for (PsiElement child = aClass.getFirstChild(); child != null; child = child.getNextSibling()) {
int order1 = getMemberOrderWeight(child, settings);
if (order1 < 0) continue;
if (order1 > order) {
if (lastMember != null) {
PsiElement nextSibling = lastMember.getNextSibling();
while (nextSibling instanceof PsiJavaToken && (nextSibling.getText().equals(",") || nextSibling.getText().equals(";"))) {
nextSibling = nextSibling.getNextSibling();
}
return nextSibling == null ? aClass.getLBrace().getNextSibling() : nextSibling;
}
else {
// The main idea is to avoid to anchor to 'white space' element because that causes reformatting algorithm
// to perform incorrectly. The algorithm is encapsulated at PostprocessReformattingAspect.doPostponedFormattingInner().
final PsiElement lBrace = aClass.getLBrace();
if (lBrace != null) {
PsiElement result = lBrace.getNextSibling();
while (result instanceof PsiWhiteSpace) {
result = result.getNextSibling();
}
return result;
}
}
}
lastMember = child;
if (anchor != null && anchor.getNextSibling() == aClass.getRBrace()) {
// Given member should be inserted as the last child.
return aClass.getRBrace();
}
if (anchor != null && anchor != aClass) {
anchor = anchor.getNextSibling();
while (anchor instanceof PsiJavaToken && (anchor.getText().equals(",") || anchor.getText().equals(";"))) {
anchor = anchor.getNextSibling();
}
if (anchor != null) {
return anchor;
}
}
// The main idea is to avoid to anchor to 'white space' element because that causes reformatting algorithm
// to perform incorrectly. The algorithm is encapsulated at the PostprocessReformattingAspect.doPostponedFormattingInner().
final PsiElement lBrace = aClass.getLBrace();
if (lBrace != null) {
PsiElement result = lBrace.getNextSibling();
while (result instanceof PsiWhiteSpace) {
result = result.getNextSibling();
}
return result;
}
return aClass.getRBrace();
}
// TODO remove as soon as an arrangement sub-system is provided for groovy.
public static int getMemberOrderWeight(PsiElement member, CodeStyleSettings settings) {
if (member instanceof PsiField) {
if (member instanceof PsiEnumConstant) {
@@ -1,8 +1,6 @@
package com.intellij.psi.impl.search;
import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VirtualFile;
@@ -13,7 +11,7 @@ import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.AnnotatedElementsSearch;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.Processor;
import com.intellij.util.QueryExecutor;
import com.intellij.util.indexing.FileBasedIndex;
@@ -21,6 +19,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* @author max
@@ -71,11 +70,8 @@ public class AnnotatedElementsSearcher implements QueryExecutor<PsiModifierListO
if (!psiManager.areElementsEquivalent(ref.resolve(), annClass)) {
return false;
}
if (useScope instanceof GlobalSearchScope &&
!((GlobalSearchScope)useScope).contains(candidate.getContainingFile().getVirtualFile())) {
return false;
}
return true;
return !(useScope instanceof GlobalSearchScope) ||
((GlobalSearchScope)useScope).contains(candidate.getContainingFile().getVirtualFile());
}
})) {
continue;
@@ -89,28 +85,27 @@ public class AnnotatedElementsSearcher implements QueryExecutor<PsiModifierListO
return true;
}
private static Collection<? extends PsiElement> getAnnotationCandidates(final PsiClass annClass, SearchScope useScope) {
AccessToken token = ReadAction.start();
try {
if (useScope instanceof GlobalSearchScope) {
return JavaAnnotationIndex.getInstance().get(annClass.getName(), annClass.getProject(), (GlobalSearchScope)useScope);
}
final ArrayList<PsiAnnotation> result = new ArrayList<PsiAnnotation>();
for (PsiElement element : ((LocalSearchScope)useScope).getScope()) {
element.accept(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitElement(PsiElement element) {
if (element instanceof PsiAnnotation) {
result.add((PsiAnnotation)element);
private static Collection<? extends PsiElement> getAnnotationCandidates(final PsiClass annClass, final SearchScope useScope) {
return ApplicationManager.getApplication().runReadAction(new Computable<Collection<? extends PsiElement>>() {
@Override
public Collection<? extends PsiElement> compute() {
if (useScope instanceof GlobalSearchScope) {
return JavaAnnotationIndex.getInstance().get(annClass.getName(), annClass.getProject(), (GlobalSearchScope)useScope);
}
final List<PsiElement> result = new ArrayList<PsiElement>();
for (PsiElement element : ((LocalSearchScope)useScope).getScope()) {
element.accept(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitElement(PsiElement element) {
if (element instanceof PsiAnnotation) {
result.add(element);
}
}
}
});
});
}
return result;
}
return result;
}
finally {
token.finish();
}
});
}
public static boolean isInstanceof(PsiElement owner, Class<? extends PsiModifierListOwner>[] types) {
@@ -123,7 +118,7 @@ public class AnnotatedElementsSearcher implements QueryExecutor<PsiModifierListO
private static boolean notAnnotation(final PsiElement found) {
if (found instanceof PsiAnnotation) return false;
VirtualFile faultyContainer = PsiUtil.getVirtualFile(found);
VirtualFile faultyContainer = PsiUtilCore.getVirtualFile(found);
LOG.error("Non annotation in annotations list: " + faultyContainer+"; element:"+found);
if (faultyContainer != null && faultyContainer.isValid()) {
FileBasedIndex.getInstance().requestReindex(faultyContainer);
@@ -15,9 +15,7 @@
*/
package com.intellij.psi.impl.search;
import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.progress.ProgressIndicatorProvider;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Computable;
@@ -178,14 +176,13 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
return true;
}
private static boolean checkInheritance(DirectClassInheritorsSearch.SearchParameters p, PsiClass aClass, PsiClass candidate) {
final AccessToken token = ReadAction.start();
try {
return !p.isCheckInheritance() || candidate.isInheritor(aClass, false);
}
finally {
token.finish();
}
private static boolean checkInheritance(final DirectClassInheritorsSearch.SearchParameters p, final PsiClass aClass, final PsiClass candidate) {
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return !p.isCheckInheritance() || candidate.isInheritor(aClass, false);
}
});
}
private static boolean processSameNamedClasses(Processor<PsiClass> consumer, PsiClass aClass, List<PsiClass> sameNamedClasses) {
@@ -340,10 +340,10 @@ public class GenericsUtil {
}
public static PsiType eliminateWildcards(PsiType type) {
return eliminateWildcardsInner(type, true);
return eliminateWildcards(type, true);
}
static PsiType eliminateWildcardsInner(PsiType type, final boolean eliminateInTypeArguments) {
public static PsiType eliminateWildcards(PsiType type, final boolean eliminateInTypeArguments) {
if (eliminateInTypeArguments && type instanceof PsiClassType) {
PsiClassType classType = ((PsiClassType)type);
JavaResolveResult resolveResult = classType.resolveGenerics();
@@ -367,7 +367,7 @@ public class GenericsUtil {
}
}
else if (type instanceof PsiArrayType) {
return eliminateWildcardsInner(((PsiArrayType)type).getComponentType(), false).createArrayType();
return eliminateWildcards(((PsiArrayType)type).getComponentType(), false).createArrayType();
}
else if (type instanceof PsiWildcardType) {
final PsiType bound = ((PsiWildcardType)type).getBound();
@@ -30,6 +30,7 @@ import java.util.*;
*/
public class LambdaUtil {
private static final Logger LOG = Logger.getInstance("#" + LambdaUtil.class.getName());
public static ThreadLocal<Set<PsiParameterList>> ourParams = new ThreadLocal<Set<PsiParameterList>>();
@Nullable
public static PsiType getFunctionalInterfaceReturnType(PsiLambdaExpression expr) {
@@ -52,8 +53,12 @@ public class LambdaUtil {
@Nullable
public static PsiMethod getFunctionalInterfaceMethod(PsiType functionalInterfaceType) {
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
final PsiClass psiClass = resolveResult.getElement();
return getFunctionalInterfaceMethod(PsiUtil.resolveGenericsClassInType(functionalInterfaceType));
}
@Nullable
public static PsiMethod getFunctionalInterfaceMethod(PsiClassType.ClassResolveResult result) {
final PsiClass psiClass = result.getElement();
if (psiClass != null) {
final MethodSignature methodSignature = getFunction(psiClass);
if (methodSignature != null) {
@@ -63,6 +68,15 @@ public class LambdaUtil {
return null;
}
public static PsiSubstitutor getSubstitutor(@NotNull PsiMethod method, @NotNull PsiClassType.ClassResolveResult resolveResult) {
final PsiClass derivedClass = resolveResult.getElement();
LOG.assertTrue(derivedClass != null);
final PsiClass methodContainingClass = method.getContainingClass();
LOG.assertTrue(methodContainingClass != null);
return TypeConversionUtil.getSuperClassSubstitutor(methodContainingClass, derivedClass, resolveResult.getSubstitutor());
}
public static boolean isValidLambdaContext(PsiElement context) {
return context instanceof PsiTypeCastExpression ||
context instanceof PsiAssignmentExpression ||
@@ -75,9 +89,10 @@ public class LambdaUtil {
}
public static boolean isLambdaFullyInferred(PsiLambdaExpression expression, PsiType functionalInterfaceType) {
if (expression.getParameterList().getParametersCount() > 0 || getFunctionalInterfaceReturnType(functionalInterfaceType) != PsiType.VOID) { //todo check that void lambdas without params check
if (expression.getParameterList().getParametersCount() > 0 ||
getFunctionalInterfaceReturnType(functionalInterfaceType) != PsiType.VOID) { //todo check that void lambdas without params check
if (functionalInterfaceType instanceof PsiClassType && ((PsiClassType)functionalInterfaceType).isRaw()) return false;
return !dependsOnTypeParams(functionalInterfaceType, expression);
return !dependsOnTypeParams(functionalInterfaceType, functionalInterfaceType, expression, null);
}
return true;
}
@@ -126,11 +141,11 @@ public class LambdaUtil {
return null;
}
public static boolean isAcceptable(PsiLambdaExpression lambdaExpression, final PsiType leftType) {
public static boolean isAcceptable(PsiLambdaExpression lambdaExpression, final PsiType leftType, boolean checkReturnType) {
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(leftType);
final PsiClass psiClass = resolveResult.getElement();
if (psiClass instanceof PsiAnonymousClass) {
return isAcceptable(lambdaExpression, ((PsiAnonymousClass)psiClass).getBaseClassType());
return isAcceptable(lambdaExpression, ((PsiAnonymousClass)psiClass).getBaseClassType(), checkReturnType);
}
final MethodSignature methodSignature = getFunction(psiClass);
if (methodSignature == null) return false;
@@ -149,16 +164,19 @@ public class LambdaUtil {
}
if (!TypeConversionUtil.erasure(lambdaFormalType)
.isAssignableFrom(TypeConversionUtil.erasure(GenericsUtil.eliminateWildcards(resolveResult.getSubstitutor().substitute(methodSignature.getSubstitutor().substitute(methodParameterType)))))) {
.isAssignableFrom(TypeConversionUtil.erasure(GenericsUtil.eliminateWildcards(
resolveResult.getSubstitutor().substitute(methodSignature.getSubstitutor().substitute(methodParameterType)))))) {
return false;
}
}
}
LOG.assertTrue(psiClass != null);
PsiType methodReturnType = getReturnType(psiClass, methodSignature);
if (methodReturnType != null) {
methodReturnType = resolveResult.getSubstitutor().substitute(methodSignature.getSubstitutor().substitute(methodReturnType));
return checkReturnTypeCompatible(lambdaExpression, methodReturnType) == null;
if (checkReturnType) {
LOG.assertTrue(psiClass != null);
PsiType methodReturnType = getReturnType(psiClass, methodSignature);
if (methodReturnType != null) {
methodReturnType = resolveResult.getSubstitutor().substitute(methodSignature.getSubstitutor().substitute(methodReturnType));
return checkReturnTypeCompatible(lambdaExpression, methodReturnType) == null;
}
}
return true;
}
@@ -274,6 +292,14 @@ public class LambdaUtil {
return depends(type, param2Check, new TypeParamsChecker(expr));
}
public static boolean dependsOnTypeParams(PsiType type,
PsiType functionalInterfaceType,
PsiLambdaExpression lambdaExpression,
PsiTypeParameter param2Check) {
return depends(type, param2Check, new TypeParamsChecker(lambdaExpression,
PsiUtil.resolveClassInType(functionalInterfaceType)));
}
public static boolean dependsOnTypeParams(PsiType type,
PsiClass aClass,
PsiMethod aMethod) {
@@ -291,7 +317,10 @@ public class LambdaUtil {
public static boolean isFreeFromTypeInferenceArgs(final PsiParameter[] methodParameters,
final PsiLambdaExpression lambdaExpression,
final PsiExpression expression) {
final PsiExpression expression,
final PsiSubstitutor subst,
final PsiType functionalInterfaceType,
final PsiTypeParameter typeParam) {
if (expression instanceof PsiCallExpression && ((PsiCallExpression)expression).getTypeArguments().length > 0) return true;
if (expression instanceof PsiNewExpression) {
final PsiJavaCodeReferenceElement classReference = ((PsiNewExpression)expression).getClassOrAnonymousClassReference();
@@ -300,16 +329,16 @@ public class LambdaUtil {
if (parameterList != null) {
final PsiTypeElement[] typeParameterElements = parameterList.getTypeParameterElements();
if (typeParameterElements.length > 0) {
if (!(typeParameterElements[0].getType() instanceof PsiDiamondType)){
if (!(typeParameterElements[0].getType() instanceof PsiDiamondType)) {
return true;
}
}
}
}
}
final PsiParameter[] lambdaParams = lambdaExpression.getParameterList().getParameters();
final PsiParameter[] lambdaParams = lambdaExpression.getParameterList().getParameters();
if (lambdaParams.length != methodParameters.length) return false;
final boolean [] independent = new boolean[]{true};
final boolean[] independent = new boolean[]{true};
expression.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitConditionalExpression(PsiConditionalExpression expression) {
@@ -335,7 +364,7 @@ public class LambdaUtil {
}
}
if (usedParamIdx > -1 && dependsOnTypeParams(methodParameters[usedParamIdx].getType(), lambdaExpression)) {
if (usedParamIdx > -1 && dependsOnTypeParams(subst.substitute(methodParameters[usedParamIdx].getType()), functionalInterfaceType, lambdaExpression, typeParam)) {
independent[0] = false;
}
}
@@ -386,22 +415,21 @@ public class LambdaUtil {
final PsiElement gParent = expressionList.getParent();
if (gParent instanceof PsiCallExpression) {
final PsiCallExpression contextCall = (PsiCallExpression)gParent;
final JavaResolveResult resolveResult = contextCall.resolveMethodGenerics();
final PsiElement resolve = resolveResult.getElement();
if (resolve instanceof PsiMethod) {
final PsiParameter[] parameters = ((PsiMethod)resolve).getParameterList().getParameters();
if (lambdaIdx < parameters.length) {
if (!tryToSubstitute) {
return parameters[lambdaIdx].getType();
}
return PsiResolveHelper.ourGuard.doPreventingRecursion(expression, true, new Computable<PsiType>() {
@Override
public PsiType compute() {
return PsiResolveHelper.ourGuard.doPreventingRecursion(expression, true, new Computable<PsiType>() {
@Override
public PsiType compute() {
final JavaResolveResult resolveResult = contextCall.resolveMethodGenerics();
final PsiElement resolve = resolveResult.getElement();
if (resolve instanceof PsiMethod) {
final PsiParameter[] parameters = ((PsiMethod)resolve).getParameterList().getParameters();
if (lambdaIdx < parameters.length) {
if (!tryToSubstitute) return parameters[lambdaIdx].getType();
return resolveResult.getSubstitutor().substitute(parameters[lambdaIdx].getType());
}
});
}
return null;
}
}
});
}
}
}
@@ -426,28 +454,38 @@ public class LambdaUtil {
final int parameterIndex = ((PsiParameterList)paramParent).getParameterIndex(param);
if (parameterIndex > -1) {
final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(param, PsiLambdaExpression.class);
PsiType type = getFunctionalInterfaceType(lambdaExpression, true);
if (type == null) {
type = getFunctionalInterfaceType(lambdaExpression, false);
}
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(type);
if (resolveResult != null) {
final PsiMethod method = getFunctionalInterfaceMethod(type);
if (method != null) {
final PsiParameter[] parameters = method.getParameterList().getParameters();
if (parameterIndex < parameters.length) {
final PsiType psiType = resolveResult.getSubstitutor().substitute(parameters[parameterIndex].getType());
if (!dependsOnTypeParams(psiType, lambdaExpression)) {
if (psiType instanceof PsiWildcardType) {
final PsiType bound = ((PsiWildcardType)psiType).getBound();
if (bound != null) {
return bound;
if (lambdaExpression != null) {
Set<PsiParameterList> currentStack = ourParams.get();
if (currentStack == null) {
currentStack = new HashSet<PsiParameterList>();
ourParams.set(currentStack);
}
final PsiParameterList parameterList = lambdaExpression.getParameterList();
try {
currentStack.add(parameterList);
PsiType type = getFunctionalInterfaceType(lambdaExpression, true);
if (type == null) {
type = getFunctionalInterfaceType(lambdaExpression, false);
}
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(type);
if (resolveResult != null) {
final PsiMethod method = getFunctionalInterfaceMethod(type);
if (method != null) {
final PsiParameter[] parameters = method.getParameterList().getParameters();
if (parameterIndex < parameters.length) {
final PsiType psiType = getSubstitutor(method, resolveResult).substitute(parameters[parameterIndex].getType());
if (!dependsOnTypeParams(psiType, type, lambdaExpression, null)) {
return GenericsUtil.eliminateWildcards(psiType);
}
}
return psiType;
}
}
}
finally {
currentStack.remove(parameterList);
}
}
}
}
@@ -457,7 +495,7 @@ public class LambdaUtil {
private static class TypeParamsChecker extends PsiTypeVisitor<Boolean> {
private PsiMethod myMethod;
private final PsiClass myClass;
private final Set<PsiTypeParameter> myUsedTypeParams = new HashSet<PsiTypeParameter>();
private final Set<PsiTypeParameter> myUsedTypeParams = new HashSet<PsiTypeParameter>();
private TypeParamsChecker(PsiMethod method, PsiClass aClass) {
myMethod = method;
@@ -465,7 +503,11 @@ public class LambdaUtil {
}
public TypeParamsChecker(PsiLambdaExpression expression) {
myClass = PsiUtil.resolveGenericsClassInType(getFunctionalInterfaceType(expression, false)).getElement();
this(expression, PsiUtil.resolveGenericsClassInType(getFunctionalInterfaceType(expression, false)).getElement());
}
public TypeParamsChecker(PsiLambdaExpression expression, PsiClass aClass) {
myClass = aClass;
PsiElement parent = expression.getParent();
while (parent instanceof PsiParenthesizedExpression) {
parent = parent.getParent();
@@ -15,19 +15,17 @@
*/
package com.intellij.psi.infos;
import com.intellij.openapi.util.Key;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.DefaultParameterTypeInferencePolicy;
import com.intellij.psi.impl.source.resolve.ParameterTypeInferencePolicy;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.containers.ConcurrentHashMap;
import com.intellij.util.containers.ConcurrentWeakHashMap;
import org.intellij.lang.annotations.MagicConstant;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* @author ik, dsl
@@ -108,6 +106,12 @@ public class MethodCandidateInfo extends CandidateInfo{
}
map.put(myArgumentList, getElement());
try {
final Set<PsiParameterList> lists = LambdaUtil.ourParams.get();
if (lists != null && !lists.isEmpty()) {
return inferTypeArguments(DefaultParameterTypeInferencePolicy.INSTANCE);
}
myCalcedSubstitutor = inferTypeArguments(DefaultParameterTypeInferencePolicy.INSTANCE);
}
finally {
@@ -648,7 +648,7 @@ public class TypeConversionUtil {
if (right instanceof PsiLambdaExpressionType) {
final PsiLambdaExpression rLambdaExpression = ((PsiLambdaExpressionType)right).getExpression();
if (left instanceof PsiClassType) {
return LambdaUtil.isAcceptable(rLambdaExpression, left);
return LambdaUtil.isAcceptable(rLambdaExpression, left, false);
}
if (left instanceof PsiLambdaExpressionType) {
final PsiLambdaExpression lLambdaExpression = ((PsiLambdaExpressionType)left).getExpression();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -20,6 +20,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.impl.JavaPsiImplementationHelper;
import org.jetbrains.annotations.NotNull;
/**
* @author yole
@@ -46,7 +47,7 @@ public class CoreJavaPsiImplementationHelper extends JavaPsiImplementationHelper
}
@Override
public PsiElement getDefaultMemberAnchor(PsiClass psiClass, PsiMember firstPsi) {
public PsiElement getDefaultMemberAnchor(@NotNull PsiClass psiClass, @NotNull PsiMember firstPsi) {
throw new UnsupportedOperationException("TODO");
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@@ -46,7 +47,8 @@ public abstract class JavaPsiImplementationHelper {
public abstract ASTNode getDefaultImportAnchor(PsiImportList list, PsiImportStatementBase statement);
public abstract PsiElement getDefaultMemberAnchor(PsiClass psiClass, PsiMember firstPsi);
@Nullable
public abstract PsiElement getDefaultMemberAnchor(@NotNull PsiClass psiClass, @NotNull PsiMember firstPsi);
public abstract void setupCatchBlock(String exceptionName, PsiElement context, PsiCatchSection element);
}
@@ -16,15 +16,13 @@
package com.intellij.psi.impl.compiled;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.JavaElementVisitor;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiTypeParameter;
import com.intellij.psi.PsiTypeParameterList;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.psi.impl.java.stubs.JavaStubElementTypes;
import com.intellij.psi.impl.java.stubs.PsiTypeParameterListStub;
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
import com.intellij.psi.impl.source.tree.TreeElement;
import com.intellij.psi.scope.PsiScopeProcessor;
import org.jetbrains.annotations.NotNull;
/**
@@ -90,4 +88,16 @@ public class ClsTypeParametersListImpl extends ClsRepositoryPsiElement<PsiTypePa
public String toString() {
return "PsiTypeParameterList";
}
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
@NotNull ResolveState state,
PsiElement lastParent,
@NotNull PsiElement place) {
final PsiTypeParameter[] typeParameters = getTypeParameters();
for (PsiTypeParameter parameter : typeParameters) {
if (!processor.execute(parameter, state)) return false;
}
return true;
}
}
@@ -35,8 +35,10 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class PsiResolveHelperImpl implements PsiResolveHelper {
public static final Pair<PsiType,ConstraintType> RAW_INFERENCE = new Pair<PsiType, ConstraintType>(null, ConstraintType.EQUALS);
private final PsiManager myManager;
public PsiResolveHelperImpl(PsiManager manager) {
@@ -206,7 +208,10 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
final Pair<PsiType,ConstraintType> currentSubstitution;
if (argumentType instanceof PsiLambdaExpressionType) {
currentSubstitution = inferSubstitutionFromLambda(typeParameter, (PsiLambdaExpressionType)argumentType, lowerBound);
if (rawType && currentSubstitution == FAILED_INFERENCE || nullPassed && currentSubstitution == null) return new Pair<PsiType, ConstraintType>(null, ConstraintType.EQUALS);
if (rawType) {
if (currentSubstitution == FAILED_INFERENCE || (currentSubstitution == null && lowerBound == PsiType.NULL)) return RAW_INFERENCE;
}
if (nullPassed && currentSubstitution == null) return RAW_INFERENCE;
} else {
currentSubstitution = getSubstitutionForTypeParameterConstraint(typeParameter, parameterType,
argumentType, true, PsiUtil.getLanguageLevel(typeParameter));
@@ -218,7 +223,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
final ConstraintType constraintType = currentSubstitution.getSecond();
final PsiType type = currentSubstitution.getFirst();
if (type == null) return new Pair<PsiType, ConstraintType>(null, ConstraintType.EQUALS);
if (type == null) return RAW_INFERENCE;
switch(constraintType) {
case EQUALS:
if (!(type instanceof PsiWildcardType)) return currentSubstitution;
@@ -590,27 +595,31 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
final PsiType functionalInterfaceType,
PsiType lowerBound) {
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
final PsiMethod method = LambdaUtil.getFunctionalInterfaceMethod(functionalInterfaceType);
final PsiMethod method = LambdaUtil.getFunctionalInterfaceMethod(resolveResult);
if (method != null) {
final Pair<PsiType, ConstraintType> constraintFromFormalParams = inferConstraintFromLambdaFormalParams(typeParam, resolveResult, method, lambdaExpression);
final PsiSubstitutor subst = LambdaUtil.getSubstitutor(method, resolveResult);
final Pair<PsiType, ConstraintType> constraintFromFormalParams = inferConstraintFromLambdaFormalParams(typeParam, subst, method, lambdaExpression);
if (constraintFromFormalParams != null) return constraintFromFormalParams;
final PsiParameter[] methodParameters = method.getParameterList().getParameters();
final PsiSubstitutor subst =
TypeConversionUtil.getSuperClassSubstitutor(method.getContainingClass(), resolveResult.getElement(), resolveResult.getSubstitutor());
final boolean methodParamsDependOnTypeParams = methodParamsDependOnTypeParams(lambdaExpression, methodParameters, subst, typeParam);
if (methodParamsDependOn(typeParam, lambdaExpression, functionalInterfaceType, methodParameters, subst)) {
if (lowerBound != PsiType.NULL) {
return null;
}
return getFailedInferenceConstraint(typeParam);
}
final Set<PsiParameterList> lists = LambdaUtil.ourParams.get();
if (lists != null && lists.contains(lambdaExpression.getParameterList())){
return null;
}
final PsiType returnType = subst.substitute(method.getReturnType());
if (returnType != null && returnType != PsiType.VOID) {
Pair<PsiType, ConstraintType> constraint = null;
final List<PsiExpression> expressions = lambdaExpression.getReturnExpressions();
for (final PsiExpression expression : expressions) {
final boolean independent = LambdaUtil.isFreeFromTypeInferenceArgs(methodParameters, lambdaExpression, expression);
if (independent && methodParamsDependOnTypeParams ) {
if (lowerBound != PsiType.NULL) {
return null;
}
return FAILED_INFERENCE;
}
final boolean independent = LambdaUtil.isFreeFromTypeInferenceArgs(methodParameters, lambdaExpression, expression, subst, functionalInterfaceType, typeParam);
if (!independent) {
if (lowerBound != PsiType.NULL) {
return null;
@@ -634,7 +643,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
}
final Pair<PsiType, ConstraintType> returnExprConstraint =
getSubstitutionForTypeParameterConstraint(typeParam, returnType, exprType, true, PsiUtil.getLanguageLevel(method));
getSubstitutionForTypeParameterConstraint(typeParam, GenericsUtil.eliminateWildcards(returnType), exprType, true, PsiUtil.getLanguageLevel(method));
if (returnExprConstraint != null) {
if (returnExprConstraint == FAILED_INFERENCE) return returnExprConstraint;
if (constraint != null) {
@@ -647,17 +656,16 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
}
if (constraint != null) return constraint;
}
if (methodParamsDependOnTypeParams) return getFailedInferenceConstraint(typeParam);
}
return null;
}
private static boolean methodParamsDependOnTypeParams(PsiLambdaExpression lambdaExpression,
PsiParameter[] methodParameters,
PsiSubstitutor subst,
PsiTypeParameter typeParam) {
private static boolean methodParamsDependOn(PsiTypeParameter typeParam, PsiLambdaExpression lambdaExpression,
PsiType functionalInterfaceType,
PsiParameter[] methodParameters,
PsiSubstitutor subst) {
for (PsiParameter parameter : methodParameters) {
if (LambdaUtil.dependsOnTypeParams(subst.substitute(parameter.getType()), lambdaExpression, typeParam)) {
if (LambdaUtil.dependsOnTypeParams(subst.substitute(parameter.getType()), functionalInterfaceType, lambdaExpression, typeParam)) {
return true;
}
}
@@ -666,7 +674,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
@Nullable
private static Pair<PsiType, ConstraintType> inferConstraintFromLambdaFormalParams(PsiTypeParameter typeParam,
PsiClassType.ClassResolveResult resolveResult,
PsiSubstitutor subst,
PsiMethod method, PsiLambdaExpression lambdaExpression) {
final PsiParameter[] parameters = lambdaExpression.getParameterList().getParameters();
if (parameters.length == 0) return null;
@@ -679,13 +687,12 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
lambdaArgs[i] = parameter.getType();
}
final PsiSubstitutor subst = resolveResult.getSubstitutor();
final PsiParameter[] methodParameters = method.getParameterList().getParameters();
PsiType[] methodParamTypes = new PsiType[methodParameters.length];
for (int i = 0; i < methodParameters.length; i++) {
methodParamTypes[i] = subst.substitute(methodParameters[i].getType());
}
return inferTypeForMethodTypeParameterInner(typeParam, methodParamTypes, lambdaArgs, subst, null, DefaultParameterTypeInferencePolicy.INSTANCE);
return inferTypeForMethodTypeParameterInner(typeParam, methodParamTypes, lambdaArgs, subst, null, DefaultParameterTypeInferencePolicy.INSTANCE);
}
private static PsiType intersectAllExtends(PsiTypeParameter typeParam, PsiType arg) {
@@ -903,8 +910,9 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
final PsiMethod method = LambdaUtil.getFunctionalInterfaceMethod(functionalInterfaceType);
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
if (method == null || methodParamsDependOnTypeParams((PsiLambdaExpression)expression, method.getParameterList().getParameters(),
TypeConversionUtil.getSuperClassSubstitutor(method.getContainingClass(), resolveResult.getElement(), resolveResult.getSubstitutor()), typeParameter)) {
if (method == null || methodParamsDependOn(typeParameter, (PsiLambdaExpression)expression,
functionalInterfaceType, method.getParameterList().getParameters(),
LambdaUtil.getSubstitutor(method, resolveResult))) {
return getFailedInferenceConstraint(typeParameter);
}
}
@@ -18,10 +18,7 @@ package com.intellij.psi.presentation.java;
import com.intellij.navigation.ItemPresentation;
import com.intellij.navigation.ItemPresentationProvider;
import com.intellij.navigation.NavigationItem;
import com.intellij.psi.PsiSubstitutor;
import com.intellij.psi.PsiVariable;
import com.intellij.psi.util.PsiFormatUtil;
import com.intellij.psi.util.PsiFormatUtilBase;
import javax.swing.*;
@@ -34,7 +31,8 @@ public class VariablePresentationProvider<T extends PsiVariable & NavigationItem
return new ItemPresentation() {
@Override
public String getPresentableText() {
return PsiFormatUtil.formatVariable(variable, PsiFormatUtilBase.SHOW_TYPE, PsiSubstitutor.EMPTY);
//return PsiFormatUtil.formatVariable(variable, PsiFormatUtilBase.SHOW_TYPE, PsiSubstitutor.EMPTY);
return variable.getName();
}
@Override
@@ -107,7 +107,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
final PsiParameter[] methodParameters = method.getParameterList().getParameters();
final PsiParameter param = i < methodParameters.length ? methodParameters[i] : methodParameters[methodParameters.length - 1];
final PsiType paramType = param.getType();
if (!LambdaUtil.isAcceptable(lambdaExpression, paramType)) {
if (!LambdaUtil.isAcceptable(lambdaExpression, conflict.getSubstitutor().substitute(paramType), true)) {
iterator.remove();
} else {
/*todo
@@ -0,0 +1,63 @@
/*
* Copyright 2000-2012 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.
*/
import java.util.*;
class LambdaTest<TT> {
interface BinaryOperator<T> {
public T eval(T left, T right);
}
interface Mapper<T, U> {
U map(T t);
}
public static <T, U> LambdaTest<U> map(final Iterable<? extends T> iterable, final Mapper<? super T, ? extends U> mapper) {
return null;
}
TT reduce(TT base, BinaryOperator<TT> reducer) {
return null;
}
public void test() {
final List<String> aStrings = Arrays.asList("1", "2", "3");
map(aStrings, s -> s.length()).reduce(0, (l, r) -> l + r);
}
}
class LambdaTest2<TypeParam> {
interface BinaryOperator<T> {
public T eval(T left, T right);
}
interface Mapper<T, U> {
U map(T t);
}
public <U> LambdaTest<U> map(final Mapper<? super TypeParam, ? extends U> mapper) {
return null;
}
TypeParam reduce(TypeParam base, BinaryOperator<TypeParam> reducer) {
return null;
}
public void test() {
final LambdaTest2<String> lt = new LambdaTest2<>();
lt.map(s -> s.length()).reduce(0, (l, r) -> l + r);
}
}
@@ -34,3 +34,27 @@ class Test3 {
bar(<error descr="Cyclic inference">x->{}</error>, new ArrayList());
}
}
class Test4 {
protected <T, U> U exerciseOps(TestData<T> data, TerminalOp1<T, U> terminal, IntermediateOp1... ops) {
return exerciseOps(data, (u, v) -> u.equals(v), terminal, ops);
}
protected static <T, U> U exerciseOps(TestData<T> data,
BiPredicate1<U, U> equalator,
TerminalOp1<T, U> terminalOp,
IntermediateOp1[] ops) {
return null;
}
public interface IntermediateOp1<T,U> {
}
public interface BiPredicate1<T, U> extends IntermediateOp1<T, U>{
boolean _(T t, U u);
}
public interface TerminalOp1<T, U> extends IntermediateOp1<T, U> {}
}
@@ -0,0 +1,11 @@
// "Replace with lambda" "false"
class Test {
{
Runnable x = new Runn<caret>able() {
public void run() {
this.toString();
}
};
}
}
@@ -2,11 +2,11 @@
class Bar {
private int myi1;
private int myi2;
private final int myI1;
private final int myI2;
private final String myI3;
private int myi1;
private int myi2;
Bar(int i1, int i2, String i3) {
myI1 = i1;
@@ -2,9 +2,9 @@
class Bar {
private int myi1;
private int myi2;
private int myi1;
private int myi2;
Bar(int <caret>i1, int i2, String i3) {
}
Bar(int <caret>i1, int i2, String i3) {
}
}
@@ -3,7 +3,6 @@ class a {
void f(b<String> r) {
r.g(<caret>this);
}
}
interface b<T> {
void g(b<T> t);
@@ -3,7 +3,7 @@ public class Test {
public static void main() {
Collection[] cc = new MyCollection[10];
}
<caret>
private static class MyCollection {
}
}
@@ -6,7 +6,7 @@ public class Test {
public static void main() {
JTable table = new JTable(new MyTableModel());
}
<caret>
private static class MyTableModel implements TableModel {
}
}
@@ -3,7 +3,7 @@ class Test {
void foo () {
new Generic<String> ();
}
<caret>
private class Generic<T> {
}
}
@@ -43,12 +43,10 @@ public class TestClass {
return yearsTo( expiry );
}
return 0.0;
}
private double yearsTo( final Date endDate ) {
Date beginDate = ( today == null ? start : today );
return ( ( endDate.getTime() - beginDate.getTime() ));
}
}
@@ -41,7 +41,6 @@ public class TestClass {
return yearsTo( expiry );
}
return 0.0;
}
private double riskFactor() {
@@ -6,5 +6,4 @@ class Test {
System.out.println(MessageFormat.format("i: {0}", i));
System.out.println(MessageFormat.format("k: {0}", j));
}
}
@@ -7,5 +7,4 @@ class Test {
System.out.println(MessageFormat.format("i: {0}", i));
System.out.println(MessageFormat.format("k: {0}", k));
}
}
@@ -48,7 +48,6 @@ public class Demo {
this.content = content;
}
}
}
@@ -1,7 +1,6 @@
public class X {
A myField;
private final Base myDelegate = new Base();
A myField;
public void method(Test t) {
myField = t.getA();
myField.methodFromA();
@@ -1,6 +1,6 @@
class A {
int fieldFromA;
private final MyBase myDelegate = new MyBase();
int fieldFromA;
public void firstMethodFromBase() {
myDelegate.firstMethodFromBase();
@@ -1,6 +1,6 @@
class Test {
private Foo myFoo;
private final Foo foo;
private Foo myFoo;
Test() {
foo = new Foo();
@@ -1,6 +1,6 @@
class Test {
private String myTimer;
private final String string;
private String myTimer;
Test() {
string = "";<caret>
@@ -1,6 +1,6 @@
class Test {
private String myTimer;
private final String string;
private String myTimer;
Test() {
string = "";
@@ -20,5 +20,4 @@ class B {
public int getI() {
return i;
}
}
@@ -6,5 +6,4 @@ class Test {
void bar() {
String s = foo();
}
}
@@ -125,6 +125,10 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testIncompleteSubst() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(BASE_PATH + "/" + getTestName(false) + ".java", false, false);
}
@@ -69,4 +69,38 @@ class Test {
rule(CLASS)]
)
}
void testInstanceInitializationBlockBoundToField() {
doTest('''\
class Test {
private int i;
public int j;
{ j = 1; }
protected int k;
}''', '''\
class Test {
public int j;
{ j = 1; }
protected int k;
private int i;
}''',
[rule(FIELD, PUBLIC), rule(FIELD, PROTECTED), rule(FIELD, PRIVATE)])
}
void testInstanceInitializationBlockAsFirstChild() {
doTest('''\
class Test {
{ j = 1; }
private int i;
public int j;
protected int k;
}''', '''\
class Test {
{ j = 1; }
public int j;
protected int k;
private int i;
}''',
[rule(FIELD, PUBLIC), rule(FIELD, PROTECTED), rule(FIELD, PRIVATE)])
}
}
@@ -18,6 +18,7 @@ package com.intellij.psi.codeStyle.arrangement
import org.junit.Before
import static com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType.*
import static com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier.PUBLIC
/**
* @author Denis Zhdanov
* @since 7/20/12 2:45 PM
@@ -198,4 +199,36 @@ class Test {
[rule(FIELD)]
)
}
void testMethodsAndConstructors() {
doTest('''\
class Test {
abstract void method1();
Test() {}
abstract void method2();
}''',
'''\
class Test {
Test() {}
abstract void method1();
abstract void method2();
}''',
[rule(CONSTRUCTOR), rule(METHOD)])
}
void testConstructorAsMethod() {
doTest('''\
class Test {
private int i;
Test() {}
public int j;
}''',
'''\
class Test {
public int j;
Test() {}
private int i;
}''',
[rule(FIELD, PUBLIC), rule(METHOD), rule(FIELD)])
}
}
+1 -1
View File
@@ -8,7 +8,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="jps-model" exported="" />
<orderEntry type="module" module-name="util" exported="" />
<orderEntry type="module" module-name="forms_rt" />
<orderEntry type="module" module-name="forms-compiler" />
@@ -37,6 +36,7 @@
<orderEntry type="module" module-name="jps-model-serialization" />
<orderEntry type="module" module-name="jps-model-impl" />
<orderEntry type="module" module-name="ui-designer-jps-plugin" />
<orderEntry type="library" scope="TEST" name="Groovy" level="project" />
</component>
</module>
@@ -1,4 +1,4 @@
package org.jetbrains.ether.dependencyView;
package org.jetbrains.jps.builders.java.dependencyView;
import org.jetbrains.asm4.ClassReader;
@@ -1,10 +1,9 @@
package org.jetbrains.ether.dependencyView;
package org.jetbrains.jps.builders.java.dependencyView;
import com.intellij.util.io.DataExternalizer;
import groovyjarjarasm.asm.Opcodes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.ether.RW;
import org.jetbrains.asm4.Opcodes;
import java.io.*;
import java.lang.annotation.RetentionPolicy;
@@ -1,4 +1,4 @@
package org.jetbrains.ether.dependencyView;
package org.jetbrains.jps.builders.java.dependencyView;
import com.intellij.openapi.util.Pair;
import gnu.trove.TIntHashSet;
@@ -1,4 +1,4 @@
package org.jetbrains.ether.dependencyView;
package org.jetbrains.jps.builders.java.dependencyView;
import java.util.Collection;
@@ -1,122 +1,122 @@
package org.jetbrains.ether.dependencyView;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.io.PersistentStringEnumerator;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 14.02.11
* Time: 2:03
* To change this template use File | Settings | File Templates.
*/
class DependencyContext {
private final static String STRING_TABLE_NAME = "strings.tab";
private final PersistentStringEnumerator myEnumerator;
private final Map<TypeRepr.AbstractType, TypeRepr.AbstractType> myTypeMap = new HashMap<TypeRepr.AbstractType, TypeRepr.AbstractType>();
private final Map<UsageRepr.Usage, UsageRepr.Usage> myUsageMap = new HashMap<UsageRepr.Usage, UsageRepr.Usage>();
UsageRepr.Usage getUsage(final UsageRepr.Usage u) {
final UsageRepr.Usage r = myUsageMap.get(u);
if (r == null) {
myUsageMap.put(u, u);
return u;
}
return r;
}
TypeRepr.AbstractType getType(final TypeRepr.AbstractType t) {
final TypeRepr.AbstractType r = myTypeMap.get(t);
if (r != null) {
return r;
}
myTypeMap.put(t, t);
return t;
}
void clearMemoryCaches() {
myTypeMap.clear();
myUsageMap.clear();
}
static File getTableFile (final File rootDir, final String name) {
final File file = new File(FileUtil.toSystemIndependentName(rootDir.getAbsoluteFile() + File.separator + name));
FileUtil.createIfDoesntExist(file);
return file;
}
DependencyContext(final File rootDir) throws IOException {
final File file = getTableFile(rootDir, STRING_TABLE_NAME);
myEnumerator = new PersistentStringEnumerator(file, true);
}
public String getValue(final int s) {
try {
return myEnumerator.valueOf(s);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public int get(final String s) {
try {
final int i = s == null ? myEnumerator.enumerate("") : myEnumerator.enumerate(s);
return i;
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public void close() {
try {
myEnumerator.close();
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public void flush() {
myEnumerator.force();
}
public Logger<Integer> getLogger(final com.intellij.openapi.diagnostic.Logger log) {
return new Logger<Integer>() {
@Override
public void debug(String comment, Integer s) {
if (log.isDebugEnabled()) {
log.debug(comment + getValue(s));
}
}
@Override
public void debug(String comment, String t) {
if (log.isDebugEnabled()){
log.debug(comment + t);
}
}
@Override
public void debug(String comment, boolean t) {
if (log.isDebugEnabled()) {
log.debug(comment + Boolean.toString(t));
}
}
};
}
}
package org.jetbrains.jps.builders.java.dependencyView;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.io.PersistentStringEnumerator;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 14.02.11
* Time: 2:03
* To change this template use File | Settings | File Templates.
*/
class DependencyContext {
private final static String STRING_TABLE_NAME = "strings.tab";
private final PersistentStringEnumerator myEnumerator;
private final Map<TypeRepr.AbstractType, TypeRepr.AbstractType> myTypeMap = new HashMap<TypeRepr.AbstractType, TypeRepr.AbstractType>();
private final Map<UsageRepr.Usage, UsageRepr.Usage> myUsageMap = new HashMap<UsageRepr.Usage, UsageRepr.Usage>();
UsageRepr.Usage getUsage(final UsageRepr.Usage u) {
final UsageRepr.Usage r = myUsageMap.get(u);
if (r == null) {
myUsageMap.put(u, u);
return u;
}
return r;
}
TypeRepr.AbstractType getType(final TypeRepr.AbstractType t) {
final TypeRepr.AbstractType r = myTypeMap.get(t);
if (r != null) {
return r;
}
myTypeMap.put(t, t);
return t;
}
void clearMemoryCaches() {
myTypeMap.clear();
myUsageMap.clear();
}
static File getTableFile (final File rootDir, final String name) {
final File file = new File(FileUtil.toSystemIndependentName(rootDir.getAbsoluteFile() + File.separator + name));
FileUtil.createIfDoesntExist(file);
return file;
}
DependencyContext(final File rootDir) throws IOException {
final File file = getTableFile(rootDir, STRING_TABLE_NAME);
myEnumerator = new PersistentStringEnumerator(file, true);
}
public String getValue(final int s) {
try {
return myEnumerator.valueOf(s);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public int get(final String s) {
try {
final int i = s == null ? myEnumerator.enumerate("") : myEnumerator.enumerate(s);
return i;
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public void close() {
try {
myEnumerator.close();
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public void flush() {
myEnumerator.force();
}
public Logger<Integer> getLogger(final com.intellij.openapi.diagnostic.Logger log) {
return new Logger<Integer>() {
@Override
public void debug(String comment, Integer s) {
if (log.isDebugEnabled()) {
log.debug(comment + getValue(s));
}
}
@Override
public void debug(String comment, String t) {
if (log.isDebugEnabled()){
log.debug(comment + t);
}
}
@Override
public void debug(String comment, boolean t) {
if (log.isDebugEnabled()) {
log.debug(comment + Boolean.toString(t));
}
}
};
}
}
@@ -1,132 +1,132 @@
package org.jetbrains.ether.dependencyView;
import com.intellij.openapi.util.Pair;
import org.jetbrains.asm4.Opcodes;
import java.util.*;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 01.03.11
* Time: 17:39
* To change this template use File | Settings | File Templates.
*/
abstract class Difference {
public static boolean isPackageLocal(final int access) {
return (access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC)) == 0;
}
public static boolean weakerAccess(final int me, final int then) {
return ((me & Opcodes.ACC_PRIVATE) > 0 && (then & Opcodes.ACC_PRIVATE) == 0) ||
((me & Opcodes.ACC_PROTECTED) > 0 && (then & Opcodes.ACC_PUBLIC) > 0) ||
(isPackageLocal(me) && (then & Opcodes.ACC_PROTECTED) > 0);
}
public static final int NONE = 0;
public static final int ACCESS = 1;
public static final int TYPE = 2;
public static final int VALUE = 4;
public static final int SIGNATURE = 8;
public static final int SUPERCLASS = 16;
public static final int USAGES = 32;
public interface Specifier<T> {
Collection<T> added();
Collection<T> removed();
Collection<Pair<T, Difference>> changed();
boolean unchanged();
}
public static <T> Specifier<T> make(final Set<T> past, final Set<T> now) {
if (past == null) {
final Collection<T> _now = Collections.unmodifiableCollection(now);
return new Specifier<T>() {
public Collection<T> added() {
return _now;
}
public Collection<T> removed() {
return Collections.emptyList();
}
public Collection<Pair<T, Difference>> changed() {
return Collections.emptyList();
}
public boolean unchanged() {
return false;
}
};
}
final Set<T> added = new HashSet<T>(now);
added.removeAll(past);
final Set<T> removed = new HashSet<T>(past);
removed.removeAll(now);
final Set<Pair<T, Difference>> changed = new HashSet<Pair<T, Difference>>();
final Set<T> intersect = new HashSet<T>(past);
final Map<T, T> nowMap = new HashMap<T, T>();
for (T s : now) {
if (intersect.contains(s)) {
nowMap.put(s, s);
}
}
intersect.retainAll(now);
for (T x : intersect) {
final T y = nowMap.get(x);
if (x instanceof Proto) {
final Proto px = (Proto)x;
final Proto py = (Proto)y;
final Difference diff = py.difference(px);
if (!diff.no()) {
changed.add(new Pair<T, Difference>(x, diff));
}
}
}
return new Specifier<T>() {
public Collection<T> added() {
return added;
}
public Collection<T> removed() {
return removed;
}
public Collection<Pair<T, Difference>> changed() {
return changed;
}
public boolean unchanged() {
return changed.isEmpty() && added.isEmpty() && removed.isEmpty();
}
};
}
public abstract int base();
public abstract boolean no();
public abstract boolean weakedAccess();
public abstract int addedModifiers();
public abstract int removedModifiers();
public abstract boolean packageLocalOn();
public abstract boolean hadValue();
}
package org.jetbrains.jps.builders.java.dependencyView;
import com.intellij.openapi.util.Pair;
import org.jetbrains.asm4.Opcodes;
import java.util.*;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 01.03.11
* Time: 17:39
* To change this template use File | Settings | File Templates.
*/
abstract class Difference {
public static boolean isPackageLocal(final int access) {
return (access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC)) == 0;
}
public static boolean weakerAccess(final int me, final int then) {
return ((me & Opcodes.ACC_PRIVATE) > 0 && (then & Opcodes.ACC_PRIVATE) == 0) ||
((me & Opcodes.ACC_PROTECTED) > 0 && (then & Opcodes.ACC_PUBLIC) > 0) ||
(isPackageLocal(me) && (then & Opcodes.ACC_PROTECTED) > 0);
}
public static final int NONE = 0;
public static final int ACCESS = 1;
public static final int TYPE = 2;
public static final int VALUE = 4;
public static final int SIGNATURE = 8;
public static final int SUPERCLASS = 16;
public static final int USAGES = 32;
public interface Specifier<T> {
Collection<T> added();
Collection<T> removed();
Collection<Pair<T, Difference>> changed();
boolean unchanged();
}
public static <T> Specifier<T> make(final Set<T> past, final Set<T> now) {
if (past == null) {
final Collection<T> _now = Collections.unmodifiableCollection(now);
return new Specifier<T>() {
public Collection<T> added() {
return _now;
}
public Collection<T> removed() {
return Collections.emptyList();
}
public Collection<Pair<T, Difference>> changed() {
return Collections.emptyList();
}
public boolean unchanged() {
return false;
}
};
}
final Set<T> added = new HashSet<T>(now);
added.removeAll(past);
final Set<T> removed = new HashSet<T>(past);
removed.removeAll(now);
final Set<Pair<T, Difference>> changed = new HashSet<Pair<T, Difference>>();
final Set<T> intersect = new HashSet<T>(past);
final Map<T, T> nowMap = new HashMap<T, T>();
for (T s : now) {
if (intersect.contains(s)) {
nowMap.put(s, s);
}
}
intersect.retainAll(now);
for (T x : intersect) {
final T y = nowMap.get(x);
if (x instanceof Proto) {
final Proto px = (Proto)x;
final Proto py = (Proto)y;
final Difference diff = py.difference(px);
if (!diff.no()) {
changed.add(new Pair<T, Difference>(x, diff));
}
}
}
return new Specifier<T>() {
public Collection<T> added() {
return added;
}
public Collection<T> removed() {
return removed;
}
public Collection<Pair<T, Difference>> changed() {
return changed;
}
public boolean unchanged() {
return changed.isEmpty() && added.isEmpty() && removed.isEmpty();
}
};
}
public abstract int base();
public abstract boolean no();
public abstract boolean weakedAccess();
public abstract int addedModifiers();
public abstract int removedModifiers();
public abstract boolean packageLocalOn();
public abstract boolean hadValue();
}
@@ -1,4 +1,4 @@
package org.jetbrains.ether.dependencyView;
package org.jetbrains.jps.builders.java.dependencyView;
public enum ElemType {
/** Class, interface (including annotation type), or enum declaration */
@@ -1,66 +1,66 @@
package org.jetbrains.ether.dependencyView;
import com.intellij.util.io.DataExternalizer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Set;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 01.02.11
* Time: 4:56
* To change this template use File | Settings | File Templates.
*/
class FieldRepr extends ProtoMember {
public void updateClassUsages(final DependencyContext context, final int owner, final Set<UsageRepr.Usage> s) {
myType.updateClassUsages(context, owner, s);
}
public FieldRepr(final DependencyContext context, final int a, final int n, final int d, final int s, final Object v) {
super(a, s, n, TypeRepr.getType(context, d), v);
}
public FieldRepr(final DependencyContext context, final DataInput in) {
super(context, in);
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final FieldRepr fieldRepr = (FieldRepr)o;
return name == fieldRepr.name;
}
@Override
public int hashCode() {
return 31 * name;
}
public static DataExternalizer<FieldRepr> externalizer(final DependencyContext context) {
return new DataExternalizer<FieldRepr>() {
@Override
public void save(final DataOutput out, final FieldRepr value) throws IOException {
value.save(out);
}
@Override
public FieldRepr read(final DataInput in) throws IOException {
return new FieldRepr(context, in);
}
};
}
public UsageRepr.Usage createUsage(final DependencyContext context, final int owner) {
return UsageRepr.createFieldUsage(context, name, owner, context.get(myType.getDescr(context)));
}
public UsageRepr.Usage createAssignUsage(final DependencyContext context, final int owner) {
return UsageRepr.createFieldAssignUsage(context, name, owner, context.get(myType.getDescr(context)));
}
}
package org.jetbrains.jps.builders.java.dependencyView;
import com.intellij.util.io.DataExternalizer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Set;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 01.02.11
* Time: 4:56
* To change this template use File | Settings | File Templates.
*/
class FieldRepr extends ProtoMember {
public void updateClassUsages(final DependencyContext context, final int owner, final Set<UsageRepr.Usage> s) {
myType.updateClassUsages(context, owner, s);
}
public FieldRepr(final DependencyContext context, final int a, final int n, final int d, final int s, final Object v) {
super(a, s, n, TypeRepr.getType(context, d), v);
}
public FieldRepr(final DependencyContext context, final DataInput in) {
super(context, in);
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final FieldRepr fieldRepr = (FieldRepr)o;
return name == fieldRepr.name;
}
@Override
public int hashCode() {
return 31 * name;
}
public static DataExternalizer<FieldRepr> externalizer(final DependencyContext context) {
return new DataExternalizer<FieldRepr>() {
@Override
public void save(final DataOutput out, final FieldRepr value) throws IOException {
value.save(out);
}
@Override
public FieldRepr read(final DataInput in) throws IOException {
return new FieldRepr(context, in);
}
};
}
public UsageRepr.Usage createUsage(final DependencyContext context, final int owner) {
return UsageRepr.createFieldUsage(context, name, owner, context.get(myType.getDescr(context)));
}
public UsageRepr.Usage createAssignUsage(final DependencyContext context, final int owner) {
return UsageRepr.createFieldAssignUsage(context, name, owner, context.get(myType.getDescr(context)));
}
}
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ether.dependencyView;
package org.jetbrains.jps.builders.java.dependencyView;
import gnu.trove.TIntIntProcedure;
@@ -1,101 +1,101 @@
/*
* Copyright 2000-2011 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 org.jetbrains.ether.dependencyView;
import gnu.trove.TIntHashSet;
import gnu.trove.TIntObjectProcedure;
import gnu.trove.TIntProcedure;
import java.io.PrintStream;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 03.11.11
* Time: 21:01
* To change this template use File | Settings | File Templates.
*/
abstract class IntIntMultiMaplet implements Streamable {
abstract boolean containsKey(final int key);
abstract TIntHashSet get(final int key);
abstract void put(final int key, final int value);
abstract void put(final int key, final TIntHashSet value);
abstract void replace(final int key, final TIntHashSet value);
abstract void putAll(IntIntMultiMaplet m);
abstract void replaceAll(IntIntMultiMaplet m);
abstract void remove(final int key);
abstract void removeFrom(final int key, final int value);
abstract void removeAll(final int key, final TIntHashSet values);
abstract void close();
abstract void forEachEntry(TIntObjectProcedure<TIntHashSet> proc);
abstract void flush(boolean memoryCachesOnly);
public void toStream(final DependencyContext context, final PrintStream stream) {
final OrderProvider op = new OrderProvider(context);
forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
@Override
public boolean execute(final int a, final TIntHashSet b) {
op.register(a);
return true;
}
});
final int[] keys = op.get();
for (final int a : keys) {
final TIntHashSet b = get(a);
stream.print(" Key: ");
stream.println(context.getValue(a));
stream.println(" Values:");
final List<String> list = new LinkedList<String>();
b.forEach(new TIntProcedure() {
@Override
public boolean execute(final int value) {
list.add(context.getValue(value));
return true;
}
});
Collections.sort(list);
for (final String l : list) {
stream.print(" ");
stream.println(l);
}
stream.println(" End Of Values");
}
}
}
/*
* Copyright 2000-2011 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 org.jetbrains.jps.builders.java.dependencyView;
import gnu.trove.TIntHashSet;
import gnu.trove.TIntObjectProcedure;
import gnu.trove.TIntProcedure;
import java.io.PrintStream;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 03.11.11
* Time: 21:01
* To change this template use File | Settings | File Templates.
*/
abstract class IntIntMultiMaplet implements Streamable {
abstract boolean containsKey(final int key);
abstract TIntHashSet get(final int key);
abstract void put(final int key, final int value);
abstract void put(final int key, final TIntHashSet value);
abstract void replace(final int key, final TIntHashSet value);
abstract void putAll(IntIntMultiMaplet m);
abstract void replaceAll(IntIntMultiMaplet m);
abstract void remove(final int key);
abstract void removeFrom(final int key, final int value);
abstract void removeAll(final int key, final TIntHashSet values);
abstract void close();
abstract void forEachEntry(TIntObjectProcedure<TIntHashSet> proc);
abstract void flush(boolean memoryCachesOnly);
public void toStream(final DependencyContext context, final PrintStream stream) {
final OrderProvider op = new OrderProvider(context);
forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
@Override
public boolean execute(final int a, final TIntHashSet b) {
op.register(a);
return true;
}
});
final int[] keys = op.get();
for (final int a : keys) {
final TIntHashSet b = get(a);
stream.print(" Key: ");
stream.println(context.getValue(a));
stream.println(" Values:");
final List<String> list = new LinkedList<String>();
b.forEach(new TIntProcedure() {
@Override
public boolean execute(final int value) {
list.add(context.getValue(value));
return true;
}
});
Collections.sort(list);
for (final String l : list) {
stream.print(" ");
stream.println(l);
}
stream.println(" End Of Values");
}
}
}
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ether.dependencyView;
package org.jetbrains.jps.builders.java.dependencyView;
import com.intellij.util.Processor;
import com.intellij.util.containers.SLRUCache;
@@ -1,291 +1,291 @@
/*
* Copyright 2000-2011 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 org.jetbrains.ether.dependencyView;
import com.intellij.openapi.util.Ref;
import com.intellij.util.Processor;
import com.intellij.util.containers.SLRUCache;
import com.intellij.util.io.DataExternalizer;
import com.intellij.util.io.KeyDescriptor;
import com.intellij.util.io.PersistentHashMap;
import gnu.trove.TIntHashSet;
import gnu.trove.TIntObjectProcedure;
import gnu.trove.TIntProcedure;
import org.jetbrains.annotations.NotNull;
import java.io.*;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 08.03.11
* Time: 15:38
* To change this template use File | Settings | File Templates.
*/
class IntIntPersistentMultiMaplet extends IntIntMultiMaplet {
private static final TIntHashSet NULL_COLLECTION = new TIntHashSet();
private static final int CACHE_SIZE = 128;
private final PersistentHashMap<Integer, TIntHashSet> myMap;
private final SLRUCache<Integer, TIntHashSet> myCache;
public IntIntPersistentMultiMaplet(final File file, final KeyDescriptor<Integer> keyExternalizer) throws IOException {
myMap = new PersistentHashMap<Integer, TIntHashSet>(file, keyExternalizer, new IntSetExternalizer());
myCache = new SLRUCache<Integer, TIntHashSet>(CACHE_SIZE, CACHE_SIZE) {
@NotNull
@Override
public TIntHashSet createValue(Integer key) {
try {
final TIntHashSet collection = myMap.get(key);
return collection == null? NULL_COLLECTION : collection;
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
};
}
@Override
public boolean containsKey(final int key) {
try {
return myMap.containsMapping(key);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public TIntHashSet get(final int key) {
final TIntHashSet collection = myCache.get(key);
return collection == NULL_COLLECTION? null : collection;
}
@Override
public void replace(int key, TIntHashSet value) {
try {
myCache.remove(key);
if (value == null || value.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, value);
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void put(final int key, final TIntHashSet value) {
try {
myCache.remove(key);
myMap.appendData(key, new PersistentHashMap.ValueDataAppender() {
public void append(final DataOutput out) throws IOException {
final Ref<IOException> exRef = new Ref<IOException>();
value.forEach(new TIntProcedure() {
@Override
public boolean execute(int value) {
try {
out.writeInt(value);
}
catch (IOException e) {
exRef.set(e);
return false;
}
return true;
}
});
final IOException exception = exRef.get();
if (exception != null) {
throw exception;
}
}
});
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void put(final int key, final int value) {
try {
myCache.remove(key);
myMap.appendData(key, new PersistentHashMap.ValueDataAppender() {
public void append(final DataOutput out) throws IOException {
out.writeInt(value);
}
});
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void removeAll(int key, TIntHashSet values) {
try {
final TIntHashSet collection = myCache.get(key);
if (collection != NULL_COLLECTION) {
if (collection.removeAll(values.toArray())) {
myCache.remove(key);
if (collection.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, collection);
}
}
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void removeFrom(final int key, final int value) {
try {
final TIntHashSet collection = myCache.get(key);
if (collection != NULL_COLLECTION) {
if (collection.remove(value)) {
myCache.remove(key);
if (collection.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, collection);
}
}
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void remove(final int key) {
try {
myCache.remove(key);
myMap.remove(key);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void putAll(IntIntMultiMaplet m) {
m.forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
@Override
public boolean execute(int key, TIntHashSet value) {
put(key, value);
return true;
}
});
}
@Override
public void replaceAll(IntIntMultiMaplet m) {
m.forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
@Override
public boolean execute(int key, TIntHashSet value) {
replace(key, value);
return true;
}
});
}
@Override
public void close() {
try {
myCache.clear();
myMap.close();
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public void flush(boolean memoryCachesOnly) {
if (memoryCachesOnly) {
if (myMap.isDirty()) {
myMap.dropMemoryCaches();
}
}
else {
myMap.force();
}
}
@Override
public void forEachEntry(final TIntObjectProcedure<TIntHashSet> procedure) {
try {
myMap.processKeysWithExistingMapping(new Processor<Integer>() {
@Override
public boolean process(Integer key) {
try {
return procedure.execute(key, myMap.get(key));
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
private static class IntSetExternalizer implements DataExternalizer<TIntHashSet> {
@Override
public void save(final DataOutput out, final TIntHashSet value) throws IOException {
final Ref<IOException> exRef = new Ref<IOException>(null);
value.forEach(new TIntProcedure() {
@Override
public boolean execute(int elem) {
try {
out.writeInt(elem);
}
catch (IOException e) {
exRef.set(e);
return false;
}
return true;
}
});
final IOException exception = exRef.get();
if (exception != null) {
throw exception;
}
}
@Override
public TIntHashSet read(final DataInput in) throws IOException {
final TIntHashSet result = new TIntHashSet();
final DataInputStream stream = (DataInputStream)in;
while (stream.available() > 0) {
result.add(in.readInt());
}
return result;
}
}
}
/*
* Copyright 2000-2011 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 org.jetbrains.jps.builders.java.dependencyView;
import com.intellij.openapi.util.Ref;
import com.intellij.util.Processor;
import com.intellij.util.containers.SLRUCache;
import com.intellij.util.io.DataExternalizer;
import com.intellij.util.io.KeyDescriptor;
import com.intellij.util.io.PersistentHashMap;
import gnu.trove.TIntHashSet;
import gnu.trove.TIntObjectProcedure;
import gnu.trove.TIntProcedure;
import org.jetbrains.annotations.NotNull;
import java.io.*;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 08.03.11
* Time: 15:38
* To change this template use File | Settings | File Templates.
*/
class IntIntPersistentMultiMaplet extends IntIntMultiMaplet {
private static final TIntHashSet NULL_COLLECTION = new TIntHashSet();
private static final int CACHE_SIZE = 128;
private final PersistentHashMap<Integer, TIntHashSet> myMap;
private final SLRUCache<Integer, TIntHashSet> myCache;
public IntIntPersistentMultiMaplet(final File file, final KeyDescriptor<Integer> keyExternalizer) throws IOException {
myMap = new PersistentHashMap<Integer, TIntHashSet>(file, keyExternalizer, new IntSetExternalizer());
myCache = new SLRUCache<Integer, TIntHashSet>(CACHE_SIZE, CACHE_SIZE) {
@NotNull
@Override
public TIntHashSet createValue(Integer key) {
try {
final TIntHashSet collection = myMap.get(key);
return collection == null? NULL_COLLECTION : collection;
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
};
}
@Override
public boolean containsKey(final int key) {
try {
return myMap.containsMapping(key);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public TIntHashSet get(final int key) {
final TIntHashSet collection = myCache.get(key);
return collection == NULL_COLLECTION? null : collection;
}
@Override
public void replace(int key, TIntHashSet value) {
try {
myCache.remove(key);
if (value == null || value.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, value);
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void put(final int key, final TIntHashSet value) {
try {
myCache.remove(key);
myMap.appendData(key, new PersistentHashMap.ValueDataAppender() {
public void append(final DataOutput out) throws IOException {
final Ref<IOException> exRef = new Ref<IOException>();
value.forEach(new TIntProcedure() {
@Override
public boolean execute(int value) {
try {
out.writeInt(value);
}
catch (IOException e) {
exRef.set(e);
return false;
}
return true;
}
});
final IOException exception = exRef.get();
if (exception != null) {
throw exception;
}
}
});
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void put(final int key, final int value) {
try {
myCache.remove(key);
myMap.appendData(key, new PersistentHashMap.ValueDataAppender() {
public void append(final DataOutput out) throws IOException {
out.writeInt(value);
}
});
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void removeAll(int key, TIntHashSet values) {
try {
final TIntHashSet collection = myCache.get(key);
if (collection != NULL_COLLECTION) {
if (collection.removeAll(values.toArray())) {
myCache.remove(key);
if (collection.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, collection);
}
}
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void removeFrom(final int key, final int value) {
try {
final TIntHashSet collection = myCache.get(key);
if (collection != NULL_COLLECTION) {
if (collection.remove(value)) {
myCache.remove(key);
if (collection.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, collection);
}
}
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void remove(final int key) {
try {
myCache.remove(key);
myMap.remove(key);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void putAll(IntIntMultiMaplet m) {
m.forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
@Override
public boolean execute(int key, TIntHashSet value) {
put(key, value);
return true;
}
});
}
@Override
public void replaceAll(IntIntMultiMaplet m) {
m.forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
@Override
public boolean execute(int key, TIntHashSet value) {
replace(key, value);
return true;
}
});
}
@Override
public void close() {
try {
myCache.clear();
myMap.close();
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public void flush(boolean memoryCachesOnly) {
if (memoryCachesOnly) {
if (myMap.isDirty()) {
myMap.dropMemoryCaches();
}
}
else {
myMap.force();
}
}
@Override
public void forEachEntry(final TIntObjectProcedure<TIntHashSet> procedure) {
try {
myMap.processKeysWithExistingMapping(new Processor<Integer>() {
@Override
public boolean process(Integer key) {
try {
return procedure.execute(key, myMap.get(key));
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
private static class IntSetExternalizer implements DataExternalizer<TIntHashSet> {
@Override
public void save(final DataOutput out, final TIntHashSet value) throws IOException {
final Ref<IOException> exRef = new Ref<IOException>(null);
value.forEach(new TIntProcedure() {
@Override
public boolean execute(int elem) {
try {
out.writeInt(elem);
}
catch (IOException e) {
exRef.set(e);
return false;
}
return true;
}
});
final IOException exception = exRef.get();
if (exception != null) {
throw exception;
}
}
@Override
public TIntHashSet read(final DataInput in) throws IOException {
final TIntHashSet result = new TIntHashSet();
final DataInputStream stream = (DataInputStream)in;
while (stream.available() > 0) {
result.add(in.readInt());
}
return result;
}
}
}
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ether.dependencyView;
package org.jetbrains.jps.builders.java.dependencyView;
import gnu.trove.TIntIntHashMap;
import gnu.trove.TIntIntProcedure;
@@ -1,137 +1,137 @@
package org.jetbrains.ether.dependencyView;
import gnu.trove.TIntHashSet;
import gnu.trove.TIntObjectHashMap;
import gnu.trove.TIntObjectProcedure;
import gnu.trove.TIntProcedure;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 08.03.11
* Time: 15:38
* To change this template use File | Settings | File Templates.
*/
class IntIntTransientMultiMaplet extends IntIntMultiMaplet {
private final TIntObjectHashMap<TIntHashSet> myMap = new TIntObjectHashMap<TIntHashSet>();
@Override
public boolean containsKey(final int key) {
return myMap.containsKey(key);
}
@Override
public TIntHashSet get(final int key) {
return myMap.get(key);
}
@Override
public void putAll(IntIntMultiMaplet m) {
m.forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
@Override
public boolean execute(int key, TIntHashSet values) {
put(key, values);
return true;
}
});
}
@Override
public void put(final int key, final TIntHashSet value) {
final TIntHashSet x = myMap.get(key);
if (x == null) {
myMap.put(key, value);
}
else {
value.forEach(new TIntProcedure() {
@Override
public boolean execute(int value) {
x.add(value);
return true;
}
});
}
}
@Override
public void replace(int key, TIntHashSet value) {
if (value == null || value.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, value);
}
}
@Override
public void put(final int key, final int value) {
final TIntHashSet collection = myMap.get(key);
if (collection == null) {
final TIntHashSet x = new TIntHashSet();
x.add(value);
myMap.put(key, x);
}
else {
collection.add(value);
}
}
@Override
public void removeFrom(final int key, final int value) {
final TIntHashSet collection = myMap.get(key);
if (collection != null) {
if (collection.remove(value)) {
if (collection.isEmpty()) {
myMap.remove(key);
}
}
}
}
@Override
public void removeAll(int key, TIntHashSet values) {
final TIntHashSet collection = myMap.get(key);
if (collection != null) {
values.forEach(new TIntProcedure() {
@Override
public boolean execute(int value) {
collection.remove(value);
return true;
}
});
if (collection.isEmpty()) {
myMap.remove(key);
}
}
}
@Override
public void remove(final int key) {
myMap.remove(key);
}
@Override
public void replaceAll(IntIntMultiMaplet m) {
m.forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
@Override
public boolean execute(int key, TIntHashSet value) {
replace(key, value);
return true;
}
});
}
@Override
public void forEachEntry(TIntObjectProcedure<TIntHashSet> procedure) {
myMap.forEachEntry(procedure);
}
@Override
public void close(){
myMap.clear(); // free memory
}
public void flush(boolean memoryCachesOnly) {
}
}
package org.jetbrains.jps.builders.java.dependencyView;
import gnu.trove.TIntHashSet;
import gnu.trove.TIntObjectHashMap;
import gnu.trove.TIntObjectProcedure;
import gnu.trove.TIntProcedure;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 08.03.11
* Time: 15:38
* To change this template use File | Settings | File Templates.
*/
class IntIntTransientMultiMaplet extends IntIntMultiMaplet {
private final TIntObjectHashMap<TIntHashSet> myMap = new TIntObjectHashMap<TIntHashSet>();
@Override
public boolean containsKey(final int key) {
return myMap.containsKey(key);
}
@Override
public TIntHashSet get(final int key) {
return myMap.get(key);
}
@Override
public void putAll(IntIntMultiMaplet m) {
m.forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
@Override
public boolean execute(int key, TIntHashSet values) {
put(key, values);
return true;
}
});
}
@Override
public void put(final int key, final TIntHashSet value) {
final TIntHashSet x = myMap.get(key);
if (x == null) {
myMap.put(key, value);
}
else {
value.forEach(new TIntProcedure() {
@Override
public boolean execute(int value) {
x.add(value);
return true;
}
});
}
}
@Override
public void replace(int key, TIntHashSet value) {
if (value == null || value.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, value);
}
}
@Override
public void put(final int key, final int value) {
final TIntHashSet collection = myMap.get(key);
if (collection == null) {
final TIntHashSet x = new TIntHashSet();
x.add(value);
myMap.put(key, x);
}
else {
collection.add(value);
}
}
@Override
public void removeFrom(final int key, final int value) {
final TIntHashSet collection = myMap.get(key);
if (collection != null) {
if (collection.remove(value)) {
if (collection.isEmpty()) {
myMap.remove(key);
}
}
}
}
@Override
public void removeAll(int key, TIntHashSet values) {
final TIntHashSet collection = myMap.get(key);
if (collection != null) {
values.forEach(new TIntProcedure() {
@Override
public boolean execute(int value) {
collection.remove(value);
return true;
}
});
if (collection.isEmpty()) {
myMap.remove(key);
}
}
}
@Override
public void remove(final int key) {
myMap.remove(key);
}
@Override
public void replaceAll(IntIntMultiMaplet m) {
m.forEachEntry(new TIntObjectProcedure<TIntHashSet>() {
@Override
public boolean execute(int key, TIntHashSet value) {
replace(key, value);
return true;
}
});
}
@Override
public void forEachEntry(TIntObjectProcedure<TIntHashSet> procedure) {
myMap.forEachEntry(procedure);
}
@Override
public void close(){
myMap.clear(); // free memory
}
public void flush(boolean memoryCachesOnly) {
}
}
@@ -1,101 +1,101 @@
/*
* Copyright 2000-2011 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 org.jetbrains.ether.dependencyView;
import gnu.trove.TIntObjectProcedure;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 03.11.11
* Time: 21:01
* To change this template use File | Settings | File Templates.
*/
abstract class IntObjectMultiMaplet<V extends Streamable> implements Streamable {
abstract boolean containsKey(final int key);
abstract Collection<V> get(final int key);
abstract void put(final int key, final V value);
abstract void put(final int key, final Collection<V> value);
abstract void replace(final int key, final Collection<V> value);
abstract void putAll(IntObjectMultiMaplet<V> m);
abstract void replaceAll(IntObjectMultiMaplet<V> m);
abstract void remove(final int key);
abstract void removeFrom(final int key, final V value);
abstract void removeAll(final int key, final Collection<V> value);
abstract void close();
abstract void forEachEntry(TIntObjectProcedure<Collection<V>> procedure);
abstract void flush(boolean memoryCachesOnly);
public void toStream(final DependencyContext context, final PrintStream stream) {
final OrderProvider op = new OrderProvider(context);
forEachEntry(new TIntObjectProcedure<Collection<V>>() {
@Override
public boolean execute(final int a, final Collection<V> b) {
op.register(a);
return true;
}
});
final int[] keys = op.get();
for (final int a : keys) {
final Collection<V> b = get(a);
stream.print(" Key: ");
stream.println(context.getValue(a));
stream.println(" Values:");
final List<String> list = new LinkedList<String>();
for (final V value : b) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final PrintStream s = new PrintStream(baos);
value.toStream(context, s);
list.add(baos.toString());
}
Collections.sort(list);
for (final String l : list) {
stream.print(l);
}
stream.println(" End Of Values");
}
}
}
/*
* Copyright 2000-2011 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 org.jetbrains.jps.builders.java.dependencyView;
import gnu.trove.TIntObjectProcedure;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 03.11.11
* Time: 21:01
* To change this template use File | Settings | File Templates.
*/
abstract class IntObjectMultiMaplet<V extends Streamable> implements Streamable {
abstract boolean containsKey(final int key);
abstract Collection<V> get(final int key);
abstract void put(final int key, final V value);
abstract void put(final int key, final Collection<V> value);
abstract void replace(final int key, final Collection<V> value);
abstract void putAll(IntObjectMultiMaplet<V> m);
abstract void replaceAll(IntObjectMultiMaplet<V> m);
abstract void remove(final int key);
abstract void removeFrom(final int key, final V value);
abstract void removeAll(final int key, final Collection<V> value);
abstract void close();
abstract void forEachEntry(TIntObjectProcedure<Collection<V>> procedure);
abstract void flush(boolean memoryCachesOnly);
public void toStream(final DependencyContext context, final PrintStream stream) {
final OrderProvider op = new OrderProvider(context);
forEachEntry(new TIntObjectProcedure<Collection<V>>() {
@Override
public boolean execute(final int a, final Collection<V> b) {
op.register(a);
return true;
}
});
final int[] keys = op.get();
for (final int a : keys) {
final Collection<V> b = get(a);
stream.print(" Key: ");
stream.println(context.getValue(a));
stream.println(" Values:");
final List<String> list = new LinkedList<String>();
for (final V value : b) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final PrintStream s = new PrintStream(baos);
value.toStream(context, s);
list.add(baos.toString());
}
Collections.sort(list);
for (final String l : list) {
stream.print(l);
}
stream.println(" End Of Values");
}
}
}
@@ -1,266 +1,266 @@
/*
* Copyright 2000-2011 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 org.jetbrains.ether.dependencyView;
import com.intellij.util.Processor;
import com.intellij.util.containers.SLRUCache;
import com.intellij.util.io.DataExternalizer;
import com.intellij.util.io.KeyDescriptor;
import com.intellij.util.io.PersistentHashMap;
import gnu.trove.TIntObjectProcedure;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.util.Collection;
import java.util.Collections;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 08.03.11
* Time: 15:38
* To change this template use File | Settings | File Templates.
*/
class IntObjectPersistentMultiMaplet<V extends Streamable> extends IntObjectMultiMaplet<V> {
private static final Collection NULL_COLLECTION = Collections.emptySet();
private static final int CACHE_SIZE = 128;
private final PersistentHashMap<Integer, Collection<V>> myMap;
private final DataExternalizer<V> myValueExternalizer;
private final SLRUCache<Integer, Collection> myCache;
public IntObjectPersistentMultiMaplet(final File file,
final KeyDescriptor<Integer> keyExternalizer,
final DataExternalizer<V> valueExternalizer,
final CollectionFactory<V> collectionFactory) throws IOException {
myValueExternalizer = valueExternalizer;
myMap = new PersistentHashMap<Integer, Collection<V>>(file, keyExternalizer, new CollectionDataExternalizer<V>(valueExternalizer, collectionFactory));
myCache = new SLRUCache<Integer, Collection>(CACHE_SIZE, CACHE_SIZE) {
@NotNull
@Override
public Collection createValue(Integer key) {
try {
final Collection<V> collection = myMap.get(key);
return collection == null? NULL_COLLECTION : collection;
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
};
}
@Override
public boolean containsKey(final int key) {
try {
return myMap.containsMapping(key);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public Collection<V> get(final int key) {
final Collection<V> collection = myCache.get(key);
return collection == NULL_COLLECTION? null : collection;
}
@Override
public void replace(int key, Collection<V> value) {
try {
myCache.remove(key);
if (value == null || value.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, value);
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void put(final int key, final Collection<V> value) {
try {
myCache.remove(key);
myMap.appendData(key, new PersistentHashMap.ValueDataAppender() {
public void append(DataOutput out) throws IOException {
for (V v : value) {
myValueExternalizer.save(out, v);
}
}
});
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void put(final int key, final V value) {
put(key, Collections.singleton(value));
}
@Override
public void removeAll(int key, Collection<V> values) {
try {
final Collection collection = myCache.get(key);
if (collection != NULL_COLLECTION) {
if (collection.removeAll(values)) {
myCache.remove(key);
if (collection.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, (Collection<V>)collection);
}
}
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void removeFrom(final int key, final V value) {
try {
final Collection collection = myCache.get(key);
if (collection != NULL_COLLECTION) {
if (collection.remove(value)) {
myCache.remove(key);
if (collection.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, (Collection<V>)collection);
}
}
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void remove(final int key) {
try {
myCache.remove(key);
myMap.remove(key);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void putAll(IntObjectMultiMaplet<V> m) {
m.forEachEntry(new TIntObjectProcedure<Collection<V>>() {
@Override
public boolean execute(int key, Collection<V> value) {
put(key, value);
return true;
}
});
}
@Override
public void replaceAll(IntObjectMultiMaplet<V> m) {
m.forEachEntry(new TIntObjectProcedure<Collection<V>>() {
@Override
public boolean execute(int key, Collection<V> value) {
replace(key, value);
return true;
}
});
}
@Override
public void close() {
try {
myCache.clear();
myMap.close();
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public void flush(boolean memoryCachesOnly) {
if (memoryCachesOnly) {
if (myMap.isDirty()) {
myMap.dropMemoryCaches();
}
}
else {
myMap.force();
}
}
@Override
public void forEachEntry(final TIntObjectProcedure<Collection<V>> procedure) {
try {
myMap.processKeysWithExistingMapping(new Processor<Integer>() {
@Override
public boolean process(Integer key) {
try {
return procedure.execute(key, myMap.get(key));
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
private static class CollectionDataExternalizer<V> implements DataExternalizer<Collection<V>> {
private final DataExternalizer<V> myElementExternalizer;
private final CollectionFactory<V> myCollectionFactory;
public CollectionDataExternalizer(DataExternalizer<V> elementExternalizer,
CollectionFactory<V> collectionFactory) {
myElementExternalizer = elementExternalizer;
myCollectionFactory = collectionFactory;
}
@Override
public void save(final DataOutput out, final Collection<V> value) throws IOException {
for (V x : value) {
myElementExternalizer.save(out, x);
}
}
@Override
public Collection<V> read(final DataInput in) throws IOException {
final Collection<V> result = myCollectionFactory.create();
final DataInputStream stream = (DataInputStream)in;
while (stream.available() > 0) {
result.add(myElementExternalizer.read(in));
}
return result;
}
}
}
/*
* Copyright 2000-2011 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 org.jetbrains.jps.builders.java.dependencyView;
import com.intellij.util.Processor;
import com.intellij.util.containers.SLRUCache;
import com.intellij.util.io.DataExternalizer;
import com.intellij.util.io.KeyDescriptor;
import com.intellij.util.io.PersistentHashMap;
import gnu.trove.TIntObjectProcedure;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.util.Collection;
import java.util.Collections;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 08.03.11
* Time: 15:38
* To change this template use File | Settings | File Templates.
*/
class IntObjectPersistentMultiMaplet<V extends Streamable> extends IntObjectMultiMaplet<V> {
private static final Collection NULL_COLLECTION = Collections.emptySet();
private static final int CACHE_SIZE = 128;
private final PersistentHashMap<Integer, Collection<V>> myMap;
private final DataExternalizer<V> myValueExternalizer;
private final SLRUCache<Integer, Collection> myCache;
public IntObjectPersistentMultiMaplet(final File file,
final KeyDescriptor<Integer> keyExternalizer,
final DataExternalizer<V> valueExternalizer,
final CollectionFactory<V> collectionFactory) throws IOException {
myValueExternalizer = valueExternalizer;
myMap = new PersistentHashMap<Integer, Collection<V>>(file, keyExternalizer, new CollectionDataExternalizer<V>(valueExternalizer, collectionFactory));
myCache = new SLRUCache<Integer, Collection>(CACHE_SIZE, CACHE_SIZE) {
@NotNull
@Override
public Collection createValue(Integer key) {
try {
final Collection<V> collection = myMap.get(key);
return collection == null? NULL_COLLECTION : collection;
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
};
}
@Override
public boolean containsKey(final int key) {
try {
return myMap.containsMapping(key);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public Collection<V> get(final int key) {
final Collection<V> collection = myCache.get(key);
return collection == NULL_COLLECTION? null : collection;
}
@Override
public void replace(int key, Collection<V> value) {
try {
myCache.remove(key);
if (value == null || value.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, value);
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void put(final int key, final Collection<V> value) {
try {
myCache.remove(key);
myMap.appendData(key, new PersistentHashMap.ValueDataAppender() {
public void append(DataOutput out) throws IOException {
for (V v : value) {
myValueExternalizer.save(out, v);
}
}
});
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void put(final int key, final V value) {
put(key, Collections.singleton(value));
}
@Override
public void removeAll(int key, Collection<V> values) {
try {
final Collection collection = myCache.get(key);
if (collection != NULL_COLLECTION) {
if (collection.removeAll(values)) {
myCache.remove(key);
if (collection.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, (Collection<V>)collection);
}
}
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void removeFrom(final int key, final V value) {
try {
final Collection collection = myCache.get(key);
if (collection != NULL_COLLECTION) {
if (collection.remove(value)) {
myCache.remove(key);
if (collection.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, (Collection<V>)collection);
}
}
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void remove(final int key) {
try {
myCache.remove(key);
myMap.remove(key);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void putAll(IntObjectMultiMaplet<V> m) {
m.forEachEntry(new TIntObjectProcedure<Collection<V>>() {
@Override
public boolean execute(int key, Collection<V> value) {
put(key, value);
return true;
}
});
}
@Override
public void replaceAll(IntObjectMultiMaplet<V> m) {
m.forEachEntry(new TIntObjectProcedure<Collection<V>>() {
@Override
public boolean execute(int key, Collection<V> value) {
replace(key, value);
return true;
}
});
}
@Override
public void close() {
try {
myCache.clear();
myMap.close();
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public void flush(boolean memoryCachesOnly) {
if (memoryCachesOnly) {
if (myMap.isDirty()) {
myMap.dropMemoryCaches();
}
}
else {
myMap.force();
}
}
@Override
public void forEachEntry(final TIntObjectProcedure<Collection<V>> procedure) {
try {
myMap.processKeysWithExistingMapping(new Processor<Integer>() {
@Override
public boolean process(Integer key) {
try {
return procedure.execute(key, myMap.get(key));
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
private static class CollectionDataExternalizer<V> implements DataExternalizer<Collection<V>> {
private final DataExternalizer<V> myElementExternalizer;
private final CollectionFactory<V> myCollectionFactory;
public CollectionDataExternalizer(DataExternalizer<V> elementExternalizer,
CollectionFactory<V> collectionFactory) {
myElementExternalizer = elementExternalizer;
myCollectionFactory = collectionFactory;
}
@Override
public void save(final DataOutput out, final Collection<V> value) throws IOException {
for (V x : value) {
myElementExternalizer.save(out, x);
}
}
@Override
public Collection<V> read(final DataInput in) throws IOException {
final Collection<V> result = myCollectionFactory.create();
final DataInputStream stream = (DataInputStream)in;
while (stream.available() > 0) {
result.add(myElementExternalizer.read(in));
}
return result;
}
}
}
@@ -1,131 +1,131 @@
package org.jetbrains.ether.dependencyView;
import gnu.trove.TIntObjectHashMap;
import gnu.trove.TIntObjectProcedure;
import java.util.Collection;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 08.03.11
* Time: 15:38
* To change this template use File | Settings | File Templates.
*/
class IntObjectTransientMultiMaplet<V extends Streamable> extends IntObjectMultiMaplet<V> {
private final TIntObjectHashMap<Collection<V>> myMap = new TIntObjectHashMap<Collection<V>>();
private final CollectionFactory<V> myCollectionFactory;
public IntObjectTransientMultiMaplet(CollectionFactory<V> collectionFactory) {
myCollectionFactory = collectionFactory;
}
@Override
public boolean containsKey(final int key) {
return myMap.containsKey(key);
}
@Override
public Collection<V> get(final int key) {
return myMap.get(key);
}
@Override
public void putAll(IntObjectMultiMaplet<V> m) {
m.forEachEntry(new TIntObjectProcedure<Collection<V>>() {
@Override
public boolean execute(int key, Collection<V> value) {
put(key, value);
return true;
}
});
}
@Override
public void put(final int key, final Collection<V> value) {
final Collection<V> x = myMap.get(key);
if (x == null) {
myMap.put(key, value);
}
else {
x.addAll(value);
}
}
@Override
public void replace(int key, Collection<V> value) {
if (value == null || value.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, value);
}
}
@Override
public void put(final int key, final V value) {
final Collection<V> collection = myMap.get(key);
if (collection == null) {
final Collection<V> x = myCollectionFactory.create();
x.add(value);
myMap.put(key, x);
}
else {
collection.add(value);
}
}
@Override
public void removeFrom(final int key, final V value) {
final Collection<V> collection = myMap.get(key);
if (collection != null) {
if (collection.remove(value)) {
if (collection.isEmpty()) {
myMap.remove(key);
}
}
}
}
@Override
public void removeAll(int key, Collection<V> values) {
final Collection<V> collection = myMap.get(key);
if (collection != null) {
if (collection.removeAll(values)) {
if (collection.isEmpty()) {
myMap.remove(key);
}
}
}
}
@Override
public void remove(final int key) {
myMap.remove(key);
}
@Override
public void replaceAll(IntObjectMultiMaplet<V> m) {
m.forEachEntry(new TIntObjectProcedure<Collection<V>>() {
@Override
public boolean execute(int key, Collection<V> value) {
replace(key, value);
return true;
}
});
}
@Override
public void forEachEntry(TIntObjectProcedure<Collection<V>> procedure) {
myMap.forEachEntry(procedure);
}
@Override
public void close(){
myMap.clear(); // free memory
}
public void flush(boolean memoryCachesOnly) {
}
}
package org.jetbrains.jps.builders.java.dependencyView;
import gnu.trove.TIntObjectHashMap;
import gnu.trove.TIntObjectProcedure;
import java.util.Collection;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 08.03.11
* Time: 15:38
* To change this template use File | Settings | File Templates.
*/
class IntObjectTransientMultiMaplet<V extends Streamable> extends IntObjectMultiMaplet<V> {
private final TIntObjectHashMap<Collection<V>> myMap = new TIntObjectHashMap<Collection<V>>();
private final CollectionFactory<V> myCollectionFactory;
public IntObjectTransientMultiMaplet(CollectionFactory<V> collectionFactory) {
myCollectionFactory = collectionFactory;
}
@Override
public boolean containsKey(final int key) {
return myMap.containsKey(key);
}
@Override
public Collection<V> get(final int key) {
return myMap.get(key);
}
@Override
public void putAll(IntObjectMultiMaplet<V> m) {
m.forEachEntry(new TIntObjectProcedure<Collection<V>>() {
@Override
public boolean execute(int key, Collection<V> value) {
put(key, value);
return true;
}
});
}
@Override
public void put(final int key, final Collection<V> value) {
final Collection<V> x = myMap.get(key);
if (x == null) {
myMap.put(key, value);
}
else {
x.addAll(value);
}
}
@Override
public void replace(int key, Collection<V> value) {
if (value == null || value.isEmpty()) {
myMap.remove(key);
}
else {
myMap.put(key, value);
}
}
@Override
public void put(final int key, final V value) {
final Collection<V> collection = myMap.get(key);
if (collection == null) {
final Collection<V> x = myCollectionFactory.create();
x.add(value);
myMap.put(key, x);
}
else {
collection.add(value);
}
}
@Override
public void removeFrom(final int key, final V value) {
final Collection<V> collection = myMap.get(key);
if (collection != null) {
if (collection.remove(value)) {
if (collection.isEmpty()) {
myMap.remove(key);
}
}
}
}
@Override
public void removeAll(int key, Collection<V> values) {
final Collection<V> collection = myMap.get(key);
if (collection != null) {
if (collection.removeAll(values)) {
if (collection.isEmpty()) {
myMap.remove(key);
}
}
}
}
@Override
public void remove(final int key) {
myMap.remove(key);
}
@Override
public void replaceAll(IntObjectMultiMaplet<V> m) {
m.forEachEntry(new TIntObjectProcedure<Collection<V>>() {
@Override
public boolean execute(int key, Collection<V> value) {
replace(key, value);
return true;
}
});
}
@Override
public void forEachEntry(TIntObjectProcedure<Collection<V>> procedure) {
myMap.forEachEntry(procedure);
}
@Override
public void close(){
myMap.clear(); // free memory
}
public void flush(boolean memoryCachesOnly) {
}
}
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ether.dependencyView;
package org.jetbrains.jps.builders.java.dependencyView;
/**
* Created by IntelliJ IDEA.
@@ -1,4 +1,4 @@
package org.jetbrains.ether.dependencyView;
package org.jetbrains.jps.builders.java.dependencyView;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Pair;
@@ -62,7 +62,7 @@ public class Mappings {
private DependencyContext myContext;
private final int myInitName;
private final int myEmptyName;
private org.jetbrains.ether.dependencyView.Logger<Integer> myDebugS;
private org.jetbrains.jps.builders.java.dependencyView.Logger<Integer> myDebugS;
private IntIntMultiMaplet myClassToSubclasses;
private IntIntMultiMaplet myClassToClassDependency;
@@ -1,229 +1,228 @@
package org.jetbrains.ether.dependencyView;
import com.intellij.util.io.DataExternalizer;
import org.jetbrains.asm4.Type;
import org.jetbrains.ether.RW;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 01.02.11
* Time: 5:03
* To change this template use File | Settings | File Templates.
*/
class MethodRepr extends ProtoMember {
interface Predicate {
boolean satisfy(MethodRepr m);
}
public final TypeRepr.AbstractType[] myArgumentTypes;
public final Set<TypeRepr.AbstractType> myExceptions;
public abstract class Diff extends Difference {
public abstract Specifier<TypeRepr.AbstractType> exceptions();
public abstract boolean defaultAdded();
public abstract boolean defaultRemoved();
}
@Override
public Difference difference(final Proto past) {
final Difference diff = super.difference(past);
final Difference.Specifier<TypeRepr.AbstractType> excs = Difference.make(((MethodRepr)past).myExceptions, myExceptions);
return new Diff() {
@Override
public int addedModifiers() {
return diff.addedModifiers();
}
@Override
public int removedModifiers() {
return diff.removedModifiers();
}
@Override
public boolean no() {
return base() == NONE && !defaultAdded() && !defaultRemoved() && excs.unchanged();
}
@Override
public boolean defaultAdded() {
return hasValue() && !((MethodRepr)past).hasValue();
}
@Override
public boolean defaultRemoved() {
return !hasValue() && ((MethodRepr)past).hasValue();
}
@Override
public Specifier<TypeRepr.AbstractType> exceptions() {
return excs;
}
@Override
public int base() {
return diff.base();
}
@Override
public boolean packageLocalOn() {
return diff.packageLocalOn();
}
@Override
public boolean hadValue() {
return ((MethodRepr)past).hasValue();
}
@Override
public boolean weakedAccess() {
return diff.weakedAccess();
}
};
}
public void updateClassUsages(final DependencyContext context, final int owner, final Set<UsageRepr.Usage> s) {
myType.updateClassUsages(context, owner, s);
for (int i = 0; i < myArgumentTypes.length; i++) {
myArgumentTypes[i].updateClassUsages(context, owner, s);
}
if (myExceptions != null) {
for (TypeRepr.AbstractType typ : myExceptions) {
typ.updateClassUsages(context, owner, s);
}
}
}
public MethodRepr(final DependencyContext context,
final int a,
final int n,
final int s,
final String d,
final String[] e,
final Object value) {
super(a, s, n, TypeRepr.getType(context, Type.getReturnType(d)), value);
myExceptions = (Set<TypeRepr.AbstractType>)TypeRepr.createClassType(context, e, new HashSet<TypeRepr.AbstractType>());
myArgumentTypes = TypeRepr.getType(context, Type.getArgumentTypes(d));
}
public MethodRepr(final DependencyContext context, final DataInput in) {
super(context, in);
try {
final DataExternalizer<TypeRepr.AbstractType> externalizer = TypeRepr.externalizer(context);
final int size = in.readInt();
myArgumentTypes = RW.read(externalizer, in, new TypeRepr.AbstractType[size]);
myExceptions = (Set<TypeRepr.AbstractType>)RW.read(externalizer, new HashSet<TypeRepr.AbstractType>(), in);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void save(final DataOutput out) {
super.save(out);
RW.save(myArgumentTypes, out);
RW.save(myExceptions, out);
}
public static DataExternalizer<MethodRepr> externalizer(final DependencyContext context) {
return new DataExternalizer<MethodRepr>() {
@Override
public void save(final DataOutput out, final MethodRepr value) throws IOException {
value.save(out);
}
@Override
public MethodRepr read(DataInput in) throws IOException {
return new MethodRepr(context, in);
}
};
}
static Predicate equalByJavaRules(final MethodRepr me) {
return new Predicate() {
@Override
public boolean satisfy(MethodRepr that) {
if (me == that) return true;
return me.name == that.name && Arrays.equals(me.myArgumentTypes, that.myArgumentTypes);
}
};
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final MethodRepr that = (MethodRepr)o;
return name == that.name && myType.equals(that.myType) && Arrays.equals(myArgumentTypes, that.myArgumentTypes);
}
@Override
public int hashCode() {
return 31 * (31 * Arrays.hashCode(myArgumentTypes) + myType.hashCode()) + name;
}
private String getDescr(final DependencyContext context) {
final StringBuilder buf = new StringBuilder();
buf.append("(");
for (TypeRepr.AbstractType t : myArgumentTypes) {
buf.append(t.getDescr(context));
}
buf.append(")");
buf.append(myType.getDescr(context));
return buf.toString();
}
public UsageRepr.Usage createUsage(final DependencyContext context, final int owner) {
return UsageRepr.createMethodUsage(context, name, owner, getDescr(context));
}
public UsageRepr.Usage createMetaUsage(final DependencyContext context, final int owner) {
return UsageRepr.createMetaMethodUsage(context, name, owner, getDescr(context));
}
@Override
public void toStream(final DependencyContext context, final PrintStream stream) {
super.toStream(context, stream);
stream.print(" Arguments : ");
for (TypeRepr.AbstractType t : myArgumentTypes) {
stream.print(t.getDescr(context));
stream.print("; ");
}
stream.println();
final TypeRepr.AbstractType[] es = myExceptions.toArray(new TypeRepr.AbstractType[myExceptions.size()]);
Arrays.sort(es, new Comparator<TypeRepr.AbstractType>() {
@Override
public int compare(final TypeRepr.AbstractType o1, final TypeRepr.AbstractType o2) {
return o1.getDescr(context).compareTo(o2.getDescr(context));
}
});
stream.print(" Exceptions : ");
for (final TypeRepr.AbstractType e : es) {
stream.print(e.getDescr(context));
stream.print("; ");
}
stream.println();
}
}
package org.jetbrains.jps.builders.java.dependencyView;
import com.intellij.util.io.DataExternalizer;
import org.jetbrains.asm4.Type;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 01.02.11
* Time: 5:03
* To change this template use File | Settings | File Templates.
*/
class MethodRepr extends ProtoMember {
interface Predicate {
boolean satisfy(MethodRepr m);
}
public final TypeRepr.AbstractType[] myArgumentTypes;
public final Set<TypeRepr.AbstractType> myExceptions;
public abstract class Diff extends Difference {
public abstract Specifier<TypeRepr.AbstractType> exceptions();
public abstract boolean defaultAdded();
public abstract boolean defaultRemoved();
}
@Override
public Difference difference(final Proto past) {
final Difference diff = super.difference(past);
final Difference.Specifier<TypeRepr.AbstractType> excs = Difference.make(((MethodRepr)past).myExceptions, myExceptions);
return new Diff() {
@Override
public int addedModifiers() {
return diff.addedModifiers();
}
@Override
public int removedModifiers() {
return diff.removedModifiers();
}
@Override
public boolean no() {
return base() == NONE && !defaultAdded() && !defaultRemoved() && excs.unchanged();
}
@Override
public boolean defaultAdded() {
return hasValue() && !((MethodRepr)past).hasValue();
}
@Override
public boolean defaultRemoved() {
return !hasValue() && ((MethodRepr)past).hasValue();
}
@Override
public Specifier<TypeRepr.AbstractType> exceptions() {
return excs;
}
@Override
public int base() {
return diff.base();
}
@Override
public boolean packageLocalOn() {
return diff.packageLocalOn();
}
@Override
public boolean hadValue() {
return ((MethodRepr)past).hasValue();
}
@Override
public boolean weakedAccess() {
return diff.weakedAccess();
}
};
}
public void updateClassUsages(final DependencyContext context, final int owner, final Set<UsageRepr.Usage> s) {
myType.updateClassUsages(context, owner, s);
for (int i = 0; i < myArgumentTypes.length; i++) {
myArgumentTypes[i].updateClassUsages(context, owner, s);
}
if (myExceptions != null) {
for (TypeRepr.AbstractType typ : myExceptions) {
typ.updateClassUsages(context, owner, s);
}
}
}
public MethodRepr(final DependencyContext context,
final int a,
final int n,
final int s,
final String d,
final String[] e,
final Object value) {
super(a, s, n, TypeRepr.getType(context, Type.getReturnType(d)), value);
myExceptions = (Set<TypeRepr.AbstractType>)TypeRepr.createClassType(context, e, new HashSet<TypeRepr.AbstractType>());
myArgumentTypes = TypeRepr.getType(context, Type.getArgumentTypes(d));
}
public MethodRepr(final DependencyContext context, final DataInput in) {
super(context, in);
try {
final DataExternalizer<TypeRepr.AbstractType> externalizer = TypeRepr.externalizer(context);
final int size = in.readInt();
myArgumentTypes = RW.read(externalizer, in, new TypeRepr.AbstractType[size]);
myExceptions = (Set<TypeRepr.AbstractType>)RW.read(externalizer, new HashSet<TypeRepr.AbstractType>(), in);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void save(final DataOutput out) {
super.save(out);
RW.save(myArgumentTypes, out);
RW.save(myExceptions, out);
}
public static DataExternalizer<MethodRepr> externalizer(final DependencyContext context) {
return new DataExternalizer<MethodRepr>() {
@Override
public void save(final DataOutput out, final MethodRepr value) throws IOException {
value.save(out);
}
@Override
public MethodRepr read(DataInput in) throws IOException {
return new MethodRepr(context, in);
}
};
}
static Predicate equalByJavaRules(final MethodRepr me) {
return new Predicate() {
@Override
public boolean satisfy(MethodRepr that) {
if (me == that) return true;
return me.name == that.name && Arrays.equals(me.myArgumentTypes, that.myArgumentTypes);
}
};
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final MethodRepr that = (MethodRepr)o;
return name == that.name && myType.equals(that.myType) && Arrays.equals(myArgumentTypes, that.myArgumentTypes);
}
@Override
public int hashCode() {
return 31 * (31 * Arrays.hashCode(myArgumentTypes) + myType.hashCode()) + name;
}
private String getDescr(final DependencyContext context) {
final StringBuilder buf = new StringBuilder();
buf.append("(");
for (TypeRepr.AbstractType t : myArgumentTypes) {
buf.append(t.getDescr(context));
}
buf.append(")");
buf.append(myType.getDescr(context));
return buf.toString();
}
public UsageRepr.Usage createUsage(final DependencyContext context, final int owner) {
return UsageRepr.createMethodUsage(context, name, owner, getDescr(context));
}
public UsageRepr.Usage createMetaUsage(final DependencyContext context, final int owner) {
return UsageRepr.createMetaMethodUsage(context, name, owner, getDescr(context));
}
@Override
public void toStream(final DependencyContext context, final PrintStream stream) {
super.toStream(context, stream);
stream.print(" Arguments : ");
for (TypeRepr.AbstractType t : myArgumentTypes) {
stream.print(t.getDescr(context));
stream.print("; ");
}
stream.println();
final TypeRepr.AbstractType[] es = myExceptions.toArray(new TypeRepr.AbstractType[myExceptions.size()]);
Arrays.sort(es, new Comparator<TypeRepr.AbstractType>() {
@Override
public int compare(final TypeRepr.AbstractType o1, final TypeRepr.AbstractType o2) {
return o1.getDescr(context).compareTo(o2.getDescr(context));
}
});
stream.print(" Exceptions : ");
for (final TypeRepr.AbstractType e : es) {
stream.print(e.getDescr(context));
stream.print("; ");
}
stream.println();
}
}
@@ -1,6 +1,4 @@
package org.jetbrains.ether.dependencyView;
import org.intellij.lang.annotations.JdkConstants;
package org.jetbrains.jps.builders.java.dependencyView;
import java.util.Collections;
import java.util.LinkedList;
@@ -1,132 +1,131 @@
package org.jetbrains.ether.dependencyView;
import org.jetbrains.asm4.Opcodes;
import org.jetbrains.ether.RW;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 01.03.11
* Time: 17:57
* To change this template use File | Settings | File Templates.
*/
class Proto implements RW.Savable, Streamable {
public final int access;
public final int signature;
public final int name;
protected Proto(final int access, final int signature, final int name) {
this.access = access;
this.signature = signature;
this.name = name;
}
protected Proto(final DataInput in) {
try {
access = in.readInt();
signature = in.readInt();
name = in.readInt();
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void save(final DataOutput out) {
try {
out.writeInt(access);
out.writeInt(signature);
out.writeInt(name);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public Difference difference(final Proto past) {
int diff = Difference.NONE;
if (past.access != access) {
diff |= Difference.ACCESS;
}
if (past.signature != signature) {
diff |= Difference.SIGNATURE;
}
final int base = diff;
return new Difference() {
@Override
public int base() {
return base;
}
@Override
public boolean no() {
return base == NONE;
}
@Override
public int addedModifiers() {
return ~past.access & access;
}
@Override
public int removedModifiers() {
return ~access & past.access;
}
@Override
public boolean packageLocalOn() {
return ((past.access & Opcodes.ACC_PRIVATE) != 0 ||
(past.access & Opcodes.ACC_PUBLIC) != 0 ||
(past.access & Opcodes.ACC_PROTECTED) != 0) &&
Difference.isPackageLocal(access);
}
@Override
public boolean hadValue() {
return false;
}
@Override
public boolean weakedAccess() {
return Difference.weakerAccess(past.access, access);
}
};
}
public void toStream(final DependencyContext context, final PrintStream stream) {
final String d = this instanceof ClassRepr ? " " : " ";
if (this instanceof ClassRepr) {
stream.print(" Class ");
stream.println(context.getValue(name));
}
if (this instanceof MethodRepr) {
stream.print(" Method ");
stream.println(context.getValue(name));
}
if (this instanceof FieldRepr) {
stream.print(" Field ");
stream.println(context.getValue(name));
}
stream.print(d);
stream.print("Access : ");
stream.println(access);
stream.print(d);
stream.print("Signature : ");
stream.println(context.getValue(signature));
}
}
package org.jetbrains.jps.builders.java.dependencyView;
import org.jetbrains.asm4.Opcodes;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 01.03.11
* Time: 17:57
* To change this template use File | Settings | File Templates.
*/
class Proto implements RW.Savable, Streamable {
public final int access;
public final int signature;
public final int name;
protected Proto(final int access, final int signature, final int name) {
this.access = access;
this.signature = signature;
this.name = name;
}
protected Proto(final DataInput in) {
try {
access = in.readInt();
signature = in.readInt();
name = in.readInt();
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void save(final DataOutput out) {
try {
out.writeInt(access);
out.writeInt(signature);
out.writeInt(name);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public Difference difference(final Proto past) {
int diff = Difference.NONE;
if (past.access != access) {
diff |= Difference.ACCESS;
}
if (past.signature != signature) {
diff |= Difference.SIGNATURE;
}
final int base = diff;
return new Difference() {
@Override
public int base() {
return base;
}
@Override
public boolean no() {
return base == NONE;
}
@Override
public int addedModifiers() {
return ~past.access & access;
}
@Override
public int removedModifiers() {
return ~access & past.access;
}
@Override
public boolean packageLocalOn() {
return ((past.access & Opcodes.ACC_PRIVATE) != 0 ||
(past.access & Opcodes.ACC_PUBLIC) != 0 ||
(past.access & Opcodes.ACC_PROTECTED) != 0) &&
Difference.isPackageLocal(access);
}
@Override
public boolean hadValue() {
return false;
}
@Override
public boolean weakedAccess() {
return Difference.weakerAccess(past.access, access);
}
};
}
public void toStream(final DependencyContext context, final PrintStream stream) {
final String d = this instanceof ClassRepr ? " " : " ";
if (this instanceof ClassRepr) {
stream.print(" Class ");
stream.println(context.getValue(name));
}
if (this instanceof MethodRepr) {
stream.print(" Method ");
stream.println(context.getValue(name));
}
if (this instanceof FieldRepr) {
stream.print(" Field ");
stream.println(context.getValue(name));
}
stream.print(d);
stream.print("Access : ");
stream.println(access);
stream.print(d);
stream.print("Signature : ");
stream.println(context.getValue(signature));
}
}
@@ -1,192 +1,192 @@
package org.jetbrains.ether.dependencyView;
import org.jetbrains.asm4.Type;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 07.03.11
* Time: 19:54
* To change this template use File | Settings | File Templates.
*/
abstract class ProtoMember extends Proto {
private final static byte STRING = 0;
private final static byte NONE = 1;
private final static byte INTEGER = 2;
private final static byte LONG = 3;
private final static byte FLOAT = 4;
private final static byte DOUBLE = 5;
private final static byte TYPE = 6;
public final TypeRepr.AbstractType myType;
public final Object myValue;
public boolean hasValue() {
return myValue != null;
}
protected ProtoMember(final int access, final int signature, final int name, final TypeRepr.AbstractType t, final Object value) {
super(access, signature, name);
this.myType = t;
this.myValue = value;
}
private static Object loadTyped(final DataInput in) {
try {
switch (in.readByte()) {
case STRING:
return in.readUTF();
case NONE:
return null;
case INTEGER:
return in.readInt();
case LONG:
return in.readLong();
case FLOAT:
return in.readFloat();
case DOUBLE:
return in.readDouble();
case TYPE :
return Type.getType(in.readUTF());
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
assert (false);
return null;
}
protected ProtoMember(final DependencyContext context, final DataInput in) {
super(in);
try {
myType = TypeRepr.externalizer(context).read(in);
myValue = loadTyped(in);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public void save(final DataOutput out) {
super.save(out);
myType.save(out);
try {
if (myValue instanceof String) {
out.writeByte(STRING);
out.writeUTF((String)myValue);
}
else if (myValue instanceof Integer) {
out.writeByte(INTEGER);
out.writeInt(((Integer)myValue).intValue());
}
else if (myValue instanceof Long) {
out.writeByte(LONG);
out.writeLong(((Long)myValue).longValue());
}
else if (myValue instanceof Float) {
out.writeByte(FLOAT);
out.writeFloat(((Float)myValue).floatValue());
}
else if (myValue instanceof Double) {
out.writeByte(DOUBLE);
out.writeDouble(((Double)myValue).doubleValue());
}
else if (myValue instanceof Type) {
out.writeByte(TYPE);
out.writeUTF(((Type)myValue).getDescriptor());
}
else {
out.writeByte(NONE);
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public Difference difference(final Proto past) {
final ProtoMember m = (ProtoMember)past;
final Difference diff = super.difference(past);
int base = diff.base();
if (!m.myType.equals(myType)) {
base |= Difference.TYPE;
}
switch ((myValue == null ? 0 : 1) + (m.myValue == null ? 0 : 2)) {
case 3:
if (!myValue.equals(m.myValue)) {
base |= Difference.VALUE;
}
break;
case 2:
base |= Difference.VALUE;
break;
case 1:
base |= Difference.VALUE;
break;
case 0:
break;
}
final int newBase = base;
return new Difference() {
@Override
public int base() {
return newBase;
}
@Override
public boolean no() {
return newBase == NONE && diff.no();
}
@Override
public int addedModifiers() {
return diff.addedModifiers();
}
@Override
public int removedModifiers() {
return diff.removedModifiers();
}
@Override
public boolean packageLocalOn() {
return diff.packageLocalOn();
}
@Override
public boolean hadValue() {
return ((ProtoMember)past).hasValue();
}
@Override
public boolean weakedAccess() {
return diff.weakedAccess();
}
};
}
public void toStream(final DependencyContext context, final PrintStream stream) {
super.toStream(context, stream);
stream.print(" Type : ");
stream.println(myType.getDescr(context));
stream.print(" Value : ");
stream.println(myValue == null ? "<null>" : myValue.toString());
}
}
package org.jetbrains.jps.builders.java.dependencyView;
import org.jetbrains.asm4.Type;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
/**
* Created by IntelliJ IDEA.
* User: db
* Date: 07.03.11
* Time: 19:54
* To change this template use File | Settings | File Templates.
*/
abstract class ProtoMember extends Proto {
private final static byte STRING = 0;
private final static byte NONE = 1;
private final static byte INTEGER = 2;
private final static byte LONG = 3;
private final static byte FLOAT = 4;
private final static byte DOUBLE = 5;
private final static byte TYPE = 6;
public final TypeRepr.AbstractType myType;
public final Object myValue;
public boolean hasValue() {
return myValue != null;
}
protected ProtoMember(final int access, final int signature, final int name, final TypeRepr.AbstractType t, final Object value) {
super(access, signature, name);
this.myType = t;
this.myValue = value;
}
private static Object loadTyped(final DataInput in) {
try {
switch (in.readByte()) {
case STRING:
return in.readUTF();
case NONE:
return null;
case INTEGER:
return in.readInt();
case LONG:
return in.readLong();
case FLOAT:
return in.readFloat();
case DOUBLE:
return in.readDouble();
case TYPE :
return Type.getType(in.readUTF());
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
assert (false);
return null;
}
protected ProtoMember(final DependencyContext context, final DataInput in) {
super(in);
try {
myType = TypeRepr.externalizer(context).read(in);
myValue = loadTyped(in);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public void save(final DataOutput out) {
super.save(out);
myType.save(out);
try {
if (myValue instanceof String) {
out.writeByte(STRING);
out.writeUTF((String)myValue);
}
else if (myValue instanceof Integer) {
out.writeByte(INTEGER);
out.writeInt(((Integer)myValue).intValue());
}
else if (myValue instanceof Long) {
out.writeByte(LONG);
out.writeLong(((Long)myValue).longValue());
}
else if (myValue instanceof Float) {
out.writeByte(FLOAT);
out.writeFloat(((Float)myValue).floatValue());
}
else if (myValue instanceof Double) {
out.writeByte(DOUBLE);
out.writeDouble(((Double)myValue).doubleValue());
}
else if (myValue instanceof Type) {
out.writeByte(TYPE);
out.writeUTF(((Type)myValue).getDescriptor());
}
else {
out.writeByte(NONE);
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public Difference difference(final Proto past) {
final ProtoMember m = (ProtoMember)past;
final Difference diff = super.difference(past);
int base = diff.base();
if (!m.myType.equals(myType)) {
base |= Difference.TYPE;
}
switch ((myValue == null ? 0 : 1) + (m.myValue == null ? 0 : 2)) {
case 3:
if (!myValue.equals(m.myValue)) {
base |= Difference.VALUE;
}
break;
case 2:
base |= Difference.VALUE;
break;
case 1:
base |= Difference.VALUE;
break;
case 0:
break;
}
final int newBase = base;
return new Difference() {
@Override
public int base() {
return newBase;
}
@Override
public boolean no() {
return newBase == NONE && diff.no();
}
@Override
public int addedModifiers() {
return diff.addedModifiers();
}
@Override
public int removedModifiers() {
return diff.removedModifiers();
}
@Override
public boolean packageLocalOn() {
return diff.packageLocalOn();
}
@Override
public boolean hadValue() {
return ((ProtoMember)past).hasValue();
}
@Override
public boolean weakedAccess() {
return diff.weakedAccess();
}
};
}
public void toStream(final DependencyContext context, final PrintStream stream) {
super.toStream(context, stream);
stream.print(" Type : ");
stream.println(myType.getDescr(context));
stream.print(" Value : ");
stream.println(myValue == null ? "<null>" : myValue.toString());
}
}
@@ -1,4 +1,4 @@
package org.jetbrains.ether;
package org.jetbrains.jps.builders.java.dependencyView;
import com.intellij.util.io.DataExternalizer;
import gnu.trove.TIntHashSet;
@@ -1,4 +1,4 @@
package org.jetbrains.ether.dependencyView;
package org.jetbrains.jps.builders.java.dependencyView;
import java.io.PrintStream;
@@ -1,9 +1,8 @@
package org.jetbrains.ether.dependencyView;
package org.jetbrains.jps.builders.java.dependencyView;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.io.DataExternalizer;
import org.jetbrains.asm4.Type;
import org.jetbrains.ether.RW;
import java.io.DataInput;
import java.io.DataOutput;
@@ -1,10 +1,9 @@
package org.jetbrains.ether.dependencyView;
package org.jetbrains.jps.builders.java.dependencyView;
import com.intellij.util.io.DataExternalizer;
import gnu.trove.TIntHashSet;
import gnu.trove.TIntProcedure;
import org.jetbrains.asm4.Type;
import org.jetbrains.ether.RW;
import java.io.*;
import java.util.*;
@@ -4,8 +4,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.ether.dependencyView.Callbacks;
import org.jetbrains.jps.Project;
import org.jetbrains.jps.builders.java.dependencyView.Callbacks;
import org.jetbrains.jps.api.BuildType;
import org.jetbrains.jps.api.CanceledStatus;
import org.jetbrains.jps.api.GlobalOptions;
@@ -80,8 +79,7 @@ public class BuildRunner {
}
final JpsModel jpsModel = myModelLoader.loadModel();
final Project project = myModelLoader.loadOldProject();
return new ProjectDescriptor(project, jpsModel, fsState, projectTimestamps, dataManager, BuildLoggingManager.DEFAULT);
return new ProjectDescriptor(jpsModel, fsState, projectTimestamps, dataManager, BuildLoggingManager.DEFAULT);
}
public void runBuild(ProjectDescriptor pd, CanceledStatus cs, @Nullable Callbacks.ConstantAffectionResolver constantSearch,
@@ -143,7 +141,7 @@ public class BuildRunner {
final CompileScope compileScope;
if (buildType == BuildType.PROJECT_REBUILD || (modules.isEmpty() && paths.isEmpty())) {
compileScope = new AllProjectScope(pd.project, pd.jpsProject, artifacts, buildType != BuildType.MAKE);
compileScope = new AllProjectScope(pd.jpsProject, artifacts, buildType != BuildType.MAKE);
}
else {
final Set<JpsModule> forcedModules;
@@ -183,10 +181,10 @@ public class BuildRunner {
}
if (filesToCompile.isEmpty()) {
compileScope = new ModulesScope(pd.project, pd.jpsProject, forcedModules, artifacts, buildType != BuildType.MAKE, includeTests);
compileScope = new ModulesScope(pd.jpsProject, forcedModules, artifacts, buildType != BuildType.MAKE, includeTests);
}
else {
compileScope = new ModulesAndFilesScope(pd.project, pd.jpsProject, forcedModules, filesToCompile, artifacts, buildType != BuildType.MAKE, includeTests);
compileScope = new ModulesAndFilesScope(pd.jpsProject, forcedModules, filesToCompile, artifacts, buildType != BuildType.MAKE, includeTests);
}
}
return compileScope;
@@ -10,7 +10,7 @@ import com.intellij.util.io.DataOutputStream;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.Channels;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.ether.dependencyView.Callbacks;
import org.jetbrains.jps.builders.java.dependencyView.Callbacks;
import org.jetbrains.jps.api.*;
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType;
import org.jetbrains.jps.incremental.MessageHandler;
@@ -25,12 +25,10 @@ import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.util.SystemProperties;
import com.jgoodies.forms.layout.CellConstraints;
import net.n3.nanoxml.IXMLBuilder;
import org.codehaus.groovy.GroovyException;
import org.jboss.netty.util.Version;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.asm4.ClassVisitor;
import org.jetbrains.asm4.ClassWriter;
import org.jetbrains.jps.MacroExpander;
import org.jetbrains.jps.javac.JavacServer;
import org.jetbrains.jps.model.JpsModel;
import org.jetbrains.jps.model.impl.JpsModelImpl;
@@ -96,12 +94,10 @@ public class ClasspathBootstrap {
cp.add(getResourcePath(Version.class)); // netty
cp.add(getResourcePath(ClassWriter.class)); // asm
cp.add(getResourcePath(ClassVisitor.class)); // asm-commons
cp.add(getResourcePath(MacroExpander.class)); // jps-model
cp.add(getResourcePath(JpsModel.class)); // jps-project-model
cp.add(getResourcePath(JpsModelImpl.class)); // jps-project-model
cp.add(getResourcePath(JpsModel.class)); // jps-model-api
cp.add(getResourcePath(JpsModelImpl.class)); // jps-model-impl
cp.add(getResourcePath(JpsProjectLoader.class)); // jps-model-serialization
cp.add(getResourcePath(AlienFormFileException.class)); // forms-compiler
cp.add(getResourcePath(GroovyException.class)); // groovy
cp.add(getResourcePath(GridConstraints.class)); // forms-rt
cp.add(getResourcePath(CellConstraints.class)); // jgoodies-forms
cp.add(getResourcePath(NotNullVerifyingInstrumenter.class)); // not-null
@@ -1,6 +1,5 @@
package org.jetbrains.jps.cmdline;
import org.jetbrains.jps.Project;
import org.jetbrains.jps.model.JpsModel;
/**
@@ -8,6 +7,4 @@ import org.jetbrains.jps.model.JpsModel;
*/
public interface JpsModelLoader {
JpsModel loadModel();
Project loadOldProject();
}
@@ -2,9 +2,6 @@ package org.jetbrains.jps.cmdline;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.ParameterizedRunnable;
import org.jetbrains.jps.Project;
import org.jetbrains.jps.idea.IdeaProjectLoader;
import org.jetbrains.jps.idea.SystemOutErrorReporter;
import org.jetbrains.jps.model.JpsElementFactory;
import org.jetbrains.jps.model.JpsModel;
import org.jetbrains.jps.model.serialization.JpsGlobalLoader;
@@ -59,24 +56,6 @@ public class JpsModelLoaderImpl implements JpsModelLoader {
}
}
@Override
public Project loadOldProject() {
final long start = System.currentTimeMillis();
try {
final Project project = new Project();
final File projectFile = new File(myProjectPath);
final String loadPath = isDirectoryBased(projectFile) ? new File(projectFile, IDEA_PROJECT_DIRNAME).getPath() : myProjectPath;
IdeaProjectLoader.loadFromPath(project, loadPath, myPathVars, null, new SystemOutErrorReporter(false));
return project;
}
finally {
final long loadTime = System.currentTimeMillis() - start;
LOG.info("Project " + myProjectPath + " loaded in " + loadTime + " ms");
}
}
private static boolean isDirectoryBased(File projectFile) {
return !(projectFile.isFile() && projectFile.getName().endsWith(".ipr"));
}
@@ -1,6 +1,5 @@
package org.jetbrains.jps.cmdline;
import org.jetbrains.jps.Project;
import org.jetbrains.jps.incremental.BuildLoggingManager;
import org.jetbrains.jps.incremental.CompilerEncodingConfiguration;
import org.jetbrains.jps.incremental.ModuleRootsIndex;
@@ -23,7 +22,6 @@ import java.util.Set;
* Date: 1/8/12
*/
public final class ProjectDescriptor {
public final Project project;
public final JpsProject jpsProject;
public final JpsModel jpsModel;
public final BuildFSState fsState;
@@ -36,13 +34,11 @@ public final class ProjectDescriptor {
private Set<JpsSdk<?>> myProjectJavaSdks;
private CompilerEncodingConfiguration myEncodingConfiguration;
public ProjectDescriptor(Project project,
JpsModel jpsModel,
public ProjectDescriptor(JpsModel jpsModel,
BuildFSState fsState,
ProjectTimestamps timestamps,
BuildDataManager dataManager,
BuildLoggingManager loggingManager) {
this.project = project;
this.jpsModel = jpsModel;
this.jpsProject = jpsModel.getProject();
this.fsState = fsState;
@@ -50,7 +46,7 @@ public final class ProjectDescriptor {
this.dataManager = dataManager;
myLoggingManager = loggingManager;
rootsIndex = new ModuleRootsIndex(jpsModel, dataManager);
myArtifactRootsIndex = new ArtifactRootsIndex(jpsModel, project, dataManager, rootsIndex);
myArtifactRootsIndex = new ArtifactRootsIndex(jpsModel, dataManager, rootsIndex);
myProjectJavaSdks = new HashSet<JpsSdk<?>>();
myEncodingConfiguration = new CompilerEncodingConfiguration(jpsModel, rootsIndex);
for (JpsModule module : jpsProject.getModules()) {
@@ -1,7 +1,6 @@
package org.jetbrains.jps.incremental;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.Project;
import org.jetbrains.jps.builders.BuildTarget;
import org.jetbrains.jps.model.JpsProject;
import org.jetbrains.jps.model.artifact.JpsArtifact;
@@ -14,8 +13,8 @@ import java.util.Set;
* Date: 9/17/11
*/
public class AllProjectScope extends CompileScope {
public AllProjectScope(Project project, JpsProject jpsProject, Set<JpsArtifact> artifacts, boolean forcedCompilation) {
super(project, jpsProject, artifacts, forcedCompilation);
public AllProjectScope(JpsProject jpsProject, Set<JpsArtifact> artifacts, boolean forcedCompilation) {
super(jpsProject, artifacts, forcedCompilation);
}
public boolean isRecompilationForced(@NotNull BuildTarget target) {
@@ -3,12 +3,12 @@ package org.jetbrains.jps.incremental;
import com.intellij.openapi.util.UserDataHolder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.AnnotationProcessingProfile;
import org.jetbrains.jps.ModuleChunk;
import org.jetbrains.jps.ProjectChunks;
import org.jetbrains.jps.ProjectPaths;
import org.jetbrains.jps.api.CanceledStatus;
import org.jetbrains.jps.cmdline.ProjectDescriptor;
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile;
import org.jetbrains.jps.model.module.JpsModule;
/**
@@ -34,7 +34,7 @@ public interface CompileContext extends UserDataHolder, MessageHandler {
void removeBuildListener(BuildListener listener);
@NotNull
AnnotationProcessingProfile getAnnotationProcessingProfile(JpsModule module);
ProcessorConfigProfile getAnnotationProcessingProfile(JpsModule module);
boolean shouldDifferentiate(ModuleChunk chunk);
@@ -13,6 +13,9 @@ import org.jetbrains.jps.incremental.messages.BuildMessage;
import org.jetbrains.jps.incremental.messages.FileDeletedEvent;
import org.jetbrains.jps.incremental.messages.FileGeneratedEvent;
import org.jetbrains.jps.incremental.messages.ProgressMessage;
import org.jetbrains.jps.model.java.JpsJavaExtensionService;
import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration;
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile;
import org.jetbrains.jps.model.module.JpsModule;
import java.util.*;
@@ -37,7 +40,7 @@ public class CompileContextImpl extends UserDataHolderBase implements CompileCon
private final CanceledStatus myCancelStatus;
private volatile float myDone = -1.0f;
private EventDispatcher<BuildListener> myListeners = EventDispatcher.create(BuildListener.class);
private Map<JpsModule, AnnotationProcessingProfile> myAnnotationProcessingProfileMap;
private Map<JpsModule, ProcessorConfigProfile> myAnnotationProcessingProfileMap;
public CompileContextImpl(CompileScope scope,
ProjectDescriptor pd, boolean isMake,
@@ -105,18 +108,18 @@ public class CompileContextImpl extends UserDataHolderBase implements CompileCon
@Override
@NotNull
public AnnotationProcessingProfile getAnnotationProcessingProfile(JpsModule module) {
final CompilerConfiguration compilerConfig = getProjectDescriptor().project.getCompilerConfiguration();
Map<JpsModule, AnnotationProcessingProfile> map = myAnnotationProcessingProfileMap;
public ProcessorConfigProfile getAnnotationProcessingProfile(JpsModule module) {
final JpsJavaCompilerConfiguration compilerConfig = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(getProjectDescriptor().jpsProject);
Map<JpsModule, ProcessorConfigProfile> map = myAnnotationProcessingProfileMap;
if (map == null) {
map = new HashMap<JpsModule, AnnotationProcessingProfile>();
map = new HashMap<JpsModule, ProcessorConfigProfile>();
final Map<String, JpsModule> namesMap = new HashMap<String, JpsModule>();
for (JpsModule m : getProjectDescriptor().jpsProject.getModules()) {
namesMap.put(m.getName(), m);
}
if (!namesMap.isEmpty()) {
for (AnnotationProcessingProfile profile : compilerConfig.getModuleAnnotationProcessingProfiles()) {
for (String name : profile.getProcessModule()) {
for (ProcessorConfigProfile profile : compilerConfig.getAnnotationProcessingConfigurations()) {
for (String name : profile.getModuleNames()) {
final JpsModule mod = namesMap.get(name);
if (mod != null) {
map.put(mod, profile);
@@ -126,8 +129,8 @@ public class CompileContextImpl extends UserDataHolderBase implements CompileCon
}
myAnnotationProcessingProfileMap = map;
}
final AnnotationProcessingProfile profile = map.get(module);
return profile != null? profile : compilerConfig.getDefaultAnnotationProcessingProfile();
final ProcessorConfigProfile profile = map.get(module);
return profile != null? profile : compilerConfig.getDefaultAnnotationProcessingConfiguration();
}
@Override
@@ -2,7 +2,6 @@ package org.jetbrains.jps.incremental;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.ModuleChunk;
import org.jetbrains.jps.Project;
import org.jetbrains.jps.builders.BuildTarget;
import org.jetbrains.jps.model.JpsProject;
import org.jetbrains.jps.model.artifact.JpsArtifact;
@@ -15,17 +14,13 @@ import java.util.Set;
* Date: 1/15/12
*/
public abstract class CompileScope {
@NotNull
private final Project myProject;
private final JpsProject myJpsProject;
private final Set<JpsArtifact> myArtifacts;
protected final boolean myForcedCompilation;
protected CompileScope(@NotNull Project project,
JpsProject jpsProject,
protected CompileScope(JpsProject jpsProject,
Set<JpsArtifact> artifacts,
boolean forcedCompilation) {
myProject = project;
myJpsProject = jpsProject;
myArtifacts = artifacts;
myForcedCompilation = forcedCompilation;
@@ -58,11 +53,6 @@ public abstract class CompileScope {
return myArtifacts;
}
@NotNull
public final Project getProject() {
return myProject;
}
public JpsProject getJpsProject() {
return myJpsProject;
}
@@ -13,7 +13,7 @@ import com.intellij.util.io.MappingFailedException;
import com.intellij.util.io.PersistentEnumerator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.ether.dependencyView.Callbacks;
import org.jetbrains.jps.builders.java.dependencyView.Callbacks;
import org.jetbrains.jps.*;
import org.jetbrains.jps.api.CanceledStatus;
import org.jetbrains.jps.api.GlobalOptions;
@@ -28,6 +28,7 @@ import org.jetbrains.jps.incremental.java.JavaBuilderLogger;
import org.jetbrains.jps.incremental.messages.*;
import org.jetbrains.jps.incremental.storage.*;
import org.jetbrains.jps.model.java.JpsJavaExtensionService;
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile;
import org.jetbrains.jps.model.module.JpsModule;
import org.jetbrains.jps.service.SharedThreadPool;
@@ -265,7 +266,8 @@ public class IncProjectBuilder {
private void cleanOutputRoots(CompileContext context) throws ProjectBuildException {
// whole project is affected
final boolean shouldClear = context.getProjectDescriptor().project.getCompilerConfiguration().isClearOutputDirectoryOnRebuild();
final boolean shouldClear = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(
context.getProjectDescriptor().jpsProject).isClearOutputDirectoryOnRebuild();
try {
if (shouldClear) {
clearOutputs(context);
@@ -321,10 +323,10 @@ public class IncProjectBuilder {
rootsToDelete.putValue(out, target);
}
final AnnotationProcessingProfile profile = context.getAnnotationProcessingProfile(target.getModule());
final ProcessorConfigProfile profile = context.getAnnotationProcessingProfile(target.getModule());
if (profile.isEnabled()) {
File annotationOut =
paths.getAnnotationProcessorGeneratedSourcesOutputDir(target.getModule(), target.isTests(), profile.getGeneratedSourcesDirName());
paths.getAnnotationProcessorGeneratedSourcesOutputDir(target.getModule(), target.isTests(), profile.getGeneratedSourcesDirectoryName());
if (annotationOut != null) {
annotationOutputs.add(annotationOut);
}
@@ -3,8 +3,8 @@ package org.jetbrains.jps.incremental;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Pair;
import org.jetbrains.ether.dependencyView.Callbacks;
import org.jetbrains.ether.dependencyView.Mappings;
import org.jetbrains.jps.builders.java.dependencyView.Callbacks;
import org.jetbrains.jps.builders.java.dependencyView.Mappings;
import org.jetbrains.jps.ModuleChunk;
import org.jetbrains.jps.ProjectPaths;
import org.jetbrains.jps.incremental.fs.RootDescriptor;

Some files were not shown because too many files have changed in this diff Show More