Skip to content

Commit

Permalink
Merge branch 'apache:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Honza-cz authored Oct 8, 2023
2 parents db8b8b3 + 7a21a21 commit 9810035
Show file tree
Hide file tree
Showing 41 changed files with 1,600 additions and 164 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,10 @@ jobs:
if: env.test_java == 'true' && success()
run: ant $OPTS -f java/java.completion test

- name: java.editor.base
if: env.test_java == 'true' && success()
run: ant $OPTS -f java/java.editor.base test

- name: java.editor
if: env.test_java == 'true' && success()
run: .github/retry.sh ant $OPTS -f java/java.editor test-unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import org.netbeans.api.java.lexer.JavaTokenId;
import org.netbeans.api.java.source.*;
import org.netbeans.api.java.source.support.ReferencesCount;
import org.netbeans.api.lexer.PartType;
import org.netbeans.api.lexer.TokenHierarchy;
import org.netbeans.api.lexer.TokenSequence;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.netbeans.modules.parsing.api.UserTask;
Expand Down Expand Up @@ -233,8 +235,11 @@ Env getCompletionEnvironment(CompilationController controller, boolean bottomUpS
ts.token().id().primaryCategory().startsWith("string") || //NOI18N
ts.token().id().primaryCategory().equals("literal")) //NOI18N
{ //TODO: Use isKeyword(...) when available
prefix = ts.token().text().toString().substring(0, len);
offset = ts.offset();
String prefixInToken = ts.token().text().toString().substring(0, len);
if (!ts.token().id().primaryCategory().startsWith("string") || !prefixInToken.endsWith("\\{")) {
prefix = prefixInToken;
offset = ts.offset();
}
} else if ((ts.token().id() == JavaTokenId.DOUBLE_LITERAL
|| ts.token().id() == JavaTokenId.FLOAT_LITERAL
|| ts.token().id() == JavaTokenId.FLOAT_LITERAL_INVALID
Expand Down Expand Up @@ -308,7 +313,7 @@ private Env getEnvImpl(CompilationController controller, TreePath orig, TreePath
&& (parent.getKind() == Tree.Kind.METHOD || TreeUtilities.CLASS_TREE_KINDS.contains(parent.getKind()))) {
controller.toPhase(withinAnonymousOrLocalClass(tu, path) ? JavaSource.Phase.RESOLVED : JavaSource.Phase.ELEMENTS_RESOLVED);
int blockPos = (int) sourcePositions.getStartPosition(root, tree);
String blockText = controller.getText().substring(blockPos, upToOffset ? offset : (int) sourcePositions.getEndPosition(root, tree));
String blockText = fixStringTemplates(path, controller.getText().substring(blockPos, upToOffset ? offset : (int) sourcePositions.getEndPosition(root, tree)));
final SourcePositions[] sp = new SourcePositions[1];
final StatementTree block = (((BlockTree) tree).isStatic() ? tu.parseStaticBlock(blockText, sp) : tu.parseStatement(blockText, sp));
if (block == null) {
Expand Down Expand Up @@ -618,7 +623,34 @@ public Tree.Kind getKind() {
}
return null;
}


private static String fixStringTemplates(TreePath tp, String blockText) {
if (!blockText.contains("\\{")) {
return blockText;
}

TokenHierarchy<String> th = TokenHierarchy.create(blockText, JavaTokenId.language());
TokenSequence<JavaTokenId> ts = th.tokenSequence(JavaTokenId.language());
StringBuilder augmented = new StringBuilder();

augmented.append(blockText);
ts.moveEnd();

while (ts.movePrevious()) {
if ((ts.token().id() == JavaTokenId.STRING_LITERAL ||
ts.token().id() == JavaTokenId.MULTILINE_STRING_LITERAL) &&
ts.token().partType() == PartType.START) {
if (ts.token().id() == JavaTokenId.STRING_LITERAL) {
augmented.append("}\"");
} else {
augmented.append("}\"\"\"");
}
}
}

return augmented.toString();
}

private static String whitespaceString(int length) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ protected void resolve(CompilationController controller) throws IOException {
case DECONSTRUCTION_PATTERN:
insideDeconstructionRecordPattern(env);
break;
case TEMPLATE:
insideStringTemplate(env);
break;
}
}

Expand Down Expand Up @@ -3389,6 +3392,16 @@ private boolean isSealedSupported(final Env env) {
return env.getController().getSourceVersion().compareTo(SourceVersion.RELEASE_15) >= 0;
}

private void insideStringTemplate(Env env) throws IOException {
final int offset = env.getOffset();
final TreePath path = env.getPath();
TokenSequence<JavaTokenId> ts = findLastNonWhitespaceToken(env, path.getLeaf(), offset);
if (ts.token().id() == JavaTokenId.STRING_LITERAL || ts.token().id() == JavaTokenId.MULTILINE_STRING_LITERAL) {
localResult(env);
addValueKeywords(env);
}
}

private void localResult(Env env) throws IOException {
addLocalMembersAndVars(env);
addClassTypes(env, null);
Expand Down Expand Up @@ -6170,6 +6183,10 @@ public boolean accept(Element e, TypeMirror t) {
break;
case BLOCK:
return null;
case TEMPLATE:
//TODO:can there be good smart types?
//(how about incomplete String templates?)
return null;
}
lastTree = tree;
path = path.getParentPath();
Expand Down Expand Up @@ -6597,4 +6614,5 @@ private static ElementKind simplifyElementKind(ElementKind kind) {
}
return kind;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
Integer i
String str
protected native Object clone()
public boolean equals(Object arg0)
protected void finalize()
public String get1(String str, Integer i)
public String get2(String str, Integer i)
public String get3(String str, Integer i)
public final native Class<?> getClass()
public native int hashCode()
public final native void notify()
public final native void notifyAll()
public String toString()
public final void wait()
public final native void wait(long arg0)
public final void wait(long arg0, int arg1)
boolean
byte
char
double
false
float
int
long
new
null
short
super
this
true
AbstractMethodError
Appendable
ArithmeticException
ArrayIndexOutOfBoundsException
ArrayStoreException
AssertionError
AutoCloseable
Boolean
BootstrapMethodError
Byte
CharSequence
Character
Class
ClassCastException
ClassCircularityError
ClassFormatError
ClassLoader
ClassNotFoundException
ClassValue
CloneNotSupportedException
Cloneable
Comparable
Compiler
Deprecated
Double
Enum
EnumConstantNotPresentException
Error
Exception
ExceptionInInitializerError
Float
FunctionalInterface
IllegalAccessError
IllegalAccessException
IllegalArgumentException
IllegalMonitorStateException
IllegalStateException
IllegalThreadStateException
IncompatibleClassChangeError
IndexOutOfBoundsException
InheritableThreadLocal
InstantiationError
InstantiationException
Integer
InternalError
InterruptedException
Iterable
LinkageError
Long
Math
NegativeArraySizeException
NoClassDefFoundError
NoSuchFieldError
NoSuchFieldException
NoSuchMethodError
NoSuchMethodException
NullPointerException
Number
NumberFormatException
Object
OutOfMemoryError
Override
Package
Process
ProcessBuilder
Readable
ReflectiveOperationException
Runnable
Runtime
RuntimeException
RuntimePermission
SafeVarargs
SecurityException
SecurityManager
Short
StackOverflowError
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
StringIndexOutOfBoundsException
StringTemplates
SuppressWarnings
System
Thread
ThreadDeath
ThreadGroup
ThreadLocal
Throwable
TypeNotPresentException
UnknownError
UnsatisfiedLinkError
UnsupportedClassVersionError
UnsupportedOperationException
VerifyError
VirtualMachineError
Void
java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
Integer i
String str
protected native Object clone()
public boolean equals(Object arg0)
protected void finalize()
public String get1(String str, Integer i)
public String get2(String str, Integer i)
public String get3(String str, Integer i)
public final native Class<?> getClass()
public native int hashCode()
public final native void notify()
public final native void notifyAll()
public String toString()
public final void wait()
public final native void wait(long arg0)
public final void wait(long arg0, int arg1)
boolean
byte
char
double
false
float
int
long
new
null
short
super
this
true
AbstractMethodError
Appendable
ArithmeticException
ArrayIndexOutOfBoundsException
ArrayStoreException
AssertionError
AutoCloseable
Boolean
BootstrapMethodError
Byte
CharSequence
Character
Class
ClassCastException
ClassCircularityError
ClassFormatError
ClassLoader
ClassNotFoundException
ClassValue
CloneNotSupportedException
Cloneable
Comparable
Compiler
Deprecated
Double
Enum
EnumConstantNotPresentException
Error
Exception
ExceptionInInitializerError
Float
FunctionalInterface
IllegalAccessError
IllegalAccessException
IllegalArgumentException
IllegalCallerException
IllegalMonitorStateException
IllegalStateException
IllegalThreadStateException
IncompatibleClassChangeError
IndexOutOfBoundsException
InheritableThreadLocal
InstantiationError
InstantiationException
Integer
InternalError
InterruptedException
Iterable
LayerInstantiationException
LinkageError
Long
Math
Module
ModuleLayer
NegativeArraySizeException
NoClassDefFoundError
NoSuchFieldError
NoSuchFieldException
NoSuchMethodError
NoSuchMethodException
NullPointerException
Number
NumberFormatException
Object
OutOfMemoryError
Override
Package
Process
ProcessBuilder
ProcessHandle
Readable
ReflectiveOperationException
Runnable
Runtime
RuntimeException
RuntimePermission
SafeVarargs
SecurityException
SecurityManager
Short
StackOverflowError
StackTraceElement
StackWalker
StrictMath
String
StringBuffer
StringBuilder
StringIndexOutOfBoundsException
StringTemplates
SuppressWarnings
System
Thread
ThreadDeath
ThreadGroup
ThreadLocal
Throwable
TypeNotPresentException
UnknownError
UnsatisfiedLinkError
UnsupportedClassVersionError
UnsupportedOperationException
VerifyError
VirtualMachineError
Void
com
java
javax
org
sun
Loading

0 comments on commit 9810035

Please sign in to comment.