Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created by IntelliJ IDEA.
* User: yole
* Date: 15.11.2006
* Time: 18:05:20
*/
package com.intellij.openapi.diff.impl.patch;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.LineTokenizer;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.changes.TransparentlyFailedValue;
import com.intellij.openapi.vcs.changes.TransparentlyFailedValueI;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PatchReader {
@NonNls public static final String NO_NEWLINE_SIGNATURE = UnifiedDiffWriter.NO_NEWLINE_SIGNATURE;
private final List myLines;
private final PatchReader.PatchContentParser myPatchContentParser;
private final AdditionalInfoParser myAdditionalInfoParser;
private List myPatches;
private enum DiffFormat { CONTEXT, UNIFIED }
@NonNls private static final String CONTEXT_HUNK_PREFIX = "***************";
@NonNls private static final String CONTEXT_FILE_PREFIX = "*** ";
@NonNls private static final Pattern ourUnifiedHunkStartPattern = Pattern.compile("@@ -(\\d+)(,(\\d+))? \\+(\\d+)(,(\\d+))? @@.*");
@NonNls private static final Pattern ourContextBeforeHunkStartPattern = Pattern.compile("\\*\\*\\* (\\d+),(\\d+) \\*\\*\\*\\*");
@NonNls private static final Pattern ourContextAfterHunkStartPattern = Pattern.compile("--- (\\d+),(\\d+) ----");
public PatchReader(CharSequence patchContent) {
this(patchContent, true);
}
public PatchReader(CharSequence patchContent, boolean saveHunks) {
myLines = LineTokenizer.tokenizeIntoList(patchContent, false);
myAdditionalInfoParser = new AdditionalInfoParser(!saveHunks);
myPatchContentParser = new PatchContentParser(saveHunks);
}
public List readAllPatches() throws PatchSyntaxException {
parseAllPatches();
return myPatches;
}
@Nullable
public CharSequence getBaseRevision(final Project project, final String relativeFilePath) {
final Map> map = myAdditionalInfoParser.getResultMap();
if (! map.isEmpty()) {
final Map inner = map.get(relativeFilePath);
if (inner != null) {
final BaseRevisionTextPatchEP baseRevisionTextPatchEP = Extensions.findExtension(PatchEP.EP_NAME, project, BaseRevisionTextPatchEP.class);
if (baseRevisionTextPatchEP != null) {
return inner.get(baseRevisionTextPatchEP.getName());
}
}
}
return null;
}
/*private void callAdditionalInfoExtensions() {
final Map> map = myAdditionalInfoParser.getResultMap();
if (! map.isEmpty()) {
PatchEP[] extensions = Extensions.getExtensions(PatchEP.EP_NAME, myProject);
final Map byName = new HashMap();
for (PatchEP extension : extensions) {
byName.put(extension.getName(), extension);
}
if (extensions == null || extensions.length == 0) return;
for (Map.Entry> entry : map.entrySet()) {
final String path = entry.getKey();
final Map extensionToContents = entry.getValue();
for (Map.Entry innerEntry : extensionToContents.entrySet()) {
final PatchEP patchEP = byName.get(innerEntry.getKey());
if (patchEP != null) {
patchEP.consumeContentBeforePatchApplied(path, innerEntry.getValue(), myCommitContext);
}
}
}
}
}*/
public List getPatches() {
return myPatches;
}
public void parseAllPatches() throws PatchSyntaxException {
final ListIterator iterator = myLines.listIterator();
if (! iterator.hasNext()) {
myPatches = Collections.emptyList();
return;
}
String next;
boolean containsAdditional = false;
while (iterator.hasNext()) {
next = iterator.next();
final boolean containsAdditionalNow = myAdditionalInfoParser.testIsStart(next);
if (containsAdditionalNow && containsAdditional) {
myAdditionalInfoParser.acceptError(new PatchSyntaxException(iterator.previousIndex(), "Contains additional information without patch itself"));
}
if (containsAdditionalNow) {
containsAdditional = containsAdditionalNow;
myAdditionalInfoParser.parse(next, iterator);
if (! iterator.hasNext()) {
myAdditionalInfoParser.acceptError(new PatchSyntaxException(iterator.previousIndex(), "Contains additional information without patch itself"));
break;
}
next = iterator.next();
}
if (myPatchContentParser.testIsStart(next)) {
myPatchContentParser.parse(next, iterator);
//iterator.previous(); // to correctly initialize next
if (containsAdditional) {
final String lastName = myPatchContentParser.getLastName();
if (lastName == null) {
myAdditionalInfoParser.acceptError(new PatchSyntaxException(iterator.previousIndex(), "Contains additional information without patch itself"));
} else {
myAdditionalInfoParser.copyToResult(lastName);
}
}
containsAdditional = false;
}
}
myPatches = myPatchContentParser.getResult();
}
public TransparentlyFailedValueI