diff options
author | Gayan Perera | 2021-05-18 18:03:45 +0000 |
---|---|---|
committer | Sarika Sinha | 2021-06-23 13:36:37 +0000 |
commit | 9fc7d75b55627a59392f4124bb4fb5df982ac14a (patch) | |
tree | ed4b88dae2d74b0baccbc67bdc98b2e003acf797 /org.eclipse.jdt.core/model/org/eclipse/jdt | |
parent | 6663040f653ec737f45831bd6af4c9d33273231c (diff) | |
download | eclipse.jdt.core-9fc7d75b55627a59392f4124bb4fb5df982ac14a.tar.gz eclipse.jdt.core-9fc7d75b55627a59392f4124bb4fb5df982ac14a.tar.xz eclipse.jdt.core-9fc7d75b55627a59392f4124bb4fb5df982ac14a.zip |
Bug 573589 - Add support for lambda evaluation with static imports
When performing lambda expression evaluation where the source file
contains static imports, the static imports are added as normal imports
into the code snippet. This happens both for source types and binary
types with source attached. For binary types with source attached this
is fixed in the SourceMapper where the imports are captured.
Change-Id: I5ce337191d688138e32f9c43adbbe652851ec90b
Signed-off-by: Gayan Perera <gayanper@gmail.com>
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/180745
Tested-by: JDT Bot <jdt-bot@eclipse.org>
Reviewed-by: Sarika Sinha <sarika.sinha@in.ibm.com>
Diffstat (limited to 'org.eclipse.jdt.core/model/org/eclipse/jdt')
-rw-r--r-- | org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java | 4 | ||||
-rw-r--r-- | org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/eval/EvaluationContextWrapper.java | 9 |
2 files changed, 12 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java index fbf63275c7..3452b8b2cc 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java @@ -58,6 +58,7 @@ import org.eclipse.jdt.core.Signature; import org.eclipse.jdt.core.SourceRange; import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.codeassist.impl.Keywords; import org.eclipse.jdt.internal.compiler.IProblemFactory; import org.eclipse.jdt.internal.compiler.ISourceElementRequestor; import org.eclipse.jdt.internal.compiler.SourceElementParser; @@ -348,6 +349,9 @@ public class SourceMapper name[nameLength] = '.'; name[nameLength + 1] = '*'; } + if(Flags.isStatic(modifiers)) { + name = CharOperation.concatAll(Keywords.STATIC, name, ' '); + } imports[importsCounter++] = name; this.importsTable.put(this.binaryTypeOrModule, imports); this.importsCounterTable.put(this.binaryTypeOrModule, Integer.valueOf(importsCounter)); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/eval/EvaluationContextWrapper.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/eval/EvaluationContextWrapper.java index 1c14be81fe..76281abe0c 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/eval/EvaluationContextWrapper.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/eval/EvaluationContextWrapper.java @@ -18,10 +18,12 @@ import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jdt.core.*; +import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.core.eval.ICodeSnippetRequestor; import org.eclipse.jdt.core.eval.IEvaluationContext; import org.eclipse.jdt.core.eval.IGlobalVariable; +import org.eclipse.jdt.internal.codeassist.impl.Keywords; import org.eclipse.jdt.internal.compiler.IProblemFactory; import org.eclipse.jdt.internal.compiler.env.INameEnvironment; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; @@ -209,7 +211,12 @@ public void evaluateCodeSnippet( if (importsLength != 0) { char[][] importsNames = new char[importsLength][]; for (int i = 0; i < importsLength; i++) { - importsNames[i] = imports[i].getElementName().toCharArray(); + IImportDeclaration importDecl = imports[i]; + if(Flags.isStatic(importDecl.getFlags())) { + importsNames[i] = CharOperation.concatAll(Keywords.STATIC, importDecl.getElementName().toCharArray(), ' '); + } else { + importsNames[i] = importDecl.getElementName().toCharArray(); + } } this.context.setImports(importsNames); // turn off import complaints for implicitly added ones |