Skip to content
Commits on Source (8)
......@@ -14,6 +14,7 @@
<pathelement path="/usr/share/java/eclipse-jface.jar"/>
<pathelement path="/usr/share/java/eclipse-jface-text.jar"/>
<pathelement path="/usr/share/java/eclipse-text.jar"/>
<pathelement path="/usr/share/java/eclipse-ui-editors.jar"/>
<pathelement path="/usr/share/java/eclipse-ui-workbench.jar"/>
<pathelement path="/usr/share/java/eclipse-ui-workbench-texteditor.jar"/>
<pathelement path="/usr/share/java/equinox-common.jar"/>
......@@ -33,6 +34,7 @@
<pathelement path="/usr/share/java/eclipse-jdt-launching.jar"/>
<pathelement path="/usr/share/java/eclipse-text.jar"/>
<pathelement path="/usr/share/java/equinox-common.jar"/>
<pathelement path="/usr/share/java/equinox-preferences.jar"/>
<pathelement path="/usr/share/java/icu4j.jar"/>
</make-bundle>
</target>
......
eclipse-jdt-ui (4.8-1) unstable; urgency=medium
* New upstream release
- Depend on libeclipse-jdt-core-java (>= 3.14)
- Depend on libeclipse-jdt-launching-java (>= 3.10)
- Depend on libeclipse-jface-java (>= 3.14)
- Depend on libeclipse-jface-text-java (>= 3.13)
- Updated the bundle dependencies
-- Emmanuel Bourg <ebourg@apache.org> Wed, 28 Nov 2018 12:58:20 +0100
eclipse-jdt-ui (4.7.3-2) unstable; urgency=medium
* Build more bundles:
......
......@@ -23,10 +23,10 @@ Build-Depends:
libeclipse-debug-core-java,
libeclipse-debug-ui-java,
libeclipse-help-java,
libeclipse-jdt-core-java,
libeclipse-jdt-launching-java,
libeclipse-jface-java,
libeclipse-jface-text-java,
libeclipse-jdt-core-java (>= 3.14),
libeclipse-jdt-launching-java (>= 3.10),
libeclipse-jface-java (>= 3.14),
libeclipse-jface-text-java (>= 3.13),
libeclipse-search-java,
libeclipse-team-core-java,
libeclipse-team-ui-java,
......@@ -62,10 +62,11 @@ Depends:
libeclipse-core-filebuffers-java,
libeclipse-core-resources-java,
libeclipse-core-runtime-java,
libeclipse-jdt-core-java,
libeclipse-jdt-core-java (>= 3.14),
libeclipse-jface-java,
libeclipse-jface-text-java,
libeclipse-text-java,
libeclipse-ui-editors-java,
libeclipse-ui-workbench-java,
libeclipse-ui-workbench-texteditor-java,
libequinox-common-java,
......@@ -112,6 +113,7 @@ Depends:
libeclipse-jdt-launching-java,
libeclipse-text-java,
libequinox-common-java,
libequinox-preferences-java,
libicu4j-java
Description: Eclipse Java Code Manipulation Functionality
Eclipse JDT UI implements the user interface for the Java IDE. It provides
......@@ -267,10 +269,10 @@ Depends:
libeclipse-debug-core-java,
libeclipse-debug-ui-java,
libeclipse-help-java,
libeclipse-jdt-core-java,
libeclipse-jdt-launching-java,
libeclipse-jface-java,
libeclipse-jface-text-java,
libeclipse-jdt-core-java (>= 3.14),
libeclipse-jdt-launching-java (>= 3.10),
libeclipse-jface-java (>= 3.14),
libeclipse-jface-text-java (>= 3.13),
libeclipse-search-java,
libeclipse-team-core-java,
libeclipse-team-ui-java,
......@@ -375,7 +377,7 @@ Depends:
libeclipse-core-jobs-java,
libeclipse-core-resources-java,
libeclipse-core-runtime-java,
libeclipse-jface-java,
libeclipse-jface-java (>= 3.14),
libeclipse-jface-text-java,
libeclipse-team-core-java,
libeclipse-team-ui-java,
......
......@@ -14,7 +14,7 @@
<parent>
<artifactId>eclipse.jdt.ui</artifactId>
<groupId>eclipse.jdt.ui</groupId>
<version>4.7.3-SNAPSHOT</version>
<version>4.8.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jdt.feature</groupId>
<artifactId>org.eclipse.jdt.astview.feature</artifactId>
......
Manifest-Version: 1.0
Automatic-Module-Name: org.eclipse.jdt.astview
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.astview; singleton:=true
Bundle-Version: 1.3.50.qualifier
Bundle-Version: 1.3.100.qualifier
Eclipse-SourceReferences: scm:git:git://git.eclipse.org/gitroot/jdt/eclipse.jdt.ui.git;path="org.eclipse.jdt.astview";tag=R4_4
Bundle-Activator: org.eclipse.jdt.astview.ASTViewPlugin
Bundle-Vendor: %providerName
......@@ -10,8 +11,8 @@ Bundle-Localization: plugin
Export-Package: org.eclipse.jdt.astview;x-internal:=true,
org.eclipse.jdt.astview.views;x-internal:=true
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.jdt.core;bundle-version="[3.13.0,4.0.0)",
org.eclipse.jdt.ui;bundle-version="[3.13.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.14.0,4.0.0)",
org.eclipse.jdt.ui;bundle-version="[3.14.0,4.0.0)",
org.eclipse.ui.ide,
org.eclipse.ui.views,
org.eclipse.jface.text,
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012, 2016 Eclipse Foundation and others.
Copyright (c) 2012, 2017 Eclipse Foundation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v1.0
which accompanies this distribution, and is available at
......@@ -14,10 +14,10 @@
<parent>
<artifactId>eclipse.jdt.ui</artifactId>
<groupId>eclipse.jdt.ui</groupId>
<version>4.7.3-SNAPSHOT</version>
<version>4.8.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.astview</artifactId>
<version>1.3.50-SNAPSHOT</version>
<version>1.3.100-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -126,8 +126,14 @@ import org.eclipse.jdt.ui.SharedASTProvider;
public class ASTView extends ViewPart implements IShowInSource, IShowInTargetList {
static final int JLS_LATEST= AST.JLS9;
static final int JLS_LATEST= AST.JLS10;
private static final int JLS10= AST.JLS10;
/**
* @deprecated to get rid of deprecation warnings in code
*/
@Deprecated
private static final int JLS9= AST.JLS9;
/**
......@@ -453,6 +459,7 @@ public class ASTView extends ViewPart implements IShowInSource, IShowInTargetLis
case JLS4:
case JLS8:
case JLS9:
case JLS10:
fCurrentASTLevel= level;
}
} catch (NumberFormatException e) {
......@@ -670,7 +677,7 @@ public class ASTView extends ViewPart implements IShowInSource, IShowInTargetLis
TreeInfoCollector collector= new TreeInfoCollector(root);
String msg= "{0} ({1}). Creation time: {2,number} ms. Size: {3,number} nodes, {4,number} bytes (AST nodes only)."; //$NON-NLS-1$
Object[] args= { element.getElementName(), version, new Long(time), new Integer(collector.getNumberOfNodes()), new Integer(collector.getSize())};
Object[] args= { element.getElementName(), version, Long.valueOf(time), Integer.valueOf(collector.getNumberOfNodes()), Integer.valueOf(collector.getSize())};
setContentDescription(MessageFormat.format(msg, args));
}
......@@ -1080,6 +1087,7 @@ public class ASTView extends ViewPart implements IShowInSource, IShowInTargetLis
new ASTLevelToggle("AST Level &4 (1.7)", JLS4), //$NON-NLS-1$
new ASTLevelToggle("AST Level &8 (1.8)", JLS8), //$NON-NLS-1$
new ASTLevelToggle("AST Level &9 (9)", JLS9), //$NON-NLS-1$
new ASTLevelToggle("AST Level 1&0 (10)", JLS10), //$NON-NLS-1$
};
fAddToTrayAction= new Action() {
......
/*******************************************************************************
* Copyright (c) 2000, 2015 IBM Corporation and others.
* Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -29,6 +29,10 @@ import org.eclipse.jface.viewers.LabelProviderChangedEvent;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.dom.ASTNode;
......@@ -41,7 +45,8 @@ public class ASTViewLabelProvider extends LabelProvider implements IColorProvide
//to dispose:
private final Font fAllocatedBoldItalic;
private final Color fLightBlue, fLightRed;
private final Color fLightRed;
private Color fSelectedElemBGColor;
public ASTViewLabelProvider() {
fSelectionStart= -1;
......@@ -55,7 +60,16 @@ public class ASTViewLabelProvider extends LabelProvider implements IColorProvide
fDarkGreen= display.getSystemColor(SWT.COLOR_DARK_GREEN);
fDarkRed= display.getSystemColor(SWT.COLOR_DARK_RED);
fLightBlue= new Color(display, 232, 242, 254); // default for AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR
fSelectedElemBGColor= new Color(display, 232, 242, 254);
String currLineColor= EditorsUI.getPreferenceStore().getString(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR);
String[] rgb= currLineColor.split(","); //$NON-NLS-1$
if (rgb.length == 3) {
try {
fSelectedElemBGColor= new Color(display, Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2]));
} catch (NumberFormatException e) {
// do nothing, colour would remain the backup value
}
}
fLightRed= new Color(display, 255, 190, 190);
fBold= PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
......@@ -157,7 +171,7 @@ public class ASTViewLabelProvider extends LabelProvider implements IColorProvide
return fLightRed;
}
if (fSelectionStart != -1 && isInside(element)) {
return fLightBlue;
return fSelectedElemBGColor;
}
return null;
}
......@@ -225,7 +239,7 @@ public class ASTViewLabelProvider extends LabelProvider implements IColorProvide
@Override
public void dispose() {
super.dispose();
fLightBlue.dispose();
fSelectedElemBGColor.dispose();
fLightRed.dispose();
fAllocatedBoldItalic.dispose();
}
......
Manifest-Version: 1.0
Automatic-Module-Name: org.eclipse.jdt.core.manipulation
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.core.manipulation; singleton:=true
Bundle-Version: 1.9.50.qualifier
Bundle-Version: 1.10.0.qualifier
Bundle-Vendor: %providerName
Bundle-Activator: org.eclipse.jdt.internal.core.manipulation.JavaManipulationPlugin
Bundle-Localization: plugin
......
/*******************************************************************************
* Copyright (c) 2006, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.core.manipulation;
import java.util.regex.Pattern;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
/**
* Gives access to the import rewrite configured with the settings as specified in the user interface.
* These settings are kept in JDT UI for compatibility reasons.
*
* <p>
* This class is not intended to be subclassed or instantiated by clients.
* </p>
* @since 1.10
*
* @noinstantiate This class is not intended to be instantiated by clients.
* @noextend This class is not intended to be subclassed by clients.
*/
public class CodeStyleConfiguration {
private static final Pattern SEMICOLON_PATTERN= Pattern.compile(";"); //$NON-NLS-1$
/**
* A named preference that holds a list of semicolon separated package names. The list specifies the import order used by
* the "Organize Imports" operation.
* <p>
* Value is of type <code>String</code>: semicolon separated list of package
* names
* </p>
*/
public static final String ORGIMPORTS_IMPORTORDER= "org.eclipse.jdt.ui.importorder"; //$NON-NLS-1$
/**
* A named preference that specifies the number of imports added before a star-import declaration is used.
* <p>
* Value is of type <code>Integer</code>: positive value specifying the number of non star-import is used
* </p>
*/
public static final String ORGIMPORTS_ONDEMANDTHRESHOLD= "org.eclipse.jdt.ui.ondemandthreshold"; //$NON-NLS-1$
/**
* A named preference that specifies the number of static imports added before a star-import declaration is used.
* <p>
* Value is of type <code>Integer</code>: positive value specifying the number of non star-import is used
* </p>
*/
public static final String ORGIMPORTS_STATIC_ONDEMANDTHRESHOLD= "org.eclipse.jdt.ui.staticondemandthreshold"; //$NON-NLS-1$
private CodeStyleConfiguration() {
// do not instantiate and subclass
}
/**
* Returns a {@link ImportRewrite} using {@link ImportRewrite#create(ICompilationUnit, boolean)} and
* configures the rewriter with the settings as specified in the JDT UI preferences.
* <p>
*
* @param cu the compilation unit to create the rewriter on
* @param restoreExistingImports specifies if the existing imports should be kept or removed.
* @return the new rewriter configured with the settings as specified in the JDT UI preferences.
* @throws JavaModelException thrown when the compilation unit could not be accessed.
*
* @see ImportRewrite#create(ICompilationUnit, boolean)
*/
public static ImportRewrite createImportRewrite(ICompilationUnit cu, boolean restoreExistingImports) throws JavaModelException {
return configureImportRewrite(ImportRewrite.create(cu, restoreExistingImports));
}
/**
* Returns a {@link ImportRewrite} using {@link ImportRewrite#create(CompilationUnit, boolean)} and
* configures the rewriter with the settings as specified in the JDT UI preferences.
*
* @param astRoot the AST root to create the rewriter on
* @param restoreExistingImports specifies if the existing imports should be kept or removed.
* @return the new rewriter configured with the settings as specified in the JDT UI preferences.
*
* @see ImportRewrite#create(CompilationUnit, boolean)
*/
public static ImportRewrite createImportRewrite(CompilationUnit astRoot, boolean restoreExistingImports) {
return configureImportRewrite(ImportRewrite.create(astRoot, restoreExistingImports));
}
private static ImportRewrite configureImportRewrite(ImportRewrite rewrite) {
IJavaProject project= rewrite.getCompilationUnit().getJavaProject();
String order= JavaManipulation.getPreference(ORGIMPORTS_IMPORTORDER, project);
if (order.endsWith(";")) { //$NON-NLS-1$
order= order.substring(0, order.length() - 1);
}
String[] split= SEMICOLON_PATTERN.split(order, -1);
rewrite.setImportOrder(split);
String thres= JavaManipulation.getPreference(ORGIMPORTS_ONDEMANDTHRESHOLD, project);
try {
int num= Integer.parseInt(thres);
if (num == 0)
num= 1;
rewrite.setOnDemandImportThreshold(num);
} catch (NumberFormatException e) {
// ignore
}
String thresStatic= JavaManipulation.getPreference(ORGIMPORTS_STATIC_ONDEMANDTHRESHOLD, project);
try {
int num= Integer.parseInt(thresStatic);
if (num == 0)
num= 1;
rewrite.setStaticOnDemandImportThreshold(num);
} catch (NumberFormatException e) {
// ignore
}
return rewrite;
}
}
/*******************************************************************************
* Copyright (c) 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.core.manipulation;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.internal.core.manipulation.JavaManipulationPlugin;
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
import org.eclipse.jdt.internal.corext.dom.IASTSharedValues;
/**
* The {@link CoreASTProvider} provides access to the {@link CompilationUnit AST root} used by
* the current active Java editor.
*
* The {@link CoreASTProvider} contains all methods/functionality that are
* not dependent on the UI, from org.eclipse.jdt.internal.ui.javaeditor.ASTProvider
* for the purpose of reuse by non-UI bundles.
*
* <p>
* This class is not intended to be subclassed or instantiated by clients.
* </p>
*
* @since 1.10
*
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public final class CoreASTProvider {
private static CoreASTProvider instance = new CoreASTProvider();
public static final String DEBUG_PREFIX= "ASTProvider > "; //$NON-NLS-1$
private volatile ITypeRoot fReconcilingJavaElement;
private ITypeRoot fActiveJavaElement;
private CompilationUnit fAST;
private Object fReconcileLock= new Object();
private Object fWaitLock= new Object();
private volatile boolean fIsReconciling;
/**
* Wait flag class.
*/
public static final class WAIT_FLAG {
private String fName;
private WAIT_FLAG(String name) {
fName= name;
}
/*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return fName;
}
}
/**
* Wait flag indicating that a client requesting an AST
* wants to wait until an AST is ready.
* <p>
* An AST will be created by this AST provider if the shared
* AST is not for the given Java element.
* </p>
*/
public static final WAIT_FLAG WAIT_YES= new WAIT_FLAG("wait yes"); //$NON-NLS-1$
/**
* Wait flag indicating that a client requesting an AST
* only wants to wait for the shared AST of the active editor.
* <p>
* No AST will be created by the AST provider.
* </p>
*/
public static final WAIT_FLAG WAIT_ACTIVE_ONLY= new WAIT_FLAG("wait active only"); //$NON-NLS-1$
/**
* Wait flag indicating that a client requesting an AST
* only wants the already available shared AST.
* <p>
* No AST will be created by the AST provider.
* </p>
*/
public static final WAIT_FLAG WAIT_NO= new WAIT_FLAG("don't wait"); //$NON-NLS-1$
/**
* Returns a shared compilation unit AST for the given Java element.
* <p>
* Clients are not allowed to modify the AST and must synchronize all access to its nodes.
* </p>
*
* @param input the Java element, must not be <code>null</code>
* @param waitFlag org.eclipse.jdt.ui.SharedASTProvider#WAIT_YES,
* org.eclipse.jdt.ui.SharedASTProvider#WAIT_NO or
* org.eclipse.jdt.ui.SharedASTProvider#WAIT_ACTIVE_ONLY
* @param progressMonitor the progress monitor or <code>null</code>
* @return the AST or <code>null</code> if the AST is not available
*/
public CompilationUnit getAST(final ITypeRoot input, WAIT_FLAG waitFlag, IProgressMonitor progressMonitor) {
if (input == null || waitFlag == null)
throw new IllegalArgumentException("input or wait flag are null"); //$NON-NLS-1$
if (progressMonitor != null && progressMonitor.isCanceled())
return null;
boolean isActiveElement;
synchronized (this) {
isActiveElement= input.equals(fActiveJavaElement);
if (isActiveElement) {
if (fAST != null) {
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER)
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "returning cached AST:" + toString(fAST) + " for: " + input.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return fAST;
}
if (waitFlag == CoreASTProvider.WAIT_NO) {
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER)
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "returning null (WAIT_NO) for: " + input.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$
return null;
}
}
}
final boolean canReturnNull= waitFlag == CoreASTProvider.WAIT_NO || (waitFlag == CoreASTProvider.WAIT_ACTIVE_ONLY && !(isActiveElement && fAST == null));
boolean isReconciling= false;
final ITypeRoot activeElement;
if (isActiveElement) {
synchronized (fReconcileLock) {
activeElement= fReconcilingJavaElement;
isReconciling= isReconciling(input);
if (!isReconciling && !canReturnNull)
aboutToBeReconciled(input);
}
} else
activeElement= null;
if (isReconciling) {
try {
// Wait for AST
synchronized (fWaitLock) {
if (isReconciling(input)) {
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER)
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "waiting for AST for: " + input.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$
fWaitLock.wait(30000); // XXX: The 30 seconds timeout is an attempt to at least avoid a deadlock. See https://bugs.eclipse.org/366048#c21
}
}
// Check whether active element is still valid
synchronized (this) {
if (activeElement == fActiveJavaElement && fAST != null) {
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER)
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "...got AST: " + toString(fAST) + " for: " + input.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return fAST;
}
}
return getAST(input, waitFlag, progressMonitor);
} catch (InterruptedException e) {
return null; // thread has been interrupted don't compute AST
}
} else if (canReturnNull)
return null;
CompilationUnit ast= null;
try {
ast= createAST(input, progressMonitor);
if (progressMonitor != null && progressMonitor.isCanceled()) {
ast= null;
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER)
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "Ignore created AST for: " + input.getElementName() + " - operation has been cancelled"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
} finally {
if (isActiveElement) {
if (fAST != null) {
// in the meantime, reconcile created a new AST. Return that one
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER)
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "Ignore created AST for " + input.getElementName() + " - AST from reconciler is newer"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
reconciled(fAST, input, null);
return fAST;
} else
reconciled(ast, input, null);
}
}
return ast;
}
/**
* Informs that reconciling for the given element is about to be started.
*
* @param javaElement the Java element
* See org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#aboutToBeReconciled()
*/
public void aboutToBeReconciled(ITypeRoot javaElement) {
if (javaElement == null)
return;
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER)
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "about to reconcile: " + toString(javaElement)); //$NON-NLS-1$ //$NON-NLS-2$
synchronized (fReconcileLock) {
fReconcilingJavaElement= javaElement;
fIsReconciling= true;
}
cache(null, javaElement);
}
/**
* Creates a new compilation unit AST.
*
* @param input the Java element for which to create the AST
* @param progressMonitor the progress monitor
* @return AST
*/
private static CompilationUnit createAST(final ITypeRoot input, final IProgressMonitor progressMonitor) {
if (!hasSource(input))
return null;
if (progressMonitor != null && progressMonitor.isCanceled())
return null;
final ASTParser parser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
parser.setResolveBindings(true);
parser.setStatementsRecovery(IASTSharedValues.SHARED_AST_STATEMENT_RECOVERY);
parser.setBindingsRecovery(IASTSharedValues.SHARED_BINDING_RECOVERY);
parser.setSource(input);
if (progressMonitor != null && progressMonitor.isCanceled())
return null;
final CompilationUnit root[]= new CompilationUnit[1];
SafeRunner.run(new ISafeRunnable() {
@Override
public void run() {
try {
if (progressMonitor != null && progressMonitor.isCanceled())
return;
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER)
System.err.println(getThreadName() + " - " + DEBUG_PREFIX + "creating AST for: " + input.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$
root[0]= (CompilationUnit)parser.createAST(progressMonitor);
//mark as unmodifiable
ASTNodes.setFlagsToAST(root[0], ASTNode.PROTECT);
} catch (OperationCanceledException ex) {
return;
}
}
@Override
public void handleException(Throwable ex) {
IStatus status= new Status(IStatus.ERROR, JavaManipulation.ID_PLUGIN, IStatus.OK, "Error in JDT Core during AST creation", ex); //$NON-NLS-1$
JavaManipulationPlugin.getDefault().getLog().log(status);
}
});
return root[0];
}
/**
* Update internal structures after reconcile.
*
* @param ast the compilation unit AST or <code>null</code> if the working copy was consistent or
* reconciliation has been cancelled
* @param javaElement the Java element for which the AST was built
* @param progressMonitor the progress monitor
* See org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#reconciled(CompilationUnit,
* boolean, IProgressMonitor)
*/
public void reconciled(CompilationUnit ast, ITypeRoot javaElement, IProgressMonitor progressMonitor) {
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER)
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "reconciled: " + toString(javaElement) + ", AST: " + toString(ast)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
synchronized (fReconcileLock) {
fIsReconciling= false;
if (javaElement == null || !javaElement.equals(fReconcilingJavaElement)) {
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER)
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + " ignoring AST of out-dated editor"); //$NON-NLS-1$ //$NON-NLS-2$
// Signal - threads might wait for wrong element
synchronized (fWaitLock) {
fWaitLock.notifyAll();
}
return;
}
cache(ast, javaElement);
}
}
/**
* Tells whether the given Java element is the one reported as currently being reconciled.
*
* @param javaElement the Java element
* @return <code>true</code> if reported as currently being reconciled
*/
private boolean isReconciling(ITypeRoot javaElement) {
return javaElement != null && javaElement.equals(fReconcilingJavaElement) && fIsReconciling;
}
/**
* Caches the given compilation unit AST for the given Java element.
*
* @param ast the ast
* @param javaElement the java element
*/
public synchronized void cache(CompilationUnit ast, ITypeRoot javaElement) {
if (fActiveJavaElement != null && !fActiveJavaElement.equals(javaElement)) {
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER && javaElement != null) // don't report call from disposeAST()
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "don't cache AST for inactive: " + toString(javaElement)); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER && (javaElement != null || ast != null)) // don't report call from disposeAST()
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "caching AST: " + toString(ast) + " for: " + toString(javaElement)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (fAST != null)
disposeAST();
fAST= ast;
// Signal AST change
synchronized (fWaitLock) {
fWaitLock.notifyAll();
}
}
/**
* Checks whether the given Java element has accessible source.
*
* @param je the Java element to test
* @return <code>true</code> if the element has source
*/
private static boolean hasSource(ITypeRoot je) {
if (je == null || !je.exists())
return false;
try {
return je.getBuffer() != null;
} catch (JavaModelException ex) {
IStatus status= new Status(IStatus.ERROR, JavaManipulation.ID_PLUGIN, IStatus.OK, "Error in JDT Core during AST creation", ex); //$NON-NLS-1$
JavaManipulationPlugin.getDefault().getLog().log(status);
}
return false;
}
/**
* Disposes the cached AST.
*/
public synchronized void disposeAST() {
if (fAST == null)
return;
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER)
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "disposing AST: " + toString(fAST) + " for: " + toString(fActiveJavaElement)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
fAST= null;
cache(null, null);
}
/**
* Returns a string for the given Java element used for debugging.
*
* @param javaElement the compilation unit AST
* @return a string used for debugging
*/
public String toString(ITypeRoot javaElement) {
if (javaElement == null)
return "null"; //$NON-NLS-1$
else
return javaElement.getElementName();
}
/**
* Returns a string for the given AST used for debugging.
*
* @param ast the compilation unit AST
* @return a string used for debugging
*/
private String toString(CompilationUnit ast) {
if (ast == null)
return "null"; //$NON-NLS-1$
List<AbstractTypeDeclaration> types= ast.types();
if (types != null && types.size() > 0)
return types.get(0).getName().getIdentifier() + "(" + ast.hashCode() + ")"; //$NON-NLS-1$//$NON-NLS-2$
else
return "AST without any type"; //$NON-NLS-1$
}
/**
* @return The name of the current thread if not null.
* Otherwise this returns the string representation of the
* current thread.
*/
public static String getThreadName() {
String name= Thread.currentThread().getName();
if (name != null)
return name;
else
return Thread.currentThread().toString();
}
/**
* @return The singleton instance of this class.
*/
public static CoreASTProvider getInstance() {
return instance;
}
private CoreASTProvider() {
// Prevent instantiation.
}
/**
* @return Whether the current java element is being reconciled.
*/
public boolean isReconciling () {
return fIsReconciling;
}
/**
* @return The java element currently being reconciled.
*/
public ITypeRoot getReconcilingJavaElement () {
return fReconcilingJavaElement;
}
/**
* @return The active java element.
*/
public ITypeRoot getActiveJavaElement () {
return fActiveJavaElement;
}
/**
* Set the active java element that is currently active.
* @param activeJavaElement the java element.
*/
public void setActiveJavaElement (ITypeRoot activeJavaElement) {
fActiveJavaElement = activeJavaElement;
}
/**
* @return The compilation unit's cached AST.
*/
public CompilationUnit getCachedAST () {
return fAST;
}
/**
* Notify all waiting threads that the AST has changed.
*/
public void waitLockNotifyAll () {
synchronized (fWaitLock) {
fWaitLock.notifyAll();
}
}
/**
* Clear the reconciliation state.
*/
public void clearReconciliation () {
synchronized (fReconcileLock) {
fIsReconciling = false;
fReconcilingJavaElement = null;
}
}
}
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.corext.codemanipulation;
package org.eclipse.jdt.core.manipulation;
import java.util.Collection;
import java.util.Iterator;
......@@ -65,12 +65,34 @@ import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
/**
* @since 1.10
*/
public class ImportReferencesCollector extends GenericVisitor {
/**
* Collect import statements from an AST node.
*
* @param node The AST node
* @param project The Java project
* @param rangeLimit The range within the source file
* @param resultingTypeImports The collected import references
* @param resultingStaticImports The collected static imports
*/
public static void collect(ASTNode node, IJavaProject project, Region rangeLimit, Collection<SimpleName> resultingTypeImports, Collection<SimpleName> resultingStaticImports) {
collect(node, project, rangeLimit, false, resultingTypeImports, resultingStaticImports);
}
/**
* Collect import statements from an AST node.
*
* @param node The AST node
* @param project The Java project
* @param rangeLimit The range within the source file
* @param skipMethodBodies If set, do not visit method bodies
* @param resultingTypeImports The collected import references
* @param resultingStaticImports The collected static imports
*/
public static void collect(ASTNode node, IJavaProject project, Region rangeLimit, boolean skipMethodBodies, Collection<SimpleName> resultingTypeImports, Collection<SimpleName> resultingStaticImports) {
ASTNode root= node.getRoot();
CompilationUnit astRoot= root instanceof CompilationUnit ? (CompilationUnit) root : null;
......@@ -206,7 +228,9 @@ public class ImportReferencesCollector extends GenericVisitor {
*/
@Override
public boolean visit(SimpleType node) {
if (node.getAST().apiLevel() < AST.JLS10 || !node.isVar()) {
typeRefFound(node.getName());
}
visitAnnotations(node);
return false;
}
......
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -10,6 +10,14 @@
*******************************************************************************/
package org.eclipse.jdt.core.manipulation;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.jdt.core.IJavaProject;
/**
* Central access point for the Java Manipulation plug-in (id <code>"org.eclipse.jdt.core.manipulation"</code>).
*/
......@@ -19,4 +27,58 @@ public class JavaManipulation {
* The id of the Java Manipulation plug-in (value <code>"org.eclipse.jdt.core.manipulation"</code>).
*/
public static final String ID_PLUGIN= "org.eclipse.jdt.core.manipulation"; //$NON-NLS-1$
/**
* Some operations can be performed without UI, but their preferences are stored
* in the JDT UI preference node. If JDT UI is not present in runtime, there are
* sane defaults, but if it exists, the preference node should be checked.
*/
private static String fgPreferenceNodeId;
/**
* @return The id of the preference node for some basic Java preferences.
* Generally this will be <code>"org.eclipse.jdt.ui"</code> but some
* environments may not have the 'org.eclipse.jdt.ui' bundle, so a
* different one can be set.
* @since 1.10
*/
public static final String getPreferenceNodeId () {
return fgPreferenceNodeId;
}
/**
* Sets the preference node to be used for basic Java preferences.
* The client should set the value back to null when finished.
*
* @param id the Id to use for the preference node
* @since 1.10
*/
public static final void setPreferenceNodeId (String id) {
Assert.isLegal(fgPreferenceNodeId == null || id == null, "Preference node already set"); //$NON-NLS-1$
fgPreferenceNodeId= id;
}
/**
* Returns the value for the given key in the given context for the JDT UI plug-in.
* @param key The preference key
* @param project The current context or <code>null</code> if no context is available and the
* workspace setting should be taken. Note that passing <code>null</code> should
* be avoided.
* @return Returns the current value for the string.
* @since 1.10
*/
public static String getPreference(String key, IJavaProject project) {
String val;
if (project != null) {
val= new ProjectScope(project.getProject()).getNode(JavaManipulation.fgPreferenceNodeId).get(key, null);
if (val != null) {
return val;
}
}
val= InstanceScope.INSTANCE.getNode(JavaManipulation.fgPreferenceNodeId).get(key, null);
if (val != null) {
return val;
}
return DefaultScope.INSTANCE.getNode(JavaManipulation.fgPreferenceNodeId).get(key, null);
}
}
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.corext.codemanipulation;
package org.eclipse.jdt.core.manipulation;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -38,6 +38,7 @@ import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
......@@ -50,6 +51,7 @@ import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.NodeFinder;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
......@@ -59,23 +61,22 @@ import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.search.TypeNameMatch;
import org.eclipse.jdt.internal.core.manipulation.JavaManipulationMessages;
import org.eclipse.jdt.internal.core.manipulation.Messages;
import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving;
import org.eclipse.jdt.internal.core.manipulation.util.BasicElementLabels;
import org.eclipse.jdt.internal.core.manipulation.util.Strings;
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
import org.eclipse.jdt.internal.corext.dom.Bindings;
import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer;
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.corext.util.JdtFlags;
import org.eclipse.jdt.internal.corext.util.Messages;
import org.eclipse.jdt.internal.corext.util.TypeNameMatchCollector;
import org.eclipse.jdt.ui.SharedASTProvider;
import org.eclipse.jdt.internal.ui.text.correction.ProblemLocation;
import org.eclipse.jdt.internal.ui.text.correction.SimilarElementsRequestor;
/**
* @since 1.10
*/
public class OrganizeImportsOperation implements IWorkspaceRunnable {
public static interface IChooseImportQuery {
/**
......@@ -140,7 +141,8 @@ public class OrganizeImportsOperation implements IWorkspaceRunnable {
}
private static ImportDeclaration getProblematicImport(IProblem problem, CompilationUnit cu) {
ASTNode coveringNode= new ProblemLocation(problem).getCoveringNode(cu);
ASTNode coveringNode= new NodeFinder(cu, problem.getSourceStart(),
problem.getSourceEnd() - problem.getSourceStart() + 1).getCoveringNode();
if (coveringNode != null) {
ASTNode importNode= ASTNodes.getParent(coveringNode, ASTNode.IMPORT_DECLARATION);
if (importNode instanceof ImportDeclaration) {
......@@ -188,13 +190,15 @@ public class OrganizeImportsOperation implements IWorkspaceRunnable {
private static class TypeReferenceProcessor {
private static class UnresolvedTypeData {
final SimpleName ref;
final int typeKinds;
final List<TypeNameMatch> foundInfos;
public UnresolvedTypeData(SimpleName ref) {
this.ref= ref;
this.typeKinds= org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getPossibleTypeKinds(ref, true);
this.typeKinds= ASTResolving.getPossibleTypeKinds(ref, true);
this.foundInfos= new ArrayList<>(3);
}
......@@ -349,7 +353,8 @@ public class OrganizeImportsOperation implements IWorkspaceRunnable {
}
final ArrayList<TypeNameMatch> typesFound= new ArrayList<>();
final IJavaProject project= fCurrPackage.getJavaProject();
IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaElement[] { project });
boolean excludeTestCode= !((IPackageFragmentRoot)fCurrPackage.getParent()).getResolvedClasspathEntry().isTest();
IJavaSearchScope scope= SearchEngine.createJavaSearchScope(excludeTestCode, new IJavaElement[] { project }, true);
TypeNameMatchCollector collector= new TypeNameMatchCollector(typesFound);
new SearchEngine().searchAllTypeNames(null, allTypes, scope, collector, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
......@@ -441,15 +446,15 @@ public class OrganizeImportsOperation implements IWorkspaceRunnable {
private boolean isOfKind(TypeNameMatch curr, int typeKinds, boolean is50OrHigher) {
int flags= curr.getModifiers();
if (Flags.isAnnotation(flags)) {
return is50OrHigher && (typeKinds & SimilarElementsRequestor.ANNOTATIONS) != 0;
return is50OrHigher && (typeKinds & TypeKinds.ANNOTATIONS) != 0;
}
if (Flags.isEnum(flags)) {
return is50OrHigher && (typeKinds & SimilarElementsRequestor.ENUMS) != 0;
return is50OrHigher && (typeKinds & TypeKinds.ENUMS) != 0;
}
if (Flags.isInterface(flags)) {
return (typeKinds & SimilarElementsRequestor.INTERFACES) != 0;
return (typeKinds & TypeKinds.INTERFACES) != 0;
}
return (typeKinds & SimilarElementsRequestor.CLASSES) != 0;
return (typeKinds & TypeKinds.CLASSES) != 0;
}
private boolean isVisible(TypeNameMatch curr) {
......@@ -504,6 +509,16 @@ public class OrganizeImportsOperation implements IWorkspaceRunnable {
private final boolean fAllowSyntaxErrors;
/**
* Creates a new OrganizeImportsOperation operation.
*
* @param cu The compilation unit
* @param astRoot the compilation unit AST node
* @param ignoreLowerCaseNames when true, type names starting with a lower case are ignored
* @param save If set, the result will be saved
* @param allowSyntaxErrors If set, the operation will only proceed when the compilation unit has no syntax errors
* @param chooseImportQuery Query element to be used for UI interaction or <code>null</code> to not select anything
*/
public OrganizeImportsOperation(ICompilationUnit cu, CompilationUnit astRoot, boolean ignoreLowerCaseNames, boolean save, boolean allowSyntaxErrors, IChooseImportQuery chooseImportQuery) {
fCompilationUnit= cu;
fASTRoot= astRoot;
......@@ -531,13 +546,13 @@ public class OrganizeImportsOperation implements IWorkspaceRunnable {
monitor= new NullProgressMonitor();
}
try {
monitor.beginTask(Messages.format(CodeGenerationMessages.OrganizeImportsOperation_description, BasicElementLabels.getFileName(fCompilationUnit)), 10);
monitor.beginTask(Messages.format(JavaManipulationMessages.OrganizeImportsOperation_description, BasicElementLabels.getFileName(fCompilationUnit)), 10);
TextEdit edit= createTextEdit(new SubProgressMonitor(monitor, 9));
if (edit == null)
return;
JavaElementUtil.applyEdit(fCompilationUnit, edit, fDoSave, new SubProgressMonitor(monitor, 1));
JavaModelUtil.applyEdit(fCompilationUnit, edit, fDoSave, new SubProgressMonitor(monitor, 1));
} finally {
monitor.done();
}
......@@ -551,18 +566,21 @@ public class OrganizeImportsOperation implements IWorkspaceRunnable {
fNumberOfImportsAdded= 0;
fNumberOfImportsRemoved= 0;
monitor.beginTask(Messages.format(CodeGenerationMessages.OrganizeImportsOperation_description, BasicElementLabels.getFileName(fCompilationUnit)), 9);
monitor.beginTask(Messages.format(JavaManipulationMessages.OrganizeImportsOperation_description, BasicElementLabels.getFileName(fCompilationUnit)), 9);
CompilationUnit astRoot= fASTRoot;
if (astRoot == null) {
astRoot= SharedASTProvider.getAST(fCompilationUnit, SharedASTProvider.WAIT_YES, new SubProgressMonitor(monitor, 2));
astRoot= CoreASTProvider.getInstance().getAST(fCompilationUnit, CoreASTProvider.WAIT_YES, new SubProgressMonitor(monitor, 2));
if (monitor.isCanceled())
throw new OperationCanceledException();
} else {
monitor.worked(2);
}
ImportRewrite importsRewrite= StubUtility.createImportRewrite(astRoot, false);
ImportRewrite importsRewrite = CodeStyleConfiguration.createImportRewrite(astRoot, false);
if (astRoot.getAST().hasResolvedBindings()) {
importsRewrite.setUseContextToFilterImplicitImports(true);
}
Set<String> oldSingleImports= new HashSet<>();
Set<String> oldDemandImports= new HashSet<>();
......@@ -717,10 +735,16 @@ public class OrganizeImportsOperation implements IWorkspaceRunnable {
return fParsingError;
}
/**
* @return Returns the number of import statements added for this operation
*/
public int getNumberOfImportsAdded() {
return fNumberOfImportsAdded;
}
/**
* @return Returns the number of import statements removed for this operation
*/
public int getNumberOfImportsRemoved() {
return fNumberOfImportsRemoved;
}
......
/*******************************************************************************
* Copyright (c) 2000, 2012 IBM Corporation and others.
* Copyright (c) 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -8,33 +8,27 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.corext.util;
package org.eclipse.jdt.core.manipulation;
import java.util.Collection;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jdt.core.search.TypeNameMatch;
import org.eclipse.jdt.core.search.TypeNameMatchRequestor;
public class TypeNameMatchCollector extends TypeNameMatchRequestor {
private final Collection<TypeNameMatch> fCollection;
public TypeNameMatchCollector(Collection<TypeNameMatch> collection) {
Assert.isNotNull(collection);
fCollection= collection;
}
private boolean inScope(TypeNameMatch match) {
return ! TypeFilter.isFiltered(match);
}
@Override
public void acceptTypeNameMatch(TypeNameMatch match) {
if (inScope(match)) {
fCollection.add(match);
}
/**
* Contains various properties for a Java element.
*
* @since 1.10
*/
public class TypeKinds {
public static final int CLASSES= 1 << 1;
public static final int INTERFACES= 1 << 2;
public static final int ANNOTATIONS= 1 << 3;
public static final int ENUMS= 1 << 4;
public static final int VARIABLES= 1 << 5;
public static final int PRIMITIVETYPES= 1 << 6;
public static final int VOIDTYPE= 1 << 7;
public static final int REF_TYPES= CLASSES | INTERFACES | ENUMS | ANNOTATIONS;
public static final int REF_TYPES_AND_VAR= REF_TYPES | VARIABLES;
public static final int ALL_TYPES= PRIMITIVETYPES | REF_TYPES_AND_VAR;
private TypeKinds () {
}
}
/*******************************************************************************
* Copyright (c) 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.core.manipulation;
import java.util.Collection;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jdt.core.IAccessRule;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.search.TypeNameMatch;
import org.eclipse.jdt.core.search.TypeNameMatchRequestor;
/**
* @since 1.10
*/
public class TypeNameMatchCollector extends TypeNameMatchRequestor {
private final Collection<TypeNameMatch> fCollection;
private Pattern[] fStringMatchers;
public TypeNameMatchCollector(Collection<TypeNameMatch> collection) {
Assert.isNotNull(collection);
fCollection= collection;
}
private boolean inScope(TypeNameMatch match) {
return ! isFiltered(match);
}
private boolean isFiltered(TypeNameMatch match) {
boolean filteredByPattern= filter(match.getFullyQualifiedName());
if (filteredByPattern)
return true;
int accessibility= match.getAccessibility();
switch (accessibility) {
case IAccessRule.K_NON_ACCESSIBLE:
return JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK));
case IAccessRule.K_DISCOURAGED:
return JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_DISCOURAGED_REFERENCE_CHECK));
default:
return false;
}
}
private boolean filter(String fullTypeName) {
Pattern[] matchers= getStringMatchers();
for (int i= 0; i < matchers.length; i++) {
Pattern curr= matchers[i];
if (curr.matcher(fullTypeName).matches()) {
return true;
}
}
return false;
}
private synchronized Pattern[] getStringMatchers() {
if (fStringMatchers == null) {
String str= getPreference("org.eclipse.jdt.ui.typefilter.enabled"); //$NON-NLS-1$
StringTokenizer tok= new StringTokenizer(str, ";"); //$NON-NLS-1$
int nTokens= tok.countTokens();
fStringMatchers= new Pattern[nTokens];
for (int i= 0; i < nTokens; i++) {
String curr= tok.nextToken();
if (curr.length() > 0) {
// Simulate '*', and '?' wildcards using '.*' and '.'
curr = curr.replaceAll("\\*", ".*"); //$NON-NLS-1$ //$NON-NLS-2$
curr = curr.replaceAll("\\?", "."); //$NON-NLS-1$ //$NON-NLS-2$
fStringMatchers[i]= Pattern.compile(curr);
}
}
}
return fStringMatchers;
}
@Override
public void acceptTypeNameMatch(TypeNameMatch match) {
if (inScope(match)) {
fCollection.add(match);
}
}
private static String getPreference(String key) {
String val;
IEclipsePreferences node= InstanceScope.INSTANCE.getNode(JavaManipulation.getPreferenceNodeId());
if (node != null) {
val= node.get(key, null);
if (val != null) {
return val;
}
}
node= DefaultScope.INSTANCE.getNode(JavaManipulation.getPreferenceNodeId());
if (node != null) {
return node.get(key, null);
}
return null;
}
}
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -26,4 +26,9 @@ public class JavaManipulationMessages extends NLS {
public static String JavaManipulationMessages_internalError;
public static String UndoCompilationUnitChange_no_file;
public static String OrganizeImportsOperation_description;
public static String JavaModelUtil_applyedit_operation;
public static String Resources_fileModified;
public static String Resources_modifiedResources;
}
###############################################################################
# Copyright (c) 2000, 2008 IBM Corporation and others.
# Copyright (c) 2000, 2018 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
......@@ -10,3 +10,8 @@
###############################################################################
JavaManipulationMessages_internalError=Internal Error
UndoCompilationUnitChange_no_file=Compilation unit ''{0}'' does not have an underlying file.
OrganizeImportsOperation_description=Organizing imports of {0}...
JavaModelUtil_applyedit_operation=Applying changes
Resources_fileModified= File ''{0}'' has been modified since the beginning of the operation
Resources_modifiedResources= There are modified resources
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -12,6 +12,9 @@ package org.eclipse.jdt.internal.core.manipulation;
import org.osgi.framework.BundleContext;
import org.eclipse.osgi.service.debug.DebugOptions;
import org.eclipse.osgi.service.debug.DebugOptionsListener;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Plugin;
......@@ -22,7 +25,9 @@ import org.eclipse.jdt.core.manipulation.JavaManipulation;
/**
* The main plug-in class to be used in the workbench.
*/
public class JavaManipulationPlugin extends Plugin {
public class JavaManipulationPlugin extends Plugin implements DebugOptionsListener {
public static boolean DEBUG_AST_PROVIDER;
//The shared instance.
private static JavaManipulationPlugin fgDefault;
......@@ -79,4 +84,9 @@ public class JavaManipulationPlugin extends Plugin {
public static void log(Throwable e) {
log(new Status(IStatus.ERROR, getPluginId(), IStatusConstants.INTERNAL_ERROR, JavaManipulationMessages.JavaManipulationMessages_internalError, e));
}
@Override
public void optionsChanged(DebugOptions options) {
DEBUG_AST_PROVIDER= options.getBooleanOption("org.eclipse.jdt.core.manipulation/debug/ASTProvider", false); //$NON-NLS-1$
}
}
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corporation and others.
* Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -59,6 +59,7 @@ import org.eclipse.jdt.core.dom.ParameterizedType;
import org.eclipse.jdt.core.dom.PrefixExpression;
import org.eclipse.jdt.core.dom.PrimitiveType;
import org.eclipse.jdt.core.dom.PrimitiveType.Code;
import org.eclipse.jdt.core.manipulation.TypeKinds;
import org.eclipse.jdt.core.dom.QualifiedName;
import org.eclipse.jdt.core.dom.QualifiedType;
import org.eclipse.jdt.core.dom.SimpleName;
......@@ -73,7 +74,9 @@ import org.eclipse.jdt.core.dom.SwitchStatement;
import org.eclipse.jdt.core.dom.TagElement;
import org.eclipse.jdt.core.dom.TryStatement;
import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.TypeLiteral;
import org.eclipse.jdt.core.dom.TypeParameter;
import org.eclipse.jdt.core.dom.VariableDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
......@@ -1010,4 +1013,118 @@ public class ASTResolving {
astParser.setBindingsRecovery(IASTSharedValues.SHARED_BINDING_RECOVERY);
return (CompilationUnit) astParser.createAST(monitor);
}
public static int getPossibleTypeKinds(ASTNode node, boolean is50OrHigher) {
int kinds= internalGetPossibleTypeKinds(node);
if (!is50OrHigher) {
kinds &= (TypeKinds.INTERFACES | TypeKinds.CLASSES);
}
return kinds;
}
private static int internalGetPossibleTypeKinds(ASTNode node) {
int kind= TypeKinds.ALL_TYPES;
int mask= TypeKinds.ALL_TYPES | TypeKinds.VOIDTYPE;
ASTNode parent= node.getParent();
while (parent instanceof QualifiedName) {
if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) {
return TypeKinds.REF_TYPES;
}
node= parent;
parent= parent.getParent();
mask= TypeKinds.REF_TYPES;
}
while (parent instanceof Type) {
if (parent instanceof QualifiedType) {
if (node.getLocationInParent() == QualifiedType.QUALIFIER_PROPERTY) {
return mask & (TypeKinds.REF_TYPES);
}
mask&= TypeKinds.REF_TYPES;
} else if (parent instanceof NameQualifiedType) {
if (node.getLocationInParent() == NameQualifiedType.QUALIFIER_PROPERTY) {
return mask & (TypeKinds.REF_TYPES);
}
mask&= TypeKinds.REF_TYPES;
} else if (parent instanceof ParameterizedType) {
if (node.getLocationInParent() == ParameterizedType.TYPE_ARGUMENTS_PROPERTY) {
return mask & TypeKinds.REF_TYPES_AND_VAR;
}
mask&= TypeKinds.CLASSES | TypeKinds.INTERFACES;
} else if (parent instanceof WildcardType) {
if (node.getLocationInParent() == WildcardType.BOUND_PROPERTY) {
return mask & TypeKinds.REF_TYPES_AND_VAR;
}
}
node= parent;
parent= parent.getParent();
}
if (parent != null) {
switch (parent.getNodeType()) {
case ASTNode.TYPE_DECLARATION:
if (node.getLocationInParent() == TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY) {
kind= TypeKinds.INTERFACES;
} else if (node.getLocationInParent() == TypeDeclaration.SUPERCLASS_TYPE_PROPERTY) {
kind= TypeKinds.CLASSES;
}
break;
case ASTNode.ENUM_DECLARATION:
kind= TypeKinds.INTERFACES;
break;
case ASTNode.METHOD_DECLARATION:
if (node.getLocationInParent() == MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) {
kind= TypeKinds.CLASSES;
} else if (node.getLocationInParent() == MethodDeclaration.RETURN_TYPE2_PROPERTY) {
kind= TypeKinds.ALL_TYPES | TypeKinds.VOIDTYPE;
}
break;
case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
kind= TypeKinds.PRIMITIVETYPES | TypeKinds.ANNOTATIONS | TypeKinds.ENUMS;
break;
case ASTNode.INSTANCEOF_EXPRESSION:
kind= TypeKinds.REF_TYPES;
break;
case ASTNode.THROW_STATEMENT:
kind= TypeKinds.CLASSES;
break;
case ASTNode.CLASS_INSTANCE_CREATION:
if (((ClassInstanceCreation) parent).getAnonymousClassDeclaration() == null) {
kind= TypeKinds.CLASSES;
} else {
kind= TypeKinds.CLASSES | TypeKinds.INTERFACES;
}
break;
case ASTNode.SINGLE_VARIABLE_DECLARATION:
int superParent= parent.getParent().getNodeType();
if (superParent == ASTNode.CATCH_CLAUSE) {
kind= TypeKinds.CLASSES;
} else if (superParent == ASTNode.ENHANCED_FOR_STATEMENT) {
kind= TypeKinds.REF_TYPES;
}
break;
case ASTNode.TAG_ELEMENT:
kind= TypeKinds.REF_TYPES;
break;
case ASTNode.MARKER_ANNOTATION:
case ASTNode.SINGLE_MEMBER_ANNOTATION:
case ASTNode.NORMAL_ANNOTATION:
kind= TypeKinds.ANNOTATIONS;
break;
case ASTNode.TYPE_PARAMETER:
if (((TypeParameter) parent).typeBounds().indexOf(node) > 0) {
kind= TypeKinds.INTERFACES;
} else {
kind= TypeKinds.REF_TYPES_AND_VAR;
}
break;
case ASTNode.TYPE_LITERAL:
kind= TypeKinds.REF_TYPES;
break;
default:
}
}
return kind & mask;
}
}