Skip to content
Open
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 @@ -27,19 +27,24 @@
* @author marekfukala
*/
public class CompilationContext {

private final FileObject file;
private final CompilationInfo info;
private final ResolverContext context = new ResolverContext();
private final ResolverContext context;
private CompilationCache cache;

private CompilationContext(FileObject file, CompilationInfo info) {
private CompilationContext(FileObject file, CompilationInfo info, ResolverContext context) {
this.file = file;
this.info = info;
this.context = context != null ? context : new ResolverContext();
}

public static CompilationContext create(FileObject file, CompilationInfo info) {
return new CompilationContext(file, info);
return create(file, info, new ResolverContext());
}

public static CompilationContext create(FileObject file, CompilationInfo info, ResolverContext context) {
return new CompilationContext(file, info, context);
}

public FileObject file() {
Expand All @@ -53,12 +58,12 @@ public CompilationInfo info() {
public ResolverContext context() {
return context;
}

public synchronized CompilationCache cache() {
if(cache == null) {
cache = new CompilationCache();
}
return cache;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private void computeOccurrences(final ELParserResult parserResult) {
try {
jsource.runUserActionTask((CompilationController info) -> {
info.toPhase(JavaSource.Phase.RESOLVED);
CompilationContext ccontext = CompilationContext.create(file, info);
CompilationContext ccontext = CompilationContext.create(file, info, parserResult.getContext());
occurrences.putAll(findMatchingTypes(ccontext, target, matching));
if (this.occurrences.isEmpty()) {
// perhaps the caret is on a resource bundle key node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@
package org.netbeans.modules.web.el;

import com.sun.el.parser.Node;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.el.ELException;

import org.netbeans.modules.csl.api.Error;
import org.netbeans.modules.csl.api.OffsetRange;
import org.netbeans.modules.csl.api.Severity;
import org.netbeans.modules.csl.spi.ParserResult;
import org.netbeans.modules.parsing.api.Snapshot;
import org.netbeans.modules.web.el.spi.ResolverContext;
import org.openide.filesystems.FileObject;

/**
Expand All @@ -42,6 +46,8 @@ public final class ELParserResult extends ParserResult {

private final FileObject file;

private final ResolverContext context = new ResolverContext();

public ELParserResult(Snapshot snapshot) {
super(snapshot);
this.file = snapshot.getSource().getFileObject();
Expand Down Expand Up @@ -132,6 +138,10 @@ public List<? extends Error> getDiagnostics() {
return result;
}

public ResolverContext getContext() {
return context;
}

private static class ELError implements Error.Badging {

private final ELElement errorElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ public CodeCompletionResult complete(final CodeCompletionContext context) {
@Override
public void run(CompilationController info) throws Exception {
info.toPhase(JavaSource.Phase.RESOLVED);
CompilationContext ccontext = CompilationContext.create(file, info);
CompilationContext ccontext;
if (context.getParserResult() instanceof ELParserResult elParserResult) {
ccontext = CompilationContext.create(file, info, elParserResult.getContext());
} else {
ccontext = CompilationContext.create(file, info);
}

// assignments to resolve
Node node = nodeToResolve instanceof AstIdentifier && assignments.containsKey((AstIdentifier) nodeToResolve) ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.netbeans.api.java.source.ClasspathInfo;

import org.netbeans.api.java.source.CompilationController;
import org.netbeans.api.java.source.JavaSource;
import org.netbeans.api.java.source.Task;
Expand All @@ -33,6 +33,7 @@
import org.netbeans.modules.csl.api.Rule.AstRule;
import org.netbeans.modules.csl.api.RuleContext;
import org.netbeans.modules.web.el.CompilationContext;
import org.netbeans.modules.web.el.ELParserResult;
import org.netbeans.modules.web.el.ELTypeUtilities;
import org.openide.filesystems.FileObject;
import org.openide.util.Exceptions;
Expand Down Expand Up @@ -64,7 +65,12 @@ public void computeHints(final HintsManager manager, final RuleContext context,
@Override
public void run(CompilationController info) throws Exception {
info.toPhase(JavaSource.Phase.RESOLVED);
CompilationContext ccontext = CompilationContext.create(file, info);
CompilationContext ccontext;
if (context.parserResult instanceof ELParserResult elParserResult) {
ccontext = CompilationContext.create(file, info, elParserResult.getContext());
} else {
ccontext = CompilationContext.create(file, info);
}
for (ELRule rule : ids) {
if (manager.isEnabled(rule)) {
rule.run(ccontext, context, hints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.sun.source.tree.Tree;
import com.sun.source.util.SourcePositions;
import com.sun.source.util.Trees;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -31,8 +32,10 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

import javax.lang.model.element.Element;
import javax.swing.text.Document;

import org.netbeans.api.java.source.ClasspathInfo;
import org.netbeans.api.java.source.CompilationController;
import org.netbeans.api.java.source.ElementHandle;
Expand All @@ -51,6 +54,7 @@
import org.netbeans.modules.web.el.AstPath;
import org.netbeans.modules.web.el.CompilationContext;
import org.netbeans.modules.web.el.ELElement;
import org.netbeans.modules.web.el.ELParserResult;
import org.netbeans.modules.web.el.ELTypeUtilities;
import org.netbeans.modules.web.el.ResourceBundles;
import org.netbeans.modules.web.el.completion.ELResourceBundleKeyCompletionItem;
Expand Down Expand Up @@ -83,7 +87,12 @@ public DeclarationLocation findDeclaration(final ParserResult info, int offset)
@Override
public void run(CompilationController cc) throws Exception {
cc.toPhase(JavaSource.Phase.RESOLVED);
CompilationContext context = CompilationContext.create(file, cc);
CompilationContext context;
if (info instanceof ELParserResult elParserResult) {
context = CompilationContext.create(file, cc, elParserResult.getContext());
} else {
context = CompilationContext.create(file, cc);
}

// resolve beans
Element javaElement = ELTypeUtilities.resolveElement(context, nodeElem.second(), nodeElem.first());
Expand Down
Loading