Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta java23 #2648

Merged
merged 13 commits into from
Jul 1, 2024
Merged
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 @@ -28,7 +28,6 @@
import org.eclipse.jdt.core.dom.IAnnotationBinding;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;

import com.sun.mirror.declaration.AnnotationMirror;
import com.sun.mirror.declaration.Modifier;
Expand Down Expand Up @@ -76,7 +75,7 @@ public Collection<Modifier> getModifiers()
else if( _astNode instanceof SingleVariableDeclaration )
modBits = ((SingleVariableDeclaration)_astNode).getModifiers();
else{
ASTNode parent = ((VariableDeclarationFragment)_astNode).getParent();
ASTNode parent = _astNode.getParent();
if( _astNode instanceof BodyDeclaration )
modBits = ((BodyDeclaration)parent).getModifiers();
}
Expand Down Expand Up @@ -148,7 +147,7 @@ private IAnnotationBinding[] getAnnotationInstancesFromAST()
extendsMods = ((SingleVariableDeclaration)_astNode).modifiers();
break;
case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
final ASTNode parent = ((VariableDeclarationFragment)_astNode).getParent();
final ASTNode parent = _astNode.getParent();
if( parent instanceof BodyDeclaration )
extendsMods = ((BodyDeclaration)parent).modifiers();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ private IAnnotationBinding[] getAnnotationInstances()
switch( binding.getKind() )
{
case IBinding.TYPE:
instances = ((ITypeBinding)binding).getAnnotations();
instances = binding.getAnnotations();
break;
case IBinding.METHOD:
instances = ((IMethodBinding)binding).getAnnotations();
instances = binding.getAnnotations();
break;
case IBinding.VARIABLE:
instances = ((IVariableBinding)binding).getAnnotations();
instances = binding.getAnnotations();
break;
case IBinding.PACKAGE:
// TODO: support package annotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@
*******************************************************************************/
package org.eclipse.jdt.apt.core.internal.env;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.apt.core.internal.AptPlugin;
import org.eclipse.jdt.apt.core.internal.util.FileSystemUtil;

/**
Expand All @@ -46,40 +42,20 @@ public BinaryFileOutputStream(IFile file, BuildEnv env) {
public void close() throws IOException {
super.close();

InputStream contents = new ByteArrayInputStream(toByteArray());
byte[] newContent = toByteArray();
boolean contentsChanged = true;
try {

boolean contentsChanged = true;
if (!_file.exists()) {
saveToDisk(contents, true);
}
else {
InputStream in = null;
InputStream oldData = null;
try {
// Only write the contents if the data is different
in = new ByteArrayInputStream(toByteArray());
oldData = new BufferedInputStream(_file.getContents());
if (FileSystemUtil.compareStreams(in, oldData)) {
contentsChanged = false;
}
}
catch (CoreException ce) {
// Ignore -- couldn't read the old data, so assume it's different
contentsChanged = true;
}
finally {
closeInputStream(in);
closeInputStream(oldData);
}
if (contentsChanged) {
contents.reset();
saveToDisk(contents, false);
}
// Only write the contents if the data is different
byte[] oldContent = _file.readAllBytes();
if (Arrays.equals(newContent, oldContent)) {
contentsChanged = false;
}
} catch (CoreException ce) {
// Ignore -- couldn't read the old data, so assume it's different
contentsChanged = true;
}
finally {
closeInputStream(contents);
if (contentsChanged) {
FileSystemUtil.saveToDisk(_file, newContent);
}

IFile parentFile = _env.getFile();
Expand All @@ -88,35 +64,4 @@ public void close() throws IOException {
_env.addGeneratedNonSourceFile(_file);
}
}

private void closeInputStream(InputStream stream) {
if (stream != null) {
try {
stream.close();
}
catch (IOException ioe) {}
}
}

private void saveToDisk(InputStream toSave, boolean create) throws IOException{
try {
FileSystemUtil.makeDerivedParentFolders(_file.getParent());
if (create) {
_file.create(toSave, IResource.FORCE | IResource.DERIVED, null);
} else {
_file.setContents(toSave, true, false, null);
}
}
catch (CoreException ce) {
if (_file.exists()) {
// Do nothing. This is a case-insensitive file system mismatch,
// and the underlying platform has saved the contents already.
}
else {
AptPlugin.log(ce, "Could not create generated file"); //$NON-NLS-1$
throw new IOException(ce.getMessage(), ce);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.eclipse.jdt.apt.core.internal.util;

import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -124,6 +123,21 @@ public static void makeDerivedParentFolders (IContainer container) throws CoreEx
container.setDerived(true, null);
}
}
public static void saveToDisk(IFile file, byte[] toSave) throws IOException{
try {
FileSystemUtil.makeDerivedParentFolders(file.getParent());
file.write(toSave, true, true, false, null);
} catch (CoreException ce) {
if (file.exists()) {
// Do nothing. This is a case-insensitive file system mismatch,
// and the underlying platform has saved the contents already.
}
else {
AptPlugin.log(ce, "Could not create generated file"); //$NON-NLS-1$
throw new IOException(ce.getMessage(), ce);
}
}
}

/**
* Returns the contents of a IFile as a string in UTF8 format
Expand All @@ -145,21 +159,20 @@ public static String getContentsOfFile(File file) throws IOException {
* @throws IOException
* @throws CoreException
*/
public static void writeStringToIFile(IFile file, String contents) throws IOException, CoreException {
byte[] data = contents.getBytes("UTF8"); //$NON-NLS-1$
ByteArrayInputStream input = new ByteArrayInputStream(data);
if (file.exists()) {
if (file.isReadOnly()) {
public static void writeStringToIFile(IFile file, String contents) throws IOException, CoreException {
byte[] data = contents.getBytes(StandardCharsets.UTF_8);
try {
file.write(data, true, false, false, null);
} catch (CoreException e) {
if (file.exists() && file.isReadOnly()) {
// provide opportunity to checkout read-only .factorypath file
ResourcesPlugin.getWorkspace().validateEdit(new IFile[]{file}, null);
ResourcesPlugin.getWorkspace().validateEdit(new IFile[] { file }, null);
file.write(data, true, false, false, null);
} else {
throw e;
}
file.setContents(input, true, false, null);
}
else {
// Even with FORCE, create() will still throw if the file already exists.
file.create(input, IResource.FORCE, null);
}
}
}
}

/**
* Stores a string into an ordinary workspace file in UTF8 format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private TestCodeUtil() {
}

public static boolean isTestCode(ICompilationUnit cu) {
IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) ((IJavaElement) cu)
IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) cu
.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
if (packageFragmentRoot != null) {
try {
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.apt.pluggable.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.apt.pluggable.core;singleton:=true
Bundle-Version: 1.4.400.qualifier
Bundle-Version: 1.4.500.qualifier
Bundle-Activator: org.eclipse.jdt.internal.apt.pluggable.core.Apt6Plugin
Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.core.runtime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@

package org.eclipse.jdt.internal.apt.pluggable.core.filer;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.apt.core.internal.util.FileSystemUtil;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.apt.pluggable.core.Apt6Plugin;
Expand Down Expand Up @@ -49,21 +45,11 @@ public IdeClassOutputStream(IdeProcessingEnvImpl env, IFile file) {
public void close() throws IOException {
super.close();
byte[] byteArray = toByteArray();
InputStream contents = new ByteArrayInputStream(byteArray);
Compiler compiler = this._env.getCompiler();

IBinaryType binaryType = null;
try {
try {
binaryType = ClassFileReader.read(this._file.getLocation().toString());
} catch(IOException ioe) {
// Files doesn't yet exist
}
if (binaryType == null) {
saveToDisk(contents, true);
} else {
saveToDisk(contents, false);
}
FileSystemUtil.saveToDisk(_file, byteArray);
binaryType = ClassFileReader.read(this._file.getLocation().toString());
char[][] splitOn = CharOperation.splitOn('/', binaryType.getName());
ReferenceBinding type = compiler.lookupEnvironment.getType(splitOn);
Expand All @@ -79,37 +65,5 @@ public void close() throws IOException {
} catch(Exception ex) {
Apt6Plugin.log(ex, "Could not create generated class file " + _file.getName()); //$NON-NLS-1$
}
finally {
closeInputStream(contents);
}
}

private void closeInputStream(InputStream stream) {
if (stream != null) {
try {
stream.close();
} catch (IOException ioe) {
// Nothing to do
}
}
}
private void saveToDisk(InputStream toSave, boolean create) throws IOException{
try {
FileSystemUtil.makeDerivedParentFolders(_file.getParent());
if (create) {
_file.create(toSave, IResource.FORCE | IResource.DERIVED, null);
} else {
_file.setContents(toSave, true, false, null);
}
}
catch (CoreException ce) {
if (_file.exists()) {
// Do nothing. This is a case-insensitive file system mismatch,
// and the underlying platform has saved the contents already.
} else {
Apt6Plugin.log(ce, "Could not create generated class file " + _file.getName()); //$NON-NLS-1$
throw new IOException(ce);
}
}
}
}
Loading
Loading