Merge remote-tracking branch 'origin/master'

This commit is contained in:
Roman Shevchenko
2012-08-07 19:21:11 +04:00
39 changed files with 522 additions and 267 deletions
@@ -50,6 +50,9 @@ public class DeploymentUtilImpl extends DeploymentUtil {
@Nullable Set<String> writtenPaths,
@Nullable FileFilter fileFilter) throws IOException {
if (fileFilter != null && !fileFilter.accept(fromFile)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Skipping " + fromFile.getAbsolutePath() + ": it wasn't accepted by filter " + fileFilter);
}
return;
}
checkPathDoNotNavigatesUpFromFile(fromFile);
@@ -69,13 +72,19 @@ public class DeploymentUtilImpl extends DeploymentUtil {
}
if (fromFile.equals(toFile)
|| writtenPaths != null && !writtenPaths.add(toFile.getPath())) {
if (LOG.isDebugEnabled()) {
LOG.debug("Skipping " + fromFile.getAbsolutePath() + ": " + toFile.getAbsolutePath() + " is already written");
}
return;
}
if (!FileUtil.isFilePathAcceptable(toFile, fileFilter)) return;
if (context.getProgressIndicator() != null) {
context.getProgressIndicator().setText("Copying files");
context.getProgressIndicator().setText2(fromFile.getPath());
if (!FileUtil.isFilePathAcceptable(toFile, fileFilter)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Skipping " + fromFile.getAbsolutePath() + ": " + toFile.getAbsolutePath() + " wasn't accepted by filter " + fileFilter);
}
return;
}
context.getProgressIndicator().setText("Copying files");
context.getProgressIndicator().setText2(fromFile.getPath());
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Copy file '" + fromFile + "' to '"+toFile+"'");
@@ -28,6 +28,7 @@ import org.jetbrains.jps.incremental.BuildLoggingManager;
import org.jetbrains.jps.incremental.CompileScope;
import org.jetbrains.jps.incremental.IncProjectBuilder;
import org.jetbrains.jps.incremental.java.JavaBuilderLoggerImpl;
import org.jetbrains.jps.model.JpsElementFactory;
import org.jetbrains.jps.model.artifact.DirectoryArtifactType;
import org.jetbrains.jps.model.artifact.JpsArtifact;
import org.jetbrains.jps.model.artifact.JpsArtifactService;
@@ -114,7 +115,8 @@ public abstract class ArtifactBuilderTestCase extends JpsBuildTestCase {
protected JpsArtifact addArtifact(String name, LayoutElementTestUtil.LayoutElementCreator root) {
assertFalse("JpsArtifact " + name + " already exists", getArtifactNames().contains(name));
JpsArtifact artifact = JpsArtifactService.getInstance().addArtifact(myJpsProject, name, root.buildElement(), DirectoryArtifactType.INSTANCE);
JpsArtifact artifact = JpsArtifactService.getInstance().addArtifact(myJpsProject, name, root.buildElement(), DirectoryArtifactType.INSTANCE,
JpsElementFactory.getInstance().createDummyElement());
artifact.setOutputPath(getAbsolutePath("out/artifacts/" + name));
return artifact;
}
@@ -1,8 +1,10 @@
package org.jetbrains.jps.model.artifact;
import org.jetbrains.jps.model.JpsDummyElement;
/**
* @author nik
*/
public class DirectoryArtifactType extends JpsArtifactType {
public class DirectoryArtifactType extends JpsArtifactType<JpsDummyElement> {
public static final DirectoryArtifactType INSTANCE = new DirectoryArtifactType();
}
@@ -1,8 +1,10 @@
package org.jetbrains.jps.model.artifact;
import org.jetbrains.jps.model.JpsDummyElement;
/**
* @author nik
*/
public class JarArtifactType extends JpsArtifactType {
public class JarArtifactType extends JpsArtifactType<JpsDummyElement> {
public static final JarArtifactType INSTANCE = new JarArtifactType();
}
@@ -3,6 +3,7 @@ package org.jetbrains.jps.model.artifact;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsCompositeElement;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.JpsNamedElement;
import org.jetbrains.jps.model.JpsReferenceableElement;
import org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement;
@@ -12,7 +13,7 @@ import org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement;
*/
public interface JpsArtifact extends JpsNamedElement, JpsReferenceableElement<JpsArtifact>, JpsCompositeElement {
@NotNull
JpsArtifactType getArtifactType();
JpsArtifactType<?> getArtifactType();
@Nullable
String getOutputPath();
@@ -31,4 +32,6 @@ public interface JpsArtifact extends JpsNamedElement, JpsReferenceableElement<Jp
JpsArtifactReference createReference();
void setBuildOnMake(boolean buildOnMake);
JpsElement getProperties();
}
@@ -1,6 +1,7 @@
package org.jetbrains.jps.model.artifact;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.JpsProject;
import org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement;
import org.jetbrains.jps.service.JpsServiceManager;
@@ -16,14 +17,14 @@ public abstract class JpsArtifactService {
return JpsServiceManager.getInstance().getService(JpsArtifactService.class);
}
public abstract JpsArtifact createArtifact(String name, JpsCompositePackagingElement rootElement, JpsArtifactType type);
public abstract <P extends JpsElement> JpsArtifact createArtifact(@NotNull String name, @NotNull JpsCompositePackagingElement rootElement,
@NotNull JpsArtifactType<P> type, @NotNull P properties);
public abstract List<JpsArtifact> getArtifacts(@NotNull JpsProject project);
public abstract JpsArtifact addArtifact(@NotNull JpsProject project,
@NotNull String name,
@NotNull JpsCompositePackagingElement rootElement,
@NotNull JpsArtifactType type);
public abstract <P extends JpsElement> JpsArtifact addArtifact(@NotNull JpsProject project, @NotNull String name,
@NotNull JpsCompositePackagingElement rootElement,
@NotNull JpsArtifactType<P> type, @NotNull P properties);
public abstract JpsArtifactReference createReference(@NotNull String artifactName);
}
@@ -1,14 +1,16 @@
package org.jetbrains.jps.model.artifact;
import org.jetbrains.jps.model.DummyJpsElementProperties;
import org.jetbrains.jps.model.JpsElementType;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.JpsElementChildRole;
/**
* @author nik
*/
public abstract class JpsArtifactType extends JpsElementType<DummyJpsElementProperties> {
@Override
public DummyJpsElementProperties createCopy(DummyJpsElementProperties properties) {
return DummyJpsElementProperties.INSTANCE;
public abstract class JpsArtifactType<P extends JpsElement> {
private final JpsElementChildRole<P> myPropertiesRole = new JpsElementChildRole<P>();
public final JpsElementChildRole<P> getPropertiesRole() {
return myPropertiesRole;
}
}
@@ -3,42 +3,42 @@ package org.jetbrains.jps.model.artifact.impl;
import com.intellij.openapi.util.Comparing;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.DummyJpsElementProperties;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.JpsElementChildRole;
import org.jetbrains.jps.model.artifact.JpsArtifact;
import org.jetbrains.jps.model.artifact.JpsArtifactType;
import org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement;
import org.jetbrains.jps.model.impl.JpsElementChildRoleBase;
import org.jetbrains.jps.model.impl.JpsNamedCompositeElementBase;
import org.jetbrains.jps.model.impl.JpsTypedDataImpl;
import org.jetbrains.jps.model.impl.JpsTypedDataRole;
/**
* @author nik
*/
public class JpsArtifactImpl extends JpsNamedCompositeElementBase<JpsArtifactImpl> implements JpsArtifact {
public class JpsArtifactImpl<P extends JpsElement> extends JpsNamedCompositeElementBase<JpsArtifactImpl<P>> implements JpsArtifact {
private static final JpsElementChildRole<JpsCompositePackagingElement>
ROOT_ELEMENT_CHILD_ROLE = JpsElementChildRoleBase.create("root element");
private static final JpsTypedDataRole<JpsArtifactType> TYPED_DATA_ROLE = new JpsTypedDataRole<JpsArtifactType>();
private final JpsArtifactType<P> myArtifactType;
private String myOutputPath;
private boolean myBuildOnMake;
public JpsArtifactImpl(@NotNull String name, @NotNull JpsCompositePackagingElement rootElement, @NotNull JpsArtifactType type) {
public JpsArtifactImpl(@NotNull String name, @NotNull JpsCompositePackagingElement rootElement, @NotNull JpsArtifactType<P> type, @NotNull P properties) {
super(name);
myArtifactType = type;
myContainer.setChild(ROOT_ELEMENT_CHILD_ROLE, rootElement);
myContainer.setChild(TYPED_DATA_ROLE, new JpsTypedDataImpl<JpsArtifactType>(type, DummyJpsElementProperties.INSTANCE));
myContainer.setChild(type.getPropertiesRole(), properties);
}
private JpsArtifactImpl(JpsArtifactImpl original) {
private JpsArtifactImpl(JpsArtifactImpl<P> original) {
super(original);
myArtifactType = original.myArtifactType;
myOutputPath = original.myOutputPath;
}
@NotNull
@Override
public JpsArtifactImpl createCopy() {
return new JpsArtifactImpl(this);
public JpsArtifactImpl<P> createCopy() {
return new JpsArtifactImpl<P>(this);
}
public String getOutputPath() {
@@ -54,8 +54,8 @@ public class JpsArtifactImpl extends JpsNamedCompositeElementBase<JpsArtifactImp
@NotNull
@Override
public JpsArtifactType getArtifactType() {
return myContainer.getChild(TYPED_DATA_ROLE).getType();
public JpsArtifactType<P> getArtifactType() {
return myArtifactType;
}
@NotNull
@@ -75,6 +75,11 @@ public class JpsArtifactImpl extends JpsNamedCompositeElementBase<JpsArtifactImp
myContainer.setChild(ROOT_ELEMENT_CHILD_ROLE, rootElement);
}
@Override
public P getProperties() {
return myContainer.getChild(myArtifactType.getPropertiesRole());
}
@Override
public boolean isBuildOnMake() {
return myBuildOnMake;
@@ -1,6 +1,7 @@
package org.jetbrains.jps.model.artifact.impl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.JpsProject;
import org.jetbrains.jps.model.artifact.JpsArtifact;
import org.jetbrains.jps.model.artifact.JpsArtifactReference;
@@ -16,6 +17,7 @@ import java.util.List;
* @author nik
*/
public class JpsArtifactServiceImpl extends JpsArtifactService {
@Override
public List<JpsArtifact> getArtifacts(@NotNull JpsProject project) {
JpsElementCollectionImpl<JpsArtifact> collection = project.getContainer().getChild(JpsArtifactRole.ARTIFACT_COLLECTION_ROLE);
@@ -23,15 +25,20 @@ public class JpsArtifactServiceImpl extends JpsArtifactService {
}
@Override
public JpsArtifact addArtifact(@NotNull JpsProject project, @NotNull String name, @NotNull JpsCompositePackagingElement rootElement,
@NotNull JpsArtifactType type) {
JpsArtifact artifact = createArtifact(name, rootElement, type);
public <P extends JpsElement> JpsArtifact addArtifact(@NotNull JpsProject project,
@NotNull String name,
@NotNull JpsCompositePackagingElement rootElement,
@NotNull JpsArtifactType<P> type,
@NotNull P properties) {
JpsArtifact artifact = createArtifact(name, rootElement, type, properties);
return project.getContainer().getOrSetChild(JpsArtifactRole.ARTIFACT_COLLECTION_ROLE).addChild(artifact);
}
@Override
public JpsArtifact createArtifact(String name, JpsCompositePackagingElement rootElement, JpsArtifactType type) {
return new JpsArtifactImpl(name, rootElement, type);
public <P extends JpsElement> JpsArtifact createArtifact(@NotNull String name, @NotNull JpsCompositePackagingElement rootElement,
@NotNull JpsArtifactType<P> type, @NotNull P properties) {
return new JpsArtifactImpl<P>(name, rootElement, type, properties);
}
@Override
@@ -8,7 +8,7 @@ import org.jetbrains.jps.model.JpsElementReference;
import org.jetbrains.jps.model.JpsProject;
import org.jetbrains.jps.model.module.JpsDependencyElement;
import org.jetbrains.jps.model.module.JpsModule;
import org.jetbrains.jps.model.serialization.artifact.JpsArtifactTypeSerializer;
import org.jetbrains.jps.model.serialization.artifact.JpsArtifactPropertiesSerializer;
import org.jetbrains.jps.model.serialization.artifact.JpsPackagingElementSerializer;
import org.jetbrains.jps.model.serialization.facet.JpsModuleExtensionLoader;
import org.jetbrains.jps.service.JpsServiceManager;
@@ -83,7 +83,7 @@ public abstract class JpsModelSerializerExtension {
return Collections.emptyList();
}
public List<JpsArtifactTypeSerializer> getArtifactTypeSerializers() {
public List<? extends JpsArtifactPropertiesSerializer<?>> getArtifactTypePropertiesSerializers() {
return Collections.emptyList();
}
}
@@ -1,6 +1,7 @@
package org.jetbrains.jps.model.serialization;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.module.JpsModuleType;
@@ -14,4 +15,6 @@ public abstract class JpsModulePropertiesSerializer<P extends JpsElement> extend
}
public abstract P loadProperties(@Nullable Element moduleRootElement);
public abstract void saveProperties(@NotNull P properties, @NotNull Element moduleRootElement);
}
@@ -180,6 +180,10 @@ public class JpsProjectLoader extends JpsLoaderBase {
public JpsDummyElement loadProperties(@Nullable Element moduleRootElement) {
return JpsElementFactory.getInstance().createDummyElement();
}
@Override
public void saveProperties(@NotNull JpsDummyElement properties, @NotNull Element moduleRootElement) {
}
};
}
}
@@ -0,0 +1,25 @@
package org.jetbrains.jps.model.serialization.artifact;
import org.jetbrains.jps.model.JpsDummyElement;
import org.jetbrains.jps.model.JpsElementFactory;
import org.jetbrains.jps.model.artifact.JpsArtifactType;
import java.util.List;
/**
* @author nik
*/
public class JpsArtifactDummyPropertiesSerializer extends JpsArtifactPropertiesSerializer<JpsDummyElement> {
public JpsArtifactDummyPropertiesSerializer(String typeId, JpsArtifactType<JpsDummyElement> type) {
super(typeId, type);
}
@Override
public JpsDummyElement loadProperties(List<ArtifactPropertiesState> stateList) {
return JpsElementFactory.getInstance().createDummyElement();
}
@Override
public void saveProperties(JpsDummyElement properties, List<ArtifactPropertiesState> stateList) {
}
}
@@ -0,0 +1,20 @@
package org.jetbrains.jps.model.serialization.artifact;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.artifact.JpsArtifactType;
import org.jetbrains.jps.model.serialization.JpsElementPropertiesSerializer;
import java.util.List;
/**
* @author nik
*/
public abstract class JpsArtifactPropertiesSerializer<P extends JpsElement> extends JpsElementPropertiesSerializer<P, JpsArtifactType<P>> {
public JpsArtifactPropertiesSerializer(String typeId, JpsArtifactType<P> type) {
super(type, typeId);
}
public abstract P loadProperties(List<ArtifactPropertiesState> stateList);
public abstract void saveProperties(P properties, List<ArtifactPropertiesState> stateList);
}
@@ -6,10 +6,7 @@ import com.intellij.util.xmlb.XmlSerializer;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsCompositeElement;
import org.jetbrains.jps.model.JpsElementFactory;
import org.jetbrains.jps.model.JpsElementReference;
import org.jetbrains.jps.model.JpsProject;
import org.jetbrains.jps.model.*;
import org.jetbrains.jps.model.artifact.*;
import org.jetbrains.jps.model.artifact.elements.*;
import org.jetbrains.jps.model.library.JpsLibraryReference;
@@ -31,9 +28,9 @@ public class JpsArtifactSerializer {
new LibraryFilesElementSerializer(),
new ArtifactOutputElementSerializer()
};
private static final JpsArtifactTypeSerializer[] STANDARD_TYPE_SERIALIZERS = {
new JpsArtifactTypeSerializer("plain", DirectoryArtifactType.INSTANCE),
new JpsArtifactTypeSerializer("jar", JarArtifactType.INSTANCE)
private static final JpsArtifactPropertiesSerializer<?>[] STANDARD_TYPE_SERIALIZERS = {
new JpsArtifactDummyPropertiesSerializer("plain", DirectoryArtifactType.INSTANCE),
new JpsArtifactDummyPropertiesSerializer("jar", JarArtifactType.INSTANCE)
};
private static final String ELEMENT_TAG = "element";
private static final String ID_ATTRIBUTE = "id";
@@ -45,13 +42,18 @@ public class JpsArtifactSerializer {
for (Element artifactElement : JDOMUtil.getChildren(componentElement, "artifact")) {
ArtifactState state = XmlSerializer.deserialize(artifactElement, ArtifactState.class);
if (state == null) continue;
JpsArtifactType artifactType = getTypeSerializer(state.getArtifactType()).getType();
JpsPackagingElement rootElement = loadPackagingElement(state.getRootElement());
if (rootElement != null) {
JpsArtifact artifact = service.addArtifact(project, state.getName(), (JpsCompositePackagingElement)rootElement, artifactType);
artifact.setBuildOnMake(state.isBuildOnMake());
artifact.setOutputPath(state.getOutputPath());
}
JpsArtifactPropertiesSerializer<?> serializer = getTypePropertiesSerializer(state.getArtifactType());
loadArtifact(project, service, state, serializer);
}
}
private static <P extends JpsElement> void loadArtifact(JpsProject project, JpsArtifactService service, ArtifactState state, JpsArtifactPropertiesSerializer<P> serializer) {
JpsPackagingElement rootElement = loadPackagingElement(state.getRootElement());
if (rootElement != null) {
JpsArtifact artifact = service.addArtifact(project, state.getName(), (JpsCompositePackagingElement)rootElement,
serializer.getType(), serializer.loadProperties(state.getPropertiesList()));
artifact.setBuildOnMake(state.isBuildOnMake());
artifact.setOutputPath(state.getOutputPath());
}
}
@@ -60,8 +62,16 @@ public class JpsArtifactSerializer {
state.setName(artifact.getName());
state.setBuildOnMake(artifact.isBuildOnMake());
state.setOutputPath(artifact.getOutputPath());
state.setArtifactType(getTypeSerializer(artifact.getArtifactType()).getTypeId());
JpsArtifactPropertiesSerializer<?> serializer = getTypePropertiesSerializer(artifact.getArtifactType());
doSaveArtifact(artifact, componentElement, state, serializer);
}
private static <P extends JpsElement> void doSaveArtifact(JpsArtifact artifact, Element componentElement, ArtifactState state,
JpsArtifactPropertiesSerializer<P> serializer) {
state.setArtifactType(serializer.getTypeId());
state.setRootElement(savePackagingElement(artifact.getRootElement()));
//noinspection unchecked
serializer.saveProperties((P)artifact.getProperties(), state.getPropertiesList());
componentElement.addContent(XmlSerializer.serialize(state, SERIALIZATION_FILTERS));
}
@@ -138,14 +148,14 @@ public class JpsArtifactSerializer {
throw new IllegalArgumentException("Serializer not found for " + elementClass);
}
private static JpsArtifactTypeSerializer getTypeSerializer(String typeId) {
for (JpsArtifactTypeSerializer serializer : STANDARD_TYPE_SERIALIZERS) {
private static JpsArtifactPropertiesSerializer<?> getTypePropertiesSerializer(String typeId) {
for (JpsArtifactPropertiesSerializer serializer : STANDARD_TYPE_SERIALIZERS) {
if (serializer.getTypeId().equals(typeId)) {
return serializer;
}
}
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
for (JpsArtifactTypeSerializer serializer : extension.getArtifactTypeSerializers()) {
for (JpsArtifactPropertiesSerializer serializer : extension.getArtifactTypePropertiesSerializers()) {
if (serializer.getTypeId().equals(typeId)) {
return serializer;
}
@@ -154,14 +164,14 @@ public class JpsArtifactSerializer {
return STANDARD_TYPE_SERIALIZERS[0];
}
private static JpsArtifactTypeSerializer getTypeSerializer(JpsArtifactType type) {
for (JpsArtifactTypeSerializer serializer : STANDARD_TYPE_SERIALIZERS) {
private static JpsArtifactPropertiesSerializer<?> getTypePropertiesSerializer(JpsArtifactType type) {
for (JpsArtifactPropertiesSerializer serializer : STANDARD_TYPE_SERIALIZERS) {
if (serializer.getType().equals(type)) {
return serializer;
}
}
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
for (JpsArtifactTypeSerializer serializer : extension.getArtifactTypeSerializers()) {
for (JpsArtifactPropertiesSerializer serializer : extension.getArtifactTypePropertiesSerializers()) {
if (serializer.getType().equals(type)) {
return serializer;
}
@@ -1,24 +0,0 @@
package org.jetbrains.jps.model.serialization.artifact;
import org.jetbrains.jps.model.artifact.JpsArtifactType;
/**
* @author nik
*/
public class JpsArtifactTypeSerializer {
private final String myTypeId;
private final JpsArtifactType myType;
public JpsArtifactTypeSerializer(String typeId, JpsArtifactType type) {
myTypeId = typeId;
myType = type;
}
public String getTypeId() {
return myTypeId;
}
public JpsArtifactType getType() {
return myType;
}
}
@@ -118,8 +118,9 @@ public class BaseIndentEnterHandler extends EnterHandlerDelegateAdapter {
if (type == myLineCommentType) {
final String restString = editorCharSequence.subSequence(caret, document.getLineEndOffset(lineNumber)).toString();
if (!StringUtil.isEmptyOrSpaces(restString)) {
EditorModificationUtil.insertStringAtCaret(editor, "\n" + lineIndent + myLineCommentPrefix);
editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(lineNumber + 1, 1));
final String linePrefix = lineIndent + myLineCommentPrefix;
EditorModificationUtil.insertStringAtCaret(editor, "\n" + linePrefix);
editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(lineNumber + 1, linePrefix.length()));
return Result.Stop;
}
else if (iterator.getStart() < lineStartOffset) {
@@ -18,14 +18,14 @@ package com.intellij.codeInsight.editorActions.wordSelection;
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiComment;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiPlainText;
import com.intellij.util.containers.CollectionFactory;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -38,28 +38,31 @@ public class NaturalLanguageTextSelectioner extends ExtendWordSelectionHandlerBa
return e instanceof PsiPlainText || e instanceof PsiComment;
}
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
final SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
return Collections.emptyList();
private static TextRange findParagraphRange(String text, int start, int end) {
int paragraphStart = text.lastIndexOf("\n\n", start);
int paragraphEnd = text.indexOf("\n\n", end);
return new TextRange(paragraphStart >= 0 ? paragraphStart + 2 : 0, paragraphEnd < 0 ? text.length() : paragraphEnd);
}
@Nullable
private static TextRange findCustomRange(String text, int start, int end, char startChar, char endChar) {
int prev = text.lastIndexOf(startChar, start);
int next = text.indexOf(endChar, end);
if (prev < 0 || next < 0) {
return null;
}
if (prev + 1 < start || next > end) {
return new TextRange(prev + 1, next);
}
int sentenceStart = selectionModel.getSelectionStart();
final int elementStart = e.getTextRange().getStartOffset();
if (sentenceStart <= elementStart) return Collections.emptyList();
return new TextRange(prev, next + 1);
}
int paragraphStart = editorText.subSequence(elementStart, sentenceStart).toString().lastIndexOf("\n\n");
if (paragraphStart < 0) paragraphStart = elementStart;
else paragraphStart += 2 + elementStart;
boolean isParagraph = paragraphStart == sentenceStart;
private static TextRange findSentenceRange(String editorText, int start, int end) {
int sentenceStart = start;
while (sentenceStart > paragraphStart) {
final char c = editorText.charAt(sentenceStart - 1);
if (!isNatural(c)) {
return Collections.emptyList();
}
if (SENTENCE_END.contains(c)) {
while (sentenceStart > 0) {
if (isSentenceEnd(editorText, sentenceStart - 1) || !isNatural(editorText.charAt(sentenceStart - 1))) {
break;
}
sentenceStart--;
@@ -68,40 +71,90 @@ public class NaturalLanguageTextSelectioner extends ExtendWordSelectionHandlerBa
sentenceStart++;
}
int sentenceEnd = selectionModel.getSelectionEnd();
final int elementEnd = e.getTextRange().getEndOffset();
if (sentenceEnd > elementEnd) {
return Collections.emptyList();
}
int paragraphEnd = editorText.subSequence(sentenceEnd, elementEnd).toString().indexOf("\n\n");
if (paragraphEnd < 0) paragraphEnd = elementEnd;
else paragraphEnd += sentenceEnd;
isParagraph &= paragraphEnd == sentenceEnd;
if (isParagraph) {
return Collections.emptyList(); //whole text
}
if (sentenceEnd > elementStart) sentenceEnd--;
while (sentenceEnd < paragraphEnd) {
final char c = editorText.charAt(sentenceEnd);
if (!isNatural(c)) {
return Collections.emptyList();
}
int sentenceEnd = Math.max(0, end - 1);
while (sentenceEnd < editorText.length()) {
sentenceEnd++;
if (SENTENCE_END.contains(c)) {
if (isSentenceEnd(editorText, sentenceEnd - 1)) {
break;
}
}
return new TextRange(sentenceStart, sentenceEnd);
}
private static boolean isSentenceEnd(String text, final int i) {
return SENTENCE_END.contains(text.charAt(i)) && (i + 1 == text.length() || Character.isWhitespace(text.charAt(i + 1)));
}
private static TextRange findNaturalRange(String editorText, int start, int end) {
while (start > 0) {
if (!isNatural(editorText.charAt(start - 1))) {
break;
}
start--;
}
if (sentenceStart == selectionModel.getSelectionStart() && sentenceEnd == selectionModel.getSelectionEnd()) {
return Arrays.asList(new TextRange(paragraphStart, paragraphEnd));
while (end < editorText.length()) {
final char c = editorText.charAt(end);
if (!isNatural(c)) {
break;
}
end++;
}
return new TextRange(start, end);
}
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
TextRange range = expandSelection(e, editorText, cursorOffset, cursorOffset);
if (range == null) {
return Collections.emptyList();
}
return Arrays.asList(new TextRange(sentenceStart, sentenceEnd));
ArrayList<TextRange> result = new ArrayList<TextRange>();
result.add(range);
while (true) {
TextRange next = expandSelection(e, editorText, range.getStartOffset(), range.getEndOffset());
if (next == null || next.equals(range)) {
break;
}
result.add(next);
range = next;
}
return result;
}
@Nullable
private static TextRange expandSelection(PsiElement e, CharSequence editorText, int selStart, int selEnd) {
TextRange range = e.getTextRange();
int shift = range.getStartOffset();
if (selStart <= shift || selEnd >= range.getEndOffset()) {
return null;
}
String elementText = editorText.subSequence(shift, range.getEndOffset()).toString();
int start = selStart - shift;
int end = selEnd - shift;
TextRange best = findSentenceRange(elementText, start, end);
best = narrowRange(best, findCustomRange(elementText, start, end, '\"', '\"'));
best = narrowRange(best, findCustomRange(elementText, start, end, '(', ')'));
TextRange natural = findNaturalRange(elementText, start, end);
if (!natural.contains(best)) {
return null;
}
TextRange paragraph = findParagraphRange(elementText, start, end);
if (best.getStartOffset() == start && best.getEndOffset() == end || !paragraph.contains(best)) {
return paragraph.shiftRight(shift);
}
return best.shiftRight(shift);
}
private static TextRange narrowRange(TextRange best, TextRange candidate) {
return candidate != null && best.contains(candidate) ? candidate : best;
}
private static boolean isNatural(char c) {
@@ -33,6 +33,7 @@ import com.intellij.navigation.ItemPresentation;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.MnemonicHelper;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.editor.Editor;
@@ -292,21 +293,36 @@ public class FileStructurePopup implements Disposable {
}
IdeFocusManager.getInstance(myProject).requestFocus(myTree, true);
myFilteringStructure.rebuild();
myAbstractTreeBuilder.queueUpdate().doWhenDone(new Runnable() {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
myTreeHasBuilt.setDone();
//noinspection SSBasedInspection
SwingUtilities.invokeLater(new Runnable() {
final AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
try {
myFilteringStructure.rebuild();
}
finally {
token.finish();
}
myAbstractTreeBuilder.queueUpdate().doWhenDone(new Runnable() {
@Override
public void run() {
selectPsiElement(myInitialPsiElement);
myTreeHasBuilt.setDone();
//noinspection SSBasedInspection
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
selectPsiElement(myInitialPsiElement);
}
});
}
});
installUpdater();
}
});
}
private void installUpdater() {
if (!ApplicationManager.getApplication().isUnitTestMode()) {
final Alarm alarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD, myPopup);
alarm.addRequest(new Runnable() {
@@ -330,24 +346,26 @@ public class FileStructurePopup implements Disposable {
myAbstractTreeBuilder.refilter(null, false, false).doWhenProcessed(new Runnable() {
@Override
public void run() {
myTree.repaint();
if (isBackspace && handleBackspace(filter)) {
return;
}
if (myFilteringStructure.getRootElement().getChildren().length == 0) {
for (JCheckBox box : myCheckBoxes.values()) {
if (!box.isSelected()) {
myAutoClicked.add(box);
myTriggeredCheckboxes.add(0, Pair.create(filter, box));
box.doClick();
filter = "";
break;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
myTree.repaint();
if (isBackspace && handleBackspace(filter)) {
return;
}
if (myFilteringStructure.getRootElement().getChildren().length == 0) {
for (JCheckBox box : myCheckBoxes.values()) {
if (!box.isSelected()) {
myAutoClicked.add(box);
myTriggeredCheckboxes.add(0, Pair.create(filter, box));
box.doClick();
filter = "";
break;
}
}
}
}
}
//if (mySpeedSearch.isPopupActive()) {
// mySpeedSearch.refreshSelection();
//}
});
}
});
}
@@ -93,6 +93,10 @@ public abstract class Property<T extends PropertiesContainer> {
return false;
}
public boolean isDefaultValueWithDepth(@NotNull T container) throws Exception {
return isDefaultValue(container);
}
public void setDefaultValue(@NotNull T container) throws Exception {
}
@@ -436,7 +436,7 @@ public abstract class PropertyTable extends JBTable {
private void addProperty(PropertiesContainer<?> component, Property property, List<Property> properties) {
if (property.isExpert() && !myShowExpertProperties) {
try {
if (property.isDefaultValue(component)) {
if (property.isDefaultValueWithDepth(component)) {
return;
}
}
@@ -152,7 +152,7 @@ default.tostring.call.problem.descriptor=Call to default 'toString()' on <code>#
octal.and.decimal.integers.in.same.array.display.name=Octal and decimal integers in same array
octal.and.decimal.integers.in.same.array.problem.descriptor=Octal and decimal integers in the same array initializer #loc
result.of.object.allocation.ignored.display.name=Result of object allocation ignored
result.of.object.allocation.ignored.problem.descriptor=Result of <code>new #ref()</code> is ignored. #loc
result.of.object.allocation.ignored.problem.descriptor=Result of <code>new #ref()</code> is ignored #loc
use.0index.in.jdbc.resultset.display.name=Use of index 0 in JDBC ResultSet
use.0index.in.jdbc.resultset.problem.descriptor=Use of index '0' in JDBC ResultSet #loc
use.0index.in.jdbc.prepared.statement.problem.descriptor=Use of index '0' in JDBC PreparedStatement #loc
@@ -951,8 +951,8 @@ throw.caught.locally.problem.descriptor=<code>#ref</code> caught by containing '
throw.caught.locally.ignore.option=Ignore rethrown exceptions
return.from.finally.block.problem.descriptor=<code>#ref</code> inside 'finally' block #loc
continue.or.break.from.finally.block.problem.descriptor=<code>#ref</code> inside 'finally' block #loc
bad.exception.declared.problem.descriptor=Prohibited exception <code>#ref</code> declared. #loc
bad.exception.caught.problem.descriptor=Prohibited exception <code>#ref</code> caught. #loc
bad.exception.declared.problem.descriptor=Prohibited exception <code>#ref</code> declared #loc
bad.exception.caught.problem.descriptor=Prohibited exception <code>#ref</code> caught #loc
checked.exception.class.problem.descriptor=Checked exception class <code>#ref</code> #loc
unchecked.exception.class.problem.descriptor=Unchecked exception class <code>#ref</code> #loc
thread.death.rethrown.problem.descriptor=<code>#ref</code> not rethrown #loc
@@ -1458,6 +1458,8 @@ interface.never.implemented.option=Ignore interfaces which only declare constant
size.replaceable.by.isempty.display.name='size() == 0' replaceable with 'isEmpty()'
size.replaceable.by.isempty.quickfix=Replace with 'isEmpty()'
size.replaceable.by.isempty.negation.ignore.option=Ignore expressions which would be replaced with '!isEmpty()'
ignored.classes.table=Ignored classes
choose.class.type.to.ignore=Choose class type to ignore
loop.condition.not.updated.inside.loop.display.name=Loop variable not updated inside loop
loop.condition.not.updated.inside.loop.problem.descriptor='#ref' is not updated inside loop #loc
utility.class.without.private.constructor.option=Ignore classes with only a main method
@@ -150,12 +150,8 @@ public class EmptyClassInspection extends BaseInspection {
if (initializers.length > 0) {
return;
}
if (ignoreClassWithParameterization) {
final PsiReferenceList extendsList = aClass.getExtendsList();
final PsiReferenceList implementsList = aClass.getImplementsList();
if (isSuperParameterization(extendsList) || isSuperParameterization(implementsList)) {
return;
}
if (ignoreClassWithParameterization && isSuperParametrization(aClass)) {
return;
}
if (AnnotationUtil.isAnnotated(aClass, ignorableAnnotations)) {
return;
@@ -166,7 +162,7 @@ public class EmptyClassInspection extends BaseInspection {
registerClassError(aClass, aClass);
}
private boolean isSuperParameterization(PsiReferenceList extendsList) {
private boolean hasTypeArguments(PsiReferenceList extendsList) {
if (extendsList == null) {
return false;
}
@@ -183,5 +179,26 @@ public class EmptyClassInspection extends BaseInspection {
}
return false;
}
private boolean isSuperParametrization(PsiClass aClass) {
if (!(aClass instanceof PsiAnonymousClass)) {
final PsiReferenceList extendsList = aClass.getExtendsList();
final PsiReferenceList implementsList = aClass.getImplementsList();
return hasTypeArguments(extendsList) || hasTypeArguments(implementsList);
}
final PsiAnonymousClass anonymousClass = (PsiAnonymousClass)aClass;
final PsiJavaCodeReferenceElement reference = anonymousClass.getBaseClassReference();
final PsiReferenceParameterList parameterList = reference.getParameterList();
if (parameterList == null) {
return false;
}
final PsiTypeElement[] elements = parameterList.getTypeParameterElements();
for (PsiTypeElement element : elements) {
if (element != null) {
return true;
}
}
return false;
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2011 Bas Leijdekkers
* Copyright 2006-2012 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,15 @@
package com.siyeh.ig.style;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
import com.intellij.codeInspection.ui.ListTable;
import com.intellij.codeInspection.ui.ListWrappingTableModel;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.OrderedSet;
import com.intellij.util.ui.CheckBox;
import com.siyeh.HardcodedMethodConstants;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
@@ -28,36 +32,47 @@ import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.psiutils.ComparisonUtils;
import com.siyeh.ig.psiutils.ExpressionUtils;
import com.siyeh.ig.ui.UiUtils;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
public class SizeReplaceableByIsEmptyInspection extends BaseInspection {
@SuppressWarnings({"PublicField"})
public boolean ignoreNegations = false;
@SuppressWarnings("PublicField")
public OrderedSet<String> ignoredTypes = new OrderedSet();
@Override
@NotNull
public String getDisplayName() {
return InspectionGadgetsBundle.message(
"size.replaceable.by.isempty.display.name");
return InspectionGadgetsBundle.message("size.replaceable.by.isempty.display.name");
}
@Override
@NotNull
protected String buildErrorString(Object... infos) {
return InspectionGadgetsBundle.message(
"expression.can.be.replaced.problem.descriptor", infos[0]);
return InspectionGadgetsBundle.message("expression.can.be.replaced.problem.descriptor", infos[0]);
}
@Override
@Nullable
public JComponent createOptionsPanel() {
return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message(
final JComponent panel = new JPanel(new BorderLayout());
final ListTable table =
new ListTable(new ListWrappingTableModel(ignoredTypes, InspectionGadgetsBundle.message("ignored.classes.table")));
JPanel tablePanel =
UiUtils.createAddRemoveTreeClassChooserPanel(table, InspectionGadgetsBundle.message("choose.class.type.to.ignore"));
final CheckBox checkBox = new CheckBox(InspectionGadgetsBundle.message(
"size.replaceable.by.isempty.negation.ignore.option"), this, "ignoreNegations");
panel.add(tablePanel, BorderLayout.CENTER);
panel.add(checkBox, BorderLayout.SOUTH);
return panel;
}
@Override
@@ -71,8 +86,7 @@ public class SizeReplaceableByIsEmptyInspection extends BaseInspection {
@NotNull
public String getName() {
return InspectionGadgetsBundle.message(
"size.replaceable.by.isempty.quickfix");
return InspectionGadgetsBundle.message("size.replaceable.by.isempty.quickfix");
}
@Override
@@ -195,6 +209,11 @@ public class SizeReplaceableByIsEmptyInspection extends BaseInspection {
if (aClass == null) {
return null;
}
for (String ignoredType : ignoredTypes) {
if (InheritanceUtil.isInheritor(aClass, ignoredType)) {
return null;
}
}
final PsiMethod[] methods = aClass.findMethodsByName("isEmpty", true);
for (PsiMethod method : methods) {
final PsiParameterList parameterList = method.getParameterList();
@@ -4,6 +4,10 @@ This inspection reports any <b>.size()</b> or <b>.length()</b>
comparisons with a <b>0</b> literal which can be replaced with a call to <b>.isEmpty()</b>.
<!-- tooltip end -->
<p>
Use the table below to add classes for which any <b>.size()</b> or <b>.length()</b> comparisons should not be replaced.
<p>
Use the checkbox below to ignore any expressions which would be replaced with '!isEmpty()'.
<p>
<small>Powered by InspectionGadgets</small>
</body>
</html>
@@ -1,9 +1,9 @@
package com.siyeh.igtest.classlayout.emptyclass;
public class EmptyClass {
{
System.out.println("");
final java.util.ArrayList<String> stringList = new java.util.ArrayList<String>() {};
System.out.println("");
}
}
class MyList extends java.util.ArrayList<String> {}
@@ -16,7 +16,7 @@
<grid id="bf5ad" binding="myProGuardPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="true"/>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none">
@@ -18,6 +18,7 @@ package org.jetbrains.android.sdk;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.projectRoots.*;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -77,7 +78,10 @@ public class AndroidSdkConfigurable implements AdditionalDataConfigurable {
public boolean isModified() {
final AndroidSdkAdditionalData data = (AndroidSdkAdditionalData)mySdk.getSdkAdditionalData();
Sdk javaSdk = data != null ? data.getJavaSdk() : null;
return javaSdk != myForm.getSelectedSdk();
final String javaSdkHomePath = javaSdk != null ? javaSdk.getHomePath() : null;
final Sdk selectedSdk = myForm.getSelectedSdk();
final String selectedSdkHomePath = selectedSdk != null ? selectedSdk.getHomePath() : null;
return !FileUtil.pathsEqual(javaSdkHomePath, selectedSdkHomePath);
}
@Override
@@ -49,6 +49,8 @@ class AndroidSdkConfigurableForm {
private final DefaultComboBoxModel myBuildTargetsModel = new DefaultComboBoxModel();
private String mySdkLocation;
private boolean myFreeze = false;
public AndroidSdkConfigurableForm(@NotNull SdkModel sdkModel, @NotNull final SdkModificator sdkModificator) {
mySdkModel = sdkModel;
myInternalJdkComboBox.setModel(myJdksModel);
@@ -76,6 +78,9 @@ class AndroidSdkConfigurableForm {
myBuildTargetComboBox.addItemListener(new ItemListener() {
public void itemStateChanged(final ItemEvent e) {
if (myFreeze) {
return;
}
final IAndroidTarget target = (IAndroidTarget)e.getItem();
List<OrderRoot> roots = AndroidSdkUtils.getLibraryRootsForTarget(target, mySdkLocation);
@@ -138,18 +143,10 @@ class AndroidSdkConfigurableForm {
mySdkLocation = androidSdk != null ? androidSdk.getHomePath() : null;
AndroidSdkData androidSdkData = mySdkLocation != null ? AndroidSdkData.parse(mySdkLocation, new EmptySdkLog()) : null;
updateBuildTargets(androidSdkData);
if (buildTarget != null) {
for (int i = 0; i < myBuildTargetsModel.getSize(); i++) {
IAndroidTarget target = (IAndroidTarget)myBuildTargetsModel.getElementAt(i);
if (buildTarget.hashString().equals(target.hashString())) {
myBuildTargetComboBox.setSelectedIndex(i);
return;
}
}
}
myBuildTargetComboBox.setSelectedItem(null);
myFreeze = true;
updateBuildTargets(androidSdkData, buildTarget);
myFreeze = false;
}
private void updateJdks() {
@@ -161,7 +158,7 @@ class AndroidSdkConfigurableForm {
}
}
private void updateBuildTargets(AndroidSdkData androidSdkData) {
private void updateBuildTargets(AndroidSdkData androidSdkData, IAndroidTarget buildTarget) {
myBuildTargetsModel.removeAllElements();
if (androidSdkData != null) {
@@ -169,6 +166,17 @@ class AndroidSdkConfigurableForm {
myBuildTargetsModel.addElement(target);
}
}
if (buildTarget != null) {
for (int i = 0; i < myBuildTargetsModel.getSize(); i++) {
IAndroidTarget target = (IAndroidTarget)myBuildTargetsModel.getElementAt(i);
if (buildTarget.hashString().equals(target.hashString())) {
myBuildTargetComboBox.setSelectedIndex(i);
return;
}
}
}
myBuildTargetComboBox.setSelectedItem(null);
}
public void addJavaSdk(Sdk sdk) {
@@ -27,6 +27,7 @@ import org.jetbrains.jps.devkit.model.JpsIdeaSdkType;
import org.jetbrains.jps.devkit.model.JpsPluginModuleProperties;
import org.jetbrains.jps.incremental.artifacts.JpsSyntheticArtifactProvider;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.JpsElementFactory;
import org.jetbrains.jps.model.JpsModel;
import org.jetbrains.jps.model.JpsSimpleElement;
import org.jetbrains.jps.model.artifact.DirectoryArtifactType;
@@ -61,8 +62,10 @@ public class JpsPluginSyntheticArtifactProvider extends JpsSyntheticArtifactProv
for (JpsModule module : model.getProject().getModules()) {
JpsElement propertiesElement = module.getProperties();
if (propertiesElement instanceof JpsSimpleElement) {
JpsPluginModuleProperties properties = ((JpsSimpleElement<JpsPluginModuleProperties>)propertiesElement).getProperties();
artifacts.add(createArtifact(module, properties));
Object properties = ((JpsSimpleElement)propertiesElement).getProperties();
if (properties instanceof JpsPluginModuleProperties) {
artifacts.add(createArtifact(module, (JpsPluginModuleProperties)properties));
}
}
}
return artifacts;
@@ -120,7 +123,7 @@ public class JpsPluginSyntheticArtifactProvider extends JpsSyntheticArtifactProv
}
String name = module.getName() + ":plugin";
JpsArtifact artifact = JpsArtifactService.getInstance().createArtifact(name, root, DirectoryArtifactType.INSTANCE);
JpsArtifact artifact = JpsArtifactService.getInstance().createArtifact(name, root, DirectoryArtifactType.INSTANCE, JpsElementFactory.getInstance().createDummyElement());
JpsTypedLibrary<JpsIdeaSdkProperties> sdk = module.getSdk(JpsIdeaSdkType.INSTANCE);
if (sdk != null) {
@@ -15,21 +15,27 @@
*/
package org.jetbrains.jps.devkit.model;
import org.jetbrains.annotations.Nullable;
/**
* @author nik
*/
public class JpsPluginModuleProperties {
private final String myPluginXmlUrl;
private final String myManifestFileUrl;
public JpsPluginModuleProperties(String pluginXmlUrl) {
public JpsPluginModuleProperties(@Nullable String pluginXmlUrl, @Nullable String manifestFileUrl) {
myPluginXmlUrl = pluginXmlUrl;
myManifestFileUrl = manifestFileUrl;
}
public JpsPluginModuleProperties(JpsPluginModuleProperties properties) {
myPluginXmlUrl = properties.getPluginXmlUrl();
}
@Nullable
public String getPluginXmlUrl() {
return myPluginXmlUrl;
}
@Nullable
public String getManifestFileUrl() {
return myManifestFileUrl;
}
}
@@ -76,15 +76,35 @@ public class JpsDevKitModelSerializerExtension extends JpsModelSerializerExtensi
}
private static class JpsPluginModulePropertiesSerializer extends JpsModulePropertiesSerializer<JpsSimpleElement<JpsPluginModuleProperties>> {
private static final String URL_ATTRIBUTE = "url";
private static final String MANIFEST_ATTRIBUTE = "manifest";
private static final String COMPONENT_NAME = "DevKit.ModuleBuildProperties";
private JpsPluginModulePropertiesSerializer() {
super(JpsPluginModuleType.INSTANCE, "PLUGIN_MODULE");
}
@Override
public JpsSimpleElement<JpsPluginModuleProperties> loadProperties(@Nullable Element moduleRootElement) {
Element component = JpsLoaderBase.findComponent(moduleRootElement, "DevKit.ModuleBuildProperties");
String pluginXmlUrl = component != null ? component.getAttributeValue("url") : null;
return JpsElementFactory.getInstance().createSimpleElement(new JpsPluginModuleProperties(pluginXmlUrl));
Element component = JpsLoaderBase.findComponent(moduleRootElement, COMPONENT_NAME);
String pluginXmlUrl = component != null ? component.getAttributeValue(URL_ATTRIBUTE) : null;
String manifestFileUrl = component != null ? component.getAttributeValue(MANIFEST_ATTRIBUTE) : null;
return JpsElementFactory.getInstance().createSimpleElement(new JpsPluginModuleProperties(pluginXmlUrl, manifestFileUrl));
}
@Override
public void saveProperties(@NotNull JpsSimpleElement<JpsPluginModuleProperties> element, @NotNull Element moduleRootElement) {
Element component = JpsLoaderBase.findComponent(moduleRootElement, COMPONENT_NAME);
if (component != null) {
String pluginXmlUrl = element.getProperties().getPluginXmlUrl();
if (pluginXmlUrl != null) {
component.setAttribute(URL_ATTRIBUTE, pluginXmlUrl);
}
String manifestFileUrl = element.getProperties().getManifestFileUrl();
if (manifestFileUrl != null) {
component.setAttribute(MANIFEST_ATTRIBUTE, manifestFileUrl);
}
}
}
}
}
@@ -20,6 +20,8 @@ import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pass;
@@ -103,18 +105,19 @@ public class ConvertConcatenationToGstringIntention extends Intention {
finally {
accessToken.finish();
}
final Document document = editor.getDocument();
if (expressions.size() == 1) {
invokeImpl(expressions.get(0));
invokeImpl(expressions.get(0), document);
}
else if (expressions.size() > 0) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
invokeImpl(expressions.get(expressions.size() - 1));
invokeImpl(expressions.get(expressions.size() - 1), document);
return;
}
IntroduceTargetChooser.showChooser(editor, expressions,
new Pass<GrExpression>() {
public void pass(final GrExpression selectedValue) {
invokeImpl(selectedValue);
invokeImpl(selectedValue, document);
}
},
new Function<GrExpression, String>() {
@@ -127,7 +130,7 @@ public class ConvertConcatenationToGstringIntention extends Intention {
}
}
private static void invokeImpl(PsiElement element) {
private static void invokeImpl(final PsiElement element, Document document) {
boolean isMultiline = containsMultilineStrings((GrExpression)element);
StringBuilder builder = new StringBuilder(element.getTextLength());
@@ -145,16 +148,21 @@ public class ConvertConcatenationToGstringIntention extends Intention {
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(element.getProject());
final GrExpression newExpr = factory.createExpressionFromText(GrStringUtil.addQuotes(text, true));
final AccessToken accessToken = WriteAction.start();
try {
final GrExpression expression = ((GrExpression)element).replaceWithExpression(newExpr, true);
if (expression instanceof GrString) {
GrStringUtil.removeUnnecessaryBracesInGString((GrString)expression);
CommandProcessor.getInstance().executeCommand(element.getProject(), new Runnable() {
@Override
public void run() {
final AccessToken accessToken = WriteAction.start();
try {
final GrExpression expression = ((GrExpression)element).replaceWithExpression(newExpr, true);
if (expression instanceof GrString) {
GrStringUtil.removeUnnecessaryBracesInGString((GrString)expression);
}
}
finally {
accessToken.finish();
}
}
}
finally {
accessToken.finish();
}
}, null, null, document);
}
private static boolean containsMultilineStrings(GrExpression expr) {
@@ -20,8 +20,10 @@ import com.intellij.psi.PsiReference;
import com.intellij.util.ThreeState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.console.GroovyShellAction;
import org.jetbrains.plugins.groovy.extensions.GroovyScriptTypeDetector;
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrForStatement;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
@@ -45,6 +47,11 @@ public class GroovyCompletionConfidence extends CompletionConfidence {
public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) {
final PsiElement position = parameters.getPosition();
PsiFile file = position.getContainingFile();
if (file instanceof GroovyFile && GroovyScriptTypeDetector.getScriptType((GroovyFile)file) != GroovyScriptTypeDetector.DEFAULT_TYPE) {
return ThreeState.NO;
}
if (position.getParent() instanceof GrReferenceElement &&
psiElement().afterLeaf(psiElement().withText("(").withParent(GrForStatement.class)).accepts(position)) {
return ThreeState.NO;
@@ -531,7 +531,6 @@ public abstract class GroovyRefactoringUtil {
argText.append("[");
for (PsiElement argument : arguments) {
argText.append(argument.getText()).append(", ");
argument.delete();
}
if (arguments.size() > 0) {
argText.delete(argText.length() - 2, argText.length());
@@ -547,7 +546,7 @@ public abstract class GroovyRefactoringUtil {
}
return GroovyPsiElementFactory.getInstance(project).createExpressionFromText(argText.toString());
}
public static boolean hasSideEffect(@NotNull GroovyPsiElement statement) {
final Ref<Boolean> hasSideEffect = new Ref<Boolean>(false);
statement.accept(new GroovyRecursiveElementVisitor() {
@@ -516,6 +516,9 @@ public class GrChangeSignatureUsageProcessor implements ChangeSignatureUsageProc
(i != parameters.length - 1 || !parameter.isVarargType())) {
final PsiType type = parameter.createType(changeInfo.getMethod().getParameterList(), argumentList.getManager());
final GrExpression arg = GroovyRefactoringUtil.generateArgFromMultiArg(substitutor, arguments, type, element.getProject());
for (PsiElement argument : arguments) {
argument.delete();
}
anchor = argumentList.addAfter(arg, anchor);
GrReferenceAdjuster.shortenReferences(anchor);
}
@@ -13,39 +13,33 @@
* limitations under the License.
*/
package org.jetbrains.plugins.groovy.refactoring.inline;
import com.intellij.lang.ASTNode;
import com.intellij.lang.refactoring.InlineHandler;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
import com.intellij.psi.impl.source.tree.TreeElement;
import com.intellij.refactoring.inline.GenericInlineHandler;
import com.intellij.refactoring.util.CommonRefactoringUtil;
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import junit.framework.Assert;
import org.jetbrains.plugins.groovy.GroovyFileType;
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
import org.jetbrains.plugins.groovy.refactoring.GroovyRefactoringUtil;
import org.jetbrains.plugins.groovy.util.TestUtils;
import java.util.List;
package org.jetbrains.plugins.groovy.refactoring.inline
import com.intellij.lang.ASTNode
import com.intellij.lang.refactoring.InlineHandler
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil
import com.intellij.psi.impl.source.tree.TreeElement
import com.intellij.refactoring.inline.GenericInlineHandler
import com.intellij.refactoring.util.CommonRefactoringUtil
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import junit.framework.Assert
import org.jetbrains.plugins.groovy.GroovyFileType
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression
import org.jetbrains.plugins.groovy.refactoring.GroovyRefactoringUtil
import org.jetbrains.plugins.groovy.util.TestUtils
/**
* @author ilyas
*/
public class InlineMethodTest extends LightCodeInsightFixtureTestCase {
@Override
protected String getBasePath() {
return TestUtils.getTestDataPath() + "groovy/refactoring/inlineMethod/";
}
final String basePath = TestUtils.testDataPath + "groovy/refactoring/inlineMethod/";
public void testAbstr1() throws Throwable { doTest(); }
public void testBlock1() throws Throwable { doTest(); }
@@ -105,31 +99,27 @@ public class InlineMethodTest extends LightCodeInsightFixtureTestCase {
public void testVarargs() {doTest();}
public void testInlineAll() throws Throwable {
public void testInlineAll() {
doTest(new GroovyInlineHandler() {
@Override
public Settings prepareInlineElement(PsiElement element, Editor editor, boolean invokedOnReference) {
return new Settings() {
public InlineHandler.Settings prepareInlineElement(PsiElement element, Editor editor, boolean invokedOnReference) {
return new InlineHandler.Settings() {
@Override
public boolean isOnlyOneReferenceToInline() {
return false;
}
};
boolean isOnlyOneReferenceToInline() {false}
}
}
});
})
}
public void testInlineNamedArgs() {
doTest();
}
public void testInlineNamedArgs() {doTest(); }
public void testInlineVarargs() {doTest()}
protected void doTest() {
doTest(new GroovyInlineHandler());
}
protected void doTest(InlineHandler handler) {
doInlineTest(myFixture, getTestDataPath() + getTestName(true) + ".test", handler);
doInlineTest(myFixture, testDataPath + getTestName(true) + ".test", handler);
}
public static void doInlineTest(final JavaCodeInsightTestFixture fixture,
@@ -140,32 +130,32 @@ public class InlineMethodTest extends LightCodeInsightFixtureTestCase {
fixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, fileText);
final PsiFile file = fixture.getFile();
final Editor editor = fixture.getEditor();
setIndentationToNode(file.getNode());
int startOffset = editor.getSelectionModel().getSelectionStart();
int endOffset = editor.getSelectionModel().getSelectionEnd();
editor.getCaretModel().moveToOffset(endOffset);
final PsiFile file = fixture.file;
final Editor editor = fixture.editor;
indentationToNode = file.node;
int startOffset = editor.selectionModel.selectionStart;
int endOffset = editor.selectionModel.selectionEnd;
editor.caretModel.moveToOffset(endOffset);
GroovyPsiElement selectedArea = GroovyRefactoringUtil.findElementInRange(file, startOffset, endOffset, GrReferenceExpression.class);
if (selectedArea == null) {
PsiElement identifier = GroovyRefactoringUtil.findElementInRange(file, startOffset, endOffset, PsiElement.class);
if (identifier != null){
Assert.assertTrue("Selected area doesn't point to method", identifier.getParent() instanceof GrVariable);
selectedArea = (GroovyPsiElement)identifier.getParent();
Assert.assertTrue("Selected area doesn't point to method", identifier.parent instanceof GrVariable);
selectedArea = (GroovyPsiElement)identifier.parent;
}
}
Assert.assertNotNull("Selected area reference points to nothing", selectedArea);
PsiElement element = selectedArea instanceof GrExpression ? selectedArea.getReference().resolve() : selectedArea;
PsiElement element = selectedArea instanceof GrExpression ? selectedArea.reference.resolve() : selectedArea;
Assert.assertNotNull("Cannot resolve selected reference expression", element);
try {
GenericInlineHandler.invoke(element, editor, inlineHandler);
editor.getSelectionModel().removeSelection();
editor.selectionModel.removeSelection();
fixture.checkResult(data.get(1), true);
}
catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
assertEquals(data.get(1), "FAIL: " + e.getMessage());
assertEquals(data.get(1), "FAIL: " + e.message);
}
}
@@ -174,7 +164,7 @@ public class InlineMethodTest extends LightCodeInsightFixtureTestCase {
CodeEditUtil.setOldIndentation(((TreeElement) element), 0);
}
for (ASTNode node : element.getChildren(null)) {
setIndentationToNode(node);
indentationToNode = node;
}
}
@@ -0,0 +1,18 @@
void foo(String... s) {
println 'hello'
bar(s)
}
void bar(String... s) {}
<selection>foo</selection>("foo", "bar")
-----
void foo(String... s) {
println 'hello'
bar(s)
}
void bar(String... s) {}
println 'hello'
bar(["foo", "bar"] as java.lang.String[])
@@ -259,7 +259,7 @@ public class MavenModuleImporter {
List<String> processors = myMavenProject.getDeclaredAnnotationProcessors();
if (processors == null && options.isEmpty() && "target/generated-sources/annotations".equals(annotationProcessorDirectory)) {
if (processors == null && options.isEmpty() && "target/generated-sources/annotations".equals(annotationProcessorDirectory.replace('\\', '/'))) {
if (moduleProfile != null) {
compilerConfiguration.removeModuleProcessorProfile(moduleProfile);
}