fix: use baeldung intellij formatter

This commit is contained in:
exaucae 2023-02-27 12:16:25 +00:00
parent a6330243e7
commit c61004285c
4 changed files with 12 additions and 21 deletions

View File

@ -5,7 +5,6 @@ import java.lang.invoke.MethodHandle;
import static java.lang.foreign.ValueLayout.*; import static java.lang.foreign.ValueLayout.*;
public class Greetings { public class Greetings {
public static void main(String[] args) throws Throwable { public static void main(String[] args) throws Throwable {
@ -20,14 +19,14 @@ public class Greetings {
FunctionDescriptor descriptor = FunctionDescriptor.of(JAVA_INT, ADDRESS); FunctionDescriptor descriptor = FunctionDescriptor.of(JAVA_INT, ADDRESS);
MethodHandle methodHandle = loaderLookup.lookup(symbolName) MethodHandle methodHandle = loaderLookup.lookup(symbolName)
.or(() -> stdlibLookup.lookup(symbolName)) .or(() -> stdlibLookup.lookup(symbolName))
.map(symbolSegment -> nativeLinker.downcallHandle(symbolSegment, descriptor)) .map(symbolSegment -> nativeLinker.downcallHandle(symbolSegment, descriptor))
.orElse(null); .orElse(null);
if (methodHandle == null) {
if(methodHandle == null){
throw new NoSuchMethodError("Method Handle was not found"); throw new NoSuchMethodError("Method Handle was not found");
}; }
;
try (MemorySession memorySession = MemorySession.openConfined()) { try (MemorySession memorySession = MemorySession.openConfined()) {
MemorySegment greetingSegment = memorySession.allocateUtf8String(greeting); MemorySegment greetingSegment = memorySession.allocateUtf8String(greeting);

View File

@ -5,15 +5,12 @@ import java.lang.foreign.MemorySession;
import java.lang.foreign.ValueLayout; import java.lang.foreign.ValueLayout;
import java.lang.foreign.SegmentAllocator; import java.lang.foreign.SegmentAllocator;
public class MemoryAllocation { public class MemoryAllocation {
public static void main(String[] args) throws Throwable { public static void main(String[] args) throws Throwable {
try (MemorySession session = MemorySession.openConfined()) { try (MemorySession session = MemorySession.openConfined()) {
String[] greetingStrings = {"hello", "world", "panama", "baeldung"}; String[] greetingStrings = { "hello", "world", "panama", "baeldung" };
SegmentAllocator allocator = SegmentAllocator.implicitAllocator(); SegmentAllocator allocator = SegmentAllocator.implicitAllocator();
MemorySegment offHeapSegment = allocator.allocateArray(ValueLayout.ADDRESS, greetingStrings.length); MemorySegment offHeapSegment = allocator.allocateArray(ValueLayout.ADDRESS, greetingStrings.length);
for (int i = 0; i < greetingStrings.length; i++) { for (int i = 0; i < greetingStrings.length; i++) {

View File

@ -10,18 +10,13 @@ import static java.lang.foreign.MemoryLayout.sequenceLayout;
import static java.lang.foreign.MemoryLayout.structLayout; import static java.lang.foreign.MemoryLayout.structLayout;
import static java.lang.foreign.ValueLayout.*; import static java.lang.foreign.ValueLayout.*;
public class MemoryLayout { public class MemoryLayout {
public static void main(String[] args) { public static void main(String[] args) {
GroupLayout pointLayout = structLayout( GroupLayout pointLayout = structLayout(JAVA_DOUBLE.withName("x"), JAVA_DOUBLE.withName("y"));
JAVA_DOUBLE.withName("x"),
JAVA_DOUBLE.withName("y")
);
SequenceLayout ptsLayout = sequenceLayout(10, SequenceLayout ptsLayout = sequenceLayout(10, pointLayout);
pointLayout);
VarHandle xvarHandle = pointLayout.varHandle(PathElement.groupElement("x")); VarHandle xvarHandle = pointLayout.varHandle(PathElement.groupElement("x"));
VarHandle yvarHandle = pointLayout.varHandle(PathElement.groupElement("y")); VarHandle yvarHandle = pointLayout.varHandle(PathElement.groupElement("y"));

View File

@ -2,7 +2,7 @@ package com.baeldung.java.panama.jextract;
import java.lang.foreign.MemorySegment; import java.lang.foreign.MemorySegment;
import java.lang.foreign.MemorySession; import java.lang.foreign.MemorySession;
// Generate JExtract bingings before uncommenting // Generate JExtract bindings before uncommenting
// import static foreign.c.stdio_h.printf; // import static foreign.c.stdio_h.printf;
public class Greetings { public class Greetings {
@ -12,8 +12,8 @@ public class Greetings {
try (MemorySession memorySession = MemorySession.openConfined()) { try (MemorySession memorySession = MemorySession.openConfined()) {
MemorySegment greetingSegment = memorySession.allocateUtf8String(greeting); MemorySegment greetingSegment = memorySession.allocateUtf8String(greeting);
// Generate JExtract bingings before uncommenting // Generate JExtract bingings before uncommenting
// printf(greetingSegment); // printf(greetingSegment);
} }
} }
} }