Skip to content

Commit

Permalink
Fix for #850: return non-null URI for CharArrayReaderSource instances
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Mar 21, 2019
1 parent 1c2d514 commit 0039c47
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 20 deletions.
1 change: 1 addition & 0 deletions base/org.eclipse.jdt.groovy.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Export-Package: org.codehaus.jdt.groovy.integration.internal;x-internal:=true,
Import-Package: org.eclipse.jdt.launching
Require-Bundle: org.codehaus.groovy;bundle-version="[2.4.16,4)";visibility:=reexport,
org.eclipse.core.expressions;visibility:=reexport,
org.eclipse.core.filesystem;visibility:=reexport,
org.eclipse.core.resources;visibility:=reexport,
org.eclipse.core.runtime;visibility:=reexport,
org.eclipse.core.variables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 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
* https://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,
Expand All @@ -15,6 +15,10 @@
*/
package org.codehaus.jdt.groovy.control;

import static org.eclipse.core.filesystem.URIUtil.toURI;

import java.net.URI;

import groovy.lang.GroovyClassLoader;

import org.codehaus.groovy.control.CompilationFailedException;
Expand All @@ -32,14 +36,19 @@ public class EclipseSourceUnit extends SourceUnit {
public EclipseSourceUnit(/*@Nullable*/ IFile file, String filePath, char[] sourceCode, boolean isReconcile,
CompilerConfiguration compilerConfig, GroovyClassLoader classLoader, ErrorCollector errorCollector, JDTResolver resolver) {

super(filePath, new CharArrayReaderSource(sourceCode), compilerConfig, classLoader, errorCollector);
super(filePath, new CharArrayReaderSource(sourceCode) {
@Override public URI getURI() {
return toURI(filePath);
}
}, compilerConfig, classLoader, errorCollector);

this.file = file;
this.resolver = resolver;
this.isReconcile = isReconcile;
}

/**
* Will be null if workspace is closed (ie- batch compilation mode)
* Will be {@code null} if workspace is closed (ie- batch compilation mode).
*/
public IFile getEclipseFile() {
return file;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 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
* https://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,
Expand All @@ -16,6 +16,7 @@
package org.codehaus.jdt.groovy.integration.internal;

import java.io.File;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -180,10 +181,14 @@ public CompilationUnit newCompilationUnit(PackageFragment parent, String name, W

@Override
public CompilationUnitDeclaration newCompilationUnitDeclaration(ICompilationUnit icu, ProblemReporter problemReporter, CompilationResult compilationResult, int sourceLength) {
if (ContentTypeUtils.isGroovyLikeFileName(compilationResult.getFileName())) {
if (ContentTypeUtils.isGroovyLikeFileName(icu.getFileName())) {

String unitName = String.valueOf(compilationResult.getFileName());
ReaderSource unitSource = new CharArrayReaderSource(icu.getContents());
String unitName = String.valueOf(icu.getFileName());
ReaderSource unitSource = new CharArrayReaderSource(icu.getContents()) {
@Override public URI getURI() {
return URI.create("platform:/resource" + unitName);
}
};

if (problemReporter.options.groovyCompilerConfigScript != null) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed 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
* https://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,
Expand Down Expand Up @@ -61,7 +61,7 @@ public CompilationUnitDeclaration dietParse(ICompilationUnit sourceUnit, Compila
}

private static boolean isGroovyLikeSourceUnit(ICompilationUnit sourceUnit) {
if (sourceUnit.getFileName() == null || !isJavaLikeButNotGroovyLikeFileName(String.valueOf(sourceUnit.getFileName()))) {
if (sourceUnit.getFileName() == null || !isJavaLikeButNotGroovyLikeFileName(new CharArraySequence(sourceUnit.getFileName()))) {
if (GROOVY_SOURCE_DISCRIMINATOR.matcher(new CharArraySequence(sourceUnit.getContents())).find()) {
Util.log(1, "Identified a Groovy source unit through inspection of its contents: " +
String.valueOf(sourceUnit.getContents(), 0, Math.min(250, sourceUnit.getContents().length)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Import-Package: org.codehaus.groovy.eclipse.codebrowsing.requestor,
org.eclipse.ui.views.contentoutline
Require-Bundle: org.codehaus.groovy.eclipse.ui;bundle-version="3.3.0";visibility:=reexport,
org.eclipse.jdt.groovy.core.tests.builder;bundle-version="3.3.0";visibility:=reexport,
org.eclipse.core.filesystem;visibility:=reexport,
org.eclipse.ui.editors;visibility:=reexport,
org.eclipse.ui.forms;visibility:=reexport,
org.eclipse.ui.ide;visibility:=reexport
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed 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
* https://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,
Expand All @@ -30,6 +30,7 @@
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.compiler.CharOperation;

public class OutlineExtender1 implements IOutlineExtender, IProjectNature {

Expand Down Expand Up @@ -63,7 +64,7 @@ public GroovyOutlinePage getGroovyOutlinePageForEditor(String contextMenuID, Gro

@Override
public boolean appliesTo(GroovyCompilationUnit unit) {
return new String(unit.getFileName()).contains("X");
return CharOperation.contains('X', unit.getFileName());
}

public static class TGroovyOutlinePage extends GroovyOutlinePage {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed 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
* https://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,
Expand All @@ -27,6 +27,7 @@
import org.codehaus.groovy.eclipse.editor.outline.GroovyOutlinePage;
import org.codehaus.jdt.groovy.model.GroovyCompilationUnit;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.groovy.core.util.GroovyUtils;

public class OutlineExtender2 extends OutlineExtender1 {
Expand All @@ -35,7 +36,7 @@ public class OutlineExtender2 extends OutlineExtender1 {

@Override
public boolean appliesTo(GroovyCompilationUnit unit) {
return new String(unit.getFileName()).contains("Y");
return CharOperation.contains('Y', unit.getFileName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Bundle-Name: Groovy AST Views
Bundle-Vendor: Pivotal Software, Inc.
Bundle-Version: 3.3.0.qualifier
Require-Bundle: org.codehaus.groovy.eclipse.ui;bundle-version="3.3.0",
org.eclipse.core.filesystem,
org.eclipse.ui.editors
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.codehaus.groovy.eclipse.astviews.Activator
Expand Down
1 change: 0 additions & 1 deletion ide/org.codehaus.groovy.eclipse.dsl/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Export-Package: org.codehaus.groovy.eclipse.dsl,
Import-Package: org.eclipse.jdt.annotation
Require-Bundle: org.codehaus.groovy.eclipse.codeassist.completion;bundle-version="3.3.0",
org.codehaus.groovy.eclipse.ui;bundle-version="3.3.0",
org.eclipse.core.filesystem,
org.eclipse.ui.ide
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.codehaus.groovy.eclipse.dsl.GroovyDSLCoreActivator
Expand Down
1 change: 0 additions & 1 deletion ide/org.codehaus.groovy.eclipse.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Import-Package: org.codehaus.groovy.frameworkadapter.util,
Require-Bundle: org.codehaus.groovy.eclipse.codebrowsing;bundle-version="3.3.0",
org.codehaus.groovy.eclipse.core;bundle-version="3.3.0";visibility:=reexport,
org.codehaus.groovy.eclipse.refactoring;bundle-version="3.3.0",
org.eclipse.core.filesystem,
org.eclipse.debug.ui,
org.eclipse.jdt.debug,
org.eclipse.jdt.debug.ui,
Expand Down

0 comments on commit 0039c47

Please sign in to comment.