1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

218265 - replace Enum class with Java 5 enums

This commit is contained in:
Mike Kucera 2008-02-07 23:13:59 +00:00
parent 6a80d1f5da
commit ecf9c5833d
13 changed files with 106 additions and 203 deletions

View file

@ -236,7 +236,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
+ fTranslationUnit.getElementName() + fTranslationUnit.getElementName()
+ " mode="+ (quickParseMode ? "skip all " : "skip indexed ") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + " mode="+ (quickParseMode ? "skip all " : "skip indexed ") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ " time="+ ( System.currentTimeMillis() - startTime ) + "ms", //$NON-NLS-1$ //$NON-NLS-2$ + " time="+ ( System.currentTimeMillis() - startTime ) + "ms", //$NON-NLS-1$ //$NON-NLS-2$
IDebugLogConstants.MODEL, false); DebugLogConstants.MODEL, false);
if (ast == null) { if (ast == null) {
return; return;
@ -249,7 +249,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
Util.debugLog("CModelBuilder2: building " //$NON-NLS-1$ Util.debugLog("CModelBuilder2: building " //$NON-NLS-1$
+"children="+ fTranslationUnit.getElementInfo().internalGetChildren().size() //$NON-NLS-1$ +"children="+ fTranslationUnit.getElementInfo().internalGetChildren().size() //$NON-NLS-1$
+" time="+ (System.currentTimeMillis() - startTime) + "ms", //$NON-NLS-1$ //$NON-NLS-2$ +" time="+ (System.currentTimeMillis() - startTime) + "ms", //$NON-NLS-1$ //$NON-NLS-2$
IDebugLogConstants.MODEL, false); DebugLogConstants.MODEL, false);
if (elementInfo instanceof ASTHolderTUInfo) { if (elementInfo instanceof ASTHolderTUInfo) {
((ASTHolderTUInfo)elementInfo).fAST= ast; ((ASTHolderTUInfo)elementInfo).fAST= ast;
@ -269,7 +269,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
private void checkCanceled() { private void checkCanceled() {
if (fProgressMonitor != null && fProgressMonitor.isCanceled()) { if (fProgressMonitor != null && fProgressMonitor.isCanceled()) {
Util.debugLog("CModelBuilder2: cancelled ", IDebugLogConstants.MODEL, false); //$NON-NLS-1$ Util.debugLog("CModelBuilder2: cancelled ", DebugLogConstants.MODEL, false); //$NON-NLS-1$
throw new OperationCanceledException(); throw new OperationCanceledException();
} }
} }

View file

@ -6,27 +6,14 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Corporation - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.internal.core.model;
/**
* @author jcamelon
*
*/
public class Enum
{
protected Enum( int enumValue )
{
this.enumValue = enumValue;
}
private final int enumValue; public enum DebugLogConstants {
/**
* @return PARSER,
*/ MODEL,
protected int getEnumValue() SCANNER,
{
return enumValue;
}
} }

View file

@ -1,27 +0,0 @@
/*******************************************************************************
* Copyright (c) 2002, 2006 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.cdt.internal.core.model;
import org.eclipse.cdt.core.parser.Enum;
public interface IDebugLogConstants {
public class DebugLogConstant extends Enum {
protected DebugLogConstant( int value )
{
super( value );
}
}
public static final DebugLogConstant PARSER = new DebugLogConstant( 1 );
public static final DebugLogConstant MODEL = new DebugLogConstant ( 2 );
public static final DebugLogConstant SCANNER = new DebugLogConstant( 3 );
}

View file

@ -635,7 +635,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} }
} catch (Exception e) { } catch (Exception e) {
// use the debug log for this exception. // use the debug log for this exception.
Util.debugLog( "Exception in CModelBuilder", IDebugLogConstants.MODEL); //$NON-NLS-1$ Util.debugLog( "Exception in CModelBuilder", DebugLogConstants.MODEL); //$NON-NLS-1$
} }
} }
@ -644,7 +644,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
mb.parse(quickParseMode); mb.parse(quickParseMode);
} catch (Exception e) { } catch (Exception e) {
// use the debug log for this exception. // use the debug log for this exception.
Util.debugLog( "Exception in contributed model builder", IDebugLogConstants.MODEL); //$NON-NLS-1$ Util.debugLog( "Exception in contributed model builder", DebugLogConstants.MODEL); //$NON-NLS-1$
} }
} }

View file

@ -25,7 +25,6 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICLogConstants; import org.eclipse.cdt.core.ICLogConstants;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.cdt.core.model.ICModelStatusConstants;
import org.eclipse.cdt.internal.core.model.IDebugLogConstants.DebugLogConstant;
import org.eclipse.cdt.internal.core.util.CharArrayBuffer; import org.eclipse.cdt.internal.core.util.CharArrayBuffer;
import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo; import org.eclipse.core.filesystem.IFileInfo;
@ -208,11 +207,11 @@ public class Util implements ICLogConstants {
Util.log(status, logType); Util.log(status, logType);
} }
public static void debugLog(String message, DebugLogConstant client) { public static void debugLog(String message, DebugLogConstants client) {
Util.debugLog(message, client, true); Util.debugLog(message, client, true);
} }
public static void debugLog(String message, DebugLogConstant client, public static void debugLog(String message, DebugLogConstants client,
boolean addTimeStamp) { boolean addTimeStamp) {
if (CCorePlugin.getDefault() == null) if (CCorePlugin.getDefault() == null)
return; return;
@ -238,12 +237,12 @@ public class Util implements ICLogConstants {
* @param client * @param client
* @return * @return
*/ */
public static boolean isActive(DebugLogConstant client) { public static boolean isActive(DebugLogConstants client) {
if (client.equals(IDebugLogConstants.PARSER)) { if (client.equals(DebugLogConstants.PARSER)) {
return VERBOSE_PARSER; return VERBOSE_PARSER;
} else if (client.equals(IDebugLogConstants.SCANNER)) } else if (client.equals(DebugLogConstants.SCANNER))
return VERBOSE_SCANNER; return VERBOSE_SCANNER;
else if (client.equals(IDebugLogConstants.MODEL)) { else if (client.equals(DebugLogConstants.MODEL)) {
return VERBOSE_MODEL; return VERBOSE_MODEL;
} }
return false; return false;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,33 +7,26 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Mike Kucera (IBM) - convert to Java 5 enum
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
public class KeywordSetKey extends Enum public enum KeywordSetKey {
{ EMPTY,
public static final KeywordSetKey EMPTY = new KeywordSetKey( 0 ); DECL_SPECIFIER_SEQUENCE,
public static final KeywordSetKey DECL_SPECIFIER_SEQUENCE = new KeywordSetKey( 1 ); DECLARATION,
public static final KeywordSetKey DECLARATION = new KeywordSetKey( 2 ); STATEMENT,
public static final KeywordSetKey STATEMENT = new KeywordSetKey(3); BASE_SPECIFIER,
public static final KeywordSetKey BASE_SPECIFIER = new KeywordSetKey(4); POST_USING,
public static final KeywordSetKey POST_USING = new KeywordSetKey( 5 ); FUNCTION_MODIFIER,
public static final KeywordSetKey FUNCTION_MODIFIER = new KeywordSetKey( 6 ); NAMESPACE_ONLY,
public static final KeywordSetKey NAMESPACE_ONLY = new KeywordSetKey(6); MACRO,
public static final KeywordSetKey MACRO = new KeywordSetKey( 7 ); PP_DIRECTIVE,
public static final KeywordSetKey PP_DIRECTIVE = new KeywordSetKey( 8 ); EXPRESSION,
public static final KeywordSetKey EXPRESSION = new KeywordSetKey( 9 ); MEMBER,
public static final KeywordSetKey MEMBER = new KeywordSetKey(10); ALL,
public static final KeywordSetKey ALL = new KeywordSetKey( 11 ); KEYWORDS,
public static final KeywordSetKey KEYWORDS = new KeywordSetKey( 12 ); TYPES,
public static final KeywordSetKey TYPES = new KeywordSetKey( 13 );
/**
* @param enumValue
*/
protected KeywordSetKey(int enumValue) {
super(enumValue);
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2007 IBM Corporation and others. * Copyright (c) 2002, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Mike Kucera (IBM)- convert to Java 5 enum
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
@ -19,27 +20,20 @@ public class ParseError extends Error {
private final ParseErrorKind errorKind; private final ParseErrorKind errorKind;
public static class ParseErrorKind extends Enum public enum ParseErrorKind
{ {
// the method called is not implemented in this particular implementation // the method called is not implemented in this particular implementation
public static final ParseErrorKind METHOD_NOT_IMPLEMENTED = new ParseErrorKind( 0 ); METHOD_NOT_IMPLEMENTED,
// offset specified is within a section of code #if'd out by the preprocessor // offset specified is within a section of code #if'd out by the preprocessor
// semantic context cannot be provided in this case // semantic context cannot be provided in this case
public static final ParseErrorKind OFFSETDUPLE_UNREACHABLE = new ParseErrorKind( 1 ); OFFSETDUPLE_UNREACHABLE,
// offset range specified is not a valid identifier or qualified name // offset range specified is not a valid identifier or qualified name
// semantic context cannot be provided in this case // semantic context cannot be provided in this case
public static final ParseErrorKind OFFSET_RANGE_NOT_NAME = new ParseErrorKind( 2 ); OFFSET_RANGE_NOT_NAME,
public static final ParseErrorKind TIMEOUT_OR_CANCELLED = new ParseErrorKind( 3 ); TIMEOUT_OR_CANCELLED,
/**
* @param enumValue
*/
protected ParseErrorKind(int enumValue) {
super(enumValue);
}
} }
public ParseErrorKind getErrorKind() public ParseErrorKind getErrorKind()

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2003, 2005 IBM Corporation and others. * Copyright (c) 2003, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,34 +7,26 @@
* *
* Contributors: * Contributors:
* IBM Corp. - Rational Software - initial implementation * IBM Corp. - Rational Software - initial implementation
* Mike Kucera (IBM) - convert to Java 5 enum
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
/** /**
* @author aniefer * Enumeration of base languages supported by CDT.
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/ */
public class ParserLanguage extends Enum { public enum ParserLanguage {
public final static ParserLanguage C = new ParserLanguage( 1 );
public final static ParserLanguage CPP = new ParserLanguage( 2 );
private ParserLanguage( int value ) C {
{ @Override public boolean isCPP() { return false; }
super( value ); @Override public String toString() { return "C"; } //$NON-NLS-1$
} },
/** CPP {
* @return @Override public boolean isCPP() { return true; }
*/ @Override public String toString() { return "C++"; } //$NON-NLS-1$
public boolean isCPP() { };
return ( this == CPP );
} public abstract boolean isCPP();
public String toString() {
if( isCPP() ) return "C++"; //$NON-NLS-1$
return "C"; //$NON-NLS-1$
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2006 IBM Corporation and others. * Copyright (c) 2002, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Mike Kucera (IBM) - convert to Java 5 enum
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
@ -14,28 +15,23 @@ package org.eclipse.cdt.core.parser;
* @author jcamelon * @author jcamelon
* *
*/ */
public class ParserMode extends Enum { public enum ParserMode {
// do not follow inclusions, do not parse function/method bodies // do not follow inclusions, do not parse function/method bodies
public static final ParserMode QUICK_PARSE = new ParserMode( 1 ); QUICK_PARSE,
//follow inclusions, do not parse function/method bodies //follow inclusions, do not parse function/method bodies
public static final ParserMode STRUCTURAL_PARSE = new ParserMode( 2 ); STRUCTURAL_PARSE,
// follow inclusions, parse function/method bodies // follow inclusions, parse function/method bodies
public static final ParserMode COMPLETE_PARSE = new ParserMode( 3 ); COMPLETE_PARSE,
// follow inclusions, parse function/method bodies, stop at particular offset // follow inclusions, parse function/method bodies, stop at particular offset
// provide optimized lookup capability for querying symbols // provide optimized lookup capability for querying symbols
public static final ParserMode COMPLETION_PARSE = new ParserMode( 4 ); COMPLETION_PARSE,
// follow inclusions, parse function/method bodies, stop at particular offset // follow inclusions, parse function/method bodies, stop at particular offset
// provide specific semantic information about an offset range or selection // provide specific semantic information about an offset range or selection
public static final ParserMode SELECTION_PARSE = new ParserMode( 5 ); SELECTION_PARSE,
protected ParserMode( int value )
{
super( value );
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2006 IBM Corporation and others. * Copyright (c) 2002, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,36 +7,18 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Mike Kucera (IBM) - convert to Java 5 enum
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.ast; package org.eclipse.cdt.core.parser.ast;
import org.eclipse.cdt.core.parser.Enum;
/** /**
* @author jcamelon * Use compareTo() to order access restriction.
*
*/ */
public class ASTAccessVisibility extends Enum { public enum ASTAccessVisibility {
public static final ASTAccessVisibility PUBLIC = new ASTAccessVisibility( 1 );
public static final ASTAccessVisibility PROTECTED = new ASTAccessVisibility( 2 );
public static final ASTAccessVisibility PRIVATE = new ASTAccessVisibility( 3 );
private ASTAccessVisibility( int constant)
{
super( constant );
}
public boolean isLessThan( ASTAccessVisibility other )
{
return getEnumValue() < other.getEnumValue();
}
public boolean isGreaterThan( ASTAccessVisibility other )
{
return getEnumValue() > other.getEnumValue();
}
PUBLIC,
PROTECTED,
PRIVATE,
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2006 IBM Corporation and others. * Copyright (c) 2002, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,26 +7,17 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Mike Kucera (IBM) - convert to Java 5 enum
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser; package org.eclipse.cdt.internal.core.parser;
import org.eclipse.cdt.core.parser.Enum;
/** /**
* @author jcamelon * @author jcamelon
* *
*/ */
public class SimpleDeclarationStrategy extends Enum public enum SimpleDeclarationStrategy {
{ TRY_CONSTRUCTOR,
public static final SimpleDeclarationStrategy TRY_CONSTRUCTOR = new SimpleDeclarationStrategy( 1 ); TRY_FUNCTION,
public static final SimpleDeclarationStrategy TRY_FUNCTION = new SimpleDeclarationStrategy( 2 ); TRY_VARIABLE,
public static final SimpleDeclarationStrategy TRY_VARIABLE = new SimpleDeclarationStrategy( 3 );
/**
* @param enumValue
*/
public SimpleDeclarationStrategy(int enumValue)
{
super(enumValue);
}
} }

View file

@ -16,7 +16,7 @@ import java.io.InputStream;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.model.IDebugLogConstants; import org.eclipse.cdt.internal.core.model.DebugLogConstants;
import org.eclipse.cdt.internal.core.parser.InternalParserUtil; import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
import org.eclipse.cdt.internal.core.parser.ParserLogService; import org.eclipse.cdt.internal.core.parser.ParserLogService;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
@ -40,8 +40,8 @@ public class ParserUtil
return parserLogService; return parserLogService;
} }
private static IParserLogService parserLogService = new ParserLogService(IDebugLogConstants.PARSER ); private static IParserLogService parserLogService = new ParserLogService(DebugLogConstants.PARSER );
private static IParserLogService scannerLogService = new ParserLogService(IDebugLogConstants.SCANNER ); private static IParserLogService scannerLogService = new ParserLogService(DebugLogConstants.SCANNER );
/** /**
* @return * @return

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2007 IBM Corporation and others. * Copyright (c) 2002, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,30 +8,28 @@
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Mike Kucera (IBM)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser; package org.eclipse.cdt.internal.core.parser;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICLogConstants; import org.eclipse.cdt.core.ICLogConstants;
import org.eclipse.cdt.core.parser.AbstractParserLogService; import org.eclipse.cdt.core.parser.AbstractParserLogService;
import org.eclipse.cdt.internal.core.model.DebugLogConstants;
import org.eclipse.cdt.internal.core.model.Util; import org.eclipse.cdt.internal.core.model.Util;
import org.eclipse.cdt.internal.core.model.IDebugLogConstants.DebugLogConstant;
/** /**
* @author jcamelon * @author jcamelon
* *
*/ */
public class ParserLogService extends AbstractParserLogService public class ParserLogService extends AbstractParserLogService {
{
final DebugLogConstant topic; private final DebugLogConstants topic;
final boolean fIsTracing; private final boolean fIsTracing;
final boolean fIsTracingExceptions; private final boolean fIsTracingExceptions;
/**
* @param constant public ParserLogService(DebugLogConstants constant) {
*/
public ParserLogService(DebugLogConstant constant) {
topic = constant; topic = constant;
if (CCorePlugin.getDefault() == null) { if (CCorePlugin.getDefault() == null) {
fIsTracing= fIsTracingExceptions= false; fIsTracing= fIsTracingExceptions= false;
@ -42,26 +40,24 @@ public class ParserLogService extends AbstractParserLogService
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IParserLogService#traceLog(java.lang.String) @Override
*/ public void traceLog(String message) {
public void traceLog(String message)
{
Util.debugLog( message, topic ); Util.debugLog( message, topic );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IParserLogService#errorLog(java.lang.String) @Override
*/ public void errorLog(String message) {
public void errorLog(String message)
{
Util.log( message, ICLogConstants.CDT ); Util.log( message, ICLogConstants.CDT );
} }
public boolean isTracing(){ @Override
public boolean isTracing() {
return fIsTracing; return fIsTracing;
} }
@Override
public boolean isTracingExceptions() { public boolean isTracingExceptions() {
return fIsTracingExceptions; return fIsTracingExceptions;
} }