Skip to content

Commits on Source 5

eclipse-jdt-ui (4.12-1) unstable; urgency=medium
* New upstream release
- Depend on libeclipse-jdt-core-java (>= 3.18)
* Standards-Version updated to 4.4.0
-- Emmanuel Bourg <ebourg@apache.org> Tue, 06 Aug 2019 09:14:34 +0200
eclipse-jdt-ui (4.11-1) unstable; urgency=medium
* New upstream release
......
......@@ -23,7 +23,7 @@ Build-Depends:
libeclipse-debug-core-java,
libeclipse-debug-ui-java,
libeclipse-help-java,
libeclipse-jdt-core-java (>= 3.16),
libeclipse-jdt-core-java (>= 3.18),
libeclipse-jdt-launching-java (>= 3.11),
libeclipse-jface-java (>= 3.14),
libeclipse-jface-text-java (>= 3.15),
......@@ -48,7 +48,7 @@ Build-Depends:
libicu4j-java,
libswt-gtk-4-java,
eclipse-debian-helper
Standards-Version: 4.3.0
Standards-Version: 4.4.0
Vcs-Git: https://salsa.debian.org/java-team/eclipse-jdt-ui.git
Vcs-Browser: https://salsa.debian.org/java-team/eclipse-jdt-ui
Homepage: https://www.eclipse.org/jdt/ui/
......@@ -111,7 +111,7 @@ Depends:
libeclipse-core-jobs-java,
libeclipse-core-resources-java,
libeclipse-core-runtime-java,
libeclipse-jdt-core-java (>= 3.16),
libeclipse-jdt-core-java (>= 3.18),
libeclipse-jdt-launching-java,
libeclipse-text-java (>= 3.8),
libequinox-common-java,
......
......@@ -14,7 +14,7 @@
<parent>
<artifactId>eclipse.jdt.ui</artifactId>
<groupId>eclipse.jdt.ui</groupId>
<version>4.11.0-SNAPSHOT</version>
<version>4.12.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jdt.feature</groupId>
<artifactId>org.eclipse.jdt.astview.feature</artifactId>
......
......@@ -3,7 +3,7 @@ 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.300.qualifier
Bundle-Version: 1.4.0.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
......@@ -11,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.15.0,4.0.0)",
org.eclipse.jdt.ui;bundle-version="[3.14.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.18.0,4.0.0)",
org.eclipse.jdt.ui;bundle-version="[3.17.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, 2018 Eclipse Foundation and others.
Copyright (c) 2012, 2019 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.11.0-SNAPSHOT</version>
<version>4.12.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.astview</artifactId>
<version>1.3.300-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corporation and others.
* Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
......@@ -119,17 +119,31 @@ import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.ASTRequestor;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.BreakStatement;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.ExpressionStatement;
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.NodeFinder;
import org.eclipse.jdt.core.dom.Statement;
import org.eclipse.jdt.core.dom.SwitchExpression;
import org.eclipse.jdt.core.dom.SwitchStatement;
import org.eclipse.jdt.core.manipulation.SharedASTProviderCore;
import org.eclipse.jdt.ui.JavaUI;
public class ASTView extends ViewPart implements IShowInSource, IShowInTargetList {
static final int JLS_LATEST= AST.JLS11;
static final int JLS_LATEST= AST.JLS12;
private static final int JLS12= AST.JLS12;
/**
* @deprecated to get rid of deprecation warnings in code
*/
@Deprecated
private static final int JLS11= AST.JLS11;
/**
......@@ -384,6 +398,59 @@ public class ASTView extends ViewPart implements IShowInSource, IShowInTargetLis
}
}
private static final class BreakStatementChecker extends ASTVisitor {
@Override
public boolean visit(BreakStatement node) {
try {
if (node != null && node.isImplicit() && isInSwitchExpressionOrStatement(node)) {
ASTNode parent= node.getParent();
List<Statement> statements= null;
if (parent instanceof Block) {
statements= ((Block) parent).statements();
} else if (parent instanceof SwitchExpression) {
statements= ((SwitchExpression) parent).statements();
} else if (parent instanceof SwitchStatement) {
statements= ((SwitchStatement) parent).statements();
}
if (statements == null) {
return true;
}
Expression exp= node.getExpression();
if (exp == null) {
statements.remove(node);
return false;
} else {
int index= statements.indexOf(node);
statements.remove(node);
node.setExpression(null);
ExpressionStatement exprStmt= node.getAST().newExpressionStatement(exp);
exprStmt.setSourceRange(node.getStartPosition(), node.getLength());
statements.add(index, exprStmt);
exprStmt.accept(this);
return false;
}
}
} catch (UnsupportedOperationException e) {
// do nothing
}
return true;
}
private boolean isInSwitchExpressionOrStatement(BreakStatement node) {
boolean result= false;
ASTNode parent= node;
while (parent != null) {
if (parent instanceof SwitchStatement || parent instanceof SwitchExpression) {
result= true;
break;
}
parent= parent.getParent();
}
return result;
}
}
private final static String SETTINGS_LINK_WITH_EDITOR= "link_with_editor"; //$NON-NLS-1$
private final static String SETTINGS_INPUT_KIND= "input_kind"; //$NON-NLS-1$
private final static String SETTINGS_NO_BINDINGS= "create_bindings"; //$NON-NLS-1$
......@@ -469,6 +536,7 @@ public class ASTView extends ViewPart implements IShowInSource, IShowInTargetLis
case JLS9:
case JLS10:
case JLS11:
case JLS12:
fCurrentASTLevel= level;
}
} catch (NumberFormatException e) {
......@@ -650,6 +718,7 @@ public class ASTView extends ViewPart implements IShowInSource, IShowInTargetLis
endTime= System.currentTimeMillis();
}
if (root != null) {
root.accept(new BreakStatementChecker());
updateContentDescription(input, root, endTime - startTime);
}
return root;
......@@ -1098,6 +1167,7 @@ public class ASTView extends ViewPart implements IShowInSource, IShowInTargetLis
new ASTLevelToggle("AST Level &9 (9)", JLS9), //$NON-NLS-1$
new ASTLevelToggle("AST Level 1&0 (10)", JLS10), //$NON-NLS-1$
new ASTLevelToggle("AST Level 1&1 (11)", JLS11), //$NON-NLS-1$
new ASTLevelToggle("AST Level 1&2 (12)", JLS12), //$NON-NLS-1$
};
fAddToTrayAction= new Action() {
......
ANNOTATION_ELEMENT_TYPE_ADDED_FIELD=Error
ANNOTATION_ELEMENT_TYPE_ADDED_METHOD_WITHOUT_DEFAULT_VALUE=Error
ANNOTATION_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error
ANNOTATION_ELEMENT_TYPE_REMOVED_FIELD=Error
ANNOTATION_ELEMENT_TYPE_REMOVED_METHOD=Error
ANNOTATION_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error
API_COMPONENT_ELEMENT_TYPE_REMOVED_API_TYPE=Error
API_COMPONENT_ELEMENT_TYPE_REMOVED_REEXPORTED_API_TYPE=Error
API_COMPONENT_ELEMENT_TYPE_REMOVED_REEXPORTED_TYPE=Error
API_COMPONENT_ELEMENT_TYPE_REMOVED_TYPE=Error
API_USE_SCAN_FIELD_SEVERITY=Error
API_USE_SCAN_METHOD_SEVERITY=Error
API_USE_SCAN_TYPE_SEVERITY=Error
CLASS_ELEMENT_TYPE_ADDED_FIELD=Error
CLASS_ELEMENT_TYPE_ADDED_METHOD=Error
CLASS_ELEMENT_TYPE_ADDED_RESTRICTIONS=Error
CLASS_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error
CLASS_ELEMENT_TYPE_CHANGED_CONTRACTED_SUPERINTERFACES_SET=Error
CLASS_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error
CLASS_ELEMENT_TYPE_CHANGED_NON_ABSTRACT_TO_ABSTRACT=Error
CLASS_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error
CLASS_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error
CLASS_ELEMENT_TYPE_REMOVED_CONSTRUCTOR=Error
CLASS_ELEMENT_TYPE_REMOVED_FIELD=Error
CLASS_ELEMENT_TYPE_REMOVED_METHOD=Error
CLASS_ELEMENT_TYPE_REMOVED_SUPERCLASS=Error
CLASS_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error
CLASS_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error
CONSTRUCTOR_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error
CONSTRUCTOR_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error
CONSTRUCTOR_ELEMENT_TYPE_CHANGED_VARARGS_TO_ARRAY=Error
CONSTRUCTOR_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error
ENUM_ELEMENT_TYPE_CHANGED_CONTRACTED_SUPERINTERFACES_SET=Error
ENUM_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error
ENUM_ELEMENT_TYPE_REMOVED_ENUM_CONSTANT=Error
ENUM_ELEMENT_TYPE_REMOVED_FIELD=Error
ENUM_ELEMENT_TYPE_REMOVED_METHOD=Error
ENUM_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error
FIELD_ELEMENT_TYPE_ADDED_VALUE=Error
FIELD_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error
FIELD_ELEMENT_TYPE_CHANGED_FINAL_TO_NON_FINAL_STATIC_CONSTANT=Error
FIELD_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error
FIELD_ELEMENT_TYPE_CHANGED_NON_STATIC_TO_STATIC=Error
FIELD_ELEMENT_TYPE_CHANGED_STATIC_TO_NON_STATIC=Error
FIELD_ELEMENT_TYPE_CHANGED_TYPE=Error
FIELD_ELEMENT_TYPE_CHANGED_VALUE=Error
FIELD_ELEMENT_TYPE_REMOVED_TYPE_ARGUMENT=Error
FIELD_ELEMENT_TYPE_REMOVED_VALUE=Error
ILLEGAL_EXTEND=Warning
ILLEGAL_IMPLEMENT=Warning
ILLEGAL_INSTANTIATE=Warning
ILLEGAL_OVERRIDE=Warning
ILLEGAL_REFERENCE=Warning
INTERFACE_ELEMENT_TYPE_ADDED_DEFAULT_METHOD=Error
INTERFACE_ELEMENT_TYPE_ADDED_FIELD=Error
INTERFACE_ELEMENT_TYPE_ADDED_METHOD=Error
INTERFACE_ELEMENT_TYPE_ADDED_RESTRICTIONS=Error
INTERFACE_ELEMENT_TYPE_ADDED_SUPER_INTERFACE_WITH_METHODS=Error
INTERFACE_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error
INTERFACE_ELEMENT_TYPE_CHANGED_CONTRACTED_SUPERINTERFACES_SET=Error
INTERFACE_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error
INTERFACE_ELEMENT_TYPE_REMOVED_FIELD=Error
INTERFACE_ELEMENT_TYPE_REMOVED_METHOD=Error
INTERFACE_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error
INTERFACE_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error
INVALID_ANNOTATION=Ignore
INVALID_JAVADOC_TAG=Ignore
INVALID_REFERENCE_IN_SYSTEM_LIBRARIES=Ignore
LEAK_EXTEND=Warning
LEAK_FIELD_DECL=Warning
LEAK_IMPLEMENT=Warning
LEAK_METHOD_PARAM=Warning
LEAK_METHOD_RETURN_TYPE=Warning
METHOD_ELEMENT_TYPE_ADDED_RESTRICTIONS=Error
METHOD_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error
METHOD_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error
METHOD_ELEMENT_TYPE_CHANGED_NON_ABSTRACT_TO_ABSTRACT=Error
METHOD_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error
METHOD_ELEMENT_TYPE_CHANGED_NON_STATIC_TO_STATIC=Error
METHOD_ELEMENT_TYPE_CHANGED_STATIC_TO_NON_STATIC=Error
METHOD_ELEMENT_TYPE_CHANGED_VARARGS_TO_ARRAY=Error
METHOD_ELEMENT_TYPE_REMOVED_ANNOTATION_DEFAULT_VALUE=Error
METHOD_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error
MISSING_EE_DESCRIPTIONS=Warning
TYPE_PARAMETER_ELEMENT_TYPE_ADDED_CLASS_BOUND=Error
TYPE_PARAMETER_ELEMENT_TYPE_ADDED_INTERFACE_BOUND=Error
TYPE_PARAMETER_ELEMENT_TYPE_CHANGED_CLASS_BOUND=Error
TYPE_PARAMETER_ELEMENT_TYPE_CHANGED_INTERFACE_BOUND=Error
TYPE_PARAMETER_ELEMENT_TYPE_REMOVED_CLASS_BOUND=Error
TYPE_PARAMETER_ELEMENT_TYPE_REMOVED_INTERFACE_BOUND=Error
UNUSED_PROBLEM_FILTERS=Warning
automatically_removed_unused_problem_filters=false
changed_execution_env=Error
eclipse.preferences.version=1
incompatible_api_component_version=Error
incompatible_api_component_version_report_major_without_breaking_change=Error
incompatible_api_component_version_report_minor_without_api_change=Error
invalid_since_tag_version=Error
malformed_since_tag=Error
missing_since_tag=Error
report_api_breakage_when_major_version_incremented=Disabled
report_resolution_errors_api_component=Warning
......@@ -3,14 +3,14 @@ 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.11.100.qualifier
Bundle-Version: 1.11.200.qualifier
Bundle-Vendor: %providerName
Bundle-Activator: org.eclipse.jdt.internal.core.manipulation.JavaManipulationPlugin
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.11.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.5.0,4.0.0)",
org.eclipse.ltk.core.refactoring;bundle-version="[3.6.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.8.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.18.0,4.0.0)",
org.eclipse.core.expressions;bundle-version="[3.4.100,4.0.0)",
org.eclipse.text;bundle-version="[3.5.0,4.0.0)",
org.eclipse.jdt.launching;bundle-version="3.9.0",
......@@ -27,6 +27,7 @@ Export-Package: org.eclipse.jdt.core.manipulation,
org.eclipse.jdt.internal.core.manipulation.util;x-friends:="org.eclipse.jdt.junit,org.eclipse.jdt.text.tests,org.eclipse.jdt.ui",
org.eclipse.jdt.internal.core.refactoring.descriptors;x-friends:="org.eclipse.jdt.ui",
org.eclipse.jdt.internal.corext;x-friends:="org.eclipse.jdt.ui",
org.eclipse.jdt.internal.corext.callhierarchy;x-friends:="org.eclipse.jdt.ui",
org.eclipse.jdt.internal.corext.codemanipulation;x-friends:="org.eclipse.jdt.ui",
org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration;x-friends:="org.eclipse.jdt.ui",
org.eclipse.jdt.internal.corext.dom;manipulation=split;mandatory:=manipulation;x-friends:="org.eclipse.jdt.ui,org.eclipse.jdt.junit",
......@@ -48,6 +49,7 @@ Export-Package: org.eclipse.jdt.core.manipulation,
org.eclipse.jdt.internal.ui.preferences;x-friends:="org.eclipse.jdt.ui",
org.eclipse.jdt.internal.ui.text;x-friends:="org.eclipse.jdt.ui",
org.eclipse.jdt.internal.ui.text.correction;x-friends:="org.eclipse.jdt.ui",
org.eclipse.jdt.internal.ui.text.correction.proposals;x-friends:="org.eclipse.jdt.ui"
org.eclipse.jdt.internal.ui.text.correction.proposals;x-friends:="org.eclipse.jdt.ui",
org.eclipse.jdt.internal.ui.util;x-friends:="org.eclipse.jdt.ui"
Import-Package: com.ibm.icu.text
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corporation and others.
* Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
......@@ -305,6 +305,10 @@ public class ImportReferencesCollector extends GenericVisitor {
@Override
public boolean visit(BreakStatement node) {
int apiLevel= node.getAST().apiLevel();
if (apiLevel >= AST.JLS12) {
evalQualifyingExpression(node.getExpression(), null);
}
return false;
}
......
/*******************************************************************************
* Copyright (c) 2007, 2018 IBM Corporation and others.
* Copyright (c) 2007, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
......@@ -30,15 +30,16 @@ import org.eclipse.jdt.core.manipulation.CoreASTProvider;
* <p>For performance reasons, not more than one AST should be kept in memory at a time. Therefore, clients must
* not keep any references to the shared AST or its nodes or bindings.
* </p>
* <p>Clients can make the following assumptions about the AST:
* <dl>
* <p>Clients can make the following assumptions about the AST:</p>
* <ul>
* <li>the AST has a {@link ITypeRoot} as source: {@link CompilationUnit#getTypeRoot()} is not null.</li>
* <li>the {@link AST#apiLevel() AST API level} is {@link AST#JLS11 API level 11} or higher</li>
* <li>the {@link AST#apiLevel() AST API level} is {@link AST#JLS12 API level 12} or higher</li>
* <li>the AST has bindings resolved ({@link AST#hasResolvedBindings()})</li>
* <li>{@link AST#hasStatementsRecovery() statement} and {@link AST#hasBindingsRecovery() bindings}
* recovery are enabled
* </li>
* </dl>
* </ul>
* <p>
* It is possible that in the future a higher API level is used, or that future options will be enabled.
* </p>
* <p>
......@@ -116,7 +117,7 @@ public class SharedASTProviderCore {
* @param waitFlag {@link #WAIT_YES}, {@link #WAIT_NO} or {@link #WAIT_ACTIVE_ONLY}
* @param progressMonitor the progress monitor or <code>null</code>
* @return the AST or <code>null</code>.
* <dl>
* <ul>
* <li>If {@link #WAIT_NO} has been specified <code>null</code> is returned if the
* element is not input of the current Java editor or no AST is available</li>
* <li>If {@link #WAIT_ACTIVE_ONLY} has been specified <code>null</code> is returned if
......@@ -124,7 +125,7 @@ public class SharedASTProviderCore {
* <li>If {@link #WAIT_YES} has been specified either the shared AST is returned or a
* new AST is created.</li>
* <li><code>null</code> will be returned if the operation gets canceled.</li>
* </dl>
* </ul>
*/
public static CompilationUnit getAST(ITypeRoot element, WAIT_FLAG waitFlag, IProgressMonitor progressMonitor) {
CoreASTProvider.WAIT_FLAG finalWaitFlag = null;
......
......@@ -36,6 +36,7 @@ import org.eclipse.jdt.core.ILocalVariable;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IModuleDescription;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.ISourceRange;
......@@ -197,6 +198,9 @@ public class JavaElementLabelComposerCore {
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
appendPackageFragmentRootLabel((IPackageFragmentRoot) element, flags);
break;
case IJavaElement.JAVA_MODULE:
appendModuleLabel((IModuleDescription) element, flags);
break;
case IJavaElement.IMPORT_CONTAINER:
case IJavaElement.IMPORT_DECLARATION:
case IJavaElement.PACKAGE_DECLARATION:
......@@ -1197,6 +1201,18 @@ public class JavaElementLabelComposerCore {
}
}
protected void appendModuleLabel(IModuleDescription module, long flags) {
fBuffer.append(module.getElementName());
// category
if (getFlag(flags, JavaElementLabelsCore.MOD_CATEGORY) && module.exists()) {
try {
appendCategoryLabel(module, flags);
} catch (JavaModelException e) {
// ignore
}
}
}
private void appendArchiveLabel(IPackageFragmentRoot root, long flags) {
boolean external= root.isExternal();
if (external) {
......
......@@ -302,11 +302,15 @@ public final class JavaElementLabelsCore {
* Prepend first category (if any) to type.
*/
public final static long T_CATEGORY= 1L << 51;
/**
* Prepend first category (if any) to module.
*/
public final static long MOD_CATEGORY= 1L << 52;
/**
* Show category for all elements.
*/
public final static long ALL_CATEGORY= Long.valueOf(F_CATEGORY | M_CATEGORY | T_CATEGORY).longValue();
public final static long ALL_CATEGORY= Long.valueOf(F_CATEGORY | M_CATEGORY | T_CATEGORY | MOD_CATEGORY).longValue();
/**
* Qualify all elements
......
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corporation and others.
* Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
......@@ -48,6 +48,7 @@ public class JavaManipulationMessages extends NLS {
public static String StatementAnalyzer_for_expression_updater;
public static String StatementAnalyzer_for_updater_body;
public static String StatementAnalyzer_switch_statement;
public static String StatementAnalyzer_switch_expression;
public static String StatementAnalyzer_synchronized_statement;
public static String StatementAnalyzer_try_statement;
public static String StatementAnalyzer_catch_argument;
......
###############################################################################
# Copyright (c) 2000, 2018 IBM Corporation and others.
# Copyright (c) 2000, 2019 IBM Corporation and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
......@@ -35,6 +35,7 @@ StatementAnalyzer_catch_argument=Operation is not applicable to a catch block's
StatementAnalyzer_while_expression_body=Operation not applicable to a while statement's expression and body.
StatementAnalyzer_try_statement=Selection must either cover whole try statement or parts of try, catch, or finally block.
StatementAnalyzer_switch_statement=Selection must either cover whole switch statement or parts of a single case block.
StatementAnalyzer_switch_expression=Selection must either cover whole switch expression or parts of a single case block.
StatementAnalyzer_synchronized_statement=Selection must either cover whole synchronized statement or parts of the synchronized block.
SurroundWithTryCatchAnalyzer_doesNotCover=Selection does not cover a set of statements. Extend selection to a valid range using the \'Expand Selection To\' actions from the \'Edit\' menu.
......
/**
* Copyright (c) 2011 Stefan Henss.
* 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:
* Stefan Henß - initial API and implementation.
*/
package org.eclipse.jdt.internal.ui.text;
import java.util.List;
public class Chain {
private final List<ChainElement> elements;
private final int expectedDimensions;
public Chain(final List<ChainElement> elements, final int expectedDimensions) {
this.elements= elements;
this.expectedDimensions= expectedDimensions;
}
public List<ChainElement> getElements() {
return elements;
}
public int getExpectedDimensions() {
return expectedDimensions;
}
}
/**
* Copyright (c) 2010, 2019 Darmstadt University of Technology 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:
* Marcel Bruch - initial API and implementation.
*/
package org.eclipse.jdt.internal.ui.text;
import org.eclipse.osgi.util.NLS;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.ILocalVariable;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.internal.core.manipulation.JavaManipulationPlugin;
/**
* Represents a transition from Type A to Type B by some chain element ( {@link IField} access,
* {@link IMethod} call, or {@link ILocalVariable} (as entrypoints only)).
*
* @see ChainFinder
*/
public class ChainElement {
public enum ElementType {
METHOD, FIELD, LOCAL_VARIABLE
}
private final IBinding element;
private ITypeBinding returnType;
private int dimension;
private ElementType elementType;
private final boolean requireThis;
public ChainElement(final IBinding binding, final boolean requireThis) {
if (binding == null) {
throw new IllegalArgumentException("???"); //$NON-NLS-1$
}
element= binding;
this.requireThis= requireThis;
initializeReturnType();
}
private void initializeReturnType() {
switch (element.getKind()) {
case IBinding.VARIABLE:
IVariableBinding tmp= ((IVariableBinding) element);
returnType= tmp.getType();
if (tmp.isField()) {
elementType= ElementType.FIELD;
} else {
elementType= ElementType.LOCAL_VARIABLE;
}
break;
case IBinding.METHOD:
returnType= ((IMethodBinding) element).getReturnType();
elementType= ElementType.METHOD;
break;
case IBinding.TYPE:
returnType= ((ITypeBinding) element);
elementType= ElementType.FIELD;
break;
default:
JavaManipulationPlugin.logErrorMessage(NLS.bind("Cannot handle {0} as return type.", element));
}
dimension= returnType.getDimensions();
}
@SuppressWarnings("unchecked")
public <T extends IBinding> T getElementBinding() {
return (T) element;
}
public ElementType getElementType() {
return elementType;
}
public ITypeBinding getReturnType() {
return returnType;
}
public int getReturnTypeDimension() {
return dimension;
}
public boolean requiresThisForQualification() {
return requireThis;
}
@Override
public int hashCode() {
return element.hashCode();
}
@Override
public boolean equals(final Object obj) {
if (obj instanceof ChainElement) {
final ChainElement other= (ChainElement) obj;
return element.equals(other.element);
}
return false;
}
@Override
public String toString() {
if (elementType == ElementType.METHOD) {
final IMethodBinding m= (IMethodBinding) element;
IJavaElement e= m.getJavaElement();
StringBuilder ret= new StringBuilder(m.getName());
if (e instanceof IMethod) {
try {
return ret.append(((IMethod) e).getSignature()).toString();
} catch (JavaModelException e1) {
return ret.toString();
}
}
}
return element.toString();
}
}
/**
* Copyright (c) 2010, 2019 Darmstadt University of Technology 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:
* Marcel Bruch - initial API and implementation.
* Stefan Henss - re-implementation in response to https://bugs.eclipse.org/bugs/show_bug.cgi?id=376796.
*/
package org.eclipse.jdt.internal.ui.text;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
public class ChainFinder {
private final List<ITypeBinding> expectedTypes;
private final List<String> excludedTypes;
private final IJavaElement invocationSite;
private final List<Chain> chains= new LinkedList<>();
private final Map<IBinding, ChainElement> edgeCache= new HashMap<>();
private final Map<Map<ITypeBinding, Boolean>, List<IBinding>> fieldsAndMethodsCache= new HashMap<>();
private final Map<Map<ChainElement, ITypeBinding>, Boolean> assignableCache= new HashMap<>();
public ChainFinder(final List<ITypeBinding> expectedTypes, final List<String> excludedTypes,
final IJavaElement invocationSite) {
this.expectedTypes= expectedTypes;
this.excludedTypes= excludedTypes;
this.invocationSite= invocationSite;
}
public void startChainSearch(final List<ChainElement> entrypoints, final int maxChains, final int minDepth,
final int maxDepth) {
for (final ITypeBinding expected : expectedTypes) {
if (expected != null && !ChainFinder.isFromExcludedType(excludedTypes, expected)) {
ITypeBinding expectedType= expected;
int expectedDimension= 0;
if (expectedType.isArray()) {
expectedDimension= expectedType.getDimensions();
expectedType= TypeBindingAnalyzer.removeArrayWrapper(expectedType);
}
searchChainsForExpectedType(expectedType, expectedDimension, entrypoints, maxChains, minDepth,
maxDepth);
}
}
}
private void searchChainsForExpectedType(final ITypeBinding expectedType, final int expectedDimensions,
final List<ChainElement> entrypoints, final int maxChains, final int minDepth, final int maxDepth) {
final LinkedList<LinkedList<ChainElement>> incompleteChains= prepareQueue(entrypoints);
while (!incompleteChains.isEmpty()) {
final LinkedList<ChainElement> chain= incompleteChains.poll();
final ChainElement edge= chain.getLast();
if (isValidEndOfChain(edge, expectedType, expectedDimensions)) {
if (chain.size() >= minDepth) {
chains.add(new Chain(chain, expectedDimensions));
if (chains.size() == maxChains) {
break;
}
}
continue;
}
if (chain.size() < maxDepth && incompleteChains.size() <= 50000) {
searchDeeper(chain, incompleteChains, edge.getReturnType());
}
}
}
/**
* Returns the potentially incomplete list of call chains that could be found before a time out
* happened. The contents of this list are mutable and may change as the search makes progress.
*
* @return The list of call chains
*/
public List<Chain> getChains() {
return chains;
}
private static LinkedList<LinkedList<ChainElement>> prepareQueue(final List<ChainElement> entrypoints) {
final LinkedList<LinkedList<ChainElement>> incompleteChains= new LinkedList<>();
for (final ChainElement entrypoint : entrypoints) {
final LinkedList<ChainElement> chain= new LinkedList<>();
chain.add(entrypoint);
incompleteChains.add(chain);
}
return incompleteChains;
}
public static boolean isFromExcludedType(final List<String> excluded, final IBinding binding) {
String tmp= String.valueOf(binding.getKey());
int index= tmp.indexOf(";"); //$NON-NLS-1$
final String key= index == -1 ? tmp : tmp.substring(0, index);
return excluded.contains(key);
}
private boolean isValidEndOfChain(final ChainElement edge, final ITypeBinding expectedType,
final int expectedDimension) {
if (edge.getElementBinding().getKind() == IBinding.TYPE) {
return false;
}
Boolean isAssignable= assignableCache.get(Collections.singletonMap(edge, expectedType));
if (isAssignable == null) {
isAssignable= TypeBindingAnalyzer.isAssignable(edge, expectedType, expectedDimension);
assignableCache.put(Collections.singletonMap(edge, expectedType), isAssignable);
}
return isAssignable.booleanValue();
}
private void searchDeeper(final LinkedList<ChainElement> chain,
final List<LinkedList<ChainElement>> incompleteChains, final ITypeBinding currentlyVisitedType) {
boolean staticOnly= false;
if (chain.getLast().getElementBinding().getKind() == IBinding.TYPE) {
staticOnly= true;
}
for (final IBinding element : findAllFieldsAndMethods(currentlyVisitedType, staticOnly)) {
final ChainElement newEdge= createEdge(element);
if (!chain.contains(newEdge)) {
incompleteChains.add(cloneChainAndAppendEdge(chain, newEdge));
}
}
}
private List<IBinding> findAllFieldsAndMethods(final ITypeBinding chainElementType, boolean staticOnly) {
List<IBinding> cached= fieldsAndMethodsCache.get(Collections.singletonMap(chainElementType, staticOnly));
if (cached == null) {
cached= new LinkedList<>();
Collection<IBinding> candidates= staticOnly
? TypeBindingAnalyzer.findAllPublicStaticFieldsAndNonVoidNonPrimitiveStaticMethods(chainElementType, invocationSite)
: TypeBindingAnalyzer.findVisibleInstanceFieldsAndRelevantInstanceMethods(chainElementType, invocationSite);
for (final IBinding binding : candidates) {
if (!ChainFinder.isFromExcludedType(excludedTypes, binding)) {
cached.add(binding);
}
}
fieldsAndMethodsCache.put(Collections.singletonMap(chainElementType, staticOnly), cached);
}
return cached;
}
private ChainElement createEdge(final IBinding member) {
ChainElement cached= edgeCache.get(member);
if (cached == null) {
cached= new ChainElement(member, false);
edgeCache.put(member, cached);
}
return cached;
}
private static LinkedList<ChainElement> cloneChainAndAppendEdge(final LinkedList<ChainElement> chain,
final ChainElement newEdge) {
@SuppressWarnings("unchecked")
final LinkedList<ChainElement> chainCopy= (LinkedList<ChainElement>) chain.clone();
chainCopy.add(newEdge);
return chainCopy;
}
}
/**
* Copyright (c) 2011, 2019 Stefan Henss 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:
* Stefan Henß - initial API and implementation.
*/
package org.eclipse.jdt.internal.ui.text;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import org.eclipse.jdt.core.CompletionContext;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.internal.corext.dom.Bindings;
import org.eclipse.jdt.internal.corext.dom.IASTSharedValues;
import org.eclipse.jdt.internal.corext.template.java.SignatureUtil;
public final class TypeBindingAnalyzer {
private static final Predicate<IVariableBinding> NON_STATIC_FIELDS_ONLY_FILTER = new Predicate<IVariableBinding>() {
@Override
public boolean test(IVariableBinding t) {
return !Modifier.isStatic(t.getModifiers());
}
};
private static final Predicate<IMethodBinding> RELEVANT_NON_STATIC_METHODS_ONLY_FILTER = new Predicate<IMethodBinding>() {
@Override
public boolean test(IMethodBinding m) {
return !Modifier.isStatic(m.getModifiers()) && !isVoid(m) & !m.isConstructor() && !hasPrimitiveReturnType(m);
}
};
private static final Predicate<IVariableBinding> STATIC_FIELDS_ONLY_FILTER = new Predicate<IVariableBinding>() {
@Override
public boolean test(IVariableBinding t) {
return Modifier.isStatic(t.getModifiers());
}
};
private static final Predicate<IMethodBinding> STATIC_NON_VOID_NON_PRIMITIVE_METHODS_ONLY_FILTER = new Predicate<IMethodBinding>() {
@Override
public boolean test(IMethodBinding m) {
return Modifier.isStatic(m.getModifiers()) && !isVoid(m) && !m.isConstructor() && hasPrimitiveReturnType(m);
}
};
private TypeBindingAnalyzer() {
}
private static boolean isVoid(final IMethodBinding m) {
return hasPrimitiveReturnType(m) && Bindings.isVoidType(m.getReturnType());
}
private static boolean hasPrimitiveReturnType(final IMethodBinding m) {
return m.getReturnType().isPrimitive();
}
public static Collection<IBinding> findVisibleInstanceFieldsAndRelevantInstanceMethods(final ITypeBinding type,
final IJavaElement invocationSite) {
return findFieldsAndMethods(type, invocationSite, NON_STATIC_FIELDS_ONLY_FILTER,
RELEVANT_NON_STATIC_METHODS_ONLY_FILTER);
}
public static Collection<IBinding> findAllPublicStaticFieldsAndNonVoidNonPrimitiveStaticMethods(
final ITypeBinding type, final IJavaElement invocationSite) {
return findFieldsAndMethods(type, invocationSite, STATIC_FIELDS_ONLY_FILTER,
STATIC_NON_VOID_NON_PRIMITIVE_METHODS_ONLY_FILTER);
}
private static Collection<IBinding> findFieldsAndMethods(final ITypeBinding type, final IJavaElement invocationSite,
final Predicate<IVariableBinding> fieldFilter, final Predicate<IMethodBinding> methodFilter) {
final Map<String, IBinding> tmp = new LinkedHashMap<>();
final IType invocationType = ((IMember) invocationSite).getCompilationUnit().findPrimaryType();
final ITypeBinding receiverType = getTypeBindingFrom(invocationType);
for (final ITypeBinding cur : findAllSupertypesIncludingArgument(type)) {
for (final IMethodBinding method : cur.getDeclaredMethods()) {
if (!methodFilter.test(method) || !methodCanBeSeenBy(method, receiverType)) {
continue;
}
final String key = createMethodKey(method);
if (!tmp.containsKey(key)) {
tmp.put(key, method);
}
}
for (final IVariableBinding field : cur.getDeclaredFields()) {
if (!fieldFilter.test(field) || !fieldCanBeSeenBy(field, receiverType)) {
continue;
}
final String key = createFieldKey(field);
if (!tmp.containsKey(key)) {
tmp.put(key, field);
}
}
}
return tmp.values();
}
private static List<ITypeBinding> findAllSupertypesIncludingArgument(final ITypeBinding type) {
final ITypeBinding base = removeArrayWrapper(type);
if (base.isPrimitive() || Bindings.isVoidType(type)) {
return Collections.emptyList();
}
final List<ITypeBinding> supertypes = new LinkedList<>();
final LinkedList<ITypeBinding> queue = new LinkedList<>();
queue.add(base);
while (!queue.isEmpty()) {
final ITypeBinding superType = queue.poll();
if (superType == null || supertypes.contains(superType)) {
continue;
}
supertypes.add(superType);
queue.add(superType.getSuperclass());
for (final ITypeBinding interfc : superType.getInterfaces()) {
queue.add(interfc);
}
}
return supertypes;
}
private static String createFieldKey(final IVariableBinding field) {
StringBuilder ret= new StringBuilder(field.getName());
try {
String typeSignature= ((IField)field.getJavaElement()).getTypeSignature();
return ret.append(typeSignature).toString();
} catch (JavaModelException e) {
return ret.toString();
}
}
private static String createMethodKey(final IMethodBinding method) {
if (method.getJavaElement() instanceof IMethod) {
StringBuilder ret= new StringBuilder().append(method.getName());
try {
IMethod m = (IMethod) method.getJavaElement();
String signature= String.valueOf(m.getSignature());
int index = signature.lastIndexOf(")"); //$NON-NLS-1$
final String signatureWithoutReturnType = index == -1 ? signature : signature.substring(0, index);
return ret.append(signatureWithoutReturnType).toString();
} catch (JavaModelException e) {
return ret.toString();
}
}
return null;
}
public static boolean isAssignable(final ChainElement edge, final ITypeBinding expectedType,
final int expectedDimension) {
if (expectedDimension <= edge.getReturnTypeDimension()) {
final ITypeBinding base = removeArrayWrapper(edge.getReturnType());
if (base.isAssignmentCompatible(expectedType)) {
return true;
}
final LinkedList<ITypeBinding> supertypes = new LinkedList<>();
supertypes.add(base);
String expectedSignature = expectedType.getBinaryName();
while (!supertypes.isEmpty()) {
final ITypeBinding type = supertypes.poll();
String typeSignature = type.getBinaryName();
if (typeSignature.equals(expectedSignature)) {
return true;
}
final ITypeBinding superclass = type.getSuperclass();
if (superclass != null) {
supertypes.add(superclass);
}
for (final ITypeBinding intf : type.getInterfaces()) {
supertypes.add(intf);
}
}
}
return false;
}
public static ITypeBinding removeArrayWrapper(final ITypeBinding type) {
if (type.getComponentType() != null) {
ITypeBinding base = type;
while (base.getComponentType() != null) {
base = base.getComponentType();
}
return base;
} else {
return type;
}
}
public static List<ITypeBinding> resolveBindingsForExpectedTypes(final IJavaProject proj, final ICompilationUnit cu, final CompletionContext ctx) {
final List<ITypeBinding> bindings = new LinkedList<>();
final IType expectedTypeSig = getExpectedType(proj, ctx);
if (expectedTypeSig == null) {
ASTParser parser= createParser(cu);
AST ast= parser.createAST(null).getAST();
ITypeBinding binding= ast.resolveWellKnownType(TypeBindingAnalyzer.getExpectedFullyQualifiedTypeName(ctx));
int dim= TypeBindingAnalyzer.getArrayDimension(ctx.getExpectedTypesSignatures());
if (dim > 0) {
binding= binding.createArrayType(dim);
}
bindings.add(binding);
} else {
IBinding[] res= resolveBindingsForTypes(cu, new IJavaElement[] { expectedTypeSig });
if (res.length == 1 && res[0] instanceof ITypeBinding) {
bindings.add((ITypeBinding) res[0]);
}
}
return bindings;
}
public static IType getExpectedType(final IJavaProject proj, final CompletionContext ctx) {
IType expected= null;
String fqExpectedType= getExpectedFullyQualifiedTypeName(ctx);
if (fqExpectedType != null) {
try {
expected= proj.findType(fqExpectedType);
} catch (JavaModelException e) {
// do nothing
}
}
return expected;
}
public static String getExpectedFullyQualifiedTypeName(final CompletionContext ctx) {
String fqExpectedType= null;
final char[][] expectedTypes= ctx.getExpectedTypesSignatures();
if (expectedTypes != null && expectedTypes.length > 0) {
fqExpectedType= SignatureUtil.stripSignatureToFQN(new String(expectedTypes[0]));
}
return fqExpectedType;
}
private static int getArrayDimension(final char[][] expectedTypesSignatures) {
if (expectedTypesSignatures != null && expectedTypesSignatures.length > 0) {
return Signature.getArrayCount(new String(expectedTypesSignatures[0]));
}
return 0;
}
private static ITypeBinding getTypeBindingFrom(IType type) {
IBinding[] res= resolveBindingsForTypes(type.getCompilationUnit(), new IJavaElement [] { type });
if (res.length == 1 && res[0] instanceof ITypeBinding) {
return (ITypeBinding) res[0];
}
return null;
}
private static boolean methodCanBeSeenBy(IMethodBinding mb, ITypeBinding invocationType) {
if (Modifier.isPublic(mb.getModifiers())) {
return true;
}
if (Bindings.equals(invocationType, mb.getDeclaringClass())) {
return true;
}
String invocationPackage= invocationType.getPackage().getName();
String methodPackage= mb.getDeclaringClass().getPackage().getName();
if (Modifier.isProtected(mb.getModifiers())) {
if (invocationPackage.equals(methodPackage)) {
return false; // isSuper ?
}
}
if (Modifier.isPrivate(mb.getModifiers())) {
ITypeBinding mTypeRoot= mb.getDeclaringClass();
while (invocationType.getDeclaringClass() != null) {
mTypeRoot= mTypeRoot.getDeclaringClass();
}
ITypeBinding invTypeRoot= invocationType;
while (invTypeRoot.getDeclaringClass() != null) {
invTypeRoot= invTypeRoot.getDeclaringClass();
}
return Bindings.equals(invTypeRoot, mTypeRoot);
}
return invocationPackage.equals(methodPackage);
}
private static boolean fieldCanBeSeenBy(IVariableBinding fb, ITypeBinding invocationType) {
if (Modifier.isPublic(fb.getModifiers())) {
return true;
}
if (Bindings.equals(invocationType, fb.getDeclaringClass())) {
return true;
}
String invocationpackage = invocationType.getPackage().getName();
String fieldPackage = fb.getDeclaringClass().getPackage().getName();
if (Modifier.isProtected(fb.getModifiers())) {
if (Bindings.equals(invocationType, fb.getDeclaringClass())) {
return true;
}
if (invocationpackage.equals(fieldPackage)) {
return true;
}
ITypeBinding currType = invocationType.getSuperclass();
while (currType != null) {
if (Bindings.equals(currType, fb.getDeclaringClass())) {
return true;
}
currType = currType.getSuperclass();
}
}
if (Modifier.isPrivate(fb.getModifiers())) {
ITypeBinding fTypeRoot= fb.getDeclaringClass();
while (invocationType.getDeclaringClass() != null) {
fTypeRoot= fTypeRoot.getDeclaringClass();
}
ITypeBinding invTypeRoot= invocationType;
while (invTypeRoot.getDeclaringClass() != null) {
invTypeRoot= invTypeRoot.getDeclaringClass();
}
if (Bindings.equalDeclarations(fTypeRoot, invTypeRoot)) {
return true;
}
}
if (! invocationpackage.equals(fieldPackage)) {
return false;
}
return false;
}
public static IBinding[] resolveBindingsForTypes(ICompilationUnit cu, IJavaElement[] elements) {
ASTParser parser= createParser(cu);
return parser.createBindings(elements, null);
}
private static ASTParser createParser(ICompilationUnit cu) {
ASTParser parser= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setProject(cu.getJavaProject());
parser.setSource(cu);
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
parser.setStatementsRecovery(true);
return parser;
}
}
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corporation and others.
* Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
......@@ -73,6 +73,7 @@ import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
import org.eclipse.jdt.core.dom.SuperMethodInvocation;
import org.eclipse.jdt.core.dom.SwitchCase;
import org.eclipse.jdt.core.dom.SwitchExpression;
import org.eclipse.jdt.core.dom.SwitchStatement;
import org.eclipse.jdt.core.dom.TagElement;
import org.eclipse.jdt.core.dom.TryStatement;
......@@ -294,8 +295,15 @@ public class ASTResolving {
}
break;
case ASTNode.SWITCH_CASE:
if (node.equals(((SwitchCase) parent).getExpression()) && parent.getParent() instanceof SwitchStatement) {
return ((SwitchStatement) parent.getParent()).getExpression().resolveTypeBinding();
SwitchCase switchCase= (SwitchCase) parent;
if (node.equals(switchCase.getExpression()) || (switchCase.getAST().apiLevel() >= AST.JLS12 && switchCase.expressions().contains(node))) {
ASTNode caseParent= switchCase.getParent();
if (caseParent instanceof SwitchStatement) {
return ((SwitchStatement) caseParent).getExpression().resolveTypeBinding();
}
if (caseParent instanceof SwitchExpression) {
return ((SwitchExpression) caseParent).getExpression().resolveTypeBinding();
}
}
break;
case ASTNode.ASSERT_STATEMENT:
......