Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref #945: formatting - Exclude new expressions #948

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.JavaResolveResult;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiCallExpression;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
Expand Down Expand Up @@ -656,11 +657,11 @@ private static boolean testMethod(PsiFile file, int offset, Predicate<? super Ps
if (element == null) {
LOG.debug("No element cannot be found at index %d".formatted(offset));
} else if (element instanceof PsiIdentifier) {
PsiMethodCallExpression parent = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class);
PsiCallExpression parent = PsiTreeUtil.getParentOfType(element, PsiCallExpression.class);
if (parent == null) {
LOG.debug("The parent PsiMethodCallExpression of the element at index %d cannot be found".formatted(offset));
} else {
JavaResolveResult[] results = parent.getMethodExpression().multiResolve(false);
LOG.debug("The parent PsiCallExpression of the element at index %d cannot be found".formatted(offset));
} else if (parent instanceof PsiMethodCallExpression methodCallExpression) {
JavaResolveResult[] results = methodCallExpression.getMethodExpression().multiResolve(false);
if (results.length == 0) {
LOG.debug("The method corresponding to the element at index %d cannot be resolved".formatted(offset));
} else if (Arrays.stream(results).map(JavaResolveResult::getElement)
Expand All @@ -671,6 +672,8 @@ private static boolean testMethod(PsiFile file, int offset, Predicate<? super Ps
} else {
LOG.trace("The method doesn't match with the predicate");
}
} else {
LOG.debug("The parent PsiCallExpression of the element at index %d is not a method call".formatted(offset));
}
} else {
LOG.trace("The element at index %d is not a PsiIdentifier".formatted(offset));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ public void testFormatting879() {
doTest("Formatting879", null);
}

/**
* Ensures that the test case defined in <a href="https://github.com/camel-tooling/camel-idea-plugin/issues/945">#945</a>
* is properly fixed.
*/
public void testFormatting945() {
doTest("Formatting945", null);
}

/**
* Ensures that a partial format not including a route has no effect.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;

public class Formatting945 extends RouteBuilder {
@Override
public void configure() {
from("direct:start")
.doTry()
.process(new ProcessorFail())
.to("mock:result")
.doCatch(IOException.class, IllegalStateException.class)
.to("mock:catch")
.doFinally()
.to("mock:finally")
.end();

from("direct:start2")
.doTry()
.unmarshal(new JacksonDataFormat(objectMapper, Foo.class))
.doCatch(JsonProcessingException.class)
.to("direct:deserialization-error-handler")
.end()
}

public static class ProcessorFail implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
throw new IOException("Forced");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;

public class Formatting945 extends RouteBuilder {
@Override
public void configure() {
from("direct:start")
.doTry()
.process(new ProcessorFail())
.to("mock:result")
.doCatch(IOException.class, IllegalStateException.class)
.to("mock:catch")
.doFinally()
.to("mock:finally")
.end();

from("direct:start2")
.doTry()
.unmarshal(new JacksonDataFormat(objectMapper, Foo.class))
.doCatch(JsonProcessingException.class)
.to("direct:deserialization-error-handler")
.end()
}

public static class ProcessorFail implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
throw new IOException("Forced");
}
}
}
Loading